[Standard library] Drop _typeByMangledName().

This underscored function was only intended for testing; drop it from the
ABI. We’re keeping _typeByName because it’s used by Foundation.
This commit is contained in:
Doug Gregor
2018-11-15 11:06:52 -08:00
parent 75947627cf
commit a53b2e285c
5 changed files with 125 additions and 150 deletions

View File

@@ -82,7 +82,16 @@ func _typeName(_ type: Any.Type, qualified: Bool = true) -> String {
/// names is stabilized, this is limited to top-level class names (Foo.bar). /// names is stabilized, this is limited to top-level class names (Foo.bar).
public // SPI(Foundation) public // SPI(Foundation)
func _typeByName(_ name: String) -> Any.Type? { func _typeByName(_ name: String) -> Any.Type? {
return _typeByMangledName(name); let nameUTF8 = Array(name.utf8)
var parametersPerLevel = [UInt]()
var flatSubstitutions = [Any.Type]()
return nameUTF8.withUnsafeBufferPointer { (nameUTF8) in
return _getTypeByMangledName(nameUTF8.baseAddress!,
UInt(nameUTF8.endIndex),
0,
parametersPerLevel,
flatSubstitutions)
}
} }
@_silgen_name("swift_getTypeByMangledName") @_silgen_name("swift_getTypeByMangledName")
@@ -93,28 +102,3 @@ internal func _getTypeByMangledName(
_ parametersPerLevel: UnsafePointer<UInt>, _ parametersPerLevel: UnsafePointer<UInt>,
_ substitutions: UnsafePointer<Any.Type>) _ substitutions: UnsafePointer<Any.Type>)
-> Any.Type? -> Any.Type?
/// Lookup a class given a mangled name. This is a placeholder while we bring
/// up this functionality.
public // TEMPORARY
func _typeByMangledName(_ name: String,
substitutions: [[Any.Type]] = []) -> Any.Type? {
// Map the substitutions to a flat representation that's easier to thread
// through to the runtime.
let numberOfLevels = UInt(substitutions.count)
var parametersPerLevel = [UInt]()
var flatSubstitutions = [Any.Type]()
for level in substitutions {
parametersPerLevel.append(UInt(level.count))
flatSubstitutions.append(contentsOf: level)
}
let nameUTF8 = Array(name.utf8)
return nameUTF8.withUnsafeBufferPointer { (nameUTF8) in
return _getTypeByMangledName(nameUTF8.baseAddress!,
UInt(nameUTF8.endIndex),
numberOfLevels,
parametersPerLevel,
flatSubstitutions)
}
}

View File

@@ -239,7 +239,8 @@ public:
/// that occur within a mangled name, using the generic arguments from /// that occur within a mangled name, using the generic arguments from
/// the given metadata. /// the given metadata.
/// ///
/// Use with \c _getTypeByMangledName to decode potentially-generic types. /// Use with \c swift__getTypeByMangledName to decode potentially-generic
/// types.
class SWIFT_RUNTIME_LIBRARY_VISIBILITY SubstGenericParametersFromMetadata { class SWIFT_RUNTIME_LIBRARY_VISIBILITY SubstGenericParametersFromMetadata {
const Metadata *base; const Metadata *base;

View File

@@ -11,18 +11,18 @@ let DemangleToMetadataTests = TestSuite("DemangleToMetadata")
DemangleToMetadataTests.test("malformed mangled names") { DemangleToMetadataTests.test("malformed mangled names") {
expectNil(_typeByMangledName("blah")) expectNil(_typeByName("blah"))
} }
DemangleToMetadataTests.test("tuple types") { DemangleToMetadataTests.test("tuple types") {
expectEqual(type(of: ()), _typeByMangledName("yt")!) expectEqual(type(of: ()), _typeByName("yt")!)
expectEqual(type(of: ((), ())), _typeByMangledName("yt_ytt")!) expectEqual(type(of: ((), ())), _typeByName("yt_ytt")!)
expectEqual(type(of: ((), b: ())), _typeByMangledName("yt_yt1bt")!) expectEqual(type(of: ((), b: ())), _typeByName("yt_yt1bt")!)
expectEqual(type(of: (a: (), ())), _typeByMangledName("yt1a_ytt")!) expectEqual(type(of: (a: (), ())), _typeByName("yt1a_ytt")!)
expectEqual(type(of: (a: (), b: ())), _typeByMangledName("yt1a_yt1bt")!) expectEqual(type(of: (a: (), b: ())), _typeByName("yt1a_yt1bt")!)
// Initial creation of metadata via demangling a type name. // Initial creation of metadata via demangling a type name.
expectNotNil(_typeByMangledName("yt1a_yt3bcdt")) expectNotNil(_typeByName("yt1a_yt3bcdt"))
} }
func f0() { } func f0() { }
@@ -51,48 +51,48 @@ func f1_escaping_autoclosure(_: @autoclosure @escaping () -> Float) { }
DemangleToMetadataTests.test("function types") { DemangleToMetadataTests.test("function types") {
// Conventions // Conventions
expectEqual(type(of: f0), _typeByMangledName("yyc")!) expectEqual(type(of: f0), _typeByName("yyc")!)
expectEqual(type(of: f0_thin), _typeByMangledName("yyXf")!) expectEqual(type(of: f0_thin), _typeByName("yyXf")!)
expectEqual(type(of: f0_c), _typeByMangledName("yyXC")!) expectEqual(type(of: f0_c), _typeByName("yyXC")!)
#if _runtime(_ObjC) #if _runtime(_ObjC)
expectEqual(type(of: f0_block), _typeByMangledName("yyXB")!) expectEqual(type(of: f0_block), _typeByName("yyXB")!)
#endif #endif
// Throwing functions // Throwing functions
expectEqual(type(of: f0_throws), _typeByMangledName("yyKc")!) expectEqual(type(of: f0_throws), _typeByName("yyKc")!)
// More parameters. // More parameters.
expectEqual(type(of: f1), _typeByMangledName("yyyt_tc")!) expectEqual(type(of: f1), _typeByName("yyyt_tc")!)
expectEqual(type(of: f2), _typeByMangledName("yyyt_yttc")!) expectEqual(type(of: f2), _typeByName("yyyt_yttc")!)
// Variadic parameters. // Variadic parameters.
expectEqual(type(of: f1_variadic), _typeByMangledName("yyytd_tc")!) expectEqual(type(of: f1_variadic), _typeByName("yyytd_tc")!)
// Inout parameters. // Inout parameters.
expectEqual(type(of: f1_inout), _typeByMangledName("yyytzc")!) expectEqual(type(of: f1_inout), _typeByName("yyytzc")!)
// Ownership parameters. // Ownership parameters.
expectEqual(type(of: f1_shared), _typeByMangledName("yyyXlhc")!) expectEqual(type(of: f1_shared), _typeByName("yyyXlhc")!)
expectEqual(type(of: f1_owned), _typeByMangledName("yyyXlnc")!) expectEqual(type(of: f1_owned), _typeByName("yyyXlnc")!)
// Mix-and-match. // Mix-and-match.
expectEqual(type(of: f2_variadic_inout), _typeByMangledName("yyytd_ytztc")!) expectEqual(type(of: f2_variadic_inout), _typeByName("yyytd_ytztc")!)
// A function type that hasn't been built before. // A function type that hasn't been built before.
expectEqual("(Int, Float, Double, String, Character, UInt, Bool) -> ()", expectEqual("(Int, Float, Double, String, Character, UInt, Bool) -> ()",
String(describing: _typeByMangledName("yySi_SfSdSSs9CharacterVSuSbtc")!)) String(describing: _typeByName("yySi_SfSdSSs9CharacterVSuSbtc")!))
// Escaping // Escaping
expectEqual(type(of: f1_escaping), _typeByMangledName("ySfSicc")!) expectEqual(type(of: f1_escaping), _typeByName("ySfSicc")!)
// Autoclosure // Autoclosure
expectEqual(type(of: f1_autoclosure), _typeByMangledName("ySfyXKc")!) expectEqual(type(of: f1_autoclosure), _typeByName("ySfyXKc")!)
expectEqual(type(of: f1_escaping_autoclosure), _typeByMangledName("ySfyXAc")!) expectEqual(type(of: f1_escaping_autoclosure), _typeByName("ySfyXAc")!)
} }
DemangleToMetadataTests.test("metatype types") { DemangleToMetadataTests.test("metatype types") {
expectEqual(type(of: type(of: ())), _typeByMangledName("ytm")!) expectEqual(type(of: type(of: ())), _typeByName("ytm")!)
expectEqual(type(of: type(of: f0)), _typeByMangledName("yycm")!) expectEqual(type(of: type(of: f0)), _typeByName("yycm")!)
} }
func f2_any_anyobject(_: Any, _: AnyObject) { } func f2_any_anyobject(_: Any, _: AnyObject) { }
@@ -109,33 +109,33 @@ func f1_composition_superclass(_: C & P1 & P2) { }
DemangleToMetadataTests.test("existential types") { DemangleToMetadataTests.test("existential types") {
// Any, AnyObject // Any, AnyObject
expectEqual(type(of: f2_any_anyobject), _typeByMangledName("yyyp_yXltc")!) expectEqual(type(of: f2_any_anyobject), _typeByName("yyyp_yXltc")!)
// References to protocols. // References to protocols.
expectEqual(type(of: f1_composition), _typeByMangledName("yy4main2P1_4main2P2pc")!) expectEqual(type(of: f1_composition), _typeByName("yy4main2P1_4main2P2pc")!)
// Reference to protocol with AnyObject. // Reference to protocol with AnyObject.
expectEqual(type(of: f1_composition_anyobject), _typeByMangledName("yy4main2P1_Xlc")!) expectEqual(type(of: f1_composition_anyobject), _typeByName("yy4main2P1_Xlc")!)
// References to superclass. // References to superclass.
expectEqual(type(of: f1_composition_superclass), _typeByMangledName("yy4main2P1_4main2P2AA1CCXcc")!) expectEqual(type(of: f1_composition_superclass), _typeByName("yy4main2P1_4main2P2AA1CCXcc")!)
// Demangle an existential type that hasn't been seen before. // Demangle an existential type that hasn't been seen before.
expectEqual("P1 & P2 & P3", String(describing: _typeByMangledName("4main2P1_4main2P24main2P3p")!)) expectEqual("P1 & P2 & P3", String(describing: _typeByName("4main2P1_4main2P24main2P3p")!))
} }
DemangleToMetadataTests.test("existential metatype types") { DemangleToMetadataTests.test("existential metatype types") {
// Any // Any
expectEqual(type(of: Any.self), _typeByMangledName("ypm")!) expectEqual(type(of: Any.self), _typeByName("ypm")!)
// AnyObject // AnyObject
expectEqual(type(of: AnyObject.self), _typeByMangledName("yXlm")!) expectEqual(type(of: AnyObject.self), _typeByName("yXlm")!)
// References to metatype of protocols. // References to metatype of protocols.
expectEqual(type(of: (P1 & P2).self), _typeByMangledName("4main2P1_4main2P2pm")!) expectEqual(type(of: (P1 & P2).self), _typeByName("4main2P1_4main2P2pm")!)
// References to metatype involving protocols and superclass. // References to metatype involving protocols and superclass.
expectEqual(type(of: (C & P1 & P2).self), _typeByMangledName("4main2P1_4main2P2AA1CCXcm")!) expectEqual(type(of: (C & P1 & P2).self), _typeByName("4main2P1_4main2P2AA1CCXcm")!)
} }
struct S { struct S {
@@ -146,23 +146,23 @@ enum E { case e }
DemangleToMetadataTests.test("nominal types") { DemangleToMetadataTests.test("nominal types") {
// Simple Struct // Simple Struct
expectEqual(type(of: S()), _typeByMangledName("4main1SV")!) expectEqual(type(of: S()), _typeByName("4main1SV")!)
// Simple Enum // Simple Enum
expectEqual(type(of: E.e), _typeByMangledName("4main1EO")!) expectEqual(type(of: E.e), _typeByName("4main1EO")!)
// Simple Class // Simple Class
expectEqual(type(of: C()), _typeByMangledName("4main1CC")!) expectEqual(type(of: C()), _typeByName("4main1CC")!)
// Swift standard library types // Swift standard library types
expectEqual(type(of: Int()), _typeByMangledName("Si")!) expectEqual(type(of: Int()), _typeByName("Si")!)
expectEqual(type(of: Int16()), _typeByMangledName("s5Int16V")!) expectEqual(type(of: Int16()), _typeByName("s5Int16V")!)
// Nested struct // Nested struct
expectEqual(type(of: S.Nested()), _typeByMangledName("4main1SV6NestedV")!) expectEqual(type(of: S.Nested()), _typeByName("4main1SV6NestedV")!)
// Class referenced by "ModuleName.ClassName" syntax. // Class referenced by "ModuleName.ClassName" syntax.
expectEqual(type(of: C()), _typeByMangledName("main.C")!) expectEqual(type(of: C()), _typeByName("main.C")!)
} }
protocol P4 { protocol P4 {
@@ -175,26 +175,15 @@ extension S: P4 {
typealias Assoc2 = String typealias Assoc2 = String
} }
DemangleToMetadataTests.test("substitutions") {
// Type parameter substitutions.
expectEqual(type(of: (1, 3.14159, "Hello")),
_typeByMangledName("yyx_q_qd__t",
substitutions: [[Int.self, Double.self], [String.self]])!)
// Associated type substitutions
expectEqual(type(of: (S(), 1, "Hello")),
_typeByMangledName("x_6Assoc14main2P4PQz6Assoc24main2P4PQzt", substitutions: [[S.self]])!)
}
enum EG<T, U> { case a } enum EG<T, U> { case a }
class CG3<T, U, V> { } class CG3<T, U, V> { }
DemangleToMetadataTests.test("simple generic specializations") { DemangleToMetadataTests.test("simple generic specializations") {
expectEqual([Int].self, _typeByMangledName("SaySiG")!) expectEqual([Int].self, _typeByName("SaySiG")!)
expectEqual(EG<Int, String>.self, _typeByMangledName("4main2EGOySiSSG")!) expectEqual(EG<Int, String>.self, _typeByName("4main2EGOySiSSG")!)
expectEqual(CG3<Int, Double, String>.self, _typeByMangledName("4main3CG3CySiSdSSG")!) expectEqual(CG3<Int, Double, String>.self, _typeByName("4main3CG3CySiSdSSG")!)
} }
extension EG { extension EG {
@@ -219,33 +208,33 @@ class CG2<T, U> {
DemangleToMetadataTests.test("nested generic specializations") { DemangleToMetadataTests.test("nested generic specializations") {
expectEqual(EG<Int, String>.NestedSG<Double>.self, expectEqual(EG<Int, String>.NestedSG<Double>.self,
_typeByMangledName("4main2EGO8NestedSGVySiSS_SdG")!) _typeByName("4main2EGO8NestedSGVySiSS_SdG")!)
expectEqual(C.Nested<Int, String>.Innermore.Innermost<Double>.self, expectEqual(C.Nested<Int, String>.Innermore.Innermost<Double>.self,
_typeByMangledName("4main1CC6NestedO9InnermoreV9InnermostVy_SiSS__SdG")!) _typeByName("4main1CC6NestedO9InnermoreV9InnermostVy_SiSS__SdG")!)
expectEqual(CG2<Int, String>.Inner<Double>.self, expectEqual(CG2<Int, String>.Inner<Double>.self,
_typeByMangledName("4main3CG2C5InnerCySiSS_SdG")!) _typeByName("4main3CG2C5InnerCySiSS_SdG")!)
expectEqual( expectEqual(
CG2<Int, String>.Inner<Double>.Innermost<Int8, Int16, Int32, Int64>.self, CG2<Int, String>.Inner<Double>.Innermost<Int8, Int16, Int32, Int64>.self,
_typeByMangledName("4main3CG2C5InnerC9InnermostVySiSS_Sd_s4Int8Vs5Int16Vs5Int32Vs5Int64VG")!) _typeByName("4main3CG2C5InnerC9InnermostVySiSS_Sd_s4Int8Vs5Int16Vs5Int32Vs5Int64VG")!)
} }
DemangleToMetadataTests.test("demangle built-in types") { DemangleToMetadataTests.test("demangle built-in types") {
expectEqual(Builtin.Int8.self, _typeByMangledName("Bi8_")!) expectEqual(Builtin.Int8.self, _typeByName("Bi8_")!)
expectEqual(Builtin.Int16.self, _typeByMangledName("Bi16_")!) expectEqual(Builtin.Int16.self, _typeByName("Bi16_")!)
expectEqual(Builtin.Int32.self, _typeByMangledName("Bi32_")!) expectEqual(Builtin.Int32.self, _typeByName("Bi32_")!)
expectEqual(Builtin.Int64.self, _typeByMangledName("Bi64_")!) expectEqual(Builtin.Int64.self, _typeByName("Bi64_")!)
expectEqual(Builtin.Int128.self, _typeByMangledName("Bi128_")!) expectEqual(Builtin.Int128.self, _typeByName("Bi128_")!)
expectEqual(Builtin.Int256.self, _typeByMangledName("Bi256_")!) expectEqual(Builtin.Int256.self, _typeByName("Bi256_")!)
expectEqual(Builtin.Int512.self, _typeByMangledName("Bi512_")!) expectEqual(Builtin.Int512.self, _typeByName("Bi512_")!)
expectEqual(Builtin.NativeObject.self, _typeByMangledName("Bo")!) expectEqual(Builtin.NativeObject.self, _typeByName("Bo")!)
expectEqual(Builtin.BridgeObject.self, _typeByMangledName("Bb")!) expectEqual(Builtin.BridgeObject.self, _typeByName("Bb")!)
expectEqual(Builtin.UnsafeValueBuffer.self, _typeByMangledName("BB")!) expectEqual(Builtin.UnsafeValueBuffer.self, _typeByName("BB")!)
expectEqual(Builtin.FPIEEE32.self, _typeByMangledName("Bf32_")!) expectEqual(Builtin.FPIEEE32.self, _typeByName("Bf32_")!)
expectEqual(Builtin.FPIEEE64.self, _typeByMangledName("Bf64_")!) expectEqual(Builtin.FPIEEE64.self, _typeByName("Bf64_")!)
expectEqual(Builtin.Vec4xFPIEEE32.self, _typeByMangledName("Bf32_Bv4_")!) expectEqual(Builtin.Vec4xFPIEEE32.self, _typeByName("Bf32_Bv4_")!)
} }
class CG4<T: P1, U: P2> { class CG4<T: P1, U: P2> {
@@ -258,14 +247,14 @@ struct ConformsToP3: P3 { }
DemangleToMetadataTests.test("protocol conformance requirements") { DemangleToMetadataTests.test("protocol conformance requirements") {
expectEqual(CG4<ConformsToP1, ConformsToP2>.self, expectEqual(CG4<ConformsToP1, ConformsToP2>.self,
_typeByMangledName("4main3CG4CyAA12ConformsToP1VAA12ConformsToP2VG")!) _typeByName("4main3CG4CyAA12ConformsToP1VAA12ConformsToP2VG")!)
expectEqual(CG4<ConformsToP1, ConformsToP2>.InnerGeneric<ConformsToP3>.self, expectEqual(CG4<ConformsToP1, ConformsToP2>.InnerGeneric<ConformsToP3>.self,
_typeByMangledName("4main3CG4C12InnerGenericVyAA12ConformsToP1VAA12ConformsToP2V_AA12ConformsToP3VG")!) _typeByName("4main3CG4C12InnerGenericVyAA12ConformsToP1VAA12ConformsToP2V_AA12ConformsToP3VG")!)
// Failure cases: failed conformance requirements. // Failure cases: failed conformance requirements.
expectNil(_typeByMangledName("4main3CG4CyAA12ConformsToP1VAA12ConformsToP1VG")) expectNil(_typeByName("4main3CG4CyAA12ConformsToP1VAA12ConformsToP1VG"))
expectNil(_typeByMangledName("4main3CG4CyAA12ConformsToP2VAA12ConformsToP2VG")) expectNil(_typeByName("4main3CG4CyAA12ConformsToP2VAA12ConformsToP2VG"))
expectNil(_typeByMangledName("4main3CG4C12InnerGenericVyAA12ConformsToP1VAA12ConformsToP2V_AA12ConformsToP2VG")) expectNil(_typeByName("4main3CG4C12InnerGenericVyAA12ConformsToP1VAA12ConformsToP2V_AA12ConformsToP2VG"))
} }
struct SG5<T: P4> where T.Assoc1: P1, T.Assoc2: P2 { } struct SG5<T: P4> where T.Assoc1: P1, T.Assoc2: P2 { }
@@ -287,12 +276,12 @@ struct ConformsToP4c : P4 {
DemangleToMetadataTests.test("associated type conformance requirements") { DemangleToMetadataTests.test("associated type conformance requirements") {
expectEqual(SG5<ConformsToP4a>.self, expectEqual(SG5<ConformsToP4a>.self,
_typeByMangledName("4main3SG5VyAA13ConformsToP4aVG")!) _typeByName("4main3SG5VyAA13ConformsToP4aVG")!)
// Failure cases: failed conformance requirements. // Failure cases: failed conformance requirements.
expectNil(_typeByMangledName("4main3SG5VyAA13ConformsToP4bVG")) expectNil(_typeByName("4main3SG5VyAA13ConformsToP4bVG"))
expectNil(_typeByMangledName("4main3SG5VyAA13ConformsToP4cVG")) expectNil(_typeByName("4main3SG5VyAA13ConformsToP4cVG"))
expectNil(_typeByMangledName("4main3SG5VyAA12ConformsToP1cVG")) expectNil(_typeByName("4main3SG5VyAA12ConformsToP1cVG"))
} }
struct SG6<T: P4> where T.Assoc1 == T.Assoc2 { } struct SG6<T: P4> where T.Assoc1 == T.Assoc2 { }
@@ -307,32 +296,32 @@ struct ConformsToP4d : P4 {
DemangleToMetadataTests.test("same-type requirements") { DemangleToMetadataTests.test("same-type requirements") {
// Concrete type. // Concrete type.
expectEqual(SG7<S>.self, expectEqual(SG7<S>.self,
_typeByMangledName("4main3SG7VyAA1SVG")!) _typeByName("4main3SG7VyAA1SVG")!)
// Other associated type. // Other associated type.
expectEqual(SG6<ConformsToP4b>.self, expectEqual(SG6<ConformsToP4b>.self,
_typeByMangledName("4main3SG6VyAA13ConformsToP4bVG")!) _typeByName("4main3SG6VyAA13ConformsToP4bVG")!)
expectEqual(SG6<ConformsToP4c>.self, expectEqual(SG6<ConformsToP4c>.self,
_typeByMangledName("4main3SG6VyAA13ConformsToP4cVG")!) _typeByName("4main3SG6VyAA13ConformsToP4cVG")!)
// Structural type. // Structural type.
expectEqual(SG8<ConformsToP4d>.self, expectEqual(SG8<ConformsToP4d>.self,
_typeByMangledName("4main3SG8VyAA13ConformsToP4dVG")!) _typeByName("4main3SG8VyAA13ConformsToP4dVG")!)
// Failure cases: types don't match. // Failure cases: types don't match.
expectNil(_typeByMangledName("4main3SG7VyAA13ConformsToP4aVG")) expectNil(_typeByName("4main3SG7VyAA13ConformsToP4aVG"))
expectNil(_typeByMangledName("4main3SG6VyAA13ConformsToP4aVG")) expectNil(_typeByName("4main3SG6VyAA13ConformsToP4aVG"))
expectNil(_typeByMangledName("4main3SG8VyAA13ConformsToP4cVG")) expectNil(_typeByName("4main3SG8VyAA13ConformsToP4cVG"))
} }
struct SG9<T: AnyObject> { } struct SG9<T: AnyObject> { }
DemangleToMetadataTests.test("AnyObject requirements") { DemangleToMetadataTests.test("AnyObject requirements") {
expectEqual(SG9<C>.self, expectEqual(SG9<C>.self,
_typeByMangledName("4main3SG9VyAA1CCG")!) _typeByName("4main3SG9VyAA1CCG")!)
// Failure cases: failed AnyObject constraint. // Failure cases: failed AnyObject constraint.
expectNil(_typeByMangledName("4main3SG9VyAA1SVG")) expectNil(_typeByName("4main3SG9VyAA1SVG"))
} }
struct SG10<T: C> { } struct SG10<T: C> { }
@@ -342,12 +331,12 @@ class C3 { }
DemangleToMetadataTests.test("superclass requirements") { DemangleToMetadataTests.test("superclass requirements") {
expectEqual(SG10<C>.self, expectEqual(SG10<C>.self,
_typeByMangledName("4main4SG10VyAA1CCG")!) _typeByName("4main4SG10VyAA1CCG")!)
expectEqual(SG10<C2>.self, expectEqual(SG10<C2>.self,
_typeByMangledName("4main4SG10VyAA2C2CG")!) _typeByName("4main4SG10VyAA2C2CG")!)
// Failure cases: not a subclass. // Failure cases: not a subclass.
expectNil(_typeByMangledName("4main4SG10VyAA2C3CG")) expectNil(_typeByName("4main4SG10VyAA2C3CG"))
} }
// //
@@ -373,24 +362,24 @@ struct ConformsToP2AndP3: P2, P3 { }
DemangleToMetadataTests.test("Nested types in extensions") { DemangleToMetadataTests.test("Nested types in extensions") {
expectEqual( expectEqual(
Dictionary<String, Int>.Inner<ConformsToP1>.self, Dictionary<String, Int>.Inner<ConformsToP1>.self,
_typeByMangledName("s10DictionaryV4mainE5InnerVySSSi_AC12ConformsToP1VG")!) _typeByName("s10DictionaryV4mainE5InnerVySSSi_AC12ConformsToP1VG")!)
expectEqual( expectEqual(
SG11<ConformsToP1>.InnerTConformsToP1<ConformsToP2>.self, SG11<ConformsToP1>.InnerTConformsToP1<ConformsToP2>.self,
_typeByMangledName("4main4SG11VA2A2P1RzlE016InnerTConformsToC0VyAA08ConformsfC0V_AA0gF2P2VG")!) _typeByName("4main4SG11VA2A2P1RzlE016InnerTConformsToC0VyAA08ConformsfC0V_AA0gF2P2VG")!)
expectEqual( expectEqual(
SG11<ConformsToP1>.InnerTConformsToP1<ConformsToP2AndP3> SG11<ConformsToP1>.InnerTConformsToP1<ConformsToP2AndP3>
.InnermostUConformsToP3<ConformsToP4a>.self, .InnermostUConformsToP3<ConformsToP4a>.self,
_typeByMangledName("4main4SG11VA2A2P1RzlE016InnerTConformsToC0VA2A2P3Rd__rlE018InnermostUConformsfG0VyAA08ConformsfC0V_AA0jf5P2AndG0V_AA0jF3P4aVG")!) _typeByName("4main4SG11VA2A2P1RzlE016InnerTConformsToC0VA2A2P3Rd__rlE018InnermostUConformsfG0VyAA08ConformsfC0V_AA0jf5P2AndG0V_AA0jF3P4aVG")!)
// Failure case: Dictionary's outer `Key: Hashable` constraint not sastified // Failure case: Dictionary's outer `Key: Hashable` constraint not sastified
expectNil(_typeByMangledName("s10DictionaryV4mainE5InnerVyAC12ConformsToP1VSi_AC12ConformsToP1VG")) expectNil(_typeByName("s10DictionaryV4mainE5InnerVyAC12ConformsToP1VSi_AC12ConformsToP1VG"))
// Failure case: Dictionary's inner `V: P1` constraint not satisfied // Failure case: Dictionary's inner `V: P1` constraint not satisfied
expectNil(_typeByMangledName("s10DictionaryV4mainE5InnerVySSSi_AC12ConformsToP2VG")) expectNil(_typeByName("s10DictionaryV4mainE5InnerVySSSi_AC12ConformsToP2VG"))
// Failure case: SG11's outer `T: P1` constraint not satisfied // Failure case: SG11's outer `T: P1` constraint not satisfied
expectNil(_typeByMangledName("4main4SG11VA2A2P1RzlE016InnerTConformsToC0VyAA08ConformsF2P2V_AHGMa")) expectNil(_typeByName("4main4SG11VA2A2P1RzlE016InnerTConformsToC0VyAA08ConformsF2P2V_AHGMa"))
// Failure case: SG11's inner `U: P2` constraint not satisfied // Failure case: SG11's inner `U: P2` constraint not satisfied
expectNil(_typeByMangledName("4main4SG11VA2A2P1RzlE016InnerTConformsToC0VyAA08ConformsfC0V_AHGMa")) expectNil(_typeByName("4main4SG11VA2A2P1RzlE016InnerTConformsToC0VyAA08ConformsfC0V_AHGMa"))
// TODO: Failure case: InnermostUConformsToP3's 'U: P3' constraint not satisfied // TODO: Failure case: InnermostUConformsToP3's 'U: P3' constraint not satisfied
@@ -419,13 +408,13 @@ extension SG12 where U == ConformsToP2 {
DemangleToMetadataTests.test("Nested types in same-type-constrained extensions") { DemangleToMetadataTests.test("Nested types in same-type-constrained extensions") {
expectEqual( expectEqual(
SG12<ConformsToP1AndP2, ConformsToP1AndP2>.InnerTEqualsU<ConformsToP3>.self, SG12<ConformsToP1AndP2, ConformsToP1AndP2>.InnerTEqualsU<ConformsToP3>.self,
_typeByMangledName("4main4SG12VA2A2P2Rzq_RszrlE13InnerTEqualsUVyAA015ConformsToP1AndC0VAH_AA0fG2P3VG")!) _typeByName("4main4SG12VA2A2P2Rzq_RszrlE13InnerTEqualsUVyAA015ConformsToP1AndC0VAH_AA0fG2P3VG")!)
expectEqual( expectEqual(
SG12<ConformsToP1, ConformsToP2>.InnerTEqualsConformsToP1<ConformsToP3>.self, SG12<ConformsToP1, ConformsToP2>.InnerTEqualsConformsToP1<ConformsToP3>.self,
_typeByMangledName("4main4SG12VA2A12ConformsToP1VRszrlE012InnerTEqualscdE0VyAeA0cD2P2V_AA0cD2P3VG")!) _typeByName("4main4SG12VA2A12ConformsToP1VRszrlE012InnerTEqualscdE0VyAeA0cD2P2V_AA0cD2P3VG")!)
expectEqual( expectEqual(
SG12<ConformsToP1, ConformsToP2>.InnerUEqualsConformsToP2<ConformsToP3>.self, SG12<ConformsToP1, ConformsToP2>.InnerUEqualsConformsToP2<ConformsToP3>.self,
_typeByMangledName("4main4SG12VA2A12ConformsToP2VRs_rlE012InnerUEqualscdE0VyAA0cD2P1VAE_AA0cD2P3VG")!) _typeByName("4main4SG12VA2A12ConformsToP2VRs_rlE012InnerUEqualscdE0VyAA0cD2P1VAE_AA0cD2P3VG")!)
// TODO: Cases where mangled name doesn't match constraints // TODO: Cases where mangled name doesn't match constraints
// T != U in InnerTEqualsU // T != U in InnerTEqualsU

View File

@@ -18,11 +18,11 @@ protocol P2 { }
@objc protocol mainP4 { } @objc protocol mainP4 { }
DemangleToMetadataTests.test("@objc classes") { DemangleToMetadataTests.test("@objc classes") {
expectEqual(type(of: C()), _typeByMangledName("4main1CC")!) expectEqual(type(of: C()), _typeByName("4main1CC")!)
} }
DemangleToMetadataTests.test("@objc enums") { DemangleToMetadataTests.test("@objc enums") {
expectEqual(type(of: E.a), _typeByMangledName("4main1EO")!) expectEqual(type(of: E.a), _typeByName("4main1EO")!)
} }
func f1_composition_objc_protocol(_: P1) { } func f1_composition_objc_protocol(_: P1) { }
@@ -30,43 +30,43 @@ func f1_composition_objc_protocol_P4(_: mainP4) { }
DemangleToMetadataTests.test("@objc protocols") { DemangleToMetadataTests.test("@objc protocols") {
expectEqual(type(of: f1_composition_objc_protocol), expectEqual(type(of: f1_composition_objc_protocol),
_typeByMangledName("yy4main2P1_pc")!) _typeByName("yy4main2P1_pc")!)
expectEqual(type(of: f1_composition_objc_protocol_P4), expectEqual(type(of: f1_composition_objc_protocol_P4),
_typeByMangledName("yy4main0A2P4_pc")!) _typeByName("yy4main0A2P4_pc")!)
} }
DemangleToMetadataTests.test("Objective-C classes") { DemangleToMetadataTests.test("Objective-C classes") {
expectEqual(type(of: NSObject()), _typeByMangledName("So8NSObjectC")!) expectEqual(type(of: NSObject()), _typeByName("So8NSObjectC")!)
} }
func f1_composition_NSCoding(_: NSCoding) { } func f1_composition_NSCoding(_: NSCoding) { }
DemangleToMetadataTests.test("Objective-C protocols") { DemangleToMetadataTests.test("Objective-C protocols") {
expectEqual(type(of: f1_composition_NSCoding), _typeByMangledName("yySo8NSCoding_pc")!) expectEqual(type(of: f1_composition_NSCoding), _typeByName("yySo8NSCoding_pc")!)
} }
DemangleToMetadataTests.test("Classes that don't exist") { DemangleToMetadataTests.test("Classes that don't exist") {
expectNil(_typeByMangledName("4main4BoomC")) expectNil(_typeByName("4main4BoomC"))
} }
DemangleToMetadataTests.test("CoreFoundation classes") { DemangleToMetadataTests.test("CoreFoundation classes") {
expectEqual(CFArray.self, _typeByMangledName("So10CFArrayRefa")!) expectEqual(CFArray.self, _typeByName("So10CFArrayRefa")!)
} }
DemangleToMetadataTests.test("Imported error types") { DemangleToMetadataTests.test("Imported error types") {
expectEqual(URLError.self, _typeByMangledName("10Foundation8URLErrorV")!) expectEqual(URLError.self, _typeByName("10Foundation8URLErrorV")!)
expectEqual(URLError.Code.self, expectEqual(URLError.Code.self,
_typeByMangledName("10Foundation8URLErrorV4CodeV")!) _typeByName("10Foundation8URLErrorV4CodeV")!)
} }
DemangleToMetadataTests.test("Imported swift_wrapper types") { DemangleToMetadataTests.test("Imported swift_wrapper types") {
expectEqual(URLFileResourceType.self, expectEqual(URLFileResourceType.self,
_typeByMangledName("So21NSURLFileResourceTypea")!) _typeByName("So21NSURLFileResourceTypea")!)
} }
DemangleToMetadataTests.test("Imported enum types") { DemangleToMetadataTests.test("Imported enum types") {
expectEqual(URLSessionTask.State.self, expectEqual(URLSessionTask.State.self,
_typeByMangledName("So21NSURLSessionTaskStateV")!) _typeByName("So21NSURLSessionTaskStateV")!)
} }
class CG4<T: P1, U: P2> { } class CG4<T: P1, U: P2> { }
@@ -77,14 +77,14 @@ class D: P2 { }
DemangleToMetadataTests.test("@objc protocol conformances") { DemangleToMetadataTests.test("@objc protocol conformances") {
expectEqual(CG4<C, C>.self, expectEqual(CG4<C, C>.self,
_typeByMangledName("4main3CG4CyAA1CCAA1CCG")!) _typeByName("4main3CG4CyAA1CCAA1CCG")!)
expectNil(_typeByMangledName("4main3CG4CyAA1DCAA1DCG")) expectNil(_typeByName("4main3CG4CyAA1DCAA1DCG"))
} }
DemangleToMetadataTests.test("synthesized declarations") { DemangleToMetadataTests.test("synthesized declarations") {
expectEqual(CLError.self, _typeByMangledName("SC7CLErrorLeV")!) expectEqual(CLError.self, _typeByName("SC7CLErrorLeV")!)
expectNil(_typeByMangledName("SC7CLErrorV")) expectNil(_typeByName("SC7CLErrorV"))
expectEqual(CLError.Code.self, _typeByMangledName("So7CLErrorV")!) expectEqual(CLError.Code.self, _typeByName("So7CLErrorV")!)
let error = NSError(domain: NSCocoaErrorDomain, code: 0) let error = NSError(domain: NSCocoaErrorDomain, code: 0)
let reflectionString = String(reflecting: CLError(_nsError: error)) let reflectionString = String(reflecting: CLError(_nsError: error))
@@ -93,18 +93,18 @@ DemangleToMetadataTests.test("synthesized declarations") {
DemangleToMetadataTests.test("members of runtime-only Objective-C classes") { DemangleToMetadataTests.test("members of runtime-only Objective-C classes") {
expectEqual(DispatchQueue.Attributes.self, expectEqual(DispatchQueue.Attributes.self,
_typeByMangledName("So17OS_dispatch_queueC8DispatchE10AttributesV")!) _typeByName("So17OS_dispatch_queueC8DispatchE10AttributesV")!)
} }
DemangleToMetadataTests.test("runtime conformance lookup via foreign superclasses") { DemangleToMetadataTests.test("runtime conformance lookup via foreign superclasses") {
expectEqual(Set<CFMutableString>.self, expectEqual(Set<CFMutableString>.self,
_typeByMangledName("ShySo18CFMutableStringRefaG")!) _typeByName("ShySo18CFMutableStringRefaG")!)
} }
class F<T: P1> { } class F<T: P1> { }
DemangleToMetadataTests.test("runtime conformance check for @objc protocol inheritance") { DemangleToMetadataTests.test("runtime conformance check for @objc protocol inheritance") {
expectEqual(F<P3>.self, _typeByMangledName("4main1FCyAA2P3PG")!) expectEqual(F<P3>.self, _typeByName("4main1FCyAA2P3PG")!)
} }
runAllTests() runAllTests()

View File

@@ -14,6 +14,7 @@ Struct _Buffer72 has been removed
Func _int64ToString(_:radix:uppercase:) has been removed Func _int64ToString(_:radix:uppercase:) has been removed
Func _int64ToStringImpl(_:_:_:_:_:) has been removed Func _int64ToStringImpl(_:_:_:_:_:) has been removed
Func _uint64ToStringImpl(_:_:_:_:_:) has been removed Func _uint64ToStringImpl(_:_:_:_:_:) has been removed
Func _typeByMangledName(_:substitutions:) has been removed
Func _withUninitializedString(_:) has been removed Func _withUninitializedString(_:) has been removed
Class _stdlib_AtomicInt has been removed Class _stdlib_AtomicInt has been removed