Skip to content

[IRGen] Fix issues impacting the mangled name <-> roundtrip verification #19958

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions lib/IRGen/GenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ void IRGenModule::emitRuntimeRegistration() {
if (DebugInfo && !Context.LangOpts.DebuggerSupport)
DebugInfo->emitArtificialFunction(RegIGF, RegistrationFunction);

// Register ObjC protocols, classes, and extensions we added.
// Register ObjC protocols we added.
if (ObjCInterop) {
if (!ObjCProtocols.empty()) {
// We need to initialize ObjC protocols in inheritance order, parents
Expand Down Expand Up @@ -649,14 +649,6 @@ void IRGenModule::emitRuntimeRegistration() {
.visitMembers(proto);
}
}

for (llvm::WeakTrackingVH &ObjCClass : ObjCClasses) {
RegIGF.Builder.CreateCall(getInstantiateObjCClassFn(), {ObjCClass});
}

for (ExtensionDecl *ext : ObjCCategoryDecls) {
CategoryInitializerVisitor(RegIGF, ext).visitMembers(ext);
}
}

// Register Swift protocols if we added any.
Expand Down Expand Up @@ -716,6 +708,17 @@ void IRGenModule::emitRuntimeRegistration() {
RegIGF.Builder.CreateCall(getRegisterTypeMetadataRecordsFn(), {begin, end});
}

// Register Objective-C classes and extensions we added.
if (ObjCInterop) {
for (llvm::WeakTrackingVH &ObjCClass : ObjCClasses) {
RegIGF.Builder.CreateCall(getInstantiateObjCClassFn(), {ObjCClass});
}

for (ExtensionDecl *ext : ObjCCategoryDecls) {
CategoryInitializerVisitor(RegIGF, ext).visitMembers(ext);
}
}

if (!FieldDescriptors.empty()) {
emitFieldDescriptors();
}
Expand Down Expand Up @@ -898,7 +901,7 @@ llvm::Constant *IRGenModule::getAddrOfAssociatedTypeGenericParamRef(
// Otherwise, build the reference path.
ConstantInitBuilder builder(*this);
auto B = builder.beginStruct();
B.addInt32(ordinal << 1);
B.addInt32(ordinal);

for (auto *assocType : reversed(assocTypePath)) {
auto proto = getConstantReferenceForProtocolDescriptor(
Expand Down
49 changes: 35 additions & 14 deletions test/IRGen/generic_types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,6 @@
// CHECK-SAME: i32 {{3|2}},
// CHECK-SAME: }

// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} internal %swift.type* @"$s13generic_types1ACMi"(%swift.type_descriptor*, i8**, i8*) {{.*}} {
// CHECK: [[T0:%.*]] = bitcast i8** %1 to %swift.type**
// CHECK: %T = load %swift.type*, %swift.type** [[T0]],
// CHECK: [[METADATA:%.*]] = call %swift.type* @swift_allocateGenericClassMetadata(%swift.type_descriptor* %0, i8** %1, i8* %2)
// CHECK-NEXT: ret %swift.type* [[METADATA]]
// CHECK: }

// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} internal %swift.type* @"$s13generic_types1BCMi"(%swift.type_descriptor*, i8**, i8*) {{.*}} {
// CHECK: [[T0:%.*]] = bitcast i8** %1 to %swift.type**
// CHECK: %T = load %swift.type*, %swift.type** [[T0]],
// CHECK: [[METADATA:%.*]] = call %swift.type* @swift_allocateGenericClassMetadata(%swift.type_descriptor* %0, i8** %1, i8* %2)
// CHECK-NEXT: ret %swift.type* [[METADATA]]
// CHECK: }

class A<T> {
var x = 0

Expand Down Expand Up @@ -149,3 +135,38 @@ func testFixed() {
var a = F(value: ClassA()).value
var b = F(value: ClassB()).value
}

// Checking generic requirement encoding
protocol P1 { }
protocol P2 {
associatedtype A
}

struct X1: P1 { }
struct X2: P2 {
typealias A = X1
}

// Check for correct root generic parameters in the generic requirements of X3.
// CHECK-LABEL: @"$sq_1A13generic_types2P2P_MXA" = linkonce_odr hidden constant

// Root: generic parameter 1
// CHECK-SAME: i32 1

// Protocol P2
// CHECK-SAME: $s13generic_types2P2Mp
struct X3<T, U> where U: P2, U.A: P1 { }

// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} internal %swift.type* @"$s13generic_types1ACMi"(%swift.type_descriptor*, i8**, i8*) {{.*}} {
// CHECK: [[T0:%.*]] = bitcast i8** %1 to %swift.type**
// CHECK: %T = load %swift.type*, %swift.type** [[T0]],
// CHECK: [[METADATA:%.*]] = call %swift.type* @swift_allocateGenericClassMetadata(%swift.type_descriptor* %0, i8** %1, i8* %2)
// CHECK-NEXT: ret %swift.type* [[METADATA]]
// CHECK: }

// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} internal %swift.type* @"$s13generic_types1BCMi"(%swift.type_descriptor*, i8**, i8*) {{.*}} {
// CHECK: [[T0:%.*]] = bitcast i8** %1 to %swift.type**
// CHECK: %T = load %swift.type*, %swift.type** [[T0]],
// CHECK: [[METADATA:%.*]] = call %swift.type* @swift_allocateGenericClassMetadata(%swift.type_descriptor* %0, i8** %1, i8* %2)
// CHECK-NEXT: ret %swift.type* [[METADATA]]
// CHECK: }
8 changes: 4 additions & 4 deletions test/Prototypes/CollectionTransformers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
// RUN: %target-run-stdlib-swift-swift3
// RUN: %target-run-stdlib-swift
// REQUIRES: executable_test

// FIXME: This test runs very slowly on watchOS.
// UNSUPPORTED: OS=watchos

public enum ApproximateCount {
case Unknown
case Precise(IntMax)
case Underestimate(IntMax)
case Overestimate(IntMax)
case Precise(Int64)
case Underestimate(Int64)
case Overestimate(Int64)
}

public protocol ApproximateCountableSequence : Sequence {
Expand Down