Skip to content

Commit f24976b

Browse files
authored
Merge pull request #70358 from tshortli/exportability-fixes
AST: DeclExportabilityVisitor fixes.
2 parents a4a6c69 + 3c68c20 commit f24976b

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

include/swift/AST/DeclExportabilityVisitor.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,8 @@ class DeclExportabilityVisitor
149149
return true; \
150150
}
151151
UNREACHABLE(Module);
152-
UNREACHABLE(TopLevelCode);
153-
UNREACHABLE(PoundDiagnostic);
154152
UNREACHABLE(Missing);
155153
UNREACHABLE(MissingMember);
156-
UNREACHABLE(MacroExpansion);
157154
UNREACHABLE(GenericTypeParam);
158155
UNREACHABLE(Param);
159156

@@ -167,11 +164,14 @@ class DeclExportabilityVisitor
167164
// context has already been checked.
168165
#define UNINTERESTING(KIND) \
169166
bool visit##KIND##Decl(const KIND##Decl *D) { return true; }
167+
UNINTERESTING(TopLevelCode);
170168
UNINTERESTING(IfConfig);
171169
UNINTERESTING(Import);
170+
UNINTERESTING(PoundDiagnostic);
172171
UNINTERESTING(PrecedenceGroup);
173172
UNINTERESTING(EnumCase);
174173
UNINTERESTING(Operator);
174+
UNINTERESTING(MacroExpansion);
175175

176176
#undef UNINTERESTING
177177
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// REQUIRES: swift_swift_parser, executable_test
2+
3+
// RUN: %empty-directory(%t)
4+
// RUN: %host-build-swift -swift-version 5 -emit-library -o %t/%target-library-name(MacroDefinition) -module-name=MacroDefinition %S/Inputs/syntax_macro_definitions.swift
5+
6+
// RUN: %target-swift-frontend -swift-version 5 -emit-module -o %t/freestanding_macro_library.swiftmodule %S/Inputs/freestanding_macro_library.swift -module-name freestanding_macro_library -load-plugin-library %t/%target-library-name(MacroDefinition)
7+
8+
// RUN: %target-swift-frontend -parse-as-library -emit-sil -load-plugin-library %t/%target-library-name(MacroDefinition) %s -module-name MacroUser -experimental-skip-non-exportable-decls | %FileCheck %s
9+
10+
@freestanding(declaration)
11+
macro anonymousTypes(public: Bool = false, causeErrors: Bool = false, _: () -> String) = #externalMacro(module: "MacroDefinition", type: "DefineAnonymousTypesMacro")
12+
13+
// CHECK: sil @$s9MacroUser03$s9A70User33_B2D49A1BE4DC7AF5CC327EB8EE2214BDLl14anonymousTypesfMf_4namefMu_C5helloSSyF : $@convention(method) (@guaranteed $s9MacroUser33_B2D49A1BE4DC7AF5CC327EB8EE2214BDLl14anonymousTypesfMf_4namefMu_) -> @owned String {
14+
#anonymousTypes(public: true) { "hello" }
15+
16+
// CHECK-NOT: s9MacroUser03$s9A71User33_B2D49A1BE4DC7AF5CC327EB8EE2214BDLl14anonymousTypesfMf_4namefMu0_O5helloSSyF
17+
#anonymousTypes(public: false) { "goodbye" }

test/SILGen/skip_non_exportable_decls.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import Swift
66

7+
#warning("!")
8+
79
// CHECK-NO-SKIP: sil_global private @$s4Test17internalGlobalVar_Wz : $Builtin.Word
810
// CHECK-SKIP-NOT: s4Test17internalGlobalVar_Wz
911

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-silgen %s -module-name Test | %FileCheck %s --check-prefixes=CHECK,CHECK-NO-SKIP
3+
// RUN: %target-swift-frontend -emit-silgen %s -module-name Test -experimental-skip-non-exportable-decls | %FileCheck %s --check-prefixes=CHECK,CHECK-SKIP
4+
5+
// CHECK-NO-SKIP: sil_global hidden @$s4Test1xSivp : $Int
6+
// CHECK-SKIP: sil_global hidden_external @$s4Test1xSivp : $Int
7+
var x = foo()
8+
9+
// CHECK-NO-SKIP: sil hidden{{.*}} @$s4Test3fooSiyF : $@convention(thin) () -> Int {
10+
// CHECK-SKIP: sil hidden_external @$s4Test3fooSiyF : $@convention(thin) () -> Int
11+
func foo() -> Int { return 1 }

0 commit comments

Comments
 (0)