Skip to content

[IRGen] Use symbolic references to (file)private entities in mangled names #20011

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
6 changes: 5 additions & 1 deletion lib/IRGen/IRGenMangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ IRGenMangler::withSymbolicReferences(IRGenModule &IGM,
// TODO: We ought to be able to use indirect symbolic references even
// when the referent may be in another file, once the on-disk
// ObjectMemoryReader can handle them.
if (!IGM.CurSourceFile || IGM.CurSourceFile != type->getParentSourceFile())
// Private entities are known to be accessible.
if (type->getEffectiveAccess() >= AccessLevel::Internal &&
(!IGM.CurSourceFile ||
IGM.CurSourceFile != type->getParentSourceFile()))
return false;

// @objc protocols don't have descriptors.
Expand All @@ -114,6 +117,7 @@ IRGenMangler::withSymbolicReferences(IRGenModule &IGM,
llvm_unreachable("symbolic referent not handled");
}
};

SymbolicReferences.clear();

body();
Expand Down
15 changes: 14 additions & 1 deletion test/IRGen/associated_type_witness.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil -primary-file %s -emit-ir > %t.ll
// RUN: %FileCheck %s -check-prefix=GLOBAL < %t.ll
// RUN: %FileCheck %s < %t.ll

// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil -primary-file %s -emit-ir -wmo -num-threads 1 > %t.ll.wmo
// RUN: %FileCheck %s -check-prefix=GLOBAL < %t.ll.wmo
// RUN: %FileCheck %s < %t.ll.wmo
// REQUIRES: CPU=x86_64

protocol P {}
Expand All @@ -12,6 +16,16 @@ protocol Assocked {

struct Universal : P, Q {}


// CHECK-LABEL: @"symbolic _____ 23associated_type_witness12OuterPrivate{{.*}}V" = linkonce_odr hidden constant
// CHECK-SAME: @"$s23associated_type_witness12OuterPrivate{{.*}}5InnerE0V9InnermostVMn"
private struct OuterPrivate {
struct InnerPrivate: HasSimpleAssoc {
struct Innermost { }
typealias Assoc = Innermost
}
}

// CHECK: [[ASSOC_TYPE_NAMES:@.*]] = private constant [29 x i8] c"OneAssoc TwoAssoc ThreeAssoc\00"
// CHECK: @"$s23associated_type_witness18HasThreeAssocTypesMp" =
// CHECK-SAME: [[ASSOC_TYPE_NAMES]] to i64
Expand Down Expand Up @@ -116,7 +130,6 @@ protocol HasSimpleAssoc {
}
protocol DerivedFromSimpleAssoc : HasSimpleAssoc {}


// Generic witness table pattern for GenericComputed : DerivedFromSimpleAssoc.
// GLOBAL-LABEL: @"$s23associated_type_witness15GenericComputedVyxGAA22DerivedFromSimpleAssocAAWp" = internal constant [2 x i8*]
// GLOBAL-SAME: @"$s23associated_type_witness15GenericComputedVyxGAA22DerivedFromSimpleAssocAAMc"
Expand Down
32 changes: 32 additions & 0 deletions test/Runtime/associated_type_demangle_private.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// RUN: %empty-directory(%t)
// RUN: %target-build-swift -parse-stdlib %s -module-name main -o %t/a.out
// RUN: %target-codesign %t/a.out
// RUN: %target-run %t/a.out
// REQUIRES: executable_test

import Swift
import StdlibUnittest

protocol P {
associatedtype A
}

fileprivate struct Foo {
fileprivate struct Inner: P {
fileprivate struct Innermost { }
typealias A = Innermost
}
}

func getP_A<T: P>(_: T.Type) -> Any.Type {
return T.A.self
}

let AssociatedTypeDemangleTests = TestSuite("AssociatedTypeDemangle")


AssociatedTypeDemangleTests.test("private types") {
expectEqual(Foo.Inner.Innermost.self, getP_A(Foo.Inner.self))
}

runAllTests()