Skip to content

Commit 66bd5e6

Browse files
authored
Add ASTMangler.AllowStandardSubstitutions to allow using a stripped-down libswiftCore (#40009)
1 parent 3b402f0 commit 66bd5e6

File tree

8 files changed

+34
-19
lines changed

8 files changed

+34
-19
lines changed

include/swift/AST/ASTMangler.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ class ASTMangler : public Mangler {
5656
/// to fill these in.
5757
bool AllowSymbolicReferences = false;
5858

59+
/// If enabled, allows the use of standard substitutions for types in the
60+
/// standard library.
61+
bool AllowStandardSubstitutions = true;
62+
5963
/// If enabled, allows the use of standard substitutions for types in the
6064
/// concurrency library.
6165
bool AllowConcurrencyStandardSubstitutions = true;

include/swift/AST/IRGenOptions.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,10 @@ class IRGenOptions {
356356
/// Whether to disable using mangled names for accessing concrete type metadata.
357357
unsigned DisableConcreteTypeMetadataMangledNameAccessors : 1;
358358

359+
/// Whether to disable referencing stdlib symbols via mangled names in
360+
/// reflection mangling.
361+
unsigned DisableStandardSubstitutionsInReflectionMangling : 1;
362+
359363
unsigned EnableGlobalISel : 1;
360364

361365
unsigned VirtualFunctionElimination : 1;
@@ -425,6 +429,7 @@ class IRGenOptions {
425429
GenerateProfile(false), EnableDynamicReplacementChaining(false),
426430
DisableRoundTripDebugTypes(false), DisableDebuggerShadowCopies(false),
427431
DisableConcreteTypeMetadataMangledNameAccessors(false),
432+
DisableStandardSubstitutionsInReflectionMangling(false),
428433
EnableGlobalISel(false), VirtualFunctionElimination(false),
429434
WitnessMethodElimination(false), ConditionalRuntimeRecords(false),
430435
InternalizeAtLink(false),

include/swift/Option/FrontendOptions.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,10 @@ def disable_debugger_shadow_copies : Flag<["-"], "disable-debugger-shadow-copies
634634
def disable_concrete_type_metadata_mangled_name_accessors : Flag<["-"], "disable-concrete-type-metadata-mangled-name-accessors">,
635635
HelpText<"Disable concrete type metadata access by mangled name">,
636636
Flags<[FrontendOption, HelpHidden]>;
637+
638+
def disable_standard_substitutions_in_reflection_mangling : Flag<["-"], "disable-standard-substitutions-in-reflection-mangling">,
639+
HelpText<"Disable referencing stdlib symbols via mangled names in reflection mangling">,
640+
Flags<[FrontendOption, HelpHidden]>;
637641

638642
def playground : Flag<["-"], "playground">,
639643
HelpText<"Apply the playground semantics and transformation">;

lib/AST/ASTMangler.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3023,6 +3023,9 @@ bool ASTMangler::tryAppendStandardSubstitution(const GenericTypeDecl *decl) {
30233023
!dc->getParentModule()->hasStandardSubstitutions())
30243024
return false;
30253025

3026+
if (!AllowStandardSubstitutions)
3027+
return false;
3028+
30263029
if (isa<NominalTypeDecl>(decl)) {
30273030
if (auto Subst = getStandardTypeSubst(
30283031
decl->getName().str(), AllowConcurrencyStandardSubstitutions)) {

lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,6 +1760,9 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
17601760
if (Args.hasArg(OPT_disable_concrete_type_metadata_mangled_name_accessors))
17611761
Opts.DisableConcreteTypeMetadataMangledNameAccessors = true;
17621762

1763+
if (Args.hasArg(OPT_disable_standard_substitutions_in_reflection_mangling))
1764+
Opts.DisableStandardSubstitutionsInReflectionMangling = true;
1765+
17631766
if (Args.hasArg(OPT_use_jit)) {
17641767
Opts.UseJIT = true;
17651768
if (const Arg *A = Args.getLastArg(OPT_dump_jit)) {
@@ -1995,32 +1998,14 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
19951998

19961999
if (Args.hasArg(OPT_enable_llvm_vfe)) {
19972000
Opts.VirtualFunctionElimination = true;
1998-
1999-
// FIXME(mracek): There are still some situations where we use mangled name
2000-
// without symbolic references, which means the dependency is not statically
2001-
// visible to the compiler/linker. Temporarily disable mangled accessors
2002-
// until we fix that.
2003-
Opts.DisableConcreteTypeMetadataMangledNameAccessors = true;
20042001
}
20052002

20062003
if (Args.hasArg(OPT_enable_llvm_wme)) {
20072004
Opts.WitnessMethodElimination = true;
2008-
2009-
// FIXME(mracek): There are still some situations where we use mangled name
2010-
// without symbolic references, which means the dependency is not statically
2011-
// visible to the compiler/linker. Temporarily disable mangled accessors
2012-
// until we fix that.
2013-
Opts.DisableConcreteTypeMetadataMangledNameAccessors = true;
20142005
}
20152006

20162007
if (Args.hasArg(OPT_conditional_runtime_records)) {
20172008
Opts.ConditionalRuntimeRecords = true;
2018-
2019-
// FIXME(mracek): There are still some situations where we use mangled name
2020-
// without symbolic references, which means the dependency is not statically
2021-
// visible to the compiler/linker. Temporarily disable mangled accessors
2022-
// until we fix that.
2023-
Opts.DisableConcreteTypeMetadataMangledNameAccessors = true;
20242009
}
20252010

20262011
if (Args.hasArg(OPT_internalize_at_link)) {

lib/IRGen/IRGenMangler.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ IRGenMangler::withSymbolicReferences(IRGenModule &IGM,
9898
// The short-substitution types in the standard library have compact
9999
// manglings already, and the runtime ought to have a lookup table for
100100
// them. Symbolic referencing would be wasteful.
101-
if (type->getModuleContext()->hasStandardSubstitutions()
101+
if (AllowStandardSubstitutions
102+
&& type->getModuleContext()->hasStandardSubstitutions()
102103
&& Mangle::getStandardTypeSubst(
103104
type->getName().str(), AllowConcurrencyStandardSubstitutions)) {
104105
return false;
@@ -159,6 +160,11 @@ IRGenMangler::mangleTypeForReflection(IRGenModule &IGM,
159160
AllowConcurrencyStandardSubstitutions = false;
160161
}
161162

163+
llvm::SaveAndRestore<bool> savedAllowStandardSubstitutions(
164+
AllowStandardSubstitutions);
165+
if (IGM.getOptions().DisableStandardSubstitutionsInReflectionMangling)
166+
AllowStandardSubstitutions = false;
167+
162168
llvm::SaveAndRestore<bool> savedAllowMarkerProtocols(
163169
AllowMarkerProtocols, false);
164170
return withSymbolicReferences(IGM, [&]{

stdlib/cmake/modules/SwiftSource.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,10 @@ function(_compile_swift_files
494494
list(APPEND swift_flags "-Xfrontend" "-disable-autolinking-runtime-compatibility-concurrency")
495495
endif()
496496

497+
if(NOT SWIFT_STDLIB_SHORT_MANGLING_LOOKUPS)
498+
list(APPEND swift_flags "-Xfrontend" "-disable-standard-substitutions-in-reflection-mangling")
499+
endif()
500+
497501
if (SWIFTFILE_IS_STDLIB_CORE OR SWIFTFILE_IS_SDK_OVERLAY)
498502
list(APPEND swift_flags "-warn-swift3-objc-inference-complete")
499503
endif()

test/lit.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,10 @@ if run_vendor == 'apple':
950950
swift_execution_tests_extra_flags += \
951951
' -Xfrontend -disable-implicit-concurrency-module-import'
952952

953+
# To have visible references from symbolic manglings
954+
swift_execution_tests_extra_flags += \
955+
' -Xfrontend -disable-standard-substitutions-in-reflection-mangling'
956+
953957
# Link all "freestanding" tests with -dead_strip, which can effectively
954958
# even remove parts of the stdlib and runtime, if it's not needed. Since
955959
# it's a very desired behavior, let's enable it for all executable tests.

0 commit comments

Comments
 (0)