mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
This commit also changes how specialized types are being emitted. Previously we would not emitthe detailed member information in the specialized type itself, and instead rely on the fact that it was present in the unspecialized type, however, this wold prevent us from emitting any bound generic members, so we're now emitting the members in both variants of the type. This uncovered a with type aliases that this commit also addresses: Because we don't canonicalize types prior to caching in order to preserve type sugar, alternative representations of recursive types (with one or more levels of recursion unfolded) could create potential infinite chains of types. This is addressed by checking whether a sugared type has an already emitted canonical representation first, and if yes, creating a typedef node pointing directly to it. The donwside of doing this is that it can lead to the disappearnce of type aliases definitions when they are used as parameters in bound generic types. However, we still preserve that a type was `MyClass<MyAlias>`. We just might have a typedef pointing director from `MyClass<MyAlias>` -> `MyClass<CanonicalType>`. rdar://144315592
31 lines
1.0 KiB
Swift
31 lines
1.0 KiB
Swift
// RUN: %target-swift-frontend -g -emit-ir %s | %FileCheck %s
|
|
|
|
public protocol P {
|
|
associatedtype AT;
|
|
}
|
|
|
|
// A generic declcontext cannot be shared, so we expect a
|
|
// forward-declared type.
|
|
// CHECK-GEN: ![[FWD:.*]] = !DICompositeType({{.*}}, name: "Generic",
|
|
// CHECK-GEN-SAME: flags: DIFlagFwdDecl
|
|
// CHECK-GEN: linkageName: "$s4main7GenericV3sety2ATQzF", scope: ![[FWD]],
|
|
public struct Generic<T : P> {
|
|
public func get() -> T.AT? {
|
|
return nil
|
|
}
|
|
public func set(_ t: T.AT) {}
|
|
}
|
|
|
|
// But only one concrete type is expected.
|
|
// CHECK: !DISubprogram({{.*}}linkageName: "$s4main8ConcreteV3getSiSgyF",
|
|
// CHECK-SAME: scope: ![[CONC:[0-9]+]],
|
|
// CHECK: ![[CONC]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Concrete", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, runtimeLang: DW_LANG_Swift, identifier: "$s4main8ConcreteVD")
|
|
public struct Concrete {
|
|
public func get() -> Int? {
|
|
return nil
|
|
}
|
|
public func set(_ t: Int) {}
|
|
}
|
|
|
|
public func getConcrete() -> Concrete? { return nil; }
|