From 7997183dbcc067c6665e5faaf2a96424f2a98912 Mon Sep 17 00:00:00 2001 From: Arnold Schwaighofer Date: Mon, 8 Jun 2020 11:45:55 -0700 Subject: [PATCH 1/2] IRGen: Move emitProtocolConformance before emitLazyDefinitions It is possible that the only mention of metadata happens as part of protocol conformannce emission. This ordering makes sure we emit this metadata. SR-12891 rdar://63819461 --- lib/IRGen/GenDecl.cpp | 9 +++-- test/IRGen/associated_type_witness.swift | 36 ++++++++++--------- test/IRGen/lazy_metadata_no_reflection.swift | 2 +- test/IRGen/protocol_conformance_records.swift | 8 ++--- test/IRGen/protocol_resilience.sil | 35 +++++++++--------- test/IRGen/reflection_metadata.swift | 2 +- 6 files changed, 47 insertions(+), 45 deletions(-) diff --git a/lib/IRGen/GenDecl.cpp b/lib/IRGen/GenDecl.cpp index 7e6710311b798..0cfa3a13d2082 100644 --- a/lib/IRGen/GenDecl.cpp +++ b/lib/IRGen/GenDecl.cpp @@ -3303,7 +3303,10 @@ llvm::Constant *IRGenModule::emitSwiftProtocols() { } void IRGenModule::addProtocolConformance(ConformanceDescription &&record) { - // Add this protocol conformance. + + emitProtocolConformance(record); + + // Add this conformance to the conformance list. ProtocolConformances.push_back(std::move(record)); } @@ -3312,10 +3315,6 @@ llvm::Constant *IRGenModule::emitProtocolConformances() { if (ProtocolConformances.empty()) return nullptr; - // Emit the conformances. - for (const auto &record : ProtocolConformances) - emitProtocolConformance(record); - // Define the global variable for the conformance list. ConstantInitBuilder builder(*this); auto descriptorArray = builder.beginArray(RelativeAddressTy); diff --git a/test/IRGen/associated_type_witness.swift b/test/IRGen/associated_type_witness.swift index 0af07e62363b9..2fa5fc429cab5 100644 --- a/test/IRGen/associated_type_witness.swift +++ b/test/IRGen/associated_type_witness.swift @@ -93,6 +93,16 @@ struct Pair : P, Q {} // GLOBAL-SAME: @"symbolic{{.*}}23associated_type_witness4PairV{{.*}}" // GLOBAL-SAME: ] +// Protocol conformance descriptor for Computed : Assocked. +// GLOBAL-LABEL: @"$s23associated_type_witness8ComputedVyxq_GAA8AssockedAAMc" = hidden constant +// GLOBAL-SAME: i16 4, +// GLOBAL-SAME: i16 1, + +// No instantiator function +// GLOBAL-SAME: i32 0, +// GLOBAL-SAME: i32 trunc (i64 sub (i64 ptrtoint ([16 x i8*]* [[PRIVATE:@.*]] to i64), i64 ptrtoint +// GLOBAL-SAME: } + struct Computed : Assocked { typealias Assoc = Pair } @@ -117,6 +127,14 @@ protocol DerivedFromSimpleAssoc : HasSimpleAssoc {} // GLOBAL-SAME: @"$s23associated_type_witness15GenericComputedVyxGAA22DerivedFromSimpleAssocAAMc" // GLOBAL-SAME: i8* null +// Protocol conformance descriptor for GenericComputed : DerivedFromSimpleAssoc. +// GLOBAL-LABEL: @"$s23associated_type_witness15GenericComputedVyxGAA22DerivedFromSimpleAssocAAMc" = hidden constant +// GLOBAL-SAME: i16 2, +// GLOBAL-SAME: i16 1, + +// Relative reference to instantiator function +// GLOBAL-SAME: i32 trunc (i64 sub (i64 ptrtoint (void (i8**, %swift.type*, i8**)* @"$s23associated_type_witness15GenericComputedVyxGAA22DerivedFromSimpleAssocAAWI" to i64), + // Relative reference to private data struct GenericComputed : DerivedFromSimpleAssoc { typealias Assoc = PBox @@ -155,7 +173,6 @@ extension ValidatorType { // MARK: Failing example extension Validator where T == String { - // GLOBAL: @"symbolic _____ySS__G 23associated_type_witness9ValidatorVAASSRszlE1VV7FailureV" struct V: ValidatorType { typealias Data = T // or String @@ -163,21 +180,6 @@ extension Validator where T == String { } } +// GLOBAL-LABEL: @"symbolic _____ySS__G 23associated_type_witness9ValidatorVAASSRszlE1VV7FailureV" -// Protocol conformance descriptor for Computed : Assocked. -// GLOBAL-LABEL: @"$s23associated_type_witness8ComputedVyxq_GAA8AssockedAAMc" = hidden constant -// GLOBAL-SAME: i16 4, -// GLOBAL-SAME: i16 1, -// No instantiator function -// GLOBAL-SAME: i32 0, -// GLOBAL-SAME: i32 trunc (i64 sub (i64 ptrtoint ([16 x i8*]* [[PRIVATE:@.*]] to i64), i64 ptrtoint -// GLOBAL-SAME: } - -// Protocol conformance descriptor for GenericComputed : DerivedFromSimpleAssoc. -// GLOBAL-LABEL: @"$s23associated_type_witness15GenericComputedVyxGAA22DerivedFromSimpleAssocAAMc" = hidden constant -// GLOBAL-SAME: i16 2, -// GLOBAL-SAME: i16 1, - -// Relative reference to instantiator function -// GLOBAL-SAME: i32 trunc (i64 sub (i64 ptrtoint (void (i8**, %swift.type*, i8**)* @"$s23associated_type_witness15GenericComputedVyxGAA22DerivedFromSimpleAssocAAWI" to i64), diff --git a/test/IRGen/lazy_metadata_no_reflection.swift b/test/IRGen/lazy_metadata_no_reflection.swift index e9896a4bfd776..f1ad1a0f2ae1b 100644 --- a/test/IRGen/lazy_metadata_no_reflection.swift +++ b/test/IRGen/lazy_metadata_no_reflection.swift @@ -34,5 +34,5 @@ public func forceMetadata() { takeMetadata(HasPropertyType.self) } -// CHECK-LABEL: @"$s4test1SVMn" = hidden constant // CHECK-LABEL: @"$s4test1SVSQAAMc" = hidden constant +// CHECK-LABEL: @"$s4test1SVMn" = hidden constant diff --git a/test/IRGen/protocol_conformance_records.swift b/test/IRGen/protocol_conformance_records.swift index a2adbef23aa54..fce8f2d76d559 100644 --- a/test/IRGen/protocol_conformance_records.swift +++ b/test/IRGen/protocol_conformance_records.swift @@ -108,10 +108,6 @@ public struct Concrete : AssociateConformance { // -- no flags are set, and no generic witness table follows // CHECK-SAME: i32 0 } -// CHECK-LABEL: @"\01l_protocols" -// CHECK-SAME: @"$s28protocol_conformance_records8RuncibleMp" -// CHECK-SAME: @"$s28protocol_conformance_records5SpoonMp" - public protocol Spoon { } // Conditional conformances @@ -167,6 +163,10 @@ extension Dependent : Associate { public typealias X = (T, T) } +// CHECK-LABEL: @"\01l_protocols" +// CHECK-SAME: @"$s28protocol_conformance_records8RuncibleMp" +// CHECK-SAME: @"$s28protocol_conformance_records5SpoonMp" + // CHECK-LABEL: @"\01l_protocol_conformances" = private constant // CHECK-SAME: @"$s28protocol_conformance_records15NativeValueTypeVAA8RuncibleAAMc" // CHECK-SAME: @"$s28protocol_conformance_records15NativeClassTypeCAA8RuncibleAAMc" diff --git a/test/IRGen/protocol_resilience.sil b/test/IRGen/protocol_resilience.sil index 43379afcd51d2..ca055c97834fd 100644 --- a/test/IRGen/protocol_resilience.sil +++ b/test/IRGen/protocol_resilience.sil @@ -11,6 +11,24 @@ import SwiftShims import resilient_protocol +// Protocol conformance descriptor for ResilientConformingType : OtherResilientProtocol + +// CHECK: @"$s19protocol_resilience23ResilientConformingTypeV010resilient_A005OtherC8ProtocolAAMc" = + +// CHECK-SAME: i32 131072, + +// -- number of witness table entries +// CHECK-SAME: i16 0, + +// -- size of private area + 'requires instantiation' bit +// CHECK-SAME: i16 1, + +// -- instantiator function +// CHECK-SAME: i32 0 + +// CHECK-SAME: } + + // Protocol descriptor for ResilientProtocol // CHECK: [[RESILIENT_PROTOCOL_NAME:@.*]] = private constant [18 x i8] c"ResilientProtocol\00 @@ -88,23 +106,6 @@ protocol InternalProtocol { // CHECK-NOT: @"$s19protocol_resilience26ConformsWithResilientAssocVAA03HaseF0AAWp" = {{(protected )?}}internal -// Protocol conformance descriptor for ResilientConformingType : OtherResilientProtocol - -// CHECK: @"$s19protocol_resilience23ResilientConformingTypeV010resilient_A005OtherC8ProtocolAAMc" = - -// CHECK-SAME: i32 131072, - -// -- number of witness table entries -// CHECK-SAME: i16 0, - -// -- size of private area + 'requires instantiation' bit -// CHECK-SAME: i16 1, - -// -- instantiator function -// CHECK-SAME: i32 0 - -// CHECK-SAME: } - // ConformsWithRequirements protocol conformance descriptor // CHECK: "$s19protocol_resilience24ConformsWithRequirementsV010resilient_A008ProtocoldE0AAMc" = hidden constant { diff --git a/test/IRGen/reflection_metadata.swift b/test/IRGen/reflection_metadata.swift index 6fb4080cff057..c398506055f0d 100644 --- a/test/IRGen/reflection_metadata.swift +++ b/test/IRGen/reflection_metadata.swift @@ -7,9 +7,9 @@ // STRIP_REFLECTION_NAMES_DAG: section "{{[^"]*swift5_assocty|.sw5asty\$B}} // STRIP_REFLECTION_NAMES-DAG: section "{{[^"]*swift5_capture|.sw5cptr\$B}} // STRIP_REFLECTION_NAMES-DAG: section "{{[^"]*swift5_typeref|.sw5tyrf\$B}} +// STRIP_REFLECTION_NAMES-DAG: private constant [6 x i8] c"Inner\00", section "{{[^"]*swift5_reflstr|.sw5rfst\$B}} // STRIP_REFLECTION_NAMES-NOT: section "{{[^"]*swift5_reflstr|.sw5rfst\$B}} // STRIP_REFLECTION_NAMES-NOT: section "{{[^"]*swift5_builtin|.sw5bltn\$B}} - // STRIP_REFLECTION_NAMES-DAG: @"$s19reflection_metadata10MyProtocol_pMF" = internal constant {{.*}}section "{{[^"]*swift5_fieldmd|.sw5flmd\$B}} // STRIP_REFLECTION_METADATA-NOT: section "{{[^"]*swift5_reflect|.sw5rfst\$B}} From 05ed0dd1a6d73d7ddf35cb110e408ff5e88ae49e Mon Sep 17 00:00:00 2001 From: Arnold Schwaighofer Date: Wed, 10 Jun 2020 08:39:10 -0700 Subject: [PATCH 2/2] Add back test case --- .../conditional_conformance_typemetadata.swift | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 test/IRGen/conditional_conformance_typemetadata.swift diff --git a/test/IRGen/conditional_conformance_typemetadata.swift b/test/IRGen/conditional_conformance_typemetadata.swift new file mode 100644 index 0000000000000..2072714fd6e0d --- /dev/null +++ b/test/IRGen/conditional_conformance_typemetadata.swift @@ -0,0 +1,16 @@ +// RUN: %target-swift-frontend -O -emit-ir %s +// RUN: %target-swift-frontend -O -primary-file %s -emit-ir + +// Make sure that we don't crash in IRGen because the only reference to the type +// E is in the protocol conformance descriptor describing the conditional +// conformace. + +private enum E {} + +private protocol P { associatedtype AT } + +private struct S {} + +extension S: P where A == E { typealias AT = B } + +print(S.AT.self)