Skip to content

Commit 08a404c

Browse files
authored
Merge pull request #12346 from adrian-prantl/18296829
Revert
2 parents d3de4f2 + dd3ac0e commit 08a404c

File tree

5 files changed

+39
-100
lines changed

5 files changed

+39
-100
lines changed

include/swift/AST/Decl.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,9 +2209,6 @@ class ValueDecl : public Decl {
22092209
return result;
22102210
}
22112211

2212-
/// Determine whether this Decl has either Private or FilePrivate access.
2213-
bool isOutermostPrivateOrFilePrivateScope() const;
2214-
22152212
/// Returns the outermost DeclContext from which this declaration can be
22162213
/// accessed, or null if the declaration is public.
22172214
///

lib/AST/ASTMangler.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,25 @@ void ASTMangler::appendSymbolKind(SymbolKind SKind) {
533533
}
534534
}
535535

536+
/// Returns true if one of the ancestor DeclContexts of \p D is either marked
537+
/// private or is a local context.
538+
static bool isInPrivateOrLocalContext(const ValueDecl *D) {
539+
const DeclContext *DC = D->getDeclContext();
540+
if (!DC->isTypeContext()) {
541+
assert((DC->isModuleScopeContext() || DC->isLocalContext()) &&
542+
"unexpected context kind");
543+
return DC->isLocalContext();
544+
}
545+
546+
auto *nominal = DC->getAsNominalTypeOrNominalTypeExtensionContext();
547+
if (nominal == nullptr)
548+
return false;
549+
550+
if (nominal->getFormalAccess() <= AccessLevel::FilePrivate)
551+
return true;
552+
return isInPrivateOrLocalContext(nominal);
553+
}
554+
536555
static bool getUnnamedParamIndex(const ParameterList *ParamList,
537556
const ParamDecl *D,
538557
unsigned &UnnamedIndex) {
@@ -574,8 +593,11 @@ static unsigned getUnnamedParamIndex(const ParamDecl *D) {
574593
}
575594

576595
static StringRef getPrivateDiscriminatorIfNecessary(const ValueDecl *decl) {
577-
if (!decl->isOutermostPrivateOrFilePrivateScope())
596+
if (!decl->hasAccess() ||
597+
decl->getFormalAccess() > AccessLevel::FilePrivate ||
598+
isInPrivateOrLocalContext(decl)) {
578599
return StringRef();
600+
}
579601

580602
// Mangle non-local private declarations with a textual discriminator
581603
// based on their enclosing file.

lib/AST/Decl.cpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,34 +1433,6 @@ AbstractStorageDecl::getAccessStrategy(AccessSemantics semantics,
14331433
llvm_unreachable("bad access semantics");
14341434
}
14351435

1436-
static bool hasPrivateOrFilePrivateFormalAccess(const ValueDecl *D) {
1437-
return D->hasAccess() && D->getFormalAccess() <= AccessLevel::FilePrivate;
1438-
}
1439-
1440-
/// Returns true if one of the ancestor DeclContexts of this ValueDecl is either
1441-
/// marked private or fileprivate or is a local context.
1442-
static bool isInPrivateOrLocalContext(const ValueDecl *D) {
1443-
const DeclContext *DC = D->getDeclContext();
1444-
if (!DC->isTypeContext()) {
1445-
assert((DC->isModuleScopeContext() || DC->isLocalContext()) &&
1446-
"unexpected context kind");
1447-
return DC->isLocalContext();
1448-
}
1449-
1450-
auto *nominal = DC->getAsNominalTypeOrNominalTypeExtensionContext();
1451-
if (nominal == nullptr)
1452-
return false;
1453-
1454-
if (hasPrivateOrFilePrivateFormalAccess(nominal))
1455-
return true;
1456-
return isInPrivateOrLocalContext(nominal);
1457-
}
1458-
1459-
bool ValueDecl::isOutermostPrivateOrFilePrivateScope() const {
1460-
return hasPrivateOrFilePrivateFormalAccess(this) &&
1461-
!isInPrivateOrLocalContext(this);
1462-
}
1463-
14641436
bool AbstractStorageDecl::hasFixedLayout() const {
14651437
// If we're in a nominal type, just query the type.
14661438
auto *dc = getDeclContext();

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,19 +1395,6 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
13951395
return nullptr;
13961396
}
13971397

1398-
/// The private discriminator is represented as an inline namespace.
1399-
llvm::DIScope *getFilePrivateScope(llvm::DIScope *Parent, TypeDecl *Decl,
1400-
DeclContext *Context) {
1401-
// Retrieve the private discriminator.
1402-
if (auto *SF = Context->getParentSourceFile()) {
1403-
auto PrivateDiscriminator = SF->getPrivateDiscriminator();
1404-
if (!PrivateDiscriminator.empty())
1405-
return DBuilder.createNameSpace(Parent, PrivateDiscriminator.str(),
1406-
/*ExportSymbols=*/true);
1407-
}
1408-
llvm_unreachable("unknown private discriminator");
1409-
}
1410-
14111398
llvm::DIType *getOrCreateType(DebugTypeInfo DbgTy) {
14121399
// Is this an empty type?
14131400
if (DbgTy.isNull())
@@ -1451,13 +1438,6 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
14511438
}
14521439
if (!Scope)
14531440
Scope = getOrCreateContext(Context);
1454-
1455-
// Scope outermost fileprivate decls in an inline private discriminator
1456-
// namespace.
1457-
if (auto *Decl = DbgTy.getDecl())
1458-
if (Context && Decl->isOutermostPrivateOrFilePrivateScope())
1459-
Scope = getFilePrivateScope(Scope, Decl, Context);
1460-
14611441
llvm::DIType *DITy = createType(DbgTy, MangledName, Scope, getFile(Scope));
14621442

14631443
// Incrementally build the DIRefMap.
@@ -1538,9 +1518,9 @@ IRGenDebugInfoImpl::IRGenDebugInfoImpl(const IRGenOptions &Opts,
15381518
CU_Nodes->addOperand(*CU);
15391519

15401520
// Create a module for the current compile unit.
1541-
auto *MDecl = IGM.getSwiftModule();
15421521
llvm::sys::path::remove_filename(AbsMainFile);
1543-
MainModule = getOrCreateModule(MDecl, TheCU, Opts.ModuleName, AbsMainFile);
1522+
MainModule = getOrCreateModule(IGM.getSwiftModule(), TheCU, Opts.ModuleName,
1523+
AbsMainFile);
15441524
DBuilder.createImportedModule(MainFile, MainModule, MainFile, 0);
15451525

15461526
// Macro definitions that were defined by the user with "-Xcc -D" on the
Lines changed: 14 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,25 @@
11
// Private discriminators should only be emitted for multi-file projects.
22

3-
// RUN: %target-swift-frontend -emit-ir %s -g -o - \
4-
// RUN: | %FileCheck --check-prefix=SINGLE %s
3+
// RUN: %target-swift-frontend -emit-ir %s -g -o - | %FileCheck --check-prefix=SINGLE %s
54
// SINGLE-NOT: !DICompileUnit({{.*}}-private-discriminator
65

7-
// RUN: %target-swift-frontend %S/../Inputs/empty.swift -primary-file %s \
8-
// RUN: -emit-ir -g | %FileCheck %s
6+
// RUN: %target-swift-frontend %S/../Inputs/empty.swift -primary-file %s -emit-ir -g | %FileCheck %s
97
// CHECK: !DICompileUnit({{.*}}flags: {{[^,]*}}-private-discriminator [[DISCRIMINATOR:_[A-Z0-9]+]]
10-
// CHECK: ![[MOD:.*]] = !DIModule(scope: null,
11-
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "InA",
12-
// CHECK-SAME: scope: ![[A:[0-9]+]],
13-
// CHECK: ![[A]] = !DICompositeType(tag: DW_TAG_structure_type, name: "A",
14-
// CHECK-SAME: scope: ![[NS:[0-9]+]]
15-
// CHECK: !DINamespace(name: "[[DISCRIMINATOR]]",
16-
// CHECK-SAME: scope: ![[OUTER:[0-9]+]], exportSymbols: true)
17-
// CHECK: ![[OUTER]] = !DICompositeType(tag: DW_TAG_structure_type,
18-
// CHECK-SAME: name: "Outer",
19-
// CHECK-SAME: scope: ![[MOD]],
208

219
func markUsed<T>(_ t: T) {}
2210

23-
public class Outer {
24-
fileprivate class A {
25-
fileprivate struct InA {
26-
let i : Int64
27-
init(_ val : Int64) { i = val }
28-
}
29-
30-
init(val : Int64) { member = InA(val) }
31-
fileprivate let member : InA
32-
// CHECK: !DISubprogram(name: "getMember"
33-
// CHECK-SAME: linkageName: "{{[^"]*}}[[DISCRIMINATOR]]
34-
// CHECK-SAME: line: [[@LINE+2]]
35-
// CHECK-SAME: isLocal: true, isDefinition: true
36-
fileprivate func getMember() -> Int64 { return member.i }
37-
}
11+
private class A {
12+
init(val : Int64) { member = val }
13+
private let member : Int64
14+
// CHECK: !DISubprogram(name: "getMember"
15+
// CHECK-SAME: linkageName: "{{[^"]*}}[[DISCRIMINATOR]]
16+
// CHECK-SAME: line: [[@LINE+2]]
17+
// CHECK-SAME: isLocal: true, isDefinition: true
18+
private func getMember() -> Int64 { return member }
19+
func getVal() -> Int64 { return getMember() }
3820
}
3921

40-
// CHECK: ![[G:[0-9]+]] = distinct !DISubprogram(name: "g",
41-
// CHECK-SAME: scope: ![[MOD]]
42-
fileprivate func g() -> Int64 {
43-
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "InG",
44-
// CHECK-SAME: scope: ![[G]],
45-
struct InG {
46-
let i : Int64
47-
init(_ val : Int64) { i = val }
48-
}
49-
50-
return InG(42).i
51-
}
52-
53-
// CHECK: distinct !DISubprogram(name: "f", {{.*}}, scope: ![[MOD]]
54-
public func f() {
55-
let a = Outer.A(val: g())
56-
markUsed(a)
22+
func f() {
23+
let a = A(val: 42)
24+
markUsed(a.getVal())
5725
}

0 commit comments

Comments
 (0)