Skip to content

Commit a4f560d

Browse files
committed
SIL: Use getLoweredRValueType() in various places
1 parent fe094c6 commit a4f560d

File tree

11 files changed

+64
-61
lines changed

11 files changed

+64
-61
lines changed

include/swift/SIL/TypeLowering.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ class TypeConverter {
808808
bool isNonObjC = false);
809809
AbstractionPattern getAbstractionPattern(EnumElementDecl *element);
810810

811-
SILType getLoweredTypeOfGlobal(VarDecl *var);
811+
CanType getLoweredTypeOfGlobal(VarDecl *var);
812812

813813
/// Return the SILFunctionType for a native function value of the
814814
/// given type.

lib/SIL/Bridging.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ using namespace swift;
2929
using namespace swift::Lowering;
3030

3131

32-
SILType TypeConverter::getLoweredTypeOfGlobal(VarDecl *var) {
32+
CanType TypeConverter::getLoweredTypeOfGlobal(VarDecl *var) {
3333
AbstractionPattern origType = getAbstractionPattern(var);
3434
assert(!origType.isTypeParameter());
35-
return getLoweredType(origType, origType.getType()).getObjectType();
35+
return getLoweredRValueType(origType, origType.getType());
3636
}
3737

3838
AnyFunctionType::Param

lib/SIL/SILFunctionType.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -857,8 +857,8 @@ static void destructureYieldsForCoroutine(SILModule &M,
857857

858858
// 'modify' yields an inout of the target type.
859859
if (accessor->getAccessorKind() == AccessorKind::Modify) {
860-
auto loweredValueTy = M.Types.getLoweredType(origType, canValueType);
861-
yields.push_back(SILYieldInfo(loweredValueTy.getASTType(),
860+
auto loweredValueTy = M.Types.getLoweredRValueType(origType, canValueType);
861+
yields.push_back(SILYieldInfo(loweredValueTy,
862862
ParameterConvention::Indirect_Inout));
863863
return;
864864
}
@@ -2411,8 +2411,7 @@ class SILTypeSubstituter :
24112411
}
24122412

24132413
AbstractionPattern abstraction(Sig, origType);
2414-
return TheSILModule.Types.getLoweredType(abstraction, substType)
2415-
.getASTType();
2414+
return TheSILModule.Types.getLoweredRValueType(abstraction, substType);
24162415
}
24172416
};
24182417

lib/SIL/SILType.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,12 @@ SILType SILType::getFieldType(VarDecl *field, SILModule &M) const {
138138
baseTy->getTypeOfMember(M.getSwiftModule(),
139139
field, nullptr)->getCanonicalType();
140140
}
141-
auto loweredTy = M.Types.getLoweredType(origFieldTy, substFieldTy);
141+
142+
auto loweredTy = M.Types.getLoweredRValueType(origFieldTy, substFieldTy);
142143
if (isAddress() || getClassOrBoundGenericClass() != nullptr) {
143-
return loweredTy.getAddressType();
144+
return SILType::getPrimitiveAddressType(loweredTy);
144145
} else {
145-
return loweredTy.getObjectType();
146+
return SILType::getPrimitiveObjectType(loweredTy);
146147
}
147148
}
148149

@@ -166,9 +167,10 @@ SILType SILType::getEnumElementType(EnumElementDecl *elt, SILModule &M) const {
166167
getASTType()->getTypeOfMember(M.getSwiftModule(), elt,
167168
elt->getArgumentInterfaceType());
168169
auto loweredTy =
169-
M.Types.getLoweredType(M.Types.getAbstractionPattern(elt), substEltTy);
170+
M.Types.getLoweredRValueType(M.Types.getAbstractionPattern(elt),
171+
substEltTy);
170172

171-
return SILType(loweredTy.getASTType(), getCategory());
173+
return SILType(loweredTy, getCategory());
172174
}
173175

174176
bool SILType::isLoadableOrOpaque(SILModule &M) const {

lib/SIL/TypeLowering.cpp

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,9 +1365,8 @@ static CanTupleType computeLoweredTupleType(TypeConverter &tc,
13651365
assert(Flags.getValueOwnership() == ValueOwnership::Default);
13661366
assert(!Flags.isVariadic());
13671367

1368-
SILType silType = tc.getLoweredType(origEltType, substEltType);
1369-
CanType loweredSubstEltType = silType.getASTType();
1370-
1368+
CanType loweredSubstEltType =
1369+
tc.getLoweredRValueType(origEltType, substEltType);
13711370
changed = (changed || substEltType != loweredSubstEltType ||
13721371
!Flags.isNone());
13731372

@@ -1395,8 +1394,8 @@ static CanType computeLoweredOptionalType(TypeConverter &tc,
13951394
assert(substType.getOptionalObjectType() == substObjectType);
13961395

13971396
CanType loweredObjectType =
1398-
tc.getLoweredType(origType.getOptionalObjectType(), substObjectType)
1399-
.getASTType();
1397+
tc.getLoweredRValueType(origType.getOptionalObjectType(),
1398+
substObjectType);
14001399

14011400
// If the object type didn't change, we don't have to rebuild anything.
14021401
if (loweredObjectType == substObjectType) {
@@ -1412,9 +1411,8 @@ computeLoweredReferenceStorageType(TypeConverter &tc,
14121411
AbstractionPattern origType,
14131412
CanReferenceStorageType substType) {
14141413
CanType loweredReferentType =
1415-
tc.getLoweredType(origType.getReferenceStorageReferentType(),
1416-
substType.getReferentType())
1417-
.getASTType();
1414+
tc.getLoweredRValueType(origType.getReferenceStorageReferentType(),
1415+
substType.getReferentType());
14181416

14191417
if (loweredReferentType == substType.getReferentType())
14201418
return substType;
@@ -1426,8 +1424,8 @@ computeLoweredReferenceStorageType(TypeConverter &tc,
14261424
CanSILFunctionType
14271425
TypeConverter::getSILFunctionType(AbstractionPattern origType,
14281426
CanFunctionType substType) {
1429-
return getLoweredType(origType, substType)
1430-
.castTo<SILFunctionType>();
1427+
return cast<SILFunctionType>(
1428+
getLoweredRValueType(origType, substType));
14311429
}
14321430

14331431
const TypeLowering &
@@ -1963,8 +1961,7 @@ SILType TypeConverter::getSubstitutedStorageType(AbstractStorageDecl *value,
19631961
substType = substType.getReferenceStorageReferent();
19641962
}
19651963

1966-
SILType silSubstType = getLoweredType(origType, substType).getAddressType();
1967-
substType = silSubstType.getASTType();
1964+
CanType substLoweredType = getLoweredRValueType(origType, substType);
19681965

19691966
// Type substitution preserves structural type structure, and the
19701967
// type-of-reference is only different in the outermost structural
@@ -1974,13 +1971,11 @@ SILType TypeConverter::getSubstitutedStorageType(AbstractStorageDecl *value,
19741971
// The only really significant manipulation there is with @weak and
19751972
// @unowned.
19761973
if (origRefType) {
1977-
substType = CanType(ReferenceStorageType::get(substType,
1978-
origRefType->getOwnership(),
1979-
Context));
1980-
return SILType::getPrimitiveType(substType, SILValueCategory::Address);
1974+
substLoweredType = CanReferenceStorageType::get(substType,
1975+
origRefType->getOwnership());
19811976
}
19821977

1983-
return silSubstType;
1978+
return SILType::getPrimitiveAddressType(substLoweredType);
19841979
}
19851980

19861981
void TypeConverter::pushGenericContext(CanGenericSignature sig) {
@@ -2492,7 +2487,8 @@ CanSILBoxType TypeConverter::getBoxTypeForEnumElement(SILType enumType,
24922487

24932488
if (boxSignature == CanGenericSignature()) {
24942489
auto eltIntfTy = elt->getArgumentInterfaceType();
2495-
auto boxVarTy = getLoweredType(eltIntfTy).getASTType();
2490+
2491+
auto boxVarTy = getLoweredRValueType(eltIntfTy);
24962492
auto layout = SILLayout::get(C, nullptr, SILField(boxVarTy, true));
24972493
return SILBoxType::get(C, layout, {});
24982494
}
@@ -2503,8 +2499,9 @@ CanSILBoxType TypeConverter::getBoxTypeForEnumElement(SILType enumType,
25032499
// Lower the enum element's argument in the box's context.
25042500
auto eltIntfTy = elt->getArgumentInterfaceType();
25052501
GenericContextScope scope(*this, boxSignature);
2506-
auto boxVarTy = getLoweredType(getAbstractionPattern(elt), eltIntfTy)
2507-
.getASTType();
2502+
2503+
auto boxVarTy = getLoweredRValueType(getAbstractionPattern(elt),
2504+
eltIntfTy);
25082505
auto layout = SILLayout::get(C, boxSignature, SILField(boxVarTy, true));
25092506

25102507
// Instantiate the layout with enum's substitution list.

lib/SILGen/LValue.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,20 @@ struct LValueTypeData {
5151
CanType SubstFormalType;
5252

5353
/// The lowered type of value that should be stored in the l-value.
54-
/// Always an object type.
5554
///
5655
/// On physical path components, projection yields an address of
5756
/// this type. On logical path components, materialize yields an
5857
/// address of this type, set expects a value of this type, and
59-
/// get yields a value of this type.
60-
SILType TypeOfRValue;
58+
/// get yields an object of this type.
59+
CanType TypeOfRValue;
6160

6261
SGFAccessKind AccessKind;
6362

6463
LValueTypeData() = default;
6564
LValueTypeData(SGFAccessKind accessKind, AbstractionPattern origFormalType,
66-
CanType substFormalType, SILType typeOfRValue)
65+
CanType substFormalType, CanType typeOfRValue)
6766
: OrigFormalType(origFormalType), SubstFormalType(substFormalType),
6867
TypeOfRValue(typeOfRValue), AccessKind(accessKind) {
69-
assert(typeOfRValue.isObject());
7068
assert(substFormalType->isMaterializable());
7169
}
7270

@@ -185,7 +183,9 @@ class PathComponent {
185183

186184
/// Returns the logical type-as-rvalue of the value addressed by the
187185
/// component. This is always an object type, never an address.
188-
SILType getTypeOfRValue() const { return TypeData.TypeOfRValue; }
186+
SILType getTypeOfRValue() const {
187+
return SILType::getPrimitiveObjectType(TypeData.TypeOfRValue);
188+
}
189189
AbstractionPattern getOrigFormalType() const {
190190
return TypeData.OrigFormalType;
191191
}
@@ -485,7 +485,9 @@ class LValue {
485485
/// Returns the type-of-rvalue of the logical object referenced by
486486
/// this l-value. Note that this may differ significantly from the
487487
/// type of l-value.
488-
SILType getTypeOfRValue() const { return getTypeData().TypeOfRValue; }
488+
SILType getTypeOfRValue() const {
489+
return SILType::getPrimitiveObjectType(getTypeData().TypeOfRValue);
490+
}
489491
CanType getSubstFormalType() const { return getTypeData().SubstFormalType; }
490492
AbstractionPattern getOrigFormalType() const {
491493
return getTypeData().OrigFormalType;

lib/SILGen/SILGen.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,8 @@ SILFunction *SILGenModule::emitLazyGlobalInitializer(StringRef funcName,
11231123
auto *type = blockParam->getType()->castTo<FunctionType>();
11241124
Type initType = FunctionType::get({}, TupleType::getEmpty(C),
11251125
type->getExtInfo());
1126-
auto initSILType = getLoweredType(initType).castTo<SILFunctionType>();
1126+
auto initSILType = cast<SILFunctionType>(
1127+
Types.getLoweredRValueType(initType));
11271128

11281129
SILGenFunctionBuilder builder(*this);
11291130
auto *f = builder.createFunction(
@@ -1337,9 +1338,10 @@ SILGenModule::canStorageUseStoredKeyPathComponent(AbstractStorageDecl *decl,
13371338
componentObjTy = genericEnv->mapTypeIntoContext(componentObjTy);
13381339
auto storageTy = M.Types.getSubstitutedStorageType(decl, componentObjTy);
13391340
auto opaqueTy =
1340-
M.Types.getLoweredType(AbstractionPattern::getOpaque(), componentObjTy);
1341+
M.Types.getLoweredRValueType(AbstractionPattern::getOpaque(),
1342+
componentObjTy);
13411343

1342-
return storageTy.getAddressType() == opaqueTy.getAddressType();
1344+
return storageTy.getASTType() == opaqueTy;
13431345
}
13441346
case AccessStrategy::DirectToAccessor:
13451347
case AccessStrategy::DispatchToAccessor:

lib/SILGen/SILGenExpr.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5159,8 +5159,7 @@ ManagedValue SILGenFunction::emitLValueToPointer(SILLocation loc, LValue &&lv,
51595159
case PTK_AutoreleasingUnsafeMutablePointer: {
51605160
// Set up a writeback through a +0 buffer.
51615161
LValueTypeData typeData = lv.getTypeData();
5162-
SILType rvalueType = SILType::getPrimitiveObjectType(
5163-
CanUnmanagedStorageType::get(typeData.TypeOfRValue.getASTType()));
5162+
auto rvalueType = CanUnmanagedStorageType::get(typeData.TypeOfRValue);
51645163

51655164
LValueTypeData unownedTypeData(
51665165
lv.getAccessKind(),

lib/SILGen/SILGenGlobalVariable.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ SILGlobalVariable *SILGenModule::getSILGlobalVariable(VarDecl *gDecl,
5454
return gv;
5555
}
5656

57-
SILType silTy = M.Types.getLoweredTypeOfGlobal(gDecl);
57+
SILType silTy = SILType::getPrimitiveObjectType(
58+
M.Types.getLoweredTypeOfGlobal(gDecl));
5859

5960
auto *silGlobal = SILGlobalVariable::create(M, silLinkage, IsNotSerialized,
6061
mangledName, silTy,

lib/SILGen/SILGenLValue.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ static LValueTypeData getAbstractedTypeData(SILGenModule &SGM,
207207
accessKind,
208208
origFormalType,
209209
substFormalType,
210-
SGM.Types.getLoweredType(origFormalType, substFormalType).getObjectType()
210+
SGM.Types.getLoweredRValueType(origFormalType, substFormalType)
211211
};
212212
}
213213

@@ -455,13 +455,13 @@ static LValueTypeData getValueTypeData(SGFAccessKind accessKind,
455455
accessKind,
456456
AbstractionPattern(formalType),
457457
formalType,
458-
value->getType().getObjectType()
458+
value->getType().getASTType(),
459459
};
460460
}
461461
static LValueTypeData getValueTypeData(SILGenFunction &SGF,
462462
SGFAccessKind accessKind, Expr *e) {
463463
CanType formalType = getSubstFormalRValueType(e);
464-
SILType loweredType = SGF.getLoweredType(formalType).getObjectType();
464+
CanType loweredType = SGF.getLoweredType(formalType).getASTType();
465465

466466
return {
467467
accessKind,
@@ -488,7 +488,8 @@ static ManagedValue getAddressOfOptionalValue(SILGenFunction &SGF,
488488
// embedded in the payload.
489489
SILValue valueAddr =
490490
SGF.B.createUncheckedTakeEnumDataAddr(loc, optAddr.forward(SGF), someDecl,
491-
valueTypeData.TypeOfRValue.getAddressType());
491+
SILType::getPrimitiveAddressType(
492+
valueTypeData.TypeOfRValue));
492493

493494
// Return the value as +1 if the optional was +1.
494495
if (hadCleanup) {
@@ -2080,7 +2081,7 @@ LValue LValue::forAddress(SGFAccessKind accessKind, ManagedValue address,
20802081
assert(address.isLValue());
20812082
LValueTypeData typeData = {
20822083
accessKind, origFormalType, substFormalType,
2083-
address.getType().getObjectType()
2084+
address.getType().getASTType()
20842085
};
20852086

20862087
LValue lv;
@@ -2133,7 +2134,7 @@ void LValue::addOrigToSubstComponent(SILType loweredSubstType) {
21332134
getAccessKind(),
21342135
AbstractionPattern(substFormalType),
21352136
substFormalType,
2136-
loweredSubstType
2137+
loweredSubstType.getASTType()
21372138
};
21382139
add<OrigToSubstComponent>(typeData, getOrigFormalType());
21392140
}
@@ -2161,7 +2162,7 @@ void LValue::addSubstToOrigComponent(AbstractionPattern origType,
21612162
getAccessKind(),
21622163
origType,
21632164
getSubstFormalType(),
2164-
loweredSubstType
2165+
loweredSubstType.getASTType()
21652166
};
21662167
add<SubstToOrigComponent>(typeData);
21672168
}
@@ -2674,7 +2675,9 @@ LValue SILGenLValue::visitDiscardAssignmentExpr(DiscardAssignmentExpr *e,
26742675
LValueOptions options) {
26752676
LValueTypeData typeData = getValueTypeData(SGF, accessKind, e);
26762677

2677-
SILValue address = SGF.emitTemporaryAllocation(e, typeData.TypeOfRValue);
2678+
SILValue address = SGF.emitTemporaryAllocation(e,
2679+
SILType::getPrimitiveObjectType(
2680+
typeData.TypeOfRValue));
26782681
address = SGF.B.createMarkUninitialized(e, address,
26792682
MarkUninitializedInst::Var);
26802683
LValue lv;
@@ -3133,7 +3136,7 @@ LValue SILGenLValue::visitKeyPathApplicationExpr(KeyPathApplicationExpr *e,
31333136

31343137
// Reabstract to the substituted abstraction level if necessary.
31353138
auto substResultSILTy = SGF.getLoweredType(substFormalType);
3136-
if (typeData.TypeOfRValue != substResultSILTy.getObjectType()) {
3139+
if (typeData.TypeOfRValue != substResultSILTy.getASTType()) {
31373140
lv.addOrigToSubstComponent(substResultSILTy);
31383141
}
31393142
}
@@ -3191,7 +3194,7 @@ LValue SILGenLValue::visitTupleElementExpr(TupleElementExpr *e,
31913194
accessKind,
31923195
baseTypeData.OrigFormalType.getTupleElementType(index),
31933196
cast<TupleType>(baseTypeData.SubstFormalType).getElementType(index),
3194-
baseTypeData.TypeOfRValue.getTupleElementType(index)
3197+
cast<TupleType>(baseTypeData.TypeOfRValue).getElementType(index)
31953198
};
31963199

31973200
lv.add<TupleElementComponent>(index, typeData);
@@ -3229,13 +3232,11 @@ LValue SILGenLValue::visitOpenExistentialExpr(OpenExistentialExpr *e,
32293232
static LValueTypeData
32303233
getOptionalObjectTypeData(SILGenFunction &SGF, SGFAccessKind accessKind,
32313234
const LValueTypeData &baseTypeData) {
3232-
EnumElementDecl *someDecl = SGF.getASTContext().getOptionalSomeDecl();
3233-
32343235
return {
32353236
accessKind,
32363237
baseTypeData.OrigFormalType.getOptionalObjectType(),
32373238
baseTypeData.SubstFormalType.getOptionalObjectType(),
3238-
baseTypeData.TypeOfRValue.getEnumElementType(someDecl, SGF.SGM.M),
3239+
baseTypeData.TypeOfRValue.getOptionalObjectType(),
32393240
};
32403241
}
32413242

@@ -4077,7 +4078,7 @@ SILGenFunction::emitOpenExistentialLValue(SILLocation loc,
40774078
assert(!formalRValueType->hasLValueType());
40784079
LValueTypeData typeData = {
40794080
accessKind, AbstractionPattern::getOpaque(), formalRValueType,
4080-
getLoweredType(formalRValueType).getObjectType()
4081+
getLoweredType(formalRValueType).getASTType()
40814082
};
40824083

40834084
// Open up the existential.

lib/SILOptimizer/IPO/GlobalOpt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,10 @@ static SILFunction *getGlobalGetterFunction(SILOptFunctionBuilder &FunctionBuild
262262
Serialized = IsSerialized;
263263
}
264264

265-
auto refType = M.Types.getLoweredType(varDecl->getInterfaceType());
265+
auto refType = M.Types.getLoweredRValueType(varDecl->getInterfaceType());
266266

267267
// Function takes no arguments and returns refType
268-
SILResultInfo Results[] = { SILResultInfo(refType.getASTType(),
268+
SILResultInfo Results[] = { SILResultInfo(refType,
269269
ResultConvention::Owned) };
270270
SILFunctionType::ExtInfo EInfo;
271271
EInfo = EInfo.withRepresentation(SILFunctionType::Representation::Thin);

0 commit comments

Comments
 (0)