Skip to content

Commit 7081293

Browse files
authored
Merge pull request #23126 from slavapestov/begin-removing-fixme-expansions
More resilience expansion plumbing for type lowering
2 parents 8a7f2ea + 268f780 commit 7081293

File tree

14 files changed

+260
-193
lines changed

14 files changed

+260
-193
lines changed

include/swift/SIL/SILFunction.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,8 @@ class SILFunction
482482

483483
const Lowering::TypeLowering &getTypeLowering(SILType type) const;
484484

485+
bool isTypeABIAccessible(SILType type) const;
486+
485487
/// Returns true if this function has a calling convention that has a self
486488
/// argument.
487489
bool hasSelfParam() const {

include/swift/SIL/SILModule.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -591,10 +591,8 @@ class SILModule {
591591

592592
/// Can value operations (copies and destroys) on the given lowered type
593593
/// be performed in this module?
594-
// FIXME: Expansion
595594
bool isTypeABIAccessible(SILType type,
596-
ResilienceExpansion forExpansion
597-
= ResilienceExpansion::Minimal);
595+
ResilienceExpansion forExpansion);
598596

599597
/// Can type metadata for the given formal type be fetched in
600598
/// the given module?

include/swift/SIL/SILType.h

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -237,19 +237,17 @@ class SILType {
237237
/// This is equivalent to, but possibly faster than, calling
238238
/// M.Types.getTypeLowering(type).isReturnedIndirectly().
239239
static bool isFormallyReturnedIndirectly(CanType type, SILModule &M,
240-
CanGenericSignature Sig,
241-
ResilienceExpansion Expansion) {
242-
return isAddressOnly(type, M, Sig, Expansion);
240+
CanGenericSignature Sig) {
241+
return isAddressOnly(type, M, Sig, ResilienceExpansion::Minimal);
243242
}
244243

245244
/// Return true if this type must be passed indirectly.
246245
///
247246
/// This is equivalent to, but possibly faster than, calling
248247
/// M.Types.getTypeLowering(type).isPassedIndirectly().
249248
static bool isFormallyPassedIndirectly(CanType type, SILModule &M,
250-
CanGenericSignature Sig,
251-
ResilienceExpansion Expansion) {
252-
return isAddressOnly(type, M, Sig, Expansion);
249+
CanGenericSignature Sig) {
250+
return isAddressOnly(type, M, Sig, ResilienceExpansion::Minimal);
253251
}
254252

255253
/// True if the type, or the referenced type of an address type, is loadable.
@@ -265,8 +263,8 @@ class SILType {
265263
/// be loadable inside a resilient function in the module.
266264
/// In other words: isLoadable(SILModule) is the conservative default, whereas
267265
/// isLoadable(SILFunction) might give a more optimistic result.
268-
bool isLoadable(SILFunction *inFunction) const {
269-
return !isAddressOnly(inFunction);
266+
bool isLoadable(const SILFunction &F) const {
267+
return !isAddressOnly(F);
270268
}
271269

272270
/// True if either:
@@ -275,20 +273,24 @@ class SILType {
275273
bool isLoadableOrOpaque(SILModule &M) const;
276274

277275
/// Like isLoadableOrOpaque(SILModule), but takes the resilience expansion of
278-
/// \p inFunction into account (see isLoadable(SILFunction)).
279-
bool isLoadableOrOpaque(SILFunction *inFunction) const;
276+
/// \p F into account (see isLoadable(SILFunction)).
277+
bool isLoadableOrOpaque(const SILFunction &F) const;
280278

281279
/// True if the type, or the referenced type of an address type, is
282280
/// address-only. This is the opposite of isLoadable.
283281
bool isAddressOnly(SILModule &M) const;
284282

285283
/// Like isAddressOnly(SILModule), but takes the resilience expansion of
286-
/// \p inFunction into account (see isLoadable(SILFunction)).
287-
bool isAddressOnly(SILFunction *inFunction) const;
284+
/// \p F into account (see isLoadable(SILFunction)).
285+
bool isAddressOnly(const SILFunction &F) const;
288286

289287
/// True if the type, or the referenced type of an address type, is trivial.
290288
bool isTrivial(SILModule &M) const;
291289

290+
/// Like isTrivial(SILModule), but takes the resilience expansion of
291+
/// \p F into account (see isLoadable(SILFunction)).
292+
bool isTrivial(const SILFunction &F) const;
293+
292294
/// True if the type, or the referenced type of an address type, is known to
293295
/// be a scalar reference-counted type. If this is false, then some part of
294296
/// the type may be opaque. It may become reference counted later after

include/swift/SIL/TypeLowering.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,16 @@ class TypeLowering {
175175
constexpr RecursiveProperties(IsTrivial_t isTrivial,
176176
IsFixedABI_t isFixedABI,
177177
IsAddressOnly_t isAddressOnly,
178-
IsResilient_t isResilient = IsNotResilient)
178+
IsResilient_t isResilient)
179179
: Flags((isTrivial ? 0U : NonTrivialFlag) |
180-
(isAddressOnly ? AddressOnlyFlag : 0U) |
181180
(isFixedABI ? 0U : NonFixedABIFlag) |
181+
(isAddressOnly ? AddressOnlyFlag : 0U) |
182182
(isResilient ? ResilientFlag : 0U)) {}
183183

184+
static constexpr RecursiveProperties forTrivial() {
185+
return {IsTrivial, IsFixedABI, IsNotAddressOnly, IsNotResilient};
186+
}
187+
184188
static constexpr RecursiveProperties forReference() {
185189
return {IsNotTrivial, IsFixedABI, IsNotAddressOnly, IsNotResilient };
186190
}
@@ -190,7 +194,7 @@ class TypeLowering {
190194
}
191195

192196
static constexpr RecursiveProperties forResilient() {
193-
return {IsNotTrivial, IsNotFixedABI, IsAddressOnly, IsResilient};
197+
return {IsTrivial, IsFixedABI, IsNotAddressOnly, IsResilient};
194198
}
195199

196200
void addSubobject(RecursiveProperties other) {
@@ -683,7 +687,9 @@ class TypeConverter {
683687
llvm::DenseMap<AnyFunctionRef, CaptureInfo> LoweredCaptures;
684688

685689
/// Cache of loadable SILType to number of (estimated) fields
686-
llvm::DenseMap<SILType, unsigned> TypeFields;
690+
///
691+
/// Second element is a ResilienceExpansion.
692+
llvm::DenseMap<std::pair<SILType, unsigned>, unsigned> TypeFields;
687693

688694
CanAnyFunctionType makeConstantInterfaceType(SILDeclRef constant);
689695

@@ -695,11 +701,8 @@ class TypeConverter {
695701
const TypeLowering &
696702
getTypeLoweringForLoweredType(TypeKey key,
697703
ResilienceExpansion forExpansion);
698-
const TypeLowering &
699-
getTypeLoweringForUncachedLoweredType(TypeKey key,
700-
ResilienceExpansion forExpansion);
701704

702-
const TypeLowering &
705+
const TypeLowering *
703706
getTypeLoweringForExpansion(TypeKey key,
704707
ResilienceExpansion forExpansion,
705708
const TypeLowering *lowering);
@@ -739,7 +742,7 @@ class TypeConverter {
739742
static ProtocolDispatchStrategy getProtocolDispatchStrategy(ProtocolDecl *P);
740743

741744
/// Count the total number of fields inside the given SIL Type
742-
unsigned countNumberOfFields(SILType Ty);
745+
unsigned countNumberOfFields(SILType Ty, ResilienceExpansion expansion);
743746

744747
/// True if a protocol uses witness tables for dynamic dispatch.
745748
static bool protocolRequiresWitnessTable(ProtocolDecl *P) {

lib/IRGen/GenEnum.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6202,8 +6202,7 @@ SingletonEnumImplStrategy::completeEnumTypeLayout(TypeConverter &TC,
62026202
if (TIK <= Opaque) {
62036203
auto alignment = eltTI.getBestKnownAlignment();
62046204
applyLayoutAttributes(TC.IGM, theEnum, /*fixed*/false, alignment);
6205-
auto enumAccessible =
6206-
IsABIAccessible_t(TC.IGM.getSILModule().isTypeABIAccessible(Type));
6205+
auto enumAccessible = IsABIAccessible_t(TC.IGM.isTypeABIAccessible(Type));
62076206
return registerEnumTypeInfo(new NonFixedEnumTypeInfo(*this, enumTy,
62086207
alignment,
62096208
eltTI.isPOD(ResilienceExpansion::Maximal),
@@ -6389,8 +6388,7 @@ TypeInfo *SinglePayloadEnumImplStrategy::completeDynamicLayout(
63896388

63906389
applyLayoutAttributes(TC.IGM, theEnum, /*fixed*/false, alignment);
63916390

6392-
auto enumAccessible =
6393-
IsABIAccessible_t(TC.IGM.getSILModule().isTypeABIAccessible(Type));
6391+
auto enumAccessible = IsABIAccessible_t(TC.IGM.isTypeABIAccessible(Type));
63946392

63956393
return registerEnumTypeInfo(new NonFixedEnumTypeInfo(*this, enumTy,
63966394
alignment,
@@ -6590,8 +6588,7 @@ TypeInfo *MultiPayloadEnumImplStrategy::completeDynamicLayout(
65906588

65916589
applyLayoutAttributes(TC.IGM, theEnum, /*fixed*/false, alignment);
65926590

6593-
auto enumAccessible =
6594-
IsABIAccessible_t(TC.IGM.getSILModule().isTypeABIAccessible(Type));
6591+
auto enumAccessible = IsABIAccessible_t(TC.IGM.isTypeABIAccessible(Type));
65956592

65966593
return registerEnumTypeInfo(new NonFixedEnumTypeInfo(*this, enumTy,
65976594
alignment, pod, bt,
@@ -6614,8 +6611,7 @@ ResilientEnumImplStrategy::completeEnumTypeLayout(TypeConverter &TC,
66146611
SILType Type,
66156612
EnumDecl *theEnum,
66166613
llvm::StructType *enumTy) {
6617-
auto abiAccessible =
6618-
IsABIAccessible_t(TC.IGM.getSILModule().isTypeABIAccessible(Type));
6614+
auto abiAccessible = IsABIAccessible_t(TC.IGM.isTypeABIAccessible(Type));
66196615
return registerEnumTypeInfo(
66206616
new ResilientEnumTypeInfo(*this, enumTy, abiAccessible));
66216617
}

lib/IRGen/GenTuple.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ namespace {
355355
FieldsAreABIAccessible_t fieldsAccessible,
356356
StructLayout &&layout) {
357357
auto tupleAccessible = IsABIAccessible_t(
358-
IGM.getSILModule().isTypeABIAccessible(TheTuple));
358+
IGM.isTypeABIAccessible(TheTuple));
359359
return NonFixedTupleTypeInfo::create(fields, fieldsAccessible,
360360
layout.getType(),
361361
layout.getAlignment(),

lib/IRGen/GenType.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,19 +1433,25 @@ const TypeInfo &IRGenFunction::getTypeInfo(SILType T) {
14331433
}
14341434

14351435
/// Return the SIL-lowering of the given type.
1436-
SILType IRGenModule::getLoweredType(AbstractionPattern orig, Type subst) {
1436+
SILType IRGenModule::getLoweredType(AbstractionPattern orig, Type subst) const {
14371437
// FIXME: Expansion
14381438
return getSILTypes().getLoweredType(orig, subst,
14391439
ResilienceExpansion::Minimal);
14401440
}
14411441

14421442
/// Return the SIL-lowering of the given type.
1443-
SILType IRGenModule::getLoweredType(Type subst) {
1443+
SILType IRGenModule::getLoweredType(Type subst) const {
14441444
// FIXME: Expansion
14451445
return getSILTypes().getLoweredType(subst,
14461446
ResilienceExpansion::Minimal);
14471447
}
14481448

1449+
bool IRGenModule::isTypeABIAccessible(SILType type) const {
1450+
// FIXME: Expansion
1451+
return getSILModule().isTypeABIAccessible(type,
1452+
ResilienceExpansion::Minimal);
1453+
}
1454+
14491455
/// Get a pointer to the storage type for the given type. Note that,
14501456
/// unlike fetching the type info and asking it for the storage type,
14511457
/// this operation will succeed for forward-declarations.

lib/IRGen/IRGenModule.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -747,8 +747,10 @@ class IRGenModule {
747747
getConformanceInfo(const ProtocolDecl *protocol,
748748
const ProtocolConformance *conformance);
749749

750-
SILType getLoweredType(AbstractionPattern orig, Type subst);
751-
SILType getLoweredType(Type subst);
750+
SILType getLoweredType(AbstractionPattern orig, Type subst) const;
751+
SILType getLoweredType(Type subst) const;
752+
bool isTypeABIAccessible(SILType type) const;
753+
752754
const TypeInfo &getTypeInfoForUnlowered(AbstractionPattern orig,
753755
CanType subst);
754756
const TypeInfo &getTypeInfoForUnlowered(AbstractionPattern orig,

lib/SIL/SILFunction.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,12 @@ const TypeLowering &SILFunction::getTypeLowering(SILType type) const {
263263
ResilienceExpansion::Minimal);
264264
}
265265

266+
bool SILFunction::isTypeABIAccessible(SILType type) const {
267+
// FIXME: Expansion
268+
return getModule().isTypeABIAccessible(type,
269+
ResilienceExpansion::Minimal);
270+
}
271+
266272
SILBasicBlock *SILFunction::createBasicBlock() {
267273
return new (getModule()) SILBasicBlock(this, nullptr, false);
268274
}

lib/SIL/SILFunctionType.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,8 @@ class DestructureResults {
370370

371371
// Otherwise, query specifically for the original type.
372372
} else {
373-
// FIXME: Get expansion from SILDeclRef
374373
return SILType::isFormallyReturnedIndirectly(
375-
origType.getType(), M, origType.getGenericSignature(),
376-
ResilienceExpansion::Minimal);
374+
origType.getType(), M, origType.getGenericSignature());
377375
}
378376
}
379377
};
@@ -453,10 +451,8 @@ static bool isFormallyPassedIndirectly(SILModule &M,
453451

454452
// Otherwise, query specifically for the original type.
455453
} else {
456-
// FIXME: Get expansion from SILDeclRef
457454
return SILType::isFormallyPassedIndirectly(
458-
origType.getType(), M, origType.getGenericSignature(),
459-
ResilienceExpansion::Minimal);
455+
origType.getType(), M, origType.getGenericSignature());
460456
}
461457
}
462458

lib/SIL/SILType.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ bool SILType::isTrivial(SILModule &M) const {
8686
.isTrivial();
8787
}
8888

89+
bool SILType::isTrivial(const SILFunction &F) const {
90+
// FIXME: Should just call F.getTypeLowering()
91+
return F.getModule().Types.getTypeLowering(*this,
92+
F.getResilienceExpansion()).isTrivial();
93+
}
94+
8995
bool SILType::isReferenceCounted(SILModule &M) const {
9096
return M.Types.getTypeLowering(*this,
9197
ResilienceExpansion::Minimal)
@@ -181,9 +187,9 @@ bool SILType::isLoadableOrOpaque(SILModule &M) const {
181187
return isLoadable(M) || !SILModuleConventions(M).useLoweredAddresses();
182188
}
183189

184-
bool SILType::isLoadableOrOpaque(SILFunction *inFunction) const {
185-
SILModule &M = inFunction->getModule();
186-
return isLoadable(inFunction) ||
190+
bool SILType::isLoadableOrOpaque(const SILFunction &F) const {
191+
SILModule &M = F.getModule();
192+
return isLoadable(F) ||
187193
!SILModuleConventions(M).useLoweredAddresses();
188194
}
189195

@@ -195,9 +201,10 @@ bool SILType::isAddressOnly(SILModule &M) const {
195201
.isAddressOnly();
196202
}
197203

198-
bool SILType::isAddressOnly(SILFunction *inFunction) const {
199-
return inFunction->getModule().Types.getTypeLowering(*this,
200-
inFunction->getResilienceExpansion()).isAddressOnly();
204+
bool SILType::isAddressOnly(const SILFunction &F) const {
205+
// FIXME: Should just call F.getTypeLowering()
206+
return F.getModule().Types.getTypeLowering(*this,
207+
F.getResilienceExpansion()).isAddressOnly();
201208
}
202209

203210
SILType SILType::substGenericArgs(SILModule &M,
@@ -414,6 +421,7 @@ SILBoxType::getFieldLoweredType(SILModule &M, unsigned index) const {
414421
return fieldTy;
415422
}
416423

424+
// FIXME: This should take a SILFunction, or a SILModule + ResilienceExpansion
417425
ValueOwnershipKind
418426
SILResultInfo::getOwnershipKind(SILModule &M,
419427
CanGenericSignature signature) const {

0 commit comments

Comments
 (0)