Skip to content

Commit 72b13e8

Browse files
committed
IRGen: Add a flag to disable mangled name type metadata accessors.
Useful as a workaround for runtime demangler bugs, or in rare cases where there are performance problems with the demangler.
1 parent bc8ff75 commit 72b13e8

File tree

5 files changed

+19
-0
lines changed

5 files changed

+19
-0
lines changed

include/swift/AST/IRGenOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ class IRGenOptions {
280280
/// Whether to disable shadow copies for local variables on the stack. This is
281281
/// only used for testing.
282282
unsigned DisableDebuggerShadowCopies : 1;
283+
284+
/// Whether to disable using mangled names for accessing concrete type metadata.
285+
unsigned DisableConcreteTypeMetadataMangledNameAccessors : 1;
283286

284287
/// Path to the profdata file to be used for PGO, or the empty string.
285288
std::string UseProfile = "";
@@ -327,6 +330,7 @@ class IRGenOptions {
327330
UseSwiftCall(false), UseTypeLayoutValueHandling(true), GenerateProfile(false),
328331
EnableDynamicReplacementChaining(false),
329332
DisableRoundTripDebugTypes(false), DisableDebuggerShadowCopies(false),
333+
DisableConcreteTypeMetadataMangledNameAccessors(false),
330334
CmdArgs(), SanitizeCoverage(llvm::SanitizerCoverageOptions()),
331335
TypeInfoFilter(TypeInfoDumpFilter::All) {}
332336

include/swift/Option/FrontendOptions.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,10 @@ def disable_debugger_shadow_copies : Flag<["-"], "disable-debugger-shadow-copies
510510
"This option is only useful for testing the compiler.">,
511511
Flags<[FrontendOption, HelpHidden]>;
512512

513+
def disable_concrete_type_metadata_mangled_name_accessors : Flag<["-"], "disable-concrete-type-metadata-mangled-name-accessors">,
514+
HelpText<"Disable concrete type metadata access by mangled name">,
515+
Flags<[FrontendOption, HelpHidden]>;
516+
513517
def playground : Flag<["-"], "playground">,
514518
HelpText<"Apply the playground semantics and transformation">;
515519

lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,9 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
12611261
if (Args.hasArg(OPT_disable_debugger_shadow_copies))
12621262
Opts.DisableDebuggerShadowCopies = true;
12631263

1264+
if (Args.hasArg(OPT_disable_concrete_type_metadata_mangled_name_accessors))
1265+
Opts.DisableConcreteTypeMetadataMangledNameAccessors = true;
1266+
12641267
if (Args.hasArg(OPT_use_jit))
12651268
Opts.UseJIT = true;
12661269

lib/IRGen/MetadataRequest.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2202,6 +2202,10 @@ irgen::getGenericTypeMetadataAccessFunction(IRGenModule &IGM,
22022202
}
22032203

22042204
static bool shouldAccessByMangledName(IRGenModule &IGM, CanType type) {
2205+
// Never access by mangled name if we've been asked not to.
2206+
if (IGM.getOptions().DisableConcreteTypeMetadataMangledNameAccessors)
2207+
return false;
2208+
22052209
// A nongeneric nominal type with nontrivial metadata has an accessor
22062210
// already we can just call.
22072211
if (auto nom = dyn_cast<NominalType>(type)) {

test/IRGen/access_type_metadata_by_mangled_name.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
// RUN: %target-swift-frontend -emit-ir -parse-stdlib %s | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-endian
2+
// RUN: %target-swift-frontend -emit-ir -disable-concrete-type-metadata-mangled-name-accessors -parse-stdlib %s | %FileCheck %s --check-prefix=DISABLED
3+
4+
// DISABLED-NOT: __swift_instantiateConcreteTypeFromMangledName
5+
// DISABLED-NOT: MD" = {{.*}} global
26

37
// CHECK: @"$s36access_type_metadata_by_mangled_name3FooCyAA3BarCyAA3ZimCyAA4ZangCGGGMD" = linkonce_odr hidden global { i32, i32 }
48

0 commit comments

Comments
 (0)