Skip to content

Commit 02fcd21

Browse files
committed
Address review comments
1 parent b3d31c7 commit 02fcd21

File tree

17 files changed

+234
-152
lines changed

17 files changed

+234
-152
lines changed

SwiftCompilerSources/Sources/AST/Declarations.swift

Lines changed: 156 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public class Decl: CustomStringConvertible, Hashable {
2929
// True if this declaration is imported from C/C++/ObjC.
3030
public var hasClangNode: Bool { bridged.hasClangNode() }
3131

32+
public var declContext: DeclContext { bridgedDecl.declContext }
33+
34+
var bridgedDecl: BridgedDecl { BridgedDecl(raw: bridged.obj) }
35+
3236
public static func ==(lhs: Decl, rhs: Decl) -> Bool { lhs === rhs }
3337

3438
public func hash(into hasher: inout Hasher) {
@@ -39,7 +43,7 @@ public class Decl: CustomStringConvertible, Hashable {
3943
public class ValueDecl: Decl {
4044
final public var nameLoc: SourceLoc? { SourceLoc(bridged: bridged.Value_getNameLoc()) }
4145
final public var userFacingName: StringRef { StringRef(bridged: bridged.Value_getUserFacingName()) }
42-
final public var baseIdentifier: swift.Identifier { bridged.Value_getBaseIdentifier() }
46+
final public var baseIdentifier: Identifier { bridged.Value_getBaseIdentifier() }
4347
final public var isObjC: Bool { bridged.Value_isObjC() }
4448
}
4549

@@ -58,8 +62,8 @@ public class NominalTypeDecl: GenericTypeDecl {
5862
bridged.NominalType_getValueTypeDestructor().getAs(DestructorDecl.self)
5963
}
6064

61-
public var declaredInterfaceType : AST.`Type` {
62-
AST.`Type`(bridged: bridged.NominalType_getDeclaredInterfaceType())
65+
public var declaredInterfaceType: Type {
66+
Type(bridged: bridged.NominalType_getDeclaredInterfaceType())
6367
}
6468
}
6569

@@ -123,8 +127,8 @@ final public class MacroDecl: ValueDecl {}
123127

124128
final public class EnumElementDecl: ValueDecl {
125129
public var hasAssociatedValues: Bool { bridged.EnumElementDecl_hasAssociatedValues() }
126-
public var parameterList: BridgedParameterList { bridged.EnumElementDecl_getParameterList() }
127-
public var nameStr: StringRef { StringRef(bridged: bridged.EnumElementDecl_getNameStr()) }
130+
public var parameterList: ParameterList { bridged.EnumElementDecl_getParameterList() }
131+
public var name: StringRef { StringRef(bridged: bridged.EnumElementDecl_getNameStr()) }
128132
}
129133

130134
final public class ExtensionDecl: Decl {}
@@ -172,3 +176,150 @@ extension Optional where Wrapped == Decl {
172176
OptionalBridgedDeclObj(self?.bridged.obj)
173177
}
174178
}
179+
180+
public typealias Identifier = swift.Identifier
181+
182+
public typealias GenericTypeParamKind = swift.GenericTypeParamKind
183+
184+
public typealias ASTContext = BridgedASTContext
185+
186+
public typealias DeclContext = BridgedDeclContext
187+
188+
public typealias Expr = BridgedExpr
189+
190+
public typealias ParameterList = BridgedParameterList
191+
192+
public typealias SourceFile = BridgedSourceFile
193+
194+
public typealias FileUnit = BridgedFileUnit
195+
196+
public typealias GenericParamList = BridgedGenericParamList
197+
198+
public typealias TrailingWhereClause = BridgedTrailingWhereClause
199+
200+
public typealias BridgedParamDecl = ASTBridging.BridgedParamDecl
201+
202+
public typealias BridgedGenericTypeParamDecl = ASTBridging.BridgedGenericTypeParamDecl
203+
204+
public typealias BridgedEnumDecl = ASTBridging.BridgedEnumDecl
205+
206+
public typealias BridgedEnumElementDecl = ASTBridging.BridgedEnumElementDecl
207+
208+
extension ParameterList {
209+
public subscript(_ index: Int) -> BridgedParamDecl {
210+
return get(index)
211+
}
212+
213+
public static func createParsed(
214+
_ astContext: ASTContext, leftParenLoc: SourceLoc?, parameters: [BridgedParamDecl],
215+
rightParenLoc: SourceLoc?
216+
) -> ParameterList {
217+
parameters.withBridgedArrayRef {
218+
ParameterList.createParsed(
219+
astContext, leftParenLoc: leftParenLoc.bridgedLocation, parameters: $0,
220+
rightParenLoc: rightParenLoc.bridgedLocation)
221+
}
222+
}
223+
}
224+
225+
extension GenericParamList {
226+
public static func createParsed(
227+
_ astContext: ASTContext, leftAngleLoc: SourceLoc?, parameters: [BridgedGenericTypeParamDecl],
228+
genericWhereClause: TrailingWhereClause?,
229+
rightAngleLoc: SourceLoc?
230+
) -> GenericParamList {
231+
return parameters.withBridgedArrayRef {
232+
GenericParamList.createParsed(
233+
astContext, leftAngleLoc: leftAngleLoc.bridgedLocation, parameters: $0,
234+
genericWhereClause: genericWhereClause.bridged, rightAngleLoc: rightAngleLoc.bridgedLocation
235+
)
236+
}
237+
}
238+
}
239+
240+
extension BridgedDecl {
241+
public var declObj: BridgedDeclObj {
242+
BridgedDeclObj(SwiftObject(raw.bindMemory(to: BridgedSwiftObject.self, capacity: 1)))
243+
}
244+
public var decl: Decl { declObj.decl }
245+
}
246+
247+
extension BridgedEnumDecl {
248+
public static func createParsed(
249+
_ astContext: ASTContext, declContext: DeclContext, enumKeywordLoc: SourceLoc?, name: String,
250+
nameLoc: SourceLoc?, genericParamList: GenericParamList?, inheritedTypes: [Type],
251+
genericWhereClause: TrailingWhereClause?, braceRange: SourceRange
252+
) -> BridgedEnumDecl {
253+
return name.withCString { strPtr in
254+
inheritedTypes.withBridgedArrayRef { types in
255+
BridgedEnumDecl.createParsed(
256+
astContext, declContext: declContext,
257+
enumKeywordLoc: enumKeywordLoc.bridgedLocation,
258+
name: astContext.getIdentifier(BridgedStringRef(data: strPtr, count: name.count)),
259+
nameLoc: nameLoc.bridgedLocation,
260+
genericParamList: genericParamList.bridged,
261+
inheritedTypes: types,
262+
genericWhereClause: genericWhereClause.bridged,
263+
braceRange: braceRange.bridged)
264+
}
265+
}
266+
}
267+
}
268+
269+
extension BridgedEnumElementDecl {
270+
public static func createParsed(
271+
_ astContext: ASTContext, declContext: DeclContext,
272+
name: Identifier, nameLoc: SourceLoc?,
273+
parameterList: ParameterList?,
274+
equalsLoc: SourceLoc?, rawValue: Expr?
275+
) -> BridgedEnumElementDecl {
276+
BridgedEnumElementDecl.createParsed(
277+
astContext, declContext: declContext,
278+
name: name, nameLoc: nameLoc.bridgedLocation,
279+
parameterList: parameterList.bridged,
280+
equalsLoc: equalsLoc.bridgedLocation, rawValue: rawValue.bridged)
281+
}
282+
}
283+
284+
extension SourceFile {
285+
public init?(bridged: BridgedNullableSourceFile) {
286+
guard let raw = bridged.raw else {
287+
return nil
288+
}
289+
self.init(raw: raw)
290+
}
291+
}
292+
293+
extension FileUnit {
294+
public var asSourceFile: SourceFile? { SourceFile(bridged: self.castToSourceFile()) }
295+
}
296+
297+
extension BridgedParamDecl {
298+
public func setInterfaceType(type: Type) {
299+
self.setInterfaceType(type.bridged)
300+
}
301+
}
302+
303+
extension ParameterList? {
304+
public var bridged: BridgedNullableParameterList {
305+
BridgedNullableParameterList(raw: self?.raw)
306+
}
307+
}
308+
309+
extension GenericParamList? {
310+
public var bridged: BridgedNullableGenericParamList {
311+
BridgedNullableGenericParamList(raw: self?.raw)
312+
}
313+
}
314+
315+
extension Expr? {
316+
public var bridged: BridgedNullableExpr {
317+
BridgedNullableExpr(raw: self?.raw)
318+
}
319+
}
320+
321+
extension TrailingWhereClause? {
322+
public var bridged: BridgedNullableTrailingWhereClause {
323+
BridgedNullableTrailingWhereClause(raw: self?.raw)
324+
}
325+
}

SwiftCompilerSources/Sources/AST/GenericSignature.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ public struct GenericSignature: CustomStringConvertible, NoReflectionChildren {
3636

3737
public var isEmpty: Bool { bridged.impl == nil }
3838

39-
public var canonicalSignature: CanGenericSignature { CanGenericSignature(bridged: bridged.getCanonicalSignature()) }
39+
public var canonicalSignature: CanonicalGenericSignature {
40+
CanonicalGenericSignature(bridged: bridged.getCanonicalSignature())
41+
}
4042
}
4143

42-
public struct CanGenericSignature {
44+
public struct CanonicalGenericSignature {
4345
public let bridged: BridgedCanGenericSignature
4446

4547
public init(bridged: BridgedCanGenericSignature) {
@@ -48,5 +50,7 @@ public struct CanGenericSignature {
4850

4951
public var isEmpty: Bool { bridged.impl == nil }
5052

51-
public var genericSignature: GenericSignature { GenericSignature(bridged: bridged.getGenericSignature()) }
53+
public var genericSignature: GenericSignature {
54+
GenericSignature(bridged: bridged.getGenericSignature())
55+
}
5256
}

SwiftCompilerSources/Sources/AST/Type.swift

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,24 +71,26 @@ public struct Type: TypeProperties, CustomStringConvertible, NoReflectionChildre
7171
return Type(bridged: bridged.mapTypeOutOfContext())
7272
}
7373

74-
public func getReducedType(sig: GenericSignature) -> CanonicalType {
75-
CanonicalType(bridged: bridged.getReducedType(sig.bridged))
74+
/// Returns a stronger canonicalization which folds away equivalent
75+
/// associated types, or type parameters that have been made concrete.
76+
public func getReducedType(of signature: GenericSignature) -> CanonicalType {
77+
CanonicalType(bridged: bridged.getReducedType(signature.bridged))
7678
}
7779

78-
public func GenericTypeParam_getName() -> swift.Identifier {
79-
return bridged.GenericTypeParam_getName()
80+
public var nameOfGenericTypeParameter: Identifier {
81+
bridged.GenericTypeParam_getName()
8082
}
8183

82-
public func GenericTypeParam_getDepth() -> UInt {
83-
return bridged.GenericTypeParam_getDepth()
84+
public var depthOfGenericTypeParameter: Int {
85+
bridged.GenericTypeParam_getDepth()
8486
}
8587

86-
public func GenericTypeParam_getIndex() -> UInt {
87-
return bridged.GenericTypeParam_getIndex()
88+
public var indexOfGenericTypeParameter: Int {
89+
bridged.GenericTypeParam_getIndex()
8890
}
8991

90-
public func GenericTypeParam_getParamKind() -> swift.GenericTypeParamKind {
91-
return bridged.GenericTypeParam_getParamKind()
92+
public var kindOfGenericTypeParameter: GenericTypeParameterKind {
93+
bridged.GenericTypeParam_getParamKind()
9294
}
9395
}
9496

@@ -110,10 +112,6 @@ public struct CanonicalType: TypeProperties, CustomStringConvertible, NoReflecti
110112
public func subst(with substitutionMap: SubstitutionMap) -> CanonicalType {
111113
return rawType.subst(with: substitutionMap).canonical
112114
}
113-
114-
public func SILFunctionType_getSubstGenericSignature() -> CanGenericSignature {
115-
CanGenericSignature(bridged: bridged.SILFunctionType_getSubstGenericSignature())
116-
}
117115
}
118116

119117
/// Implements the common members of `AST.Type`, `AST.CanonicalType` and `SIL.Type`.
@@ -270,6 +268,12 @@ extension TypeProperties {
270268
public func checkConformance(to protocol: ProtocolDecl) -> Conformance {
271269
return Conformance(bridged: rawType.bridged.checkConformance(`protocol`.bridged))
272270
}
271+
272+
/// The generic signature that the component types are specified in terms of, if any.
273+
public var substitutedGenericSignatureOfFunctionType: CanonicalGenericSignature {
274+
CanonicalGenericSignature(
275+
bridged: rawType.canonical.bridged.SILFunctionType_getSubstGenericSignature())
276+
}
273277
}
274278

275279
public struct TypeArray : RandomAccessCollection, CustomReflectable {
@@ -327,3 +331,5 @@ extension CanonicalType: Equatable {
327331
lhs.rawType == rhs.rawType
328332
}
329333
}
334+
335+
public typealias GenericTypeParameterKind = swift.GenericTypeParamKind

SwiftCompilerSources/Sources/Basic/SourceLoc.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ extension Optional<SourceLoc> {
3535
}
3636
}
3737

38+
public struct SourceRange {
39+
public let bridged: swift.SourceRange
40+
41+
public init(start: SourceLoc?) {
42+
self.bridged = swift.SourceRange(start: start.bridgedLocation)
43+
}
44+
}
45+
3846
public struct CharSourceRange {
3947
public let start: SourceLoc
4048
public let byteLength: UInt32

SwiftCompilerSources/Sources/SIL/Argument.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ public class Argument : Value, Hashable {
5050

5151
public var sourceLoc: SourceLoc? { findVarDecl()?.nameLoc }
5252

53-
public func replaceAllUsesWith(newArg: Argument) {
54-
bridged.replaceAllUsesWith(newArg.bridged)
55-
}
56-
5753
public static func ==(lhs: Argument, rhs: Argument) -> Bool {
5854
lhs === rhs
5955
}

SwiftCompilerSources/Sources/SIL/BasicBlock.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ final public class BasicBlock : CustomStringConvertible, HasShortDescription, Ha
6868
(decl as Decl?).bridged).argument as! FunctionArgument
6969
}
7070

71-
public func insertPhiArgument(atPosition: Int, type: Type, ownership: Ownership, _ context: some MutatingContext) -> Argument {
71+
public func insertPhiArgument(
72+
atPosition: Int, type: Type, ownership: Ownership, _ context: some MutatingContext
73+
) -> Argument {
7274
context.notifyInstructionsChanged()
7375
return bridged.insertPhiArgument(atPosition, type.bridged, ownership._bridged).argument
7476
}

SwiftCompilerSources/Sources/SIL/Builder.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -662,13 +662,6 @@ public struct Builder {
662662
return notifyNew(tuple.getAs(TupleInst.self))
663663
}
664664

665-
public func createTuple(elements: [Value]) -> TupleInst {
666-
let tuple = elements.withBridgedValues { valuesRef in
667-
return bridged.createTuple(valuesRef)
668-
}
669-
return notifyNew(tuple.getAs(TupleInst.self))
670-
}
671-
672665
public func createTupleExtract(tuple: Value, elementIndex: Int) -> TupleExtractInst {
673666
return notifyNew(bridged.createTupleExtract(tuple.bridged, elementIndex).getAs(TupleExtractInst.self))
674667
}

SwiftCompilerSources/Sources/SIL/Context.swift

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ extension Context {
4949
public func getBuiltinIntegerType(bitWidth: Int) -> Type { _bridged.getBuiltinIntegerType(bitWidth).type }
5050

5151
public func getTupleType(elements: [Type]) -> AST.`Type` {
52-
let bridgedElements = elements.map { $0.bridged }
53-
return bridgedElements.withBridgedArrayRef {
54-
AST.`Type`(bridged: _bridged.getTupleType($0))
55-
}
52+
return getTupleType(elements: elements.map{ $0.rawType })
5653
}
5754

5855
public func getTupleType(elements: [AST.`Type`]) -> AST.`Type` {
@@ -62,11 +59,10 @@ extension Context {
6259
}
6360
}
6461

65-
public func getTupleTypeWithLabels(elements: [AST.`Type`], labels: [swift.Identifier]) -> AST.`Type` {
66-
assert(elements.count == labels.count)
67-
return elements.withBridgedArrayRef{
68-
eltArr in labels.withBridgedArrayRef{labelsArr in
69-
AST.`Type`(bridged: _bridged.getTupleTypeWithLabels(eltArr, labelsArr))}}
62+
public func getTupleType(elements: [(label: Identifier, type: AST.`Type`)]) -> AST.`Type` {
63+
return elements.map{$0.type}.withBridgedArrayRef{
64+
types in elements.map{$0.label}.withBridgedArrayRef{labels in
65+
AST.`Type`(bridged: _bridged.getTupleTypeWithLabels(types, labels))}}
7066
}
7167

7268
public var swiftArrayDecl: NominalTypeDecl {

SwiftCompilerSources/Sources/SIL/Function.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ final public class Function : CustomStringConvertible, HasShortDescription, Hash
2626
return Location(bridged: bridged.getLocation())
2727
}
2828

29-
public var sourceFile: BridgedNullableSourceFile {
30-
return bridged.getSourceFile()
31-
}
29+
public var sourceFile: SourceFile? { SourceFile(bridged: bridged.getSourceFile()) }
3230

3331
final public var description: String {
3432
return String(taking: bridged.getDebugDescription())

SwiftCompilerSources/Sources/SIL/Instruction.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,6 @@ final public class PartialApplyInst : SingleValueInstruction, ApplySite {
13511351
public var hasUnknownResultIsolation: Bool { bridged.PartialApplyInst_hasUnknownResultIsolation() }
13521352
public var unappliedArgumentCount: Int { bridged.PartialApply_getCalleeArgIndexOfFirstAppliedArg() }
13531353
public var calleeConvention: ArgumentConvention { type.bridged.getCalleeConvention().convention }
1354-
public var substitutionMap: SubstitutionMap { SubstitutionMap(bridged: bridged.PartialApplyInst_getSubstitutionMap()) }
13551354
}
13561355

13571356
final public class ApplyInst : SingleValueInstruction, FullApplySite {
@@ -1930,7 +1929,6 @@ final public class SwitchValueInst : TermInst {
19301929
final public class SwitchEnumInst : TermInst {
19311930

19321931
public var enumOp: Value { operands[0].value }
1933-
public var numCases: Int { bridged.SwitchEnumInst_getNumCases() }
19341932

19351933
public struct CaseIndexArray : RandomAccessCollection {
19361934
fileprivate let switchEnum: SwitchEnumInst
@@ -1949,6 +1947,8 @@ final public class SwitchEnumInst : TermInst {
19491947
zip(caseIndices, successors)
19501948
}
19511949

1950+
public var numCases: Int { caseIndices.count }
1951+
19521952
// This does not handle the special case where the default covers exactly
19531953
// the "missing" case.
19541954
public func getUniqueSuccessor(forCaseIndex: Int) -> BasicBlock? {

0 commit comments

Comments
 (0)