Skip to content

[6.0][IRGen] Strip marker protocols in a few more places #74138

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 2 commits into from
Jun 5, 2024
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
3 changes: 3 additions & 0 deletions lib/IRGen/IRGenMangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ IRGenMangler::mangleTypeForFlatUniqueTypeRef(CanGenericSignature sig,
// mangled name.
configureForSymbolicMangling();

llvm::SaveAndRestore<bool> savedAllowMarkerProtocols(
AllowMarkerProtocols, false);

// We don't make the substitution adjustments above because they're
// target-specific and so would break the goal of getting a unique
// string.
Expand Down
3 changes: 0 additions & 3 deletions lib/IRGen/IRGenMangler.h
Original file line number Diff line number Diff line change
Expand Up @@ -706,9 +706,6 @@ class IRGenMangler : public Mangle::ASTMangler {
llvm::function_ref<void ()> body);

std::string mangleTypeSymbol(Type type, const char *Op) {
llvm::SaveAndRestore<bool> savedAllowMarkerProtocols(AllowMarkerProtocols,
false);

beginMangling();
appendType(type, nullptr);
appendOperator(Op);
Expand Down
10 changes: 10 additions & 0 deletions lib/IRGen/MetadataRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1989,6 +1989,16 @@ namespace {

MetadataResponse visitExistentialType(CanExistentialType type,
DynamicMetadataRequest request) {
if (auto *PCT =
type->getConstraintType()->getAs<ProtocolCompositionType>()) {
auto constraintTy = PCT->withoutMarkerProtocols();
if (constraintTy->getClassOrBoundGenericClass()) {
auto response = IGF.emitTypeMetadataRef(
constraintTy->getCanonicalType(), request);
return setLocal(type, response);
}
}

if (auto metadata = tryGetLocal(type, request))
return metadata;

Expand Down
6 changes: 3 additions & 3 deletions test/IRGen/marker_protocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extension Int: P { }
extension Array: P where Element: P { }

// No mention of the marker protocol for runtime type instantiation.
// CHECK-LABEL: @"$sSS_yptMD" =
// CHECK-LABEL: @"$sSS_15marker_protocol1P_ptMD" =
// CHECK-SAME: @"symbolic SS_ypt"

// CHECK-LABEL: @"$s15marker_protocol1QMp" = {{(dllexport |protected )?}}constant
Expand Down Expand Up @@ -47,7 +47,7 @@ struct HasMarkers {

// Note: no mention of marker protocols when forming a dictionary.
// CHECK-LABEL: define{{.*}}@"$s15marker_protocol0A12InDictionaryypyF"
// CHECK: call ptr @__swift_instantiateConcreteTypeFromMangledName({{.*}} @"$sSS_yptMD")
// CHECK: call ptr @__swift_instantiateConcreteTypeFromMangledName({{.*}} @"$sSS_15marker_protocol1P_ptMD")
public func markerInDictionary() -> Any {
let dict: [String: P] = ["answer" : 42]
return dict
Expand Down Expand Up @@ -92,7 +92,7 @@ let v1 = (any C & P).self
let v2 = C.self

// CHECK-LABEL: define hidden swiftcc void @"$s15marker_protocol23testProtocolCompositionyyF"()
// CHECK: [[V1:%.*]] = call ptr @__swift_instantiateConcreteTypeFromMangledName(ptr @"$s15marker_protocol1CCMD")
// CHECK: [[V1:%.*]] = call ptr @__swift_instantiateConcreteTypeFromMangledName(ptr @"$s15marker_protocol1P_AA1CCXcMD")
// CHECK: [[V2:%.*]] = load ptr, ptr @"$s15marker_protocol2v2AA1CCmvp"
func testProtocolComposition() {
print(v1 == v2)
Expand Down
4 changes: 2 additions & 2 deletions test/IRGen/marker_protocol_backdeploy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ protocol R { }
// Suppress marker protocols when forming existentials at runtime
public func takeAnyType<T>(_: T.Type) { }

// CHECK-LABEL: define {{.*}}@"$s26marker_protocol_backdeploy1Q_AA1RpMa"
// CHECK: $s26marker_protocol_backdeploy1Q_AA1RpML
// CHECK-LABEL: define {{.*}}@"$ss8Sendable_26marker_protocol_backdeploy1QAB1RpMa"
// CHECK: ss8Sendable_26marker_protocol_backdeploy1QAB1RpML
// CHECK-NOT: Sendable
// CHECK: s26marker_protocol_backdeploy1QMp
// CHECK-NOT: Sendable
Expand Down
31 changes: 31 additions & 0 deletions test/Interpreter/protocol_composition_with_markers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,34 @@ do {
print(v1 == v2)
// CHECK: true
}

@_marker
protocol Marker {
}

do {
print(G<any (C & Sendable)>.self)
// CHECK: G<C>

class D<T> {
}

print((D<Int> & Sendable).self)
// CHECK: D<Int>

print((D<C & Marker> & Sendable).self)
// CHECK: D<C>

print((any Marker & Sendable).self)
// CHECK: Any

print((AnyObject & Sendable & Marker).self)
// CHECK: AnyObject

func generic<T>(_: T.Type) {
print((D<T> & Sendable).self)
}

generic(Int.self)
// CHECK: D<Int>
}
27 changes: 27 additions & 0 deletions test/Interpreter/rdar128667580.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// RUN: %empty-directory(%t)
// RUN: split-file %s %t

// RUN: %target-clang %t/Impl.m -c -o %t/Test.o
// RUN: %target-build-swift %t/main.swift -import-objc-header %t/Test.h %t/Test.o -Xfrontend -disable-concrete-type-metadata-mangled-name-accessors -o %t/main
// RUN: %target-codesign %t/main
// RUN: %target-run %t/main | %FileCheck %s

// REQUIRES: executable_test
// REQUIRES: objc_interop
// REQUIRES: concurrency

//--- Test.h
#import "Foundation/Foundation.h"

@interface Test : NSObject { }
@end

//--- Impl.m
#import "Test.h"

@implementation Test
@end

//--- main.swift
print((any Test & Sendable).self)
// CHECK: Test