Skip to content

Commit b049e69

Browse files
authored
Merge pull request swiftlang#71377 from tshortli/lazy-typecheck-requires-library-evolution
Frontend: Ignore lazy typechecking flags when emitting non-resilient modules
2 parents 4b72554 + 67661cc commit b049e69

8 files changed

+71
-42
lines changed

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ ERROR(cannot_emit_ir_skipping_function_bodies,none,
166166
WARNING(emit_reference_dependencies_without_primary_file,none,
167167
"ignoring -emit-reference-dependencies (requires -primary-file)", ())
168168

169+
WARNING(ignoring_option_requires_option,none,
170+
"ignoring %0 (requires %1)", (StringRef, StringRef))
171+
169172
WARNING(warn_implicit_concurrency_import_failed,none,
170173
"unable to perform implicit import of \"_Concurrency\" module: no such module found", ())
171174
REMARK(warn_implicit_string_processing_import_failed,none,

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -318,11 +318,21 @@ bool ArgsToFrontendOptionsConverter::convert(
318318
A->getOption().matches(OPT_serialize_debugging_options);
319319
}
320320

321-
Opts.SkipNonExportableDecls |=
322-
Args.hasArg(OPT_experimental_skip_non_exportable_decls);
323-
Opts.SkipNonExportableDecls |=
324-
Args.hasArg(OPT_experimental_skip_non_inlinable_function_bodies) &&
325-
Args.hasArg(OPT_experimental_skip_non_inlinable_function_bodies_is_lazy);
321+
if (Args.hasArg(OPT_enable_library_evolution)) {
322+
Opts.SkipNonExportableDecls |=
323+
Args.hasArg(OPT_experimental_skip_non_exportable_decls);
324+
325+
Opts.SkipNonExportableDecls |=
326+
Args.hasArg(OPT_experimental_skip_non_inlinable_function_bodies) &&
327+
Args.hasArg(
328+
OPT_experimental_skip_non_inlinable_function_bodies_is_lazy);
329+
} else {
330+
if (Args.hasArg(OPT_experimental_skip_non_exportable_decls))
331+
Diags.diagnose(SourceLoc(), diag::ignoring_option_requires_option,
332+
"-experimental-skip-non-exportable-decls",
333+
"-enable-library-evolution");
334+
}
335+
326336
// HACK: The driver currently erroneously passes all flags to module interface
327337
// verification jobs. -experimental-skip-non-exportable-decls is not
328338
// appropriate for verification tasks and should be ignored, though.

lib/Frontend/CompilerInvocation.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,10 +1523,25 @@ static bool ParseTypeCheckerArgs(TypeCheckerOptions &Opts, ArgList &Args,
15231523
Opts.DebugGenericSignatures |= Args.hasArg(OPT_debug_generic_signatures);
15241524
Opts.DebugInverseRequirements |= Args.hasArg(OPT_debug_inverse_requirements);
15251525

1526-
Opts.EnableLazyTypecheck |= Args.hasArg(OPT_experimental_lazy_typecheck);
1527-
Opts.EnableLazyTypecheck |=
1528-
Args.hasArg(OPT_experimental_skip_non_inlinable_function_bodies) &&
1529-
Args.hasArg(OPT_experimental_skip_non_inlinable_function_bodies_is_lazy);
1526+
if (Args.hasArg(OPT_enable_library_evolution)) {
1527+
Opts.EnableLazyTypecheck |= Args.hasArg(OPT_experimental_lazy_typecheck);
1528+
Opts.EnableLazyTypecheck |=
1529+
Args.hasArg(OPT_experimental_skip_non_inlinable_function_bodies) &&
1530+
Args.hasArg(
1531+
OPT_experimental_skip_non_inlinable_function_bodies_is_lazy);
1532+
} else {
1533+
if (Args.hasArg(OPT_experimental_lazy_typecheck))
1534+
Diags.diagnose(SourceLoc(), diag::ignoring_option_requires_option,
1535+
"-experimental-lazy-typecheck",
1536+
"-enable-library-evolution");
1537+
1538+
if (Args.hasArg(
1539+
OPT_experimental_skip_non_inlinable_function_bodies_is_lazy))
1540+
Diags.diagnose(SourceLoc(), diag::ignoring_option_requires_option,
1541+
"-experimental-skip-non-inlinable-function-bodies-is-lazy",
1542+
"-enable-library-evolution");
1543+
}
1544+
15301545
// HACK: The driver currently erroneously passes all flags to module interface
15311546
// verification jobs. -experimental-skip-non-exportable-decls is not
15321547
// appropriate for verification tasks and should be ignored, though.

test/Macros/skip_non_exportable_decls.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
// 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)
77

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
8+
// RUN: %target-swift-frontend -parse-as-library -enable-library-evolution -emit-sil -load-plugin-library %t/%target-library-name(MacroDefinition) %s -module-name MacroUser -experimental-skip-non-exportable-decls | %FileCheck %s
99

1010
@freestanding(declaration)
1111
macro anonymousTypes(public: Bool = false, causeErrors: Bool = false, _: () -> String) = #externalMacro(module: "MacroDefinition", type: "DefineAnonymousTypesMacro")

test/SILGen/lazy_typecheck_var_init.swift

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %target-swift-frontend -emit-silgen %s -parse-as-library -module-name Test | %FileCheck %s --check-prefixes=CHECK,CHECK-NON-LAZY
2-
// RUN: %target-swift-frontend -emit-silgen %s -parse-as-library -module-name Test -experimental-lazy-typecheck | %FileCheck %s --check-prefixes=CHECK,CHECK-LAZY
1+
// RUN: %target-swift-frontend -emit-silgen %s -parse-as-library -enable-library-evolution -module-name Test | %FileCheck %s --check-prefixes=CHECK,CHECK-NON-LAZY
2+
// RUN: %target-swift-frontend -emit-silgen %s -parse-as-library -enable-library-evolution -module-name Test -experimental-lazy-typecheck | %FileCheck %s --check-prefixes=CHECK,CHECK-LAZY
33

44
enum E {
55
case a, b
@@ -16,25 +16,25 @@ func internalFunc(_ e: E = .a) -> Int {
1616
public var globalVar = internalFunc()
1717

1818
public struct S {
19-
// CHECK-LABEL: sil [transparent]{{.*}} @$s4Test1SV11instanceVarSivpfi : $@convention(thin) () -> Int {
19+
// CHECK-LABEL: sil hidden [transparent]{{.*}} @$s4Test1SV11instanceVarSivpfi : $@convention(thin) () -> Int {
2020
public var instanceVar = internalFunc()
2121

22-
// CHECK-LABEL: sil [transparent]{{.*}} @$s4Test1SV12instanceVar2Sivpfi : $@convention(thin) () -> Int {
22+
// CHECK-LABEL: sil hidden [transparent]{{.*}} @$s4Test1SV12instanceVar2Sivpfi : $@convention(thin) () -> Int {
2323
public var instanceVar2 = internalFunc(.b)
2424

2525
// CHECK-NOT: s4Test1SV15lazyInstanceVarSivpfi
26-
// CHECK-LABEL: sil [transparent]{{.*}} @$s4Test1SV018$__lazy_storage_$_B11InstanceVar33_0E4F053AA3AB7D4CDE3A37DBA8EF0430LLSiSgvpfi : $@convention(thin) () -> Optional<Int> {
26+
// CHECK-LABEL: sil hidden [transparent]{{.*}} @$s4Test1SV018$__lazy_storage_$_B11InstanceVar33_0E4F053AA3AB7D4CDE3A37DBA8EF0430LLSiSgvpfi : $@convention(thin) () -> Optional<Int> {
2727
public lazy var lazyInstanceVar = internalFunc()
2828

2929
// CHECK-LABEL: sil private [global_init_once_fn]{{.*}} @$s4Test1SV9staticVar_WZ : $@convention(c) (Builtin.RawPointer) -> () {
3030
public static var staticVar = internalFunc()
3131

3232
// FIXME: This initializer should be subsumed.
33-
// CHECK-LAZY: sil [transparent] [ossa] @$s4Test1SV15subsumedInitVarSivpfi : $@convention(thin) () -> Int {
34-
// CHECK-NON-LAZY-NOT: sil [transparent] [ossa] @$s4Test1SV15subsumedInitVarSivpfi : $@convention(thin) () -> Int {
33+
// CHECK-LAZY: sil hidden [transparent]{{.*}} @$s4Test1SV15subsumedInitVarSivpfi : $@convention(thin) () -> Int {
34+
// CHECK-NON-LAZY-NOT: sil hidden [transparent]{{.*}} @$s4Test1SV15subsumedInitVarSivpfi : $@convention(thin) () -> Int {
3535
public var subsumedInitVar = internalFunc()
3636

37-
// CHECK-LABEL: sil [transparent] [ossa] @$s4Test1SV19varWithInitAccessorSivpfi : $@convention(thin) () -> Int {
37+
// CHECK-LABEL: sil hidden [transparent] [ossa] @$s4Test1SV19varWithInitAccessorSivpfi : $@convention(thin) () -> Int {
3838
public var varWithInitAccessor: Int = internalFunc() {
3939
@storageRestrictions(initializes: subsumedInitVar)
4040
init {
@@ -51,8 +51,9 @@ extension S {
5151
public static var staticVarInExtension = internalFunc()
5252
}
5353

54+
// CHECK-LABEL: sil{{.*}} @$s4Test8returnsSAA1SVyF : $@convention(thin) () -> @out S
5455
public func returnsS() -> S {
5556
// Force the synthesized initializer for S to be emitted.
56-
// CHECK: function_ref @$s4Test1SVACycfC : $@convention(method) (@thin S.Type) -> S
57+
// CHECK: function_ref @$s4Test1SVACycfC : $@convention(method) (@thin S.Type) -> @out S
5758
return S()
5859
}

test/SILGen/skip_non_exportable_decls.swift

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-frontend -emit-silgen %s -parse-as-library -module-name Test | %FileCheck %s --check-prefixes=CHECK,CHECK-NO-SKIP
3-
// RUN: %target-swift-frontend -emit-silgen %s -parse-as-library -module-name Test -experimental-skip-non-exportable-decls | %FileCheck %s --check-prefixes=CHECK,CHECK-SKIP
2+
// RUN: %target-swift-frontend -emit-silgen %s -parse-as-library -enable-library-evolution -module-name Test | %FileCheck %s --check-prefixes=CHECK,CHECK-NO-SKIP
3+
// RUN: %target-swift-frontend -emit-silgen %s -parse-as-library -enable-library-evolution -module-name Test -experimental-skip-non-exportable-decls | %FileCheck %s --check-prefixes=CHECK,CHECK-SKIP
44

55
import Swift
66

@@ -15,7 +15,7 @@ import Swift
1515
// CHECK-NO-SKIP: sil_global private @$s4Test15publicGlobalVar_Wz : $Builtin.Word
1616
// CHECK-SKIP-NOT: s4Test15publicGlobalVar_Wz
1717

18-
// CHECK: sil_global @$s4Test15publicGlobalVarSivp : $Int
18+
// CHECK: sil_global private @$s4Test15publicGlobalVarSivp : $Int
1919

2020
// CHECK-NO-SKIP: sil private{{.*}} @$s4Test11privateFunc33_CFB3F9DC47F5EF9E1D08B58758351A08LLyyF : $@convention(thin) () -> () {
2121
// CHECK-SKIP-NOT: s4Test11privateFunc33_CFB3F9DC47F5EF9E1D08B58758351A08LLyyF
@@ -46,7 +46,7 @@ internal func internalFuncWithNestedFunc() {
4646
// CHECK-SKIP-NOT: s4Test022internalFuncWithNestedC0yyFyycyXEfU_
4747

4848
// CHECK-NO-SKIP: sil private{{.*}} @$s4Test022internalFuncWithNestedC0yyFyycyXEfU_6$deferL_yyF : $@convention(thin) () -> () {
49-
// CHECK-SKIP-NOT: @$s4Test022internalFuncWithNestedC0yyFyycyXEfU_6$deferL_yyF
49+
// CHECK-SKIP-NOT: sil{{.*}} @$s4Test022internalFuncWithNestedC0yyFyycyXEfU_6$deferL_yyF
5050

5151
// CHECK: sil{{.*}} @$s4Test10publicFuncyyF : $@convention(thin) () -> () {
5252
public func publicFunc() {}
@@ -73,8 +73,8 @@ internal var internalGlobalVar = 1
7373
// CHECK-NO-SKIP: sil private [global_init_once_fn]{{.*}} @$s4Test15publicGlobalVar_WZ : $@convention(c) (Builtin.RawPointer) -> () {
7474
// CHECK-SKIP-NOT: s4Test15publicGlobalVar_WZ
7575

76-
// CHECK-NO-SKIP: sil [global_init]{{.*}} @$s4Test15publicGlobalVarSivau : $@convention(thin) () -> Builtin.RawPointer {
77-
// CHECK-SKIP-NOT: s4Test15publicGlobalVarSivau
76+
// CHECK-NO-SKIP: sil hidden [global_init]{{.*}} @$s4Test15publicGlobalVarSivau : $@convention(thin) () -> Builtin.RawPointer {
77+
// CHECK-SKIP-NOT: sil{{.*}} s4Test15publicGlobalVarSivau
7878
public var publicGlobalVar = 1
7979

8080
// CHECK: sil [serialized]{{.*}} @$s4Test023inlinableFuncWithNestedC0yyF : $@convention(thin) () -> () {
@@ -94,9 +94,9 @@ public var publicGlobalVar = 1
9494

9595
@propertyWrapper
9696
public struct PublicWrapper<T> {
97-
// CHECK: sil [transparent] [serialized]{{.*}} @$s4Test13PublicWrapperV12wrappedValuexvg : $@convention(method) <T> (@in_guaranteed PublicWrapper<T>) -> @out T {
98-
// CHECK: sil [transparent] [serialized]{{.*}} @$s4Test13PublicWrapperV12wrappedValuexvs : $@convention(method) <T> (@in T, @inout PublicWrapper<T>) -> () {
99-
// CHECK: sil [transparent] [serialized]{{.*}} @$s4Test13PublicWrapperV12wrappedValuexvM : $@yield_once @convention(method) <T> (@inout PublicWrapper<T>) -> @yields @inout T {
97+
// CHECK: sil{{.*}} @$s4Test13PublicWrapperV12wrappedValuexvg : $@convention(method) <T> (@in_guaranteed PublicWrapper<T>) -> @out T {
98+
// CHECK: sil{{.*}} @$s4Test13PublicWrapperV12wrappedValuexvs : $@convention(method) <T> (@in T, @inout PublicWrapper<T>) -> () {
99+
// CHECK: sil{{.*}} @$s4Test13PublicWrapperV12wrappedValuexvM : $@yield_once @convention(method) <T> (@inout PublicWrapper<T>) -> @yields @inout T {
100100
public var wrappedValue: T
101101

102102
// CHECK: sil{{.*}} @$s4Test13PublicWrapperV12wrappedValueACyxGx_tcfC : $@convention(method) <T> (@in T, @thin PublicWrapper<T>.Type) -> @out PublicWrapper<T> {
@@ -118,24 +118,24 @@ private class PrivateClass {
118118
}
119119

120120
public class PublicClass {
121-
// CHECK-NO-SKIP: sil [transparent]{{.*}} @$s4Test11PublicClassC11internalVarSivpfi : $@convention(thin) () -> Int {
121+
// CHECK-NO-SKIP: sil{{.*}} @$s4Test11PublicClassC11internalVarSivpfi : $@convention(thin) () -> Int {
122122
// CHECK-SKIP-NOT: s4Test11PublicClassC11internalVarSivpfi
123-
// CHECK-NO-SKIP: sil hidden [transparent]{{.*}} @$s4Test11PublicClassC11internalVarSivg : $@convention(method) (@guaranteed PublicClass) -> Int {
123+
// CHECK-NO-SKIP: sil hidden{{.*}} @$s4Test11PublicClassC11internalVarSivg : $@convention(method) (@guaranteed PublicClass) -> Int {
124124
// CHECK-SKIP-NOT: s4Test11PublicClassC11internalVarSivg
125-
// CHECK-NO-SKIP: sil hidden [transparent]{{.*}} @$s4Test11PublicClassC11internalVarSivs : $@convention(method) (Int, @guaranteed PublicClass) -> () {
125+
// CHECK-NO-SKIP: sil hidden{{.*}} @$s4Test11PublicClassC11internalVarSivs : $@convention(method) (Int, @guaranteed PublicClass) -> () {
126126
// CHECK-SKIP-NOT: s4Test11PublicClassC11internalVarSivs
127-
// CHECK-NO-SKIP: sil hidden [transparent]{{.*}} @$s4Test11PublicClassC11internalVarSivM : $@yield_once @convention(method) (@guaranteed PublicClass) -> @yields @inout Int {
127+
// CHECK-NO-SKIP: sil hidden{{.*}} @$s4Test11PublicClassC11internalVarSivM : $@yield_once @convention(method) (@guaranteed PublicClass) -> @yields @inout Int {
128128
// CHECK-SKIP-NOT: s4Test11PublicClassC11internalVarSivM
129129
var internalVar = 1
130130

131-
// CHECK-NO-SKIP: sil [transparent]{{.*}} @$s4Test11PublicClassC9publicVarSivpfi : $@convention(thin) () -> Int {
131+
// CHECK-NO-SKIP: sil{{.*}} @$s4Test11PublicClassC9publicVarSivpfi : $@convention(thin) () -> Int {
132132
// CHECK-SKIP-NOT: s4Test11PublicClassC9publicVarSivpfi
133-
// CHECK: sil [transparent] [serialized]{{.*}} @$s4Test11PublicClassC9publicVarSivg : $@convention(method) (@guaranteed PublicClass) -> Int {
134-
// CHECK: sil [transparent] [serialized]{{.*}} @$s4Test11PublicClassC9publicVarSivs : $@convention(method) (Int, @guaranteed PublicClass) -> () {
135-
// CHECK: sil [transparent] [serialized]{{.*}} @$s4Test11PublicClassC9publicVarSivM : $@yield_once @convention(method) (@guaranteed PublicClass) -> @yields @inout Int {
133+
// CHECK: sil{{.*}} @$s4Test11PublicClassC9publicVarSivg : $@convention(method) (@guaranteed PublicClass) -> Int {
134+
// CHECK: sil{{.*}} @$s4Test11PublicClassC9publicVarSivs : $@convention(method) (Int, @guaranteed PublicClass) -> () {
135+
// CHECK: sil{{.*}} @$s4Test11PublicClassC9publicVarSivM : $@yield_once @convention(method) (@guaranteed PublicClass) -> @yields @inout Int {
136136
public var publicVar = 1
137137

138-
// CHECK-NO-SKIP: sil{{.*}} @$s4Test11PublicClassC16publicWrappedVarSivpfP : $@convention(thin) (Int) -> PublicWrapper<Int> {
138+
// CHECK-NO-SKIP: sil{{.*}} @$s4Test11PublicClassC16publicWrappedVarSivpfP : $@convention(thin) (Int) -> @out PublicWrapper<Int> {
139139
// CHECK-SKIP-NOT: s4Test11PublicClassC16publicWrappedVarSivpfP
140140
// CHECK: sil{{.*}} @$s4Test11PublicClassC16publicWrappedVarSivg : $@convention(method) (@guaranteed PublicClass) -> Int {
141141
// CHECK: sil{{.*}} @$s4Test11PublicClassC16publicWrappedVarSivs : $@convention(method) (Int, @guaranteed PublicClass) -> () {
@@ -174,7 +174,7 @@ extension PublicClass {
174174
// CHECK-NO-SKIP-NEXT: }
175175
// CHECK-SKIP-NOT: sil_vtable PrivateClass
176176

177-
// CHECK-LABEL: sil_vtable [serialized] PublicClass {
177+
// CHECK-LABEL: sil_vtable PublicClass {
178178
// CHECK-NO-SKIP-NEXT: #PublicClass.internalVar!getter
179179
// CHECK-SKIP-NOT: #PublicClass.internalVar!getter
180180
// CHECK-NO-SKIP-NEXT: #PublicClass.internalVar!setter
@@ -194,4 +194,4 @@ extension PublicClass {
194194
// CHECK-NEXT: #PublicClass.deinit!deallocator
195195
// CHECK-NEXT: }
196196

197-
// CHECK: sil_property #PublicClass.publicVar ()
197+
// CHECK: sil_property #PublicClass.publicVar

test/SILGen/skip_non_exportable_decls_top_level.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// 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
2+
// RUN: %target-swift-frontend -enable-library-evolution -emit-silgen %s -module-name Test | %FileCheck %s --check-prefixes=CHECK,CHECK-NO-SKIP
3+
// RUN: %target-swift-frontend -enable-library-evolution -emit-silgen %s -module-name Test -experimental-skip-non-exportable-decls | %FileCheck %s --check-prefixes=CHECK,CHECK-SKIP
44

55
// CHECK-NO-SKIP: sil_global hidden @$s4Test1xSivp : $Int
66
// CHECK-SKIP: sil_global hidden_external @$s4Test1xSivp : $Int

test/Sema/lazy-typecheck.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: not %target-typecheck-verify-swift
2-
// RUN: %target-typecheck-verify-swift -experimental-lazy-typecheck
2+
// RUN: %target-typecheck-verify-swift -enable-library-evolution -experimental-lazy-typecheck
33

44
// With lazy typechecking enabled and no compiler outputs specified, no errors
55
// should be emitted for this semantically invalid code.

0 commit comments

Comments
 (0)