Skip to content

Commit d36af3b

Browse files
authored
Merge pull request swiftlang#22725 from compnerd/windows-conforms
IRGen: make Windows use resilient conformances
2 parents 0235a81 + 8357457 commit d36af3b

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

include/swift/AST/IRGenOptions.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ class IRGenOptions {
174174
/// Force lazy initialization of class metadata
175175
/// Used on Windows to avoid cross-module references.
176176
unsigned LazyInitializeClassMetadata : 1;
177+
unsigned LazyInitializeProtocolConformances : 1;
177178

178179
/// Normally if the -read-legacy-type-info flag is not specified, we look for
179180
/// a file named "legacy-<arch>.yaml" in SearchPathOpts.RuntimeLibraryPath.
@@ -234,7 +235,7 @@ class IRGenOptions {
234235
ValueNames(false), EnableReflectionMetadata(true),
235236
EnableReflectionNames(true), EnableAnonymousContextMangledNames(false),
236237
EnableResilienceBypass(false), LazyInitializeClassMetadata(false),
237-
DisableLegacyTypeInfo(false),
238+
LazyInitializeProtocolConformances(false), DisableLegacyTypeInfo(false),
238239
UseIncrementalLLVMCodeGen(true), UseSwiftCall(false),
239240
GenerateProfile(false), EnableDynamicReplacementChaining(false),
240241
DisableRoundTripDebugTypes(false),

lib/Frontend/CompilerInvocation.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,11 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
10801080
// (e.g. NativeObject). Force the lazy initialization of the VWT always.
10811081
Opts.LazyInitializeClassMetadata = Triple.isOSBinFormatCOFF();
10821082

1083+
// PE/COFF cannot deal with cross-module reference to the protocol conformance
1084+
// witness. Use a runtime initialized value for the protocol conformance
1085+
// witness.
1086+
Opts.LazyInitializeProtocolConformances = Triple.isOSBinFormatCOFF();
1087+
10831088
if (Args.hasArg(OPT_disable_legacy_type_info)) {
10841089
Opts.DisableLegacyTypeInfo = true;
10851090
}

lib/IRGen/GenProto.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,9 @@ class DirectConformanceInfo : public ConformanceInfo {
10751075

10761076
llvm::Constant *tryGetConstantTable(IRGenModule &IGM,
10771077
CanType conformingType) const override {
1078+
if (IGM.getOptions().LazyInitializeProtocolConformances &&
1079+
RootConformance->getDeclContext()->getParentModule() != IGM.getSwiftModule())
1080+
return nullptr;
10781081
return IGM.getAddrOfWitnessTable(RootConformance);
10791082
}
10801083
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module -DA -parse-as-library -parse-stdlib -module-name A %s -o %t/A.swiftmodule
3+
// RUN: %target-swift-frontend -emit-ir -DB -I %t -parse-as-library -parse-stdlib -module-name B -o - %s | %FileCheck %s -check-prefix CHECK-%target-import-type
4+
5+
#if A
6+
public protocol P {
7+
}
8+
9+
public enum E : P {
10+
}
11+
#endif
12+
13+
#if B
14+
import A
15+
16+
public protocol Q : P {
17+
}
18+
19+
extension E : Q {
20+
}
21+
#endif
22+
23+
// CHECK-DIRECT: @"$s1A1EO1B1QADWP" ={{( dllexport)?}}{{( protected)?}} constant [2 x i8*] [i8* bitcast (%swift.protocol_conformance_descriptor* @"$s1A1EO1B1QADMc" to i8*), i8* bitcast (i8** @"$s1A1EOAA1PAAWP" to i8*)]
24+
// CHECK-INDIRECT: @"$s1A1EO1B1QADWP" ={{( dllexport)?}}{{( protected)?}} constant [2 x i8*] [i8* bitcast (%swift.protocol_conformance_descriptor* @"$s1A1EO1B1QADMc" to i8*), i8* null]
25+

0 commit comments

Comments
 (0)