Skip to content

Commit d04c335

Browse files
committed
SIL: Remove default arguments from resilience expansion parameters
Each call site will soon have to think about passing in the right expansion instead of just assuming the default will be OK. But there are now only a few call sites left, because most have been refactored to use convenience APIs that pass in the right resilience expansion already.
1 parent b7ef5c7 commit d04c335

File tree

12 files changed

+62
-45
lines changed

12 files changed

+62
-45
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: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -765,8 +765,7 @@ class TypeConverter {
765765
/// Lowers a Swift type to a SILType, and returns the SIL TypeLowering
766766
/// for that type.
767767
const TypeLowering &
768-
getTypeLowering(Type t, ResilienceExpansion forExpansion =
769-
ResilienceExpansion::Minimal) {
768+
getTypeLowering(Type t, ResilienceExpansion forExpansion) {
770769
AbstractionPattern pattern(getCurGenericContext(), t->getCanonicalType());
771770
return getTypeLowering(pattern, t, forExpansion);
772771
}
@@ -775,33 +774,28 @@ class TypeConverter {
775774
/// patterns of the given original type.
776775
const TypeLowering &getTypeLowering(AbstractionPattern origType,
777776
Type substType,
778-
ResilienceExpansion forExpansion =
779-
ResilienceExpansion::Minimal);
777+
ResilienceExpansion forExpansion);
780778

781779
/// Returns the SIL TypeLowering for an already lowered SILType. If the
782780
/// SILType is an address, returns the TypeLowering for the pointed-to
783781
/// type.
784782
const TypeLowering &
785-
getTypeLowering(SILType t, ResilienceExpansion forExpansion =
786-
ResilienceExpansion::Minimal);
783+
getTypeLowering(SILType t, ResilienceExpansion forExpansion);
787784

788785
// Returns the lowered SIL type for a Swift type.
789-
SILType getLoweredType(Type t, ResilienceExpansion forExpansion
790-
= ResilienceExpansion::Minimal) {
786+
SILType getLoweredType(Type t, ResilienceExpansion forExpansion) {
791787
return getTypeLowering(t, forExpansion).getLoweredType();
792788
}
793789

794790
// Returns the lowered SIL type for a Swift type.
795791
SILType getLoweredType(AbstractionPattern origType, Type substType,
796-
ResilienceExpansion forExpansion =
797-
ResilienceExpansion::Minimal) {
792+
ResilienceExpansion forExpansion) {
798793
return getTypeLowering(origType, substType, forExpansion)
799794
.getLoweredType();
800795
}
801796

802797
SILType getLoweredLoadableType(Type t,
803-
ResilienceExpansion forExpansion =
804-
ResilienceExpansion::Minimal) {
798+
ResilienceExpansion forExpansion) {
805799
const TypeLowering &ti = getTypeLowering(t, forExpansion);
806800
assert(
807801
(ti.isLoadable() || !SILModuleConventions(M).useLoweredAddresses()) &&
@@ -810,11 +804,16 @@ class TypeConverter {
810804
}
811805

812806
CanType getLoweredRValueType(Type t) {
813-
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();
814810
}
815811

816812
CanType getLoweredRValueType(AbstractionPattern origType, Type substType) {
817-
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();
818817
}
819818

820819
AbstractionPattern getAbstractionPattern(AbstractStorageDecl *storage,

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: 10 additions & 4 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;
@@ -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/TypeLowering.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ CaptureKind TypeConverter::getDeclCaptureKind(CapturedValue capture) {
9898
if (var->isImmutable() &&
9999
(!SILModuleConventions(M).useLoweredAddresses() ||
100100
// FIXME: Expansion
101-
!getTypeLowering(var->getType()).isAddressOnly()))
101+
!getTypeLowering(var->getType(),
102+
ResilienceExpansion::Minimal).isAddressOnly()))
102103
return CaptureKind::Constant;
103104

104105
// In-out parameters are captured by address.

lib/SILGen/SILGen.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,11 @@ getBridgingFn(Optional<SILDeclRef> &cacheSlot,
112112
auto funcTy = SGM.Types.getConstantFunctionType(c);
113113
SILFunctionConventions fnConv(funcTy, SGM.M);
114114

115+
auto toSILType = [&SGM](Type ty) {
116+
return SGM.Types.getLoweredType(ty, ResilienceExpansion::Minimal);
117+
};
118+
115119
if (inputTypes) {
116-
auto toSILType = [&SGM](Type ty) { return SGM.getLoweredType(ty); };
117120
if (fnConv.hasIndirectSILResults()
118121
|| funcTy->getNumParameters() != inputTypes->size()
119122
|| !std::equal(
@@ -127,7 +130,7 @@ getBridgingFn(Optional<SILDeclRef> &cacheSlot,
127130
}
128131

129132
if (outputType
130-
&& fnConv.getSingleSILResultType() != SGM.getLoweredType(*outputType)) {
133+
&& fnConv.getSingleSILResultType() != toSILType(*outputType)) {
131134
SGM.diagnose(fd->getLoc(), diag::bridging_function_not_correct_type,
132135
moduleName.str(), functionName);
133136
llvm::report_fatal_error("unable to set up the ObjC bridge!");
@@ -953,7 +956,9 @@ bool SILGenModule::hasNonTrivialIVars(ClassDecl *cd) {
953956
auto *vd = dyn_cast<VarDecl>(member);
954957
if (!vd || !vd->hasStorage()) continue;
955958

956-
const TypeLowering &ti = Types.getTypeLowering(vd->getType());
959+
// FIXME: Expansion
960+
auto &ti = Types.getTypeLowering(vd->getType(),
961+
ResilienceExpansion::Minimal);
957962
if (!ti.isTrivial())
958963
return true;
959964
}

lib/SILGen/SILGen.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,6 @@ class LLVM_LIBRARY_VISIBILITY SILGenModule : public ASTVisitor<SILGenModule> {
166166

167167
/// True if a function has been emitted for a given SILDeclRef.
168168
bool hasFunction(SILDeclRef constant);
169-
170-
/// Get the lowered type for a Swift type.
171-
SILType getLoweredType(Type t) {
172-
return Types.getTypeLowering(t).getLoweredType();
173-
}
174169

175170
/// Get or create the declaration of a reabstraction thunk with the
176171
/// given signature.

lib/SILGen/SILGenApply.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5995,7 +5995,8 @@ static void collectFakeIndexParameters(SILGenModule &SGM,
59955995
}
59965996

59975997
// Use conventions that will produce a +1 value.
5998-
auto &tl = SGM.Types.getTypeLowering(substType);
5998+
auto &tl = SGM.Types.getTypeLowering(substType,
5999+
ResilienceExpansion::Minimal);
59996000
ParameterConvention convention;
60006001
if (tl.isFormallyPassedIndirectly()) {
60016002
convention = ParameterConvention::Indirect_In;

lib/SILGen/SILGenExpr.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3336,9 +3336,12 @@ lowerKeyPathSubscriptIndexTypes(
33363336
if (sig) {
33373337
indexTy = indexTy.subst(subscriptSubs);
33383338
}
3339+
3340+
// FIXME: Expansion
33393341
auto indexLoweredTy = SGM.Types.getLoweredType(
33403342
AbstractionPattern::getOpaque(),
3341-
indexTy);
3343+
indexTy,
3344+
ResilienceExpansion::Minimal);
33423345
indexLoweredTy = indexLoweredTy.mapTypeOutOfContext();
33433346
indexPatterns.push_back({indexTy->mapTypeOutOfContext()
33443347
->getCanonicalType(),

lib/SILOptimizer/IPO/CapturePromotion.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@ computeNewArgInterfaceTypes(SILFunction *F,
365365
assert(paramBoxTy->getLayout()->getFields().size() == 1
366366
&& "promoting compound box not implemented yet");
367367
auto paramBoxedTy = paramBoxTy->getFieldType(F->getModule(), 0);
368-
auto &paramTL = Types.getTypeLowering(paramBoxedTy);
368+
auto &paramTL = Types.getTypeLowering(paramBoxedTy,
369+
ResilienceExpansion::Minimal);
369370
ParameterConvention convention;
370371
if (paramTL.isFormallyPassedIndirectly()) {
371372
convention = ParameterConvention::Indirect_In;

0 commit comments

Comments
 (0)