Skip to content

Commit c12819f

Browse files
committed
Address review comments
1 parent c1f4bcf commit c12819f

File tree

8 files changed

+55
-74
lines changed

8 files changed

+55
-74
lines changed

SwiftCompilerSources/Sources/AST/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ add_swift_compiler_module(AST
1111
Basic
1212
SOURCES
1313
Declarations.swift
14+
DeclContext.swift
1415
Conformance.swift
1516
DiagnosticEngine.swift
1617
GenericSignature.swift
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import ASTBridging
2+
3+
public protocol DeclContext : AnyObject {
4+
var bridgedDeclContext: BridgedDeclContext { get }
5+
}
6+
7+
extension DeclContext {
8+
public var astContext: ASTContext { bridgedDeclContext.astContext }
9+
}
10+
11+
public class UnknownDeclContext : DeclContext {
12+
public var bridgedDeclContext: BridgedDeclContext
13+
public init(bridged: BridgedDeclContext) { bridgedDeclContext = bridged }
14+
}

SwiftCompilerSources/Sources/AST/Declarations.swift

Lines changed: 28 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -16,48 +16,35 @@ import ASTBridging
1616
/// The base class for all declarations in Swift.
1717
@_semantics("arc.immortal")
1818
public class Decl: CustomStringConvertible, Hashable {
19-
public var bridged: BridgedDeclObj { BridgedDeclObj(SwiftObject(self)) }
19+
final public var bridged: BridgedDeclObj { BridgedDeclObj(SwiftObject(self)) }
2020

21-
public var description: String { String(taking: bridged.getDebugDescription()) }
21+
final public var description: String { String(taking: bridged.getDebugDescription()) }
2222

2323
/// The module in which this declaration resides.
24-
public var parentModule: ModuleDecl { bridged.getModuleContext().getAs(ModuleDecl.self) }
24+
final public var parentModule: ModuleDecl { bridged.getModuleContext().getAs(ModuleDecl.self) }
2525

2626
/// The parent DeclContext if it is a Decl.
27-
public var parent: Decl? { bridged.getParent().decl }
27+
final public var parent: Decl? { bridged.getParent().decl }
2828

2929
// True if this declaration is imported from C/C++/ObjC.
30-
public var hasClangNode: Bool { bridged.hasClangNode() }
30+
final public var hasClangNode: Bool { bridged.hasClangNode() }
3131

32-
public var declContext: DeclContext {
32+
final public var declContext: DeclContext {
3333
if let decl = parent {
3434
return decl as! DeclContext
3535
}
36-
return DeclContextObj(bridged: bridged.getDeclContext())
36+
return UnknownDeclContext(bridged: bridged.getDeclContext())
3737
}
3838

39-
public var bridgedDecl: BridgedDecl { BridgedDecl(raw: bridged.obj) }
39+
final public var bridgedDecl: BridgedDecl { BridgedDecl(raw: bridged.obj) }
4040

4141
public static func ==(lhs: Decl, rhs: Decl) -> Bool { lhs === rhs }
4242

43-
public func hash(into hasher: inout Hasher) {
43+
final public func hash(into hasher: inout Hasher) {
4444
hasher.combine(ObjectIdentifier(self))
4545
}
4646

47-
public func setImplicit() { bridged.setImplicit() }
48-
}
49-
50-
public protocol DeclContext {
51-
var bridgedDeclContext: BridgedDeclContext { get }
52-
}
53-
54-
extension DeclContext {
55-
public var astContext: ASTContext { bridgedDeclContext.astContext }
56-
}
57-
58-
fileprivate class DeclContextObj : DeclContext {
59-
public var bridgedDeclContext: BridgedDeclContext
60-
public init(bridged: BridgedDeclContext) { bridgedDeclContext = bridged }
47+
final public func setImplicit() { bridged.setImplicit() }
6148
}
6249

6350
public protocol GenericContext: Decl, DeclContext {}
@@ -108,9 +95,9 @@ final public class EnumDecl: NominalTypeDecl {
10895
public var hasRawType: Bool { bridged.Enum_hasRawType() }
10996

11097
public static func create(
111-
_ astContext: ASTContext, declContext: DeclContext, enumKeywordLoc: SourceLoc?, name: String,
112-
nameLoc: SourceLoc?, genericParamList: GenericParamList?, inheritedTypes: [Type],
113-
genericWhereClause: TrailingWhereClause?, braceRange: SourceRange
98+
declContext: DeclContext, enumKeywordLoc: SourceLoc?, name: String,
99+
nameLoc: SourceLoc?, genericParamList: GenericParameterList?, inheritedTypes: [Type],
100+
genericWhereClause: TrailingWhereClause?, braceRange: SourceRange, _ astContext: ASTContext
114101
) -> EnumDecl {
115102
name.withCString { strPtr in
116103
inheritedTypes.withBridgedArrayRef { types in
@@ -208,10 +195,10 @@ final public class EnumElementDecl: ValueDecl {
208195
public var name: StringRef { StringRef(bridged: bridged.EnumElementDecl_getNameStr()) }
209196

210197
public static func create(
211-
_ astContext: ASTContext, declContext: DeclContext,
198+
declContext: DeclContext,
212199
name: Identifier, nameLoc: SourceLoc?,
213200
parameterList: ParameterList?,
214-
equalsLoc: SourceLoc?, rawValue: Expr?
201+
equalsLoc: SourceLoc?, rawValue: Expr?, _ astContext: ASTContext
215202
) -> EnumElementDecl {
216203
BridgedEnumElementDecl.createParsed(
217204
astContext, declContext: declContext.bridgedDeclContext,
@@ -282,48 +269,30 @@ public typealias SourceFile = BridgedSourceFile
282269

283270
public typealias FileUnit = BridgedFileUnit
284271

285-
public class GenericParamList {
272+
public class GenericParameterList {
286273
public var bridged: BridgedGenericParamList
287274
public init(bridged: BridgedGenericParamList) { self.bridged = bridged }
288275
}
289276

290277
public typealias TrailingWhereClause = BridgedTrailingWhereClause
291278

292279
public class ParameterList : RandomAccessCollection {
293-
public class Iterator : IteratorProtocol {
294-
public typealias Element = ParamDecl
295-
private var index : Int = 0
296-
private let parameterList : ParameterList
297-
init(parameterList : ParameterList) { self.parameterList = parameterList }
298-
public func next() -> Element? {
299-
if index < parameterList.bridged.size {
300-
return parameterList.bridged.get(index).asDecl.declObj.getAs(ParamDecl.self)
301-
}
302-
return nil
303-
}
304-
}
305-
public typealias Index = Int
306-
public var startIndex: Index { 0 }
307-
public var endIndex: Index { bridged.size }
308-
public func index(after i: Index) -> Index { i + 1 }
309-
310-
public func makeIterator() -> Iterator {
311-
Self.Iterator(parameterList: self)
312-
}
280+
public var startIndex: Int { 0 }
281+
public var endIndex: Int { bridged.size }
313282

314283
public var bridged: BridgedParameterList
315284

316285
public init(bridged: BridgedParameterList) {
317286
self.bridged = bridged
318287
}
319288

320-
public subscript(_ index: Index) -> ParamDecl {
289+
public subscript(_ index: Int) -> ParamDecl {
321290
return bridged.get(index).asDecl.declObj.getAs(ParamDecl.self)
322291
}
323292

324293
public static func create(
325-
_ astContext: ASTContext, leftParenLoc: SourceLoc?, parameters: [ParamDecl],
326-
rightParenLoc: SourceLoc?
294+
leftParenLoc: SourceLoc?, parameters: [ParamDecl],
295+
rightParenLoc: SourceLoc?, _ astContext: ASTContext
327296
) -> ParameterList {
328297
ParameterList(bridged: parameters.map{BridgedParamDecl(raw: $0.bridged.obj)}.withBridgedArrayRef {
329298
BridgedParameterList.createParsed(
@@ -333,15 +302,15 @@ public class ParameterList : RandomAccessCollection {
333302
}
334303
}
335304

336-
extension GenericParamList {
305+
extension GenericParameterList {
337306
public static func create(
338-
_ astContext: ASTContext, leftAngleLoc: SourceLoc?, parameters: [GenericTypeParamDecl],
307+
leftAngleLoc: SourceLoc?, parameters: [GenericTypeParamDecl],
339308
genericWhereClause: TrailingWhereClause?,
340-
rightAngleLoc: SourceLoc?
341-
) -> GenericParamList {
309+
rightAngleLoc: SourceLoc?, _ astContext: ASTContext
310+
) -> GenericParameterList {
342311
let paramsNew = parameters.map{ ASTBridging.BridgedGenericTypeParamDecl(raw: $0.bridged.obj) }
343312
return paramsNew.withBridgedArrayRef {
344-
GenericParamList(bridged: BridgedGenericParamList.createParsed(
313+
GenericParameterList(bridged: BridgedGenericParamList.createParsed(
345314
astContext, leftAngleLoc: leftAngleLoc.bridgedLocation, parameters: $0,
346315
genericWhereClause: genericWhereClause.bridged, rightAngleLoc: rightAngleLoc.bridgedLocation
347316
))
@@ -371,10 +340,7 @@ extension FileUnit {
371340

372341
extension ParameterList? {
373342
public var bridged: BridgedParameterList? {
374-
if self == nil {
375-
return nil
376-
}
377-
return self!.bridged
343+
return self?.bridged
378344
}
379345
}
380346

@@ -384,7 +350,7 @@ extension BridgedParameterList? {
384350
}
385351
}
386352

387-
extension GenericParamList? {
353+
extension GenericParameterList? {
388354
public var bridged: BridgedNullableGenericParamList {
389355
BridgedNullableGenericParamList(raw: self?.bridged.raw)
390356
}

SwiftCompilerSources/Sources/AST/Type.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ public struct Type: TypeProperties, CustomStringConvertible, NoReflectionChildre
6767
return Type(bridged: bridged.subst(substitutionMap.bridged))
6868
}
6969

70-
public func mapOutOfContext() -> Type {
71-
return Type(bridged: bridged.mapTypeOutOfContext())
70+
public func mapOutOfEnvironment() -> Type {
71+
return Type(bridged: bridged.mapOutOfEnvironment())
7272
}
7373

7474
/// Returns a stronger canonicalization which folds away equivalent

SwiftCompilerSources/Sources/SIL/Function.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ final public class Function : CustomStringConvertible, HasShortDescription, Hash
9494
return AST.`Type`(bridged: bridged.mapTypeIntoEnvironment(type.bridged))
9595
}
9696

97-
public func mapTypeIntoContext(_ type: Type) -> Type {
98-
return Type(bridged: bridged.mapTypeIntoContext(type.bridged))
97+
public func mapTypeIntoEnvironment(_ type: Type) -> Type {
98+
return Type(bridged: bridged.mapTypeIntoEnvironment(type.bridged))
9999
}
100100

101101
/// Returns true if the function is a definition and not only an external declaration.

SwiftCompilerSources/Sources/SIL/Type.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ public struct Type : TypeProperties, CustomStringConvertible, NoReflectionChildr
233233
return false
234234
}
235235

236-
public func mapOutOfContext(in function: Function) -> Type {
237-
rawType.mapOutOfContext().canonical.loweredType(in: function)
236+
public func mapOutOfEnvironment(in function: Function) -> Type {
237+
rawType.mapOutOfEnvironment().canonical.loweredType(in: function)
238238
}
239239
}
240240

include/swift/AST/ASTBridgingImpl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,8 +718,8 @@ bool BridgedASTType::isSILPackElementAddress() const {
718718
return unbridged()->castTo<swift::SILPackType>()->isElementAddress();
719719
}
720720

721-
BridgedASTType BridgedASTType::mapTypeOutOfContext() const {
722-
return {unbridged()->mapTypeOutOfContext().getPointer()};
721+
BridgedASTType BridgedASTType::mapOutOfEnvironment() const {
722+
return {unbridged()->mapTypeOutOfEnvironment().getPointer()};
723723
}
724724

725725
BridgedCanType

include/swift/SIL/SILBridgingImpl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,8 @@ bool BridgedType::isAddress() const {
342342
return unbridged().isAddress();
343343
}
344344

345-
BridgedType BridgedType::mapTypeOutOfContext() const {
346-
return unbridged().mapTypeOutOfContext();
345+
BridgedType BridgedType::mapTypeOutOfEnvironment() const {
346+
return unbridged().mapTypeOutOfEnvironment();
347347
}
348348

349349
BridgedCanType BridgedType::getCanType() const {
@@ -812,8 +812,8 @@ BridgedASTType BridgedFunction::mapTypeIntoEnvironment(BridgedASTType ty) const
812812
return {getFunction()->mapTypeIntoEnvironment(ty.unbridged()).getPointer()};
813813
}
814814

815-
BridgedType BridgedFunction::mapTypeIntoContext(BridgedType ty) const {
816-
return {getFunction()->mapTypeIntoContext(ty.unbridged())};
815+
BridgedType BridgedFunction::mapTypeIntoEnvironment(BridgedType ty) const {
816+
return {getFunction()->mapTypeIntoEnvironment(ty.unbridged())};
817817
}
818818

819819
OptionalBridgedBasicBlock BridgedFunction::getFirstBlock() const {

0 commit comments

Comments
 (0)