Skip to content

Commit 9a5f216

Browse files
committed
[Import as member] Turn on CoreGraphics.
Introduces CoreGraphics.apinotes, in which we enable the import-as-member inference system. Additionally, include some explicit SwiftNames, for when inference doesn't produce the right result, and to aid compatibility with the overlays. Refactors many of the trivial overlays out, shrinking the CoreGraphics.swift overlay by over half. Updates in-tree test cases. The names we currently have will be highly in flux for a while, and are likely to change frequently over the near term. There are a few remaining known bugs that are worked around by apinotes entries.
1 parent 8a4e795 commit 9a5f216

File tree

8 files changed

+88
-137
lines changed

8 files changed

+88
-137
lines changed

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,11 @@ endif()
683683
#
684684
# Set up global CMake variables for API notes.
685685
#
686-
686+
# API notes version 1.0.0
687+
#
688+
# Change the above comment to 'touch' this file and keep incremental builds
689+
# working when adding a new apinotes file.
690+
#
687691
set(SWIFT_API_NOTES_PATH "${SWIFT_SOURCE_DIR}/apinotes")
688692
if(NOT EXISTS "${SWIFT_API_NOTES_PATH}/Foundation.apinotes")
689693
message(FATAL_ERROR "API notes are not available in ${SWIFT_API_NOTES_PATH}")

apinotes/CoreGraphics.apinotes

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
Name: CoreGraphics
3+
SwiftInferImportAsMember: true
4+
# The below are inline functions that are irrelevant due to memberwise inits
5+
Functions:
6+
- Name: CGPointMake
7+
Availability: nonswift
8+
- Name: CGSizeMake
9+
Availability: nonswift
10+
- Name: CGVectorMake
11+
Availability: nonswift
12+
- Name: CGRectMake
13+
Availability: nonswift
14+
- Name: CGAffineTransformMake
15+
Availability: nonswift
16+
# The below are fixups that inference didn't quite do what we wanted, and are
17+
# pulled over from what used to be in the overlays
18+
- Name: CGRectIsNull
19+
SwiftName: "getter:CGRect.isNull(self:)"
20+
- Name: CGRectIsEmpty
21+
SwiftName: "getter:CGRect.isEmpty(self:)"
22+
- Name: CGRectIsInfinite
23+
SwiftName: "getter:CGRect.isInfinite(self:)"
24+
- Name: CGRectStandardize
25+
SwiftName: "getter:CGRect.standardized(self:)"
26+
- Name: CGRectIntegral
27+
SwiftName: "getter:CGRect.integral(self:)"
28+
- Name: CGRectInset
29+
SwiftName: "CGRect.insetBy(self:dx:dy:)"
30+
- Name: CGRectOffset
31+
SwiftName: "CGRect.offsetBy(self:dx:dy:)"
32+
- Name: CGRectUnion
33+
SwiftName: "CGRect.union(self:_:)"
34+
- Name: CGRectIntersection
35+
SwiftName: "CGRect.intersect(self:_:)"
36+
- Name: CGRectContainsRect
37+
SwiftName: "CGRect.contains(self:_:)"
38+
- Name: CGRectContainsPoint
39+
SwiftName: "CGRect.contains(self:_:)"
40+
- Name: CGRectIntersectsRect
41+
SwiftName: "CGRect.intersects(self:_:)"
42+
# The below are left alone, due to an unknown bug
43+
# FIXME: fix me
44+
- Name: CGColorSpaceCreateDeviceRGB
45+
SwiftName: "CGColorSpaceCreateDeviceRGB()"
46+
47+
# The below are globals that are defined as opaque C constants for no good
48+
# reason.
49+
Globals:
50+
- Name: CGPointZero
51+
Availability: nonswift
52+
- Name: CGSizeZero
53+
Availability: nonswift
54+
- Name: CGVectorZero
55+
Availability: nonswift
56+
- Name: CGRectZero
57+
Availability: nonswift
58+
- Name: CGAffineTransformIdentity
59+
Availability: nonswift
60+
# The below are left alone, due to an unknown bug
61+
# FIXME: fix me
62+
- Name: kCGColorBlack
63+
SwiftName: "kCGColorBlack"
64+
- Name: kCGColorWhite
65+
SwiftName: "kCGColorWhite"

lib/ClangImporter/SwiftLookupTable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ const uint16_t SWIFT_LOOKUP_TABLE_VERSION_MAJOR = 1;
146146
/// Lookup table minor version number.
147147
///
148148
/// When the format changes IN ANY WAY, this number should be incremented.
149-
const uint16_t SWIFT_LOOKUP_TABLE_VERSION_MINOR = 11; // globals-as-members
149+
const uint16_t SWIFT_LOOKUP_TABLE_VERSION_MINOR = 12; // CG import-as-member
150150

151151
/// A lookup table that maps Swift names to the set of Clang
152152
/// declarations with that particular name.

stdlib/public/SDK/CoreGraphics/CoreGraphics.swift

Lines changed: 8 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,6 @@ public extension CGRect {
130130
@_transparent // @fragile
131131
get { return CGRect(x: 0, y: 0, width: 0, height: 0) }
132132
}
133-
static var null: CGRect {
134-
@_transparent // @fragile
135-
get { return CGRectNull }
136-
}
137-
static var infinite: CGRect {
138-
@_transparent // @fragile
139-
get { return CGRectInfinite }
140-
}
141133

142134
@_transparent // @fragile
143135
init(x: CGFloat, y: CGFloat, width: CGFloat, height: CGFloat) {
@@ -157,61 +149,6 @@ public extension CGRect {
157149
size: CGSize(width: width, height: height))
158150
}
159151

160-
var width: CGFloat {
161-
@_transparent // @fragile
162-
get { return CGRectGetWidth(self) }
163-
}
164-
var height: CGFloat {
165-
@_transparent // @fragile
166-
get { return CGRectGetHeight(self) }
167-
}
168-
169-
var minX: CGFloat {
170-
@_transparent // @fragile
171-
get { return CGRectGetMinX(self) }
172-
}
173-
var midX: CGFloat {
174-
@_transparent // @fragile
175-
get { return CGRectGetMidX(self) }
176-
}
177-
var maxX: CGFloat {
178-
@_transparent // @fragile
179-
get { return CGRectGetMaxX(self) }
180-
}
181-
var minY: CGFloat {
182-
@_transparent // @fragile
183-
get { return CGRectGetMinY(self) }
184-
}
185-
var midY: CGFloat {
186-
@_transparent // @fragile
187-
get { return CGRectGetMidY(self) }
188-
}
189-
var maxY: CGFloat {
190-
@_transparent // @fragile
191-
get { return CGRectGetMaxY(self) }
192-
}
193-
var isNull: Bool {
194-
@_transparent // @fragile
195-
get { return CGRectIsNull(self) }
196-
}
197-
var isEmpty: Bool {
198-
@_transparent // @fragile
199-
get { return CGRectIsEmpty(self) }
200-
}
201-
var isInfinite: Bool {
202-
@_transparent // @fragile
203-
get { return CGRectIsInfinite(self) }
204-
}
205-
var standardized: CGRect {
206-
@_transparent // @fragile
207-
get { return CGRectStandardize(self) }
208-
}
209-
210-
var integral: CGRect {
211-
@_transparent // @fragile
212-
get { return CGRectIntegral(self) }
213-
}
214-
215152
@_transparent // @fragile
216153
mutating func standardizeInPlace() {
217154
self = standardized
@@ -222,45 +159,21 @@ public extension CGRect {
222159
self = integral
223160
}
224161

225-
@_transparent // @fragile
226-
@warn_unused_result(mutable_variant: "insetInPlace")
227-
func insetBy(dx dx: CGFloat, dy: CGFloat) -> CGRect {
228-
return CGRectInset(self, dx, dy)
229-
}
230-
231162
@_transparent // @fragile
232163
mutating func insetInPlace(dx dx: CGFloat, dy: CGFloat) {
233164
self = insetBy(dx: dx, dy: dy)
234165
}
235166

236-
@_transparent // @fragile
237-
@warn_unused_result(mutable_variant: "offsetInPlace")
238-
func offsetBy(dx dx: CGFloat, dy: CGFloat) -> CGRect {
239-
return CGRectOffset(self, dx, dy)
240-
}
241-
242167
@_transparent // @fragile
243168
mutating func offsetInPlace(dx dx: CGFloat, dy: CGFloat) {
244169
self = offsetBy(dx: dx, dy: dy)
245170
}
246171

247-
@_transparent // @fragile
248-
@warn_unused_result(mutable_variant: "unionInPlace")
249-
func union(rect: CGRect) -> CGRect {
250-
return CGRectUnion(self, rect)
251-
}
252-
253172
@_transparent // @fragile
254173
mutating func unionInPlace(rect: CGRect) {
255174
self = union(rect)
256175
}
257176

258-
@_transparent // @fragile
259-
@warn_unused_result(mutable_variant: "intersectInPlace")
260-
func intersect(rect: CGRect) -> CGRect {
261-
return CGRectIntersection(self, rect)
262-
}
263-
264177
@_transparent // @fragile
265178
mutating func intersectInPlace(rect: CGRect) {
266179
self = intersect(rect)
@@ -273,27 +186,10 @@ public extension CGRect {
273186
{
274187
var slice = CGRect.zero
275188
var remainder = CGRect.zero
276-
CGRectDivide(self, &slice, &remainder, atDistance, fromEdge)
189+
divide(slice: &slice, remainder: &remainder, amount: atDistance,
190+
edge: fromEdge)
277191
return (slice, remainder)
278192
}
279-
280-
@_transparent // @fragile
281-
@warn_unused_result
282-
func contains(rect: CGRect) -> Bool {
283-
return CGRectContainsRect(self, rect)
284-
}
285-
286-
@_transparent // @fragile
287-
@warn_unused_result
288-
func contains(point: CGPoint) -> Bool {
289-
return CGRectContainsPoint(self, point)
290-
}
291-
292-
@_transparent // @fragile
293-
@warn_unused_result
294-
func intersects(rect: CGRect) -> Bool {
295-
return CGRectIntersectsRect(self, rect)
296-
}
297193
}
298194

299195
extension CGRect : CustomReflectable, CustomPlaygroundQuickLookable {
@@ -321,28 +217,13 @@ extension CGRect : Equatable {}
321217
@_transparent // @fragile
322218
@warn_unused_result
323219
public func == (lhs: CGRect, rhs: CGRect) -> Bool {
324-
return CGRectEqualToRect(lhs, rhs)
325-
}
326-
327-
// Overlay the C names of these constants with transparent definitions. The
328-
// C constants are opaque extern globals for no good reason.
329-
330-
public var CGPointZero: CGPoint {
331-
@_transparent // @fragile
332-
get { return CGPoint.zero }
333-
}
334-
335-
public var CGRectZero: CGRect {
336-
@_transparent // @fragile
337-
get { return CGRect.zero }
220+
return lhs.equalToRect(rect2: rhs)
338221
}
339222

340-
public var CGSizeZero: CGSize {
341-
@_transparent // @fragile
342-
get { return CGSize.zero }
223+
extension CGAffineTransform {
224+
public static var identity: CGAffineTransform {
225+
@_transparent // @fragile
226+
get { return CGAffineTransform(a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0) }
227+
}
343228
}
344229

345-
public var CGAffineTransformIdentity: CGAffineTransform {
346-
@_transparent // @fragile
347-
get { return CGAffineTransform(a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0) }
348-
}

test/Interpreter/SDK/CALayer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ func hangCanary(o: AnyObject) {
2222

2323
class FooLayer: CALayer {
2424
var black: CGColor
25-
var white: CGColor = CGColorGetConstantColor(kCGColorWhite)!
25+
var white: CGColor = CGColor.getConstantColor(colorName: kCGColorWhite)!
2626

2727
override init() {
28-
black = CGColorGetConstantColor(kCGColorBlack)!
28+
black = CGColor.getConstantColor(colorName: kCGColorBlack)!
2929
super.init()
3030
hangCanary(self)
3131
}

test/Interpreter/SDK/c_pointers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ typealias XXColor = UIColor
2323
//
2424

2525
let rgb = CGColorSpaceCreateDeviceRGB()
26-
let cgRed = CGColorCreate(rgb, [1.0, 0.0, 0.0, 1.0])!
26+
let cgRed = CGColor(space: rgb, components: [1.0, 0.0, 0.0, 1.0])!
2727

2828
let nsRed = XXColor(cgColor: cgRed)
2929

test/Interpreter/SDK/cf_extensions.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ extension CGColorSpace {
2222
extension CGColor {
2323
class func create(colorSpace colorSpace: CGColorSpace, components: [CGFloat])
2424
-> CGColor {
25-
return CGColorCreate(colorSpace, components)!
25+
return CGColor(space: colorSpace, components: components)!
2626
}
2727

28-
var r: CGFloat { return CGColorGetComponents(self)[0] }
29-
var g: CGFloat { return CGColorGetComponents(self)[1] }
30-
var b: CGFloat { return CGColorGetComponents(self)[2] }
28+
var r: CGFloat { return components[0] }
29+
var g: CGFloat { return components[1] }
30+
var b: CGFloat { return components[2] }
3131
}
3232

3333
let pink = CGColor.create(colorSpace: .deviceRGB(),

test/Interpreter/SDK/cf_type_bridging.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import AppKit
1010
import UIKit
1111
#endif
1212

13-
let foo: [CGColor] = [CGColorCreate(CGColorSpaceCreateDeviceRGB(), [1.0, 0.0, 0.0, 1.0])!]
13+
let foo: [CGColor] = [CGColor(space: CGColorSpaceCreateDeviceRGB(),
14+
components: [1.0, 0.0, 0.0, 1.0])!]
1415

1516
let bar = foo as NSArray
1617

0 commit comments

Comments
 (0)