Skip to content

Commit a8b1723

Browse files
committed
Reflection: Don't use the old box mangling
The TypeDecoder doesn't support the new box mangling yet and instead just decodes it as Builtin.NativeObject, but that's OK because the Remote Mirrors lowered the old box mangling as Builtin.NativeObject anyway.
1 parent 62754f3 commit a8b1723

File tree

7 files changed

+11
-33
lines changed

7 files changed

+11
-33
lines changed

lib/IRGen/GenReflection.cpp

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -203,27 +203,16 @@ class ReflectionMetadataBuilder {
203203

204204
/// Add a 32-bit relative offset to a mangled typeref string
205205
/// in the typeref reflection section.
206-
void addTypeRef(ModuleDecl *ModuleContext, CanType type,
207-
CanGenericSignature Context = {}) {
206+
void addTypeRef(ModuleDecl *ModuleContext, CanType type) {
208207
assert(type);
209208

210209
// Generic parameters should be written in terms of interface types
211210
// for the purposes of reflection metadata
212211
assert(!type->hasArchetype() && "Forgot to map typeref out of context");
213212

214-
// TODO: As a compatibility hack, mangle single-field boxes with the legacy
215-
// mangling in reflection metadata.
216-
bool isSingleFieldOfBox = false;
217-
auto boxTy = dyn_cast<SILBoxType>(type);
218-
if (boxTy && boxTy->getLayout()->getFields().size() == 1) {
219-
GenericContextScope scope(IGM, Context);
220-
type = boxTy->getFieldLoweredType(IGM.getSILModule(), 0);
221-
isSingleFieldOfBox = true;
222-
}
223213
IRGenMangler mangler;
224214
auto MangledStr = mangler.mangleTypeForReflection(IGM, type,
225-
ModuleContext,
226-
isSingleFieldOfBox);
215+
ModuleContext);
227216
auto mangledName = IGM.getAddrOfStringForTypeRef(MangledStr);
228217
B.addRelativeAddress(mangledName);
229218
}
@@ -238,8 +227,7 @@ class ReflectionMetadataBuilder {
238227
} else {
239228
CanType type = nominal->getDeclaredType()->getCanonicalType();
240229
mangledStr =
241-
mangler.mangleTypeForReflection(IGM, type, nominal->getModuleContext(),
242-
/*isSingleFieldOfBox=*/false);
230+
mangler.mangleTypeForReflection(IGM, type, nominal->getModuleContext());
243231
}
244232
auto mangledName = IGM.getAddrOfStringForTypeRef(mangledStr);
245233
B.addRelativeAddress(mangledName);
@@ -754,8 +742,7 @@ class CaptureDescriptorBuilder : public ReflectionMetadataBuilder {
754742

755743
// Now add typerefs of all of the captures.
756744
for (auto CaptureType : CaptureTypes) {
757-
addTypeRef(IGM.getSILModule().getSwiftModule(), CaptureType,
758-
OrigCalleeType->getGenericSignature());
745+
addTypeRef(IGM.getSILModule().getSwiftModule(), CaptureType);
759746
addBuiltinTypeRefs(CaptureType);
760747
}
761748

lib/IRGen/IRGenMangler.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ std::string IRGenMangler::manglePartialApplyForwarder(StringRef FuncName) {
8282
SymbolicMangling
8383
IRGenMangler::mangleTypeForReflection(IRGenModule &IGM,
8484
Type Ty,
85-
ModuleDecl *Module,
86-
bool isSingleFieldOfBox) {
85+
ModuleDecl *Module) {
8786
Mod = Module;
8887
OptimizeProtocolNames = false;
8988

@@ -109,8 +108,6 @@ IRGenMangler::mangleTypeForReflection(IRGenModule &IGM,
109108
SymbolicReferences.clear();
110109

111110
appendType(Ty);
112-
if (isSingleFieldOfBox)
113-
appendOperator("Xb");
114111

115112
return {finalize(), std::move(SymbolicReferences)};
116113
}

lib/IRGen/IRGenMangler.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,7 @@ class IRGenMangler : public Mangle::ASTMangler {
355355

356356
SymbolicMangling mangleTypeForReflection(IRGenModule &IGM,
357357
Type Ty,
358-
ModuleDecl *Module,
359-
bool isSingleFieldOfBox);
358+
ModuleDecl *Module);
360359

361360
std::string mangleTypeForLLVMTypeName(CanType Ty);
362361

lib/IRGen/MetadataRequest.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,7 @@ llvm::Constant *IRGenModule::getAddrOfStringForTypeRef(
303303
llvm::Constant *irgen::getTypeRef(IRGenModule &IGM, CanType type) {
304304
IRGenMangler Mangler;
305305
auto SymbolicName = Mangler.mangleTypeForReflection(IGM, type,
306-
IGM.getSwiftModule(),
307-
/*single-field box*/ false);
306+
IGM.getSwiftModule());
308307

309308
return IGM.getAddrOfStringForTypeRef(SymbolicName);
310309
}

test/Reflection/capture_descriptors.sil

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ bb0(%i: $Int, %p: $@thick P.Type):
4141

4242
// CHECK: - Capture types:
4343
// CHECK-NEXT: (struct Swift.Int)
44-
// CHECK-NEXT: (sil_box
45-
// CHECK-NEXT: (struct Swift.Int))
44+
// CHECK-NEXT: (builtin Builtin.NativeObject)
4645
// CHECK-NEXT: (existential_metatype
4746
// CHECK-NEXT: (protocol_composition
4847
// CHECK-NEXT: (protocol capture_descriptors.P)))
@@ -76,8 +75,7 @@ bb0:
7675

7776
// CHECK: - Capture types:
7877
// CHECK-NEXT: (struct Swift.Int)
79-
// CHECK-NEXT: (sil_box
80-
// CHECK-NEXT: (struct Swift.String))
78+
// CHECK-NEXT: (builtin Builtin.NativeObject)
8179
// CHECK-NEXT: - Metadata sources:
8280

8381

test/Reflection/typeref_decoding.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -708,8 +708,7 @@
708708
// CHECK: CAPTURE DESCRIPTORS:
709709
// CHECK: ====================
710710
// CHECK: - Capture types:
711-
// CHECK: (sil_box
712-
// CHECK: (generic_type_parameter depth=0 index=0))
711+
// CHECK: (builtin Builtin.NativeObject)
713712
// CHECK: - Metadata sources:
714713
// CHECK: (generic_type_parameter depth=0 index=0)
715714
// CHECK: (closure_binding index=0)

test/Reflection/typeref_decoding_asan.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -708,8 +708,7 @@
708708
// CHECK: CAPTURE DESCRIPTORS:
709709
// CHECK: ====================
710710
// CHECK: - Capture types:
711-
// CHECK: (sil_box
712-
// CHECK: (generic_type_parameter depth=0 index=0))
711+
// CHECK: (builtin Builtin.NativeObject)
713712
// CHECK: - Metadata sources:
714713
// CHECK: (generic_type_parameter depth=0 index=0)
715714
// CHECK: (closure_binding index=0)

0 commit comments

Comments
 (0)