Skip to content

Commit f2e785e

Browse files
committed
(wip) reflection flag for alloc_box
1 parent 85760d5 commit f2e785e

File tree

4 files changed

+28
-13
lines changed

4 files changed

+28
-13
lines changed

include/swift/SIL/SILBuilder.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,14 +420,15 @@ class SILBuilder {
420420

421421
AllocBoxInst *createAllocBox(SILLocation Loc, CanSILBoxType BoxType,
422422
Optional<SILDebugVariable> Var = None,
423-
bool hasDynamicLifetime = false) {
423+
bool hasDynamicLifetime = false,
424+
bool reflection = false) {
424425
llvm::SmallString<4> Name;
425426
Loc.markAsPrologue();
426427
assert((!dyn_cast_or_null<VarDecl>(Loc.getAsASTNode<Decl>()) || Var) &&
427428
"location is a VarDecl, but SILDebugVariable is empty");
428429
return insert(AllocBoxInst::create(getSILDebugLocation(Loc), BoxType, *F,
429430
substituteAnonymousArgs(Name, Var, Loc),
430-
hasDynamicLifetime));
431+
hasDynamicLifetime, reflection));
431432
}
432433

433434
AllocExistentialBoxInst *

include/swift/SIL/SILInstruction.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2289,30 +2289,38 @@ class AllocRefDynamicInst final
22892289
class AllocBoxInst final
22902290
: public InstructionBaseWithTrailingOperands<
22912291
SILInstructionKind::AllocBoxInst,
2292-
AllocBoxInst, AllocationInst, char> {
2292+
AllocBoxInst, AllocationInst, char>
2293+
{
22932294
friend SILBuilder;
22942295

22952296
TailAllocatedDebugVariable VarInfo;
22962297

2297-
bool dynamicLifetime = false;
2298+
unsigned HasDynamicLifetime : 1;
2299+
unsigned Reflection : 1;
22982300

22992301
AllocBoxInst(SILDebugLocation DebugLoc, CanSILBoxType BoxType,
23002302
ArrayRef<SILValue> TypeDependentOperands, SILFunction &F,
2301-
Optional<SILDebugVariable> Var, bool hasDynamicLifetime);
2303+
Optional<SILDebugVariable> Var, bool hasDynamicLifetime,
2304+
bool reflection = false);
23022305

23032306
static AllocBoxInst *create(SILDebugLocation Loc, CanSILBoxType boxType,
23042307
SILFunction &F,
23052308
Optional<SILDebugVariable> Var,
2306-
bool hasDynamicLifetime);
2309+
bool hasDynamicLifetime,
2310+
bool reflection = false);
23072311

23082312
public:
23092313
CanSILBoxType getBoxType() const {
23102314
return getType().castTo<SILBoxType>();
23112315
}
23122316

2313-
void setDynamicLifetime() { dynamicLifetime = true; }
2314-
bool hasDynamicLifetime() const { return dynamicLifetime; }
2317+
void setDynamicLifetime() { HasDynamicLifetime = true; }
2318+
bool hasDynamicLifetime() const { return HasDynamicLifetime; }
23152319

2320+
/// True if the box should be emitted with reflection metadata for its
2321+
/// contents.
2322+
bool emitReflectionMetadata() const { return Reflection; }
2323+
23162324
// Return the type of the memory stored in the alloc_box.
23172325
SILType getAddressType() const;
23182326

lib/SIL/IR/SILInstructions.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,24 +323,27 @@ bool AllocRefDynamicInst::isDynamicTypeDeinitAndSizeKnownEquivalentToBaseType()
323323
AllocBoxInst::AllocBoxInst(SILDebugLocation Loc, CanSILBoxType BoxType,
324324
ArrayRef<SILValue> TypeDependentOperands,
325325
SILFunction &F, Optional<SILDebugVariable> Var,
326-
bool hasDynamicLifetime)
326+
bool hasDynamicLifetime,
327+
bool reflection)
327328
: InstructionBaseWithTrailingOperands(
328329
TypeDependentOperands, Loc, SILType::getPrimitiveObjectType(BoxType)),
329330
VarInfo(Var, getTrailingObjects<char>()),
330-
dynamicLifetime(hasDynamicLifetime) {}
331+
HasDynamicLifetime(hasDynamicLifetime),
332+
Reflection(reflection) {}
331333

332334
AllocBoxInst *AllocBoxInst::create(SILDebugLocation Loc,
333335
CanSILBoxType BoxType,
334336
SILFunction &F,
335337
Optional<SILDebugVariable> Var,
336-
bool hasDynamicLifetime) {
338+
bool hasDynamicLifetime,
339+
bool reflection) {
337340
SmallVector<SILValue, 8> TypeDependentOperands;
338341
collectTypeDependentOperands(TypeDependentOperands, F, BoxType);
339342
auto Sz = totalSizeToAlloc<swift::Operand, char>(TypeDependentOperands.size(),
340343
Var ? Var->Name.size() : 0);
341344
auto Buf = F.getModule().allocateInst(Sz, alignof(AllocBoxInst));
342345
return ::new (Buf) AllocBoxInst(Loc, BoxType, TypeDependentOperands, F, Var,
343-
hasDynamicLifetime);
346+
hasDynamicLifetime, reflection);
344347
}
345348

346349
SILType AllocBoxInst::getAddressType() const {

lib/SILOptimizer/Transforms/PartialApplySimplification.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,10 @@ void PartialApplySimplificationPass::processKnownCallee(SILFunction *callee,
488488

489489
auto newFunctionRef = B.createFunctionRef(loc, callee);
490490
auto boxTy = SILBoxType::get(C, newBoxLayout, pa->getSubstitutionMap());
491-
auto newBox = B.createAllocBox(loc, boxTy);
491+
auto newBox = B.createAllocBox(loc, boxTy,
492+
/*debug variable*/ None,
493+
/*dynamic lifetime*/ false,
494+
/*reflection*/ true);
492495

493496
// Transfer the formerly partially-applied arguments into the box.
494497
auto appliedArgs = pa->getArguments();

0 commit comments

Comments
 (0)