Skip to content

Commit 95ba21d

Browse files
authored
Merge pull request #23110 from slavapestov/resilience-expansion-has-no-default
SIL: Remove default arguments from resilience expansion parameters
2 parents 56c8105 + d04c335 commit 95ba21d

21 files changed

+207
-151
lines changed

include/swift/SIL/SILBuilder.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,9 @@ class SILBuilder {
198198
SILModule &getModule() const { return C.Module; }
199199
ASTContext &getASTContext() const { return getModule().getASTContext(); }
200200
const Lowering::TypeLowering &getTypeLowering(SILType T) const {
201-
return getModule().getTypeLowering(T);
201+
// FIXME: Expansion
202+
return getModule().Types.getTypeLowering(T,
203+
ResilienceExpansion::Minimal);
202204
}
203205

204206
void setOpenedArchetypesTracker(SILOpenedArchetypesTracker *Tracker) {
@@ -2155,13 +2157,15 @@ class SILBuilder {
21552157
if (!SILModuleConventions(M).useLoweredAddresses())
21562158
return true;
21572159

2160+
// FIXME: Just call getTypeLowering() here, and move this code there
2161+
21582162
auto expansion = ResilienceExpansion::Maximal;
21592163
// If there's no current SILFunction, we're inserting into a global
21602164
// variable initializer.
21612165
if (F)
21622166
expansion = F->getResilienceExpansion();
21632167

2164-
return M.getTypeLowering(Ty, expansion).isLoadable();
2168+
return M.Types.getTypeLowering(Ty, expansion).isLoadable();
21652169
}
21662170

21672171
void appendOperandTypeName(SILType OpdTy, llvm::SmallString<16> &Name) {

include/swift/SIL/SILModule.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -315,13 +315,6 @@ class SILModule {
315315
/// This converts Swift types to SILTypes.
316316
mutable Lowering::TypeConverter Types;
317317

318-
/// Look up the TypeLowering for a SILType.
319-
const Lowering::TypeLowering &
320-
getTypeLowering(SILType t, ResilienceExpansion expansion =
321-
ResilienceExpansion::Minimal) {
322-
return Types.getTypeLowering(t, expansion);
323-
}
324-
325318
/// Invalidate cached entries in SIL Loader.
326319
void invalidateSILLoaderCaches();
327320

include/swift/SIL/TypeLowering.h

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -216,26 +216,29 @@ class TypeLowering {
216216
};
217217

218218
private:
219+
friend class TypeConverter;
220+
219221
/// The SIL type of values with this Swift type.
220222
SILType LoweredType;
221223

222224
RecursiveProperties Properties;
223225
unsigned ReferenceCounted : 1;
224226

225-
public:
226227
/// The resilience expansion for this type lowering.
227228
/// If the type is not resilient at all, this is always Minimal.
228-
ResilienceExpansion forExpansion = ResilienceExpansion::Minimal;
229+
unsigned ForExpansion : 1;
229230

230231
/// A single linked list of lowerings for different resilience expansions.
231232
/// The first lowering is always for ResilientExpansion::Minimal.
232-
mutable const TypeLowering *nextExpansion = nullptr;
233+
mutable const TypeLowering *NextExpansion = nullptr;
233234

234235
protected:
235236
TypeLowering(SILType type, RecursiveProperties properties,
236-
IsReferenceCounted_t isRefCounted)
237+
IsReferenceCounted_t isRefCounted,
238+
ResilienceExpansion forExpansion)
237239
: LoweredType(type), Properties(properties),
238-
ReferenceCounted(isRefCounted) {}
240+
ReferenceCounted(isRefCounted),
241+
ForExpansion(unsigned(forExpansion)) {}
239242

240243
public:
241244
TypeLowering(const TypeLowering &) = delete;
@@ -247,12 +250,22 @@ class TypeLowering {
247250
/// convention?
248251
///
249252
/// This is independent of whether the SIL argument is address type.
250-
bool isFormallyPassedIndirectly() const { return isAddressOnly(); }
253+
bool isFormallyPassedIndirectly() const {
254+
assert(!isResilient() ||
255+
getResilienceExpansion() == ResilienceExpansion::Minimal &&
256+
"calling convention uses minimal resilience expansion");
257+
return isAddressOnly();
258+
}
251259

252260
/// Are r-values of this type returned indirectly by formal convention?
253261
///
254262
/// This is independent of whether the SIL result is address type.
255-
bool isFormallyReturnedIndirectly() const { return isAddressOnly(); }
263+
bool isFormallyReturnedIndirectly() const {
264+
assert(!isResilient() ||
265+
getResilienceExpansion() == ResilienceExpansion::Minimal &&
266+
"calling convention uses minimal resilience expansion");
267+
return isAddressOnly();
268+
}
256269

257270
RecursiveProperties getRecursiveProperties() const {
258271
return Properties;
@@ -306,6 +319,10 @@ class TypeLowering {
306319
return Properties.isResilient();
307320
}
308321

322+
ResilienceExpansion getResilienceExpansion() const {
323+
return ResilienceExpansion(ForExpansion);
324+
}
325+
309326
/// Produce an exact copy of the value in the given address as a
310327
/// scalar. The caller is responsible for destroying this value,
311328
/// e.g. by releasing it.
@@ -748,8 +765,7 @@ class TypeConverter {
748765
/// Lowers a Swift type to a SILType, and returns the SIL TypeLowering
749766
/// for that type.
750767
const TypeLowering &
751-
getTypeLowering(Type t, ResilienceExpansion forExpansion =
752-
ResilienceExpansion::Minimal) {
768+
getTypeLowering(Type t, ResilienceExpansion forExpansion) {
753769
AbstractionPattern pattern(getCurGenericContext(), t->getCanonicalType());
754770
return getTypeLowering(pattern, t, forExpansion);
755771
}
@@ -758,33 +774,28 @@ class TypeConverter {
758774
/// patterns of the given original type.
759775
const TypeLowering &getTypeLowering(AbstractionPattern origType,
760776
Type substType,
761-
ResilienceExpansion forExpansion =
762-
ResilienceExpansion::Minimal);
777+
ResilienceExpansion forExpansion);
763778

764779
/// Returns the SIL TypeLowering for an already lowered SILType. If the
765780
/// SILType is an address, returns the TypeLowering for the pointed-to
766781
/// type.
767782
const TypeLowering &
768-
getTypeLowering(SILType t, ResilienceExpansion forExpansion =
769-
ResilienceExpansion::Minimal);
783+
getTypeLowering(SILType t, ResilienceExpansion forExpansion);
770784

771785
// Returns the lowered SIL type for a Swift type.
772-
SILType getLoweredType(Type t, ResilienceExpansion forExpansion
773-
= ResilienceExpansion::Minimal) {
786+
SILType getLoweredType(Type t, ResilienceExpansion forExpansion) {
774787
return getTypeLowering(t, forExpansion).getLoweredType();
775788
}
776789

777790
// Returns the lowered SIL type for a Swift type.
778791
SILType getLoweredType(AbstractionPattern origType, Type substType,
779-
ResilienceExpansion forExpansion =
780-
ResilienceExpansion::Minimal) {
792+
ResilienceExpansion forExpansion) {
781793
return getTypeLowering(origType, substType, forExpansion)
782794
.getLoweredType();
783795
}
784796

785797
SILType getLoweredLoadableType(Type t,
786-
ResilienceExpansion forExpansion =
787-
ResilienceExpansion::Minimal) {
798+
ResilienceExpansion forExpansion) {
788799
const TypeLowering &ti = getTypeLowering(t, forExpansion);
789800
assert(
790801
(ti.isLoadable() || !SILModuleConventions(M).useLoweredAddresses()) &&
@@ -793,11 +804,16 @@ class TypeConverter {
793804
}
794805

795806
CanType getLoweredRValueType(Type t) {
796-
return getLoweredType(t).getASTType();
807+
// We're ignoring the category (object vs address), so the resilience
808+
// expansion does not matter.
809+
return getLoweredType(t, ResilienceExpansion::Minimal).getASTType();
797810
}
798811

799812
CanType getLoweredRValueType(AbstractionPattern origType, Type substType) {
800-
return getLoweredType(origType, substType).getASTType();
813+
// We're ignoring the category (object vs address), so the resilience
814+
// expansion does not matter.
815+
return getLoweredType(origType, substType,
816+
ResilienceExpansion::Minimal).getASTType();
801817
}
802818

803819
AbstractionPattern getAbstractionPattern(AbstractStorageDecl *storage,

lib/IRGen/GenKeyPath.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,7 @@ emitKeyPathComponent(IRGenModule &IGM,
11501150
case KeyPathPatternComponent::Kind::TupleElement:
11511151
assert(baseTy->is<TupleType>() && "not a tuple");
11521152

1153-
SILType loweredTy = IGM.getSILTypes().getLoweredType(baseTy);
1153+
SILType loweredTy = IGM.getLoweredType(baseTy);
11541154

11551155
// Tuple with fixed layout
11561156
//

lib/IRGen/GenType.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,12 +1434,16 @@ const TypeInfo &IRGenFunction::getTypeInfo(SILType T) {
14341434

14351435
/// Return the SIL-lowering of the given type.
14361436
SILType IRGenModule::getLoweredType(AbstractionPattern orig, Type subst) {
1437-
return getSILTypes().getLoweredType(orig, subst);
1437+
// FIXME: Expansion
1438+
return getSILTypes().getLoweredType(orig, subst,
1439+
ResilienceExpansion::Minimal);
14381440
}
14391441

14401442
/// Return the SIL-lowering of the given type.
14411443
SILType IRGenModule::getLoweredType(Type subst) {
1442-
return getSILTypes().getLoweredType(subst);
1444+
// FIXME: Expansion
1445+
return getSILTypes().getLoweredType(subst,
1446+
ResilienceExpansion::Minimal);
14431447
}
14441448

14451449
/// Get a pointer to the storage type for the given type. Note that,

lib/SIL/SILFunctionType.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,8 @@ class DestructureResults {
315315
return;
316316
}
317317

318-
auto &substResultTL = M.Types.getTypeLowering(origType, substType);
318+
auto &substResultTL = M.Types.getTypeLowering(origType, substType,
319+
ResilienceExpansion::Minimal);
319320

320321
// Determine the result convention.
321322
ResultConvention convention;
@@ -590,7 +591,8 @@ class DestructureInputs {
590591

591592
unsigned origParamIndex = NextOrigParamIndex++;
592593

593-
auto &substTL = M.Types.getTypeLowering(origType, substType);
594+
auto &substTL = M.Types.getTypeLowering(origType, substType,
595+
ResilienceExpansion::Minimal);
594596
ParameterConvention convention;
595597
if (ownership == ValueOwnership::InOut) {
596598
convention = ParameterConvention::Indirect_Inout;
@@ -627,10 +629,10 @@ class DestructureInputs {
627629
return false;
628630

629631
auto foreignErrorTy =
630-
M.Types.getLoweredType(Foreign.Error->getErrorParameterType());
632+
M.Types.getLoweredRValueType(Foreign.Error->getErrorParameterType());
631633

632634
// Assume the error parameter doesn't have interesting lowering.
633-
Inputs.push_back(SILParameterInfo(foreignErrorTy.getASTType(),
635+
Inputs.push_back(SILParameterInfo(foreignErrorTy,
634636
ParameterConvention::Direct_Unowned));
635637
NextOrigParamIndex++;
636638
return true;
@@ -748,8 +750,11 @@ lowerCaptureContextParameters(SILModule &M, AnyFunctionRef function,
748750
auto type = VD->getInterfaceType();
749751
auto canType = type->getCanonicalType(origGenericSig);
750752

753+
// FIXME: Could be changed to Maximal at some point without impacting ABI,
754+
// as long as we make sure all call sites are non inlinable.
751755
auto &loweredTL =
752-
Types.getTypeLowering(AbstractionPattern(genericSig, canType), canType);
756+
Types.getTypeLowering(AbstractionPattern(genericSig, canType), canType,
757+
ResilienceExpansion::Minimal);
753758
auto loweredTy = loweredTL.getLoweredType();
754759
switch (Types.getDeclCaptureKind(capture)) {
755760
case CaptureKind::None:
@@ -806,7 +811,8 @@ static void destructureYieldsForReadAccessor(SILModule &M,
806811
return;
807812
}
808813

809-
auto &tl = M.Types.getTypeLowering(origType, valueType);
814+
auto &tl = M.Types.getTypeLowering(origType, valueType,
815+
ResilienceExpansion::Minimal);
810816
auto convention = [&] {
811817
if (isFormallyPassedIndirectly(M, origType, valueType, tl))
812818
return ParameterConvention::Indirect_In_Guaranteed;

lib/SIL/SILType.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,15 @@ SILType SILType::getSILTokenType(const ASTContext &C) {
8181
}
8282

8383
bool SILType::isTrivial(SILModule &M) const {
84-
return M.getTypeLowering(*this).isTrivial();
84+
return M.Types.getTypeLowering(*this,
85+
ResilienceExpansion::Minimal)
86+
.isTrivial();
8587
}
8688

8789
bool SILType::isReferenceCounted(SILModule &M) const {
88-
return M.getTypeLowering(*this).isReferenceCounted();
90+
return M.Types.getTypeLowering(*this,
91+
ResilienceExpansion::Minimal)
92+
.isReferenceCounted();
8993
}
9094

9195
bool SILType::isNoReturnFunction() const {
@@ -187,11 +191,12 @@ bool SILType::isLoadableOrOpaque(SILFunction *inFunction) const {
187191
/// address-only. For example, it could be a resilient struct or something of
188192
/// unknown size.
189193
bool SILType::isAddressOnly(SILModule &M) const {
190-
return M.getTypeLowering(*this).isAddressOnly();
194+
return M.Types.getTypeLowering(*this, ResilienceExpansion::Minimal)
195+
.isAddressOnly();
191196
}
192197

193198
bool SILType::isAddressOnly(SILFunction *inFunction) const {
194-
return inFunction->getModule().getTypeLowering(*this,
199+
return inFunction->getModule().Types.getTypeLowering(*this,
195200
inFunction->getResilienceExpansion()).isAddressOnly();
196201
}
197202

lib/SIL/SILVerifier.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,14 @@ void verifyKeyPathComponent(SILModule &M,
128128
bool forPropertyDescriptor,
129129
bool hasIndices) {
130130
auto &C = M.getASTContext();
131-
131+
132+
auto opaque = AbstractionPattern::getOpaque();
132133
auto loweredBaseTy =
133-
M.Types.getLoweredType(AbstractionPattern::getOpaque(), baseTy);
134+
M.Types.getLoweredType(opaque, baseTy, expansion);
134135
auto componentTy = component.getComponentType().subst(patternSubs)
135136
->getCanonicalType();
136137
auto loweredComponentTy =
137-
M.Types.getLoweredType(AbstractionPattern::getOpaque(), componentTy);
138+
M.Types.getLoweredType(opaque, componentTy, expansion);
138139

139140
auto checkIndexEqualsAndHash = [&]{
140141
if (!component.getSubscriptIndices().empty()) {
@@ -386,15 +387,14 @@ void verifyKeyPathComponent(SILModule &M,
386387
require(loweredBaseTy.is<TupleType>(),
387388
"invalid baseTy, should have been a TupleType");
388389

389-
auto tupleTy = loweredBaseTy.getAs<TupleType>();
390+
auto tupleTy = loweredBaseTy.castTo<TupleType>();
390391
auto eltIdx = component.getTupleIndex();
391392

392393
require(eltIdx < tupleTy->getNumElements(),
393394
"invalid element index, greater than # of tuple elements");
394395

395-
auto eltTy = tupleTy->getElementType(eltIdx)
396-
->getReferenceStorageReferent()
397-
->getCanonicalType();
396+
auto eltTy = tupleTy.getElementType(eltIdx)
397+
.getReferenceStorageReferent();
398398

399399
require(eltTy == componentTy,
400400
"tuple element type should match the type of the component");

0 commit comments

Comments
 (0)