Skip to content

Commit a3d8d9c

Browse files
committed
SIL: Add a new overload of SILType::isTrivial() taking a SILFunction
1 parent ced5548 commit a3d8d9c

File tree

4 files changed

+40
-34
lines changed

4 files changed

+40
-34
lines changed

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

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 {

lib/SIL/SILVerifier.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,7 +1551,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
15511551
void checkLoadInst(LoadInst *LI) {
15521552
require(LI->getType().isObject(), "Result of load must be an object");
15531553
require(!fnConv.useLoweredAddresses()
1554-
|| LI->getType().isLoadable(LI->getFunction()),
1554+
|| LI->getType().isLoadable(*LI->getFunction()),
15551555
"Load must have a loadable type");
15561556
require(LI->getOperand()->getType().isAddress(),
15571557
"Load operand must be an address");
@@ -1571,14 +1571,14 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
15711571
require(F.hasOwnership(),
15721572
"Load with qualified ownership in an unqualified function");
15731573
// TODO: Could probably make this a bit stricter.
1574-
require(!LI->getType().isTrivial(LI->getModule()),
1574+
require(!LI->getType().isTrivial(*LI->getFunction()),
15751575
"load [copy] or load [take] can only be applied to non-trivial "
15761576
"types");
15771577
break;
15781578
case LoadOwnershipQualifier::Trivial:
15791579
require(F.hasOwnership(),
15801580
"Load with qualified ownership in an unqualified function");
1581-
require(LI->getType().isTrivial(LI->getModule()),
1581+
require(LI->getType().isTrivial(*LI->getFunction()),
15821582
"A load with trivial ownership must load a trivial type");
15831583
break;
15841584
}
@@ -1590,7 +1590,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
15901590
"Inst with qualified ownership in a function that is not qualified");
15911591
require(LBI->getType().isObject(), "Result of load must be an object");
15921592
require(!fnConv.useLoweredAddresses()
1593-
|| LBI->getType().isLoadable(LBI->getFunction()),
1593+
|| LBI->getType().isLoadable(*LBI->getFunction()),
15941594
"Load must have a loadable type");
15951595
require(LBI->getOperand()->getType().isAddress(),
15961596
"Load operand must be an address");
@@ -1708,7 +1708,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
17081708
require(SI->getSrc()->getType().isObject(),
17091709
"Can't store from an address source");
17101710
require(!fnConv.useLoweredAddresses()
1711-
|| SI->getSrc()->getType().isLoadable(SI->getFunction()),
1711+
|| SI->getSrc()->getType().isLoadable(*SI->getFunction()),
17121712
"Can't store a non loadable type");
17131713
require(SI->getDest()->getType().isAddress(),
17141714
"Must store to an address dest");
@@ -1729,7 +1729,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
17291729
F.hasOwnership(),
17301730
"Inst with qualified ownership in a function that is not qualified");
17311731
// TODO: Could probably make this a bit stricter.
1732-
require(!SI->getSrc()->getType().isTrivial(SI->getModule()),
1732+
require(!SI->getSrc()->getType().isTrivial(*SI->getFunction()),
17331733
"store [init] or store [assign] can only be applied to "
17341734
"non-trivial types");
17351735
break;
@@ -1738,7 +1738,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
17381738
F.hasOwnership(),
17391739
"Inst with qualified ownership in a function that is not qualified");
17401740
SILValue Src = SI->getSrc();
1741-
require(Src->getType().isTrivial(SI->getModule()) ||
1741+
require(Src->getType().isTrivial(*SI->getFunction()) ||
17421742
Src.getOwnershipKind() == ValueOwnershipKind::Any,
17431743
"A store with trivial ownership must store a type with trivial "
17441744
"ownership");
@@ -1934,7 +1934,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
19341934
void checkCopyValueInst(CopyValueInst *I) {
19351935
require(I->getOperand()->getType().isObject(),
19361936
"Source value should be an object value");
1937-
require(!I->getOperand()->getType().isTrivial(I->getModule()),
1937+
require(!I->getOperand()->getType().isTrivial(*I->getFunction()),
19381938
"Source value should be non-trivial");
19391939
require(!fnConv.useLoweredAddresses() || F.hasOwnership(),
19401940
"copy_value is only valid in functions with qualified "
@@ -1944,7 +1944,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
19441944
void checkDestroyValueInst(DestroyValueInst *I) {
19451945
require(I->getOperand()->getType().isObject(),
19461946
"Source value should be an object value");
1947-
require(!I->getOperand()->getType().isTrivial(I->getModule()),
1947+
require(!I->getOperand()->getType().isTrivial(*I->getFunction()),
19481948
"Source value should be non-trivial");
19491949
require(!fnConv.useLoweredAddresses() || F.hasOwnership(),
19501950
"destroy_value is only valid in functions with qualified "
@@ -3585,7 +3585,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
35853585
"unchecked_trivial_bit_cast must operate on a value");
35863586
require(BI->getType().isObject(),
35873587
"unchecked_trivial_bit_cast must produce a value");
3588-
require(BI->getType().isTrivial(F.getModule()),
3588+
require(BI->getType().isTrivial(F),
35893589
"unchecked_trivial_bit_cast must produce a value of trivial type");
35903590
}
35913591

0 commit comments

Comments
 (0)