Skip to content

Commit 5d11e9f

Browse files
authored
Merge pull request #64821 from drexin/wip-107477762-5.9
[5.9][IRGen] Add flags to enable or disable generation of layout string va…
2 parents 5498b22 + 6db61ed commit 5d11e9f

File tree

6 files changed

+77
-18
lines changed

6 files changed

+77
-18
lines changed

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,5 +528,9 @@ WARNING(enable_interop_flag_deprecated,none,
528528
"the -enable-experimental-cxx-interop flag is deprecated. Please pass "
529529
"'-cxx-interoperability-mode=' instead.", ())
530530

531+
ERROR(layout_string_instantiation_without_layout_strings,none,
532+
"-enable-layout-string-value-witnesses-instantiation can not be enabled "
533+
"without -enable-layout-string-value-witnesses.", ())
534+
531535
#define UNDEFINE_DIAGNOSTIC_MACROS
532536
#include "DefineDiagnosticMacros.h"

include/swift/AST/IRGenOptions.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,12 @@ class IRGenOptions {
380380
/// using TypeInfo entries.
381381
unsigned ForceStructTypeLayouts : 1;
382382

383+
/// Enable generation and use of layout string based value witnesses
384+
unsigned EnableLayoutStringValueWitnesses : 1;
385+
386+
/// Enable runtime instantiation of value witness strings for generic types
387+
unsigned EnableLayoutStringValueWitnessesInstantiation : 1;
388+
383389
/// Instrument code to generate profiling information.
384390
unsigned GenerateProfile : 1;
385391

@@ -493,6 +499,8 @@ class IRGenOptions {
493499
CompactAbsoluteFunctionPointer(false), DisableLegacyTypeInfo(false),
494500
PrespecializeGenericMetadata(false), UseIncrementalLLVMCodeGen(true),
495501
UseTypeLayoutValueHandling(true), ForceStructTypeLayouts(false),
502+
EnableLayoutStringValueWitnesses(false),
503+
EnableLayoutStringValueWitnessesInstantiation(false),
496504
GenerateProfile(false), EnableDynamicReplacementChaining(false),
497505
DisableDebuggerShadowCopies(false),
498506
DisableConcreteTypeMetadataMangledNameAccessors(false),

include/swift/Option/FrontendOptions.td

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,18 @@ def disable_type_layouts : Flag<["-"], "disable-type-layout">,
10181018
def force_struct_type_layouts : Flag<["-"], "force-struct-type-layouts">,
10191019
HelpText<"Force type layout based lowering for structs">;
10201020

1021+
def enable_layout_string_value_witnesses : Flag<["-"], "enable-layout-string-value-witnesses">,
1022+
HelpText<"Enable layout string based value witnesses">;
1023+
1024+
def disable_layout_string_value_witnesses : Flag<["-"], "disable-layout-string-value-witnesses">,
1025+
HelpText<"Disable layout string based value witnesses">;
1026+
1027+
def enable_layout_string_value_witnesses_instantiation : Flag<["-"], "enable-layout-string-value-witnesses-instantiation">,
1028+
HelpText<"Enable runtime instantiation of layout string value witnesses for generic types">;
1029+
1030+
def disable_layout_string_value_witnesses_instantiation : Flag<["-"], "disable-layout-string-value-witnesses-instantiation">,
1031+
HelpText<"Disable runtime instantiation of layout string value witnesses for generic types">;
1032+
10211033
def disable_interface_lockfile : Flag<["-"], "disable-interface-lock">,
10221034
HelpText<"Don't lock interface file when building module">;
10231035

lib/Frontend/CompilerInvocation.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2671,6 +2671,21 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
26712671
Args.hasFlag(OPT_enable_relative_protocol_witness_tables,
26722672
OPT_disable_relative_protocol_witness_tables,
26732673
Opts.UseRelativeProtocolWitnessTables);
2674+
2675+
Opts.EnableLayoutStringValueWitnesses = Args.hasFlag(OPT_enable_layout_string_value_witnesses,
2676+
OPT_disable_layout_string_value_witnesses,
2677+
Opts.EnableLayoutStringValueWitnesses);
2678+
2679+
Opts.EnableLayoutStringValueWitnessesInstantiation = Args.hasFlag(OPT_enable_layout_string_value_witnesses_instantiation,
2680+
OPT_disable_layout_string_value_witnesses_instantiation,
2681+
Opts.EnableLayoutStringValueWitnessesInstantiation);
2682+
2683+
if (Opts.EnableLayoutStringValueWitnessesInstantiation &&
2684+
!Opts.EnableLayoutStringValueWitnesses) {
2685+
Diags.diagnose(SourceLoc(), diag::layout_string_instantiation_without_layout_strings);
2686+
return true;
2687+
}
2688+
26742689
return false;
26752690
}
26762691

lib/IRGen/GenMeta.cpp

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2590,15 +2590,17 @@ void irgen::emitLazyTypeContextDescriptor(IRGenModule &IGM,
25902590
auto &ti = IGM.getTypeInfo(lowered);
25912591
auto *typeLayoutEntry =
25922592
ti.buildTypeLayoutEntry(IGM, lowered, /*useStructLayouts*/ true);
2593-
if (IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnesses)) {
2593+
if (IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnesses) &&
2594+
IGM.getOptions().EnableLayoutStringValueWitnesses) {
25942595

25952596
auto genericSig =
25962597
lowered.getNominalOrBoundGenericNominal()->getGenericSignature();
25972598
hasLayoutString = !!typeLayoutEntry->layoutString(IGM, genericSig);
25982599
}
25992600

26002601
if (auto sd = dyn_cast<StructDecl>(type)) {
2601-
if (IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnessesInstantiation)) {
2602+
if (IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnessesInstantiation) &&
2603+
IGM.getOptions().EnableLayoutStringValueWitnessesInstantiation) {
26022604
hasLayoutString |= requiresForeignTypeMetadata(type) ||
26032605
needsSingletonMetadataInitialization(IGM, type) ||
26042606
(type->isGenericContext() && !isa<FixedTypeInfo>(ti));
@@ -2895,7 +2897,8 @@ static void emitInitializeFieldOffsetVectorWithLayoutString(
28952897
bool isVWTMutable, MetadataDependencyCollector *collector) {
28962898
auto &IGM = IGF.IGM;
28972899
assert(IGM.Context.LangOpts.hasFeature(
2898-
Feature::LayoutStringValueWitnessesInstantiation));
2900+
Feature::LayoutStringValueWitnessesInstantiation) &&
2901+
IGM.getOptions().EnableLayoutStringValueWitnesses);
28992902

29002903
auto *target = T.getStructOrBoundGenericStruct();
29012904

@@ -3007,7 +3010,9 @@ static void emitInitializeValueMetadata(IRGenFunction &IGF,
30073010

30083011
if (IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnesses) &&
30093012
IGM.Context.LangOpts.hasFeature(
3010-
Feature::LayoutStringValueWitnessesInstantiation)) {
3013+
Feature::LayoutStringValueWitnessesInstantiation) &&
3014+
IGM.getOptions().EnableLayoutStringValueWitnesses &&
3015+
IGM.getOptions().EnableLayoutStringValueWitnessesInstantiation) {
30113016
emitInitializeFieldOffsetVectorWithLayoutString(IGF, loweredTy, metadata,
30123017
isVWTMutable, collector);
30133018
} else {
@@ -3122,7 +3127,8 @@ namespace {
31223127
Impl &asImpl() { return *static_cast<Impl*>(this); }
31233128

31243129
llvm::Constant *emitLayoutString() {
3125-
if (!IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnesses))
3130+
if (!IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnesses) ||
3131+
!IGM.getOptions().EnableLayoutStringValueWitnesses)
31263132
return nullptr;
31273133
auto lowered = getLoweredTypeInPrimaryContext(
31283134
IGM, Target->getDeclaredType()->getCanonicalType());
@@ -3205,7 +3211,8 @@ namespace {
32053211
asImpl().emitInitializeMetadata(IGF, metadata, false, collector);
32063212

32073213
if (IGM.Context.LangOpts.hasFeature(
3208-
Feature::LayoutStringValueWitnesses)) {
3214+
Feature::LayoutStringValueWitnesses) &&
3215+
IGM.getOptions().EnableLayoutStringValueWitnesses) {
32093216
if (auto *layoutString = getLayoutString()) {
32103217
auto layoutStringCast = IGF.Builder.CreateBitCast(layoutString,
32113218
IGM.Int8PtrTy);
@@ -3781,7 +3788,8 @@ namespace {
37813788
}
37823789

37833790
llvm::Constant *emitLayoutString() {
3784-
if (!IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnesses))
3791+
if (!IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnesses) ||
3792+
!IGM.getOptions().EnableLayoutStringValueWitnesses)
37853793
return nullptr;
37863794
auto lowered = getLoweredTypeInPrimaryContext(
37873795
IGM, Target->getDeclaredType()->getCanonicalType());
@@ -4985,11 +4993,13 @@ namespace {
49854993
}
49864994

49874995
bool hasLayoutString() {
4988-
if (!IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnesses)) {
4996+
if (!IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnesses) ||
4997+
!IGM.getOptions().EnableLayoutStringValueWitnesses) {
49894998
return false;
49904999
}
49915000

4992-
if (IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnessesInstantiation)) {
5001+
if (IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnessesInstantiation) &&
5002+
IGM.getOptions().EnableLayoutStringValueWitnessesInstantiation) {
49935003
return !!getLayoutString() || needsSingletonMetadataInitialization(IGM, Target);
49945004
}
49955005

@@ -5028,7 +5038,8 @@ namespace {
50285038
}
50295039

50305040
llvm::Constant *emitLayoutString() {
5031-
if (!IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnesses))
5041+
if (!IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnesses) ||
5042+
!IGM.getOptions().EnableLayoutStringValueWitnesses)
50325043
return nullptr;
50335044
auto lowered = getLoweredTypeInPrimaryContext(
50345045
IGM, Target->getDeclaredType()->getCanonicalType());
@@ -5179,12 +5190,14 @@ namespace {
51795190

51805191
bool hasLayoutString() {
51815192
if (!IGM.Context.LangOpts.hasFeature(
5182-
Feature::LayoutStringValueWitnesses)) {
5193+
Feature::LayoutStringValueWitnesses) ||
5194+
!IGM.getOptions().EnableLayoutStringValueWitnesses) {
51835195
return false;
51845196
}
51855197
return !!getLayoutString() ||
51865198
(IGM.Context.LangOpts.hasFeature(
51875199
Feature::LayoutStringValueWitnessesInstantiation) &&
5200+
IGM.getOptions().EnableLayoutStringValueWitnessesInstantiation &&
51885201
(HasDependentVWT || HasDependentMetadata) &&
51895202
!isa<FixedTypeInfo>(IGM.getTypeInfo(getLoweredType())));
51905203
}
@@ -5444,7 +5457,8 @@ namespace {
54445457
}
54455458

54465459
llvm::Constant *emitLayoutString() {
5447-
if (!IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnesses))
5460+
if (!IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnesses) ||
5461+
!IGM.getOptions().EnableLayoutStringValueWitnesses)
54485462
return nullptr;
54495463
auto lowered = getLoweredTypeInPrimaryContext(
54505464
IGM, Target->getDeclaredType()->getCanonicalType());

lib/IRGen/GenValueWitness.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,8 @@ bool isRuntimeInstatiatedLayoutString(IRGenModule &IGM,
921921
const TypeLayoutEntry *typeLayoutEntry) {
922922
if (IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnesses) &&
923923
IGM.Context.LangOpts.hasFeature(
924-
Feature::LayoutStringValueWitnessesInstantiation)) {
924+
Feature::LayoutStringValueWitnessesInstantiation) &&
925+
IGM.getOptions().EnableLayoutStringValueWitnessesInstantiation) {
925926
return (typeLayoutEntry->isAlignedGroup() &&
926927
!typeLayoutEntry->isFixedSize(IGM));
927928
}
@@ -986,7 +987,8 @@ static void addValueWitness(IRGenModule &IGM, ConstantStructBuilder &B,
986987
return addFunction(getNoOpVoidFunction(IGM));
987988
} else if (concreteTI.isSingleSwiftRetainablePointer(ResilienceExpansion::Maximal)) {
988989
return addFunction(getDestroyStrongFunction(IGM));
989-
} else if (IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnesses)) {
990+
} else if (IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnesses) &&
991+
IGM.getOptions().EnableLayoutStringValueWitnesses) {
990992
if (auto *typeLayoutEntry =
991993
concreteTI.buildTypeLayoutEntry(IGM, concreteType,
992994
/*useStructLayouts*/true)) {
@@ -1013,7 +1015,8 @@ static void addValueWitness(IRGenModule &IGM, ConstantStructBuilder &B,
10131015
case ValueWitness::InitializeWithTake:
10141016
if (concreteTI.isBitwiseTakable(ResilienceExpansion::Maximal)) {
10151017
return addFunction(getMemCpyFunction(IGM, concreteTI));
1016-
} else if (IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnesses)) {
1018+
} else if (IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnesses) &&
1019+
IGM.getOptions().EnableLayoutStringValueWitnesses) {
10171020
if (auto *typeLayoutEntry =
10181021
concreteTI.buildTypeLayoutEntry(IGM, concreteType,
10191022
/*useStructLayouts*/true)) {
@@ -1032,7 +1035,8 @@ static void addValueWitness(IRGenModule &IGM, ConstantStructBuilder &B,
10321035
return addFunction(getMemCpyFunction(IGM, concreteTI));
10331036
} else if (concreteTI.isSingleSwiftRetainablePointer(ResilienceExpansion::Maximal)) {
10341037
return addFunction(getAssignWithCopyStrongFunction(IGM));
1035-
} else if (IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnesses)) {
1038+
} else if (IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnesses) &&
1039+
IGM.getOptions().EnableLayoutStringValueWitnesses) {
10361040
if (auto *typeLayoutEntry =
10371041
concreteTI.buildTypeLayoutEntry(IGM, concreteType,
10381042
/*useStructLayouts*/true)) {
@@ -1051,7 +1055,8 @@ static void addValueWitness(IRGenModule &IGM, ConstantStructBuilder &B,
10511055
return addFunction(getMemCpyFunction(IGM, concreteTI));
10521056
} else if (concreteTI.isSingleSwiftRetainablePointer(ResilienceExpansion::Maximal)) {
10531057
return addFunction(getAssignWithTakeStrongFunction(IGM));
1054-
} else if (IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnesses)) {
1058+
} else if (IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnesses) &&
1059+
IGM.getOptions().EnableLayoutStringValueWitnesses) {
10551060
if (auto *typeLayoutEntry =
10561061
concreteTI.buildTypeLayoutEntry(IGM, concreteType,
10571062
/*useStructLayouts*/true)) {
@@ -1070,7 +1075,8 @@ static void addValueWitness(IRGenModule &IGM, ConstantStructBuilder &B,
10701075
return addFunction(getMemCpyFunction(IGM, concreteTI));
10711076
} else if (concreteTI.isSingleSwiftRetainablePointer(ResilienceExpansion::Maximal)) {
10721077
return addFunction(getInitWithCopyStrongFunction(IGM));
1073-
} else if (IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnesses)) {
1078+
} else if (IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnesses) &&
1079+
IGM.getOptions().EnableLayoutStringValueWitnesses) {
10741080
if (auto *typeLayoutEntry =
10751081
concreteTI.buildTypeLayoutEntry(IGM, concreteType,
10761082
/*useStructLayouts*/true)) {

0 commit comments

Comments
 (0)