Skip to content

Commit 98abbdb

Browse files
committed
Emit reflection metadata, but not reflection names, by default
This allows the reflection type lowering test to pass with the default build configuration.
1 parent 22f193d commit 98abbdb

File tree

11 files changed

+33
-33
lines changed

11 files changed

+33
-33
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ option(SWIFT_STDLIB_ENABLE_RESILIENCE
231231

232232
option(SWIFT_STDLIB_ENABLE_REFLECTION_METADATA
233233
"Build the standard libraries and overlays with remote reflection metadata; see docs/proposals/RemoteMirrors.rst"
234+
TRUE)
235+
236+
option(SWIFT_STDLIB_ENABLE_REFLECTION_NAMES
237+
"Build the standard libraries and overlays with remote reflection names; see docs/proposals/RemoteMirrors.rst"
234238
FALSE)
235239

236240
option(SWIFT_STDLIB_SIL_SERIALIZE_ALL

cmake/modules/AddSwift.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,10 @@ function(_compile_swift_files dependency_target_out_var_name)
394394
list(APPEND swift_flags "-Xfrontend" "-enable-reflection-metadata")
395395
endif()
396396

397+
if(SWIFT_STDLIB_ENABLE_REFLECTION_NAMES AND SWIFTFILE_IS_STDLIB)
398+
list(APPEND swift_flags "-Xfrontend" "-enable-reflection-names")
399+
endif()
400+
397401
if(SWIFT_EMIT_SORTED_SIL_OUTPUT)
398402
list(APPEND swift_flags "-Xfrontend" "-emit-sorted-sil")
399403
endif()

include/swift/AST/IRGenOptions.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ class IRGenOptions {
140140
unsigned HasValueNamesSetting : 1;
141141
unsigned ValueNames : 1;
142142

143-
/// Only strip the field names section from nominal type field metadata.
144-
unsigned StripReflectionNames : 1;
143+
/// Emit nominal type field metadata.
144+
unsigned EnableReflectionMetadata : 1;
145145

146-
/// Strip all nominal type field metadata.
147-
unsigned StripReflectionMetadata : 1;
146+
/// Emit names of struct stored properties and enum cases.
147+
unsigned EnableReflectionNames : 1;
148148

149149
/// List of backend command-line options for -embed-bitcode.
150150
std::vector<uint8_t> CmdArgs;
@@ -165,7 +165,7 @@ class IRGenOptions {
165165
EmitStackPromotionChecks(false), GenerateProfile(false),
166166
PrintInlineTree(false), EmbedMode(IRGenEmbedMode::None),
167167
HasValueNamesSetting(false), ValueNames(false),
168-
StripReflectionNames(true), StripReflectionMetadata(true),
168+
EnableReflectionMetadata(false), EnableReflectionNames(false),
169169
CmdArgs(), UseIncrementalLLVMCodeGen(true)
170170
{}
171171

include/swift/Option/FrontendOptions.td

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,8 @@ def enable_llvm_value_names : Flag<["-"], "enable-llvm-value-names">,
193193
def enable_reflection_metadata : Flag<["-"], "enable-reflection-metadata">,
194194
HelpText<"Enable emission of reflection metadata for nominal types">;
195195

196-
def strip_reflection_metadata : Flag<["-"], "strip-reflection-metadata">,
197-
HelpText<"Strip all reflection metadata for nominal types">;
198-
199-
def strip_reflection_names : Flag<["-"], "strip-reflection-names">,
200-
HelpText<"Strip names of stored properties and enum cases from"
196+
def enable_reflection_names : Flag<["-"], "enable-reflection-names">,
197+
HelpText<"Enable emission of names of stored properties and enum cases in"
201198
"reflection metadata">;
202199

203200
def stack_promotion_checks : Flag<["-"], "emit-stack-promotion-checks">,

lib/Frontend/CompilerInvocation.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,17 +1262,10 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
12621262
}
12631263

12641264
if (Args.hasArg(OPT_enable_reflection_metadata)) {
1265-
Opts.StripReflectionMetadata = false;
1266-
Opts.StripReflectionNames = false;
1267-
}
1268-
1269-
if (Args.hasArg(OPT_strip_reflection_names)) {
1270-
Opts.StripReflectionNames = true;
1271-
}
1272-
1273-
if (Args.hasArg(OPT_strip_reflection_metadata)) {
1274-
Opts.StripReflectionMetadata = true;
1275-
Opts.StripReflectionNames = true;
1265+
Opts.EnableReflectionMetadata = true;
1266+
if (Args.hasArg(OPT_enable_reflection_names)) {
1267+
Opts.EnableReflectionNames = true;
1268+
}
12761269
}
12771270

12781271
return false;

lib/IRGen/GenReflection.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,11 @@ class FieldTypeMetadataBuilder : public ReflectionMetadataBuilder {
175175
addBuiltinTypeRefs(type);
176176
}
177177

178-
if (IGM.Opts.StripReflectionNames) {
179-
addConstantInt32(0);
180-
} else {
178+
if (IGM.Opts.EnableReflectionNames) {
181179
auto fieldName = IGM.getAddrOfFieldName(value->getNameStr());
182180
addRelativeAddress(fieldName);
181+
} else {
182+
addConstantInt32(0);
183183
}
184184
}
185185

@@ -380,8 +380,8 @@ llvm::Constant *IRGenModule::getAddrOfStringForTypeRef(StringRef Str) {
380380
}
381381

382382
void IRGenModule::emitReflectionMetadataRecords() {
383-
auto DontHaveDecls = NominalTypeDecls.empty() && ExtensionDecls.empty();
384-
if (Opts.StripReflectionMetadata || DontHaveDecls)
383+
auto DoNotHaveDecls = NominalTypeDecls.empty() && ExtensionDecls.empty();
384+
if (!Opts.EnableReflectionMetadata || DoNotHaveDecls)
385385
return;
386386

387387
// We collect all referenced builtin types and emit records for them.

stdlib/private/SwiftReflectionTest/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
set(swift_reflection_test_compile_flags
2-
"-Xfrontend" "-enable-reflection-metadata")
2+
"-Xfrontend" "-enable-reflection-names")
33

44
add_swift_library(swiftSwiftReflectionTest SHARED IS_STDLIB
55
SwiftReflectionTest.swift

test/IRGen/reflection_metadata.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// RUN: %target-swift-frontend -enable-reflection-metadata -emit-ir %S/Inputs/reflection_metadata.swift | FileCheck %s
2-
// RUN: %target-swift-frontend -enable-reflection-metadata -strip-reflection-names -emit-ir %S/Inputs/reflection_metadata.swift | FileCheck %s --check-prefix=STRIP_REFLECTION_NAMES
3-
// RUN: %target-swift-frontend -enable-reflection-metadata -strip-reflection-metadata -emit-ir %S/Inputs/reflection_metadata.swift | FileCheck %s --check-prefix=STRIP_REFLECTION_METADATA
1+
// RUN: %target-swift-frontend -enable-reflection-metadata -enable-reflection-names -emit-ir %S/Inputs/reflection_metadata.swift | FileCheck %s
2+
// RUN: %target-swift-frontend -enable-reflection-metadata -emit-ir %S/Inputs/reflection_metadata.swift | FileCheck %s --check-prefix=STRIP_REFLECTION_NAMES
3+
// RUN: %target-swift-frontend -emit-ir %S/Inputs/reflection_metadata.swift | FileCheck %s --check-prefix=STRIP_REFLECTION_METADATA
44

55
// STRIP_REFLECTION_NAMES-NOT: {{.*}}swift3_reflstr
66
// STRIP_REFLECTION_NAMES_DAG: {{.*}}swift3_reflect
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// RUN: rm -rf %t && mkdir -p %t
2-
// RUN: %target-build-swift %S/Inputs/ConcreteTypes.swift %S/Inputs/GenericTypes.swift %S/Inputs/Protocols.swift %S/Inputs/Extensions.swift -parse-as-library -emit-module -emit-library -module-name TypesToReflect -Xfrontend -enable-reflection-metadata -o %t/libTypesToReflect
2+
// RUN: %target-build-swift %S/Inputs/ConcreteTypes.swift %S/Inputs/GenericTypes.swift %S/Inputs/Protocols.swift %S/Inputs/Extensions.swift -parse-as-library -emit-module -emit-library -module-name TypesToReflect -Xfrontend -enable-reflection-metadata -Xfrontend -enable-reflection-names -o %t/libTypesToReflect
33
// RUN: %target-swift-reflection-dump -binary-filename %t/libTypesToReflect > %t/typeref_decoding.txt
44
// RUN: diff -u %S/typeref_decoding.result.txt %t/typeref_decoding.txt
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: rm -rf %t && mkdir -p %t
2-
// RUN: %target-build-swift %S/Inputs/ObjectiveCTypes.swift -parse-as-library -emit-module -emit-library -module-name TypesToReflect -Xfrontend -enable-reflection-metadata -o %t/libTypesToReflect
2+
// RUN: %target-build-swift %S/Inputs/ObjectiveCTypes.swift -parse-as-library -emit-module -emit-library -module-name TypesToReflect -Xfrontend -enable-reflection-metadata -Xfrontend -enable-reflection-names -o %t/libTypesToReflect
33
// RUN: %target-swift-reflection-dump -binary-filename %t/libTypesToReflect > %t/typeref_decoding.txt
44
// RUN: diff -u %S/typeref_decoding_objc.result.txt %t/typeref_decoding.txt
55
// REQUIRES: objc_interop

0 commit comments

Comments
 (0)