Skip to content

Commit e0bf2ff

Browse files
committed
[SIL/DI] NFC: Remove TypeWrappers feature functionality
1 parent 61ab4d5 commit e0bf2ff

21 files changed

+76
-816
lines changed

include/swift/SIL/SILBuilder.h

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -888,30 +888,13 @@ class SILBuilder {
888888
Qualifier));
889889
}
890890

891-
AssignByWrapperInst *
892-
createAssignByPropertyWrapper(SILLocation Loc, SILValue Src, SILValue Dest,
893-
SILValue Initializer, SILValue Setter,
894-
AssignByWrapperInst::Mode mode) {
895-
return createAssignByWrapper(
896-
Loc, AssignByWrapperInst::Originator::PropertyWrapper, Src, Dest,
897-
Initializer, Setter, mode);
898-
}
899-
900-
AssignByWrapperInst *
901-
createAssignByTypeWrapper(SILLocation Loc, SILValue Src, SILValue Dest,
902-
SILValue Setter, AssignByWrapperInst::Mode mode) {
903-
return createAssignByWrapper(
904-
Loc, AssignByWrapperInst::Originator::TypeWrapper, Src, Dest,
905-
SILUndef::get(Dest->getType(), getModule()), Setter, mode);
906-
}
907-
908-
AssignByWrapperInst *
909-
createAssignByWrapper(SILLocation Loc, AssignByWrapperInst::Originator origin,
910-
SILValue Src, SILValue Dest, SILValue Initializer,
911-
SILValue Setter, AssignByWrapperInst::Mode mode) {
912-
return insert(new (getModule())
913-
AssignByWrapperInst(getSILDebugLocation(Loc), origin, Src,
914-
Dest, Initializer, Setter, mode));
891+
AssignByWrapperInst *createAssignByWrapper(SILLocation Loc, SILValue Src,
892+
SILValue Dest,
893+
SILValue Initializer,
894+
SILValue Setter,
895+
AssignByWrapperInst::Mode mode) {
896+
return insert(new (getModule()) AssignByWrapperInst(
897+
getSILDebugLocation(Loc), Src, Dest, Initializer, Setter, mode));
915898
}
916899

917900
StoreBorrowInst *createStoreBorrow(SILLocation Loc, SILValue Src,

include/swift/SIL/SILCloner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,7 @@ void SILCloner<ImplClass>::visitAssignByWrapperInst(AssignByWrapperInst *Inst) {
12721272
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
12731273
recordClonedInstruction(
12741274
Inst, getBuilder().createAssignByWrapper(
1275-
getOpLocation(Inst->getLoc()), Inst->getOriginator(),
1275+
getOpLocation(Inst->getLoc()),
12761276
getOpValue(Inst->getSrc()), getOpValue(Inst->getDest()),
12771277
getOpValue(Inst->getInitializer()),
12781278
getOpValue(Inst->getSetter()), Inst->getMode()));

include/swift/SIL/SILInstruction.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4782,9 +4782,6 @@ class AssignByWrapperInst
47824782
USE_SHARED_UINT8;
47834783

47844784
public:
4785-
/// The kind of a wrapper that is being applied.
4786-
enum class Originator : uint8_t { TypeWrapper, PropertyWrapper };
4787-
47884785
enum Mode {
47894786
/// The mode is not decided yet (by DefiniteInitialization).
47904787
Unknown,
@@ -4804,18 +4801,14 @@ class AssignByWrapperInst
48044801
};
48054802

48064803
private:
4807-
Originator originator;
4808-
4809-
AssignByWrapperInst(SILDebugLocation DebugLoc, Originator origin,
4804+
AssignByWrapperInst(SILDebugLocation DebugLoc,
48104805
SILValue Src, SILValue Dest, SILValue Initializer,
48114806
SILValue Setter, Mode mode);
48124807

48134808
public:
48144809
SILValue getInitializer() { return Operands[2].get(); }
48154810
SILValue getSetter() { return Operands[3].get(); }
48164811

4817-
Originator getOriginator() const { return originator; }
4818-
48194812
Mode getMode() const {
48204813
return Mode(sharedUInt8().AssignByWrapperInst.mode);
48214814
}

lib/SIL/IR/SILInstructions.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,13 +1234,11 @@ AssignInst::AssignInst(SILDebugLocation Loc, SILValue Src, SILValue Dest,
12341234
}
12351235

12361236
AssignByWrapperInst::AssignByWrapperInst(SILDebugLocation Loc,
1237-
AssignByWrapperInst::Originator origin,
12381237
SILValue Src, SILValue Dest,
12391238
SILValue Initializer, SILValue Setter,
12401239
AssignByWrapperInst::Mode mode)
1241-
: AssignInstBase(Loc, Src, Dest, Initializer, Setter), originator(origin) {
1242-
assert(Initializer->getType().is<SILFunctionType>() ||
1243-
(isa<SILUndef>(Initializer) && originator == Originator::TypeWrapper));
1240+
: AssignInstBase(Loc, Src, Dest, Initializer, Setter) {
1241+
assert(Initializer->getType().is<SILFunctionType>());
12441242
sharedUInt8().AssignByWrapperInst.mode = uint8_t(mode);
12451243
}
12461244

lib/SIL/IR/SILPrinter.cpp

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,20 +1714,6 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
17141714
}
17151715

17161716
void visitAssignByWrapperInst(AssignByWrapperInst *AI) {
1717-
{
1718-
*this << "origin ";
1719-
1720-
switch (AI->getOriginator()) {
1721-
case AssignByWrapperInst::Originator::TypeWrapper:
1722-
*this << "type_wrapper";
1723-
break;
1724-
case AssignByWrapperInst::Originator::PropertyWrapper:
1725-
*this << "property_wrapper";
1726-
}
1727-
1728-
*this << ", ";
1729-
}
1730-
17311717
*this << getIDAndType(AI->getSrc()) << " to ";
17321718
switch (AI->getMode()) {
17331719
case AssignByWrapperInst::Unknown:
@@ -1742,13 +1728,9 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
17421728
*this << "[assign_wrapped_value] ";
17431729
break;
17441730
}
1745-
1746-
*this << getIDAndType(AI->getDest());
1747-
1748-
if (AI->getOriginator() == AssignByWrapperInst::Originator::PropertyWrapper)
1749-
*this << ", init " << getIDAndType(AI->getInitializer());
1750-
1751-
*this << ", set " << getIDAndType(AI->getSetter());
1731+
*this << getIDAndType(AI->getDest())
1732+
<< ", init " << getIDAndType(AI->getInitializer())
1733+
<< ", set " << getIDAndType(AI->getSetter());
17521734
}
17531735

17541736
void visitMarkUninitializedInst(MarkUninitializedInst *MU) {

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 5 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,35 +2248,6 @@ bool SILParser::parseSILDebugLocation(SILLocation &L, SILBuilder &B) {
22482248
return false;
22492249
}
22502250

2251-
static bool
2252-
parseAssignByWrapperOriginator(AssignByWrapperInst::Originator &Result,
2253-
SILParser &P) {
2254-
if (P.parseVerbatim("origin"))
2255-
return true;
2256-
2257-
SourceLoc loc;
2258-
Identifier origin;
2259-
2260-
if (P.parseSILIdentifier(origin, loc, diag::expected_in_attribute_list))
2261-
return true;
2262-
2263-
// Then try to parse one of our other initialization kinds. We do not support
2264-
// parsing unknown here so we use that as our fail value.
2265-
auto Tmp =
2266-
llvm::StringSwitch<Optional<AssignByWrapperInst::Originator>>(
2267-
origin.str())
2268-
.Case("type_wrapper", AssignByWrapperInst::Originator::TypeWrapper)
2269-
.Case("property_wrapper",
2270-
AssignByWrapperInst::Originator::PropertyWrapper)
2271-
.Default(None);
2272-
2273-
if (!Tmp)
2274-
return true;
2275-
2276-
Result = *Tmp;
2277-
return false;
2278-
}
2279-
22802251
static bool parseAssignByWrapperMode(AssignByWrapperInst::Mode &Result,
22812252
SILParser &P) {
22822253
StringRef Str;
@@ -4406,30 +4377,14 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
44064377
case SILInstructionKind::AssignByWrapperInst: {
44074378
SILValue Src, DestAddr, InitFn, SetFn;
44084379
SourceLoc DestLoc;
4409-
AssignByWrapperInst::Originator originator;
44104380
AssignByWrapperInst::Mode mode;
44114381

4412-
if (parseAssignByWrapperOriginator(originator, *this))
4413-
return true;
4414-
4415-
if (P.parseToken(tok::comma, diag::expected_tok_in_sil_instr, ","))
4416-
return true;
4417-
44184382
if (parseTypedValueRef(Src, B) || parseVerbatim("to") ||
44194383
parseAssignByWrapperMode(mode, *this) ||
4420-
parseTypedValueRef(DestAddr, DestLoc, B))
4421-
return true;
4422-
4423-
if (originator == AssignByWrapperInst::Originator::PropertyWrapper) {
4424-
if (P.parseToken(tok::comma, diag::expected_tok_in_sil_instr, ",") ||
4425-
parseVerbatim("init") || parseTypedValueRef(InitFn, B))
4426-
return true;
4427-
} else {
4428-
assert(originator == AssignByWrapperInst::Originator::TypeWrapper);
4429-
InitFn = SILUndef::get(DestAddr->getType(), B.getModule());
4430-
}
4431-
4432-
if (P.parseToken(tok::comma, diag::expected_tok_in_sil_instr, ",") ||
4384+
parseTypedValueRef(DestAddr, DestLoc, B) ||
4385+
P.parseToken(tok::comma, diag::expected_tok_in_sil_instr, ",") ||
4386+
parseVerbatim("init") || parseTypedValueRef(InitFn, B) ||
4387+
P.parseToken(tok::comma, diag::expected_tok_in_sil_instr, ",") ||
44334388
parseVerbatim("set") || parseTypedValueRef(SetFn, B) ||
44344389
parseSILDebugLocation(InstLoc, B))
44354390
return true;
@@ -4440,7 +4395,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
44404395
return true;
44414396
}
44424397

4443-
ResultVal = B.createAssignByWrapper(InstLoc, originator, Src, DestAddr,
4398+
ResultVal = B.createAssignByWrapper(InstLoc, Src, DestAddr,
44444399
InitFn, SetFn, mode);
44454400
break;
44464401
}

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2571,13 +2571,11 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
25712571
"assign instruction can only exist in raw SIL");
25722572
require(Dest->getType().isAddress(), "Must store to an address dest");
25732573

2574-
if (AI->getOriginator() ==
2575-
AssignByWrapperInst::Originator::PropertyWrapper) {
2576-
SILValue initFn = AI->getInitializer();
2577-
CanSILFunctionType initTy = initFn->getType().castTo<SILFunctionType>();
2578-
SILFunctionConventions initConv(initTy, AI->getModule());
2579-
checkAssignByWrapperArgs(Src->getType(), initConv);
2580-
switch (initConv.getNumIndirectSILResults()) {
2574+
SILValue initFn = AI->getInitializer();
2575+
CanSILFunctionType initTy = initFn->getType().castTo<SILFunctionType>();
2576+
SILFunctionConventions initConv(initTy, AI->getModule());
2577+
checkAssignByWrapperArgs(Src->getType(), initConv);
2578+
switch (initConv.getNumIndirectSILResults()) {
25812579
case 0:
25822580
require(initConv.getNumDirectSILResults() == 1,
25832581
"wrong number of init function results");
@@ -2598,13 +2596,6 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
25982596
break;
25992597
default:
26002598
require(false, "wrong number of indirect init function results");
2601-
}
2602-
} else {
2603-
require(AI->getOriginator() ==
2604-
AssignByWrapperInst::Originator::TypeWrapper,
2605-
"wrong originator");
2606-
require(isa<SILUndef>(AI->getInitializer()),
2607-
"assignment via type wrapper does not have initializer");
26082599
}
26092600

26102601
SILValue setterFn = AI->getSetter();

lib/SILGen/SILGen.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,24 +1448,6 @@ void SILGenModule::emitConstructor(ConstructorDecl *decl) {
14481448
SILDeclRef constant(decl);
14491449
DeclContext *declCtx = decl->getDeclContext();
14501450

1451-
// Make sure that default & memberwise initializers of $Storage
1452-
// in a type wrapped type are always emitted because they would
1453-
// later be used to initialize its `$storage` property.
1454-
if (auto *SD = declCtx->getSelfStructDecl()) {
1455-
auto &ctx = SD->getASTContext();
1456-
if (SD->getName() == ctx.Id_TypeWrapperStorage &&
1457-
(decl->isMemberwiseInitializer() ||
1458-
decl == SD->getDefaultInitializer())) {
1459-
#ifndef NDEBUG
1460-
auto *wrapped = SD->getDeclContext()->getSelfNominalTypeDecl();
1461-
assert(wrapped->hasTypeWrapper());
1462-
#endif
1463-
1464-
emitFunctionDefinition(constant, getFunction(constant, ForDefinition));
1465-
return;
1466-
}
1467-
}
1468-
14691451
if (declCtx->getSelfClassDecl()) {
14701452
// Designated initializers for classes, as well as @objc convenience
14711453
// initializers, have separate entry points for allocation and

lib/SILGen/SILGenDecl.cpp

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,69 +1385,6 @@ void SILGenFunction::emitPatternBinding(PatternBindingDecl *PBD,
13851385
bool isLocalVar =
13861386
singleVar && singleVar->getDeclContext()->isLocalContext();
13871387
emitInitializer(Init, singleVar, isLocalVar, initialization);
1388-
} else if (singleVar &&
1389-
singleVar->isTypeWrapperLocalStorageForInitializer()) {
1390-
// If any of the type wrapper managed properties had default initializers
1391-
// we need to emit them as assignments to `_storage` elements as part
1392-
// of its initialization.
1393-
1394-
auto storageVarType = singleVar->getType()->castTo<TupleType>();
1395-
auto *wrappedDecl = cast<NominalTypeDecl>(
1396-
singleVar->getDeclContext()->getInnermostTypeContext());
1397-
1398-
SmallVector<std::pair<VarDecl *, Expr *>, 2> fieldsToInitialize;
1399-
fieldsToInitialize.resize_for_overwrite(storageVarType->getNumElements());
1400-
1401-
unsigned numInitializable = 0;
1402-
for (auto member : wrappedDecl->getMembers()) {
1403-
auto *PBD = dyn_cast<PatternBindingDecl>(member);
1404-
// Check every member that is managed by the type wrapper.
1405-
if (!(PBD && PBD->getSingleVar() &&
1406-
PBD->getSingleVar()->isAccessedViaTypeWrapper()))
1407-
continue;
1408-
1409-
auto *field = PBD->getSingleVar();
1410-
auto fieldNo = storageVarType->getNamedElementId(field->getName());
1411-
1412-
if (auto *initExpr = PBD->getInit(/*index=*/0)) {
1413-
fieldsToInitialize[fieldNo] = {PBD->getSingleVar(), initExpr};
1414-
++numInitializable;
1415-
}
1416-
}
1417-
1418-
if (numInitializable == 0) {
1419-
initialization->finishUninitialized(*this);
1420-
return;
1421-
}
1422-
1423-
// If there are any initializable fields, let's split _storage into
1424-
// element initializers and emit initializations for individual fields.
1425-
1426-
assert(initialization->canSplitIntoTupleElements());
1427-
1428-
SmallVector<InitializationPtr, 4> scratch;
1429-
auto fieldInits = initialization->splitIntoTupleElements(
1430-
*this, PBD, storageVarType->getCanonicalType(), scratch);
1431-
1432-
for (unsigned i : range(fieldInits.size())) {
1433-
VarDecl *field;
1434-
Expr *initExpr;
1435-
1436-
std::tie(field, initExpr) = fieldsToInitialize[i];
1437-
1438-
auto &fieldInit = fieldInits[i];
1439-
if (initExpr) {
1440-
// If there is wrapped value expression, we have to emit a
1441-
// backing property initializer call, otherwise let's use
1442-
// default expression (which is just `.init()` call).
1443-
emitInitializer(initExpr, field, bool(getWrappedValueExpr(field)),
1444-
fieldInit);
1445-
} else {
1446-
fieldInit->finishUninitialized(*this);
1447-
}
1448-
}
1449-
1450-
initialization->finishInitialization(*this);
14511388
} else {
14521389
// Otherwise, mark it uninitialized for DI to resolve.
14531390
initialization->finishUninitialized(*this);

0 commit comments

Comments
 (0)