Skip to content

Commit eec18b0

Browse files
authored
Merge pull request #6871 from gottesmm/fix_sil_result_info
2 parents 3950ada + 4063694 commit eec18b0

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

include/swift/AST/Types.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2936,7 +2936,9 @@ class SILResultInfo {
29362936
return out;
29372937
}
29382938

2939-
ValueOwnershipKind getOwnershipKind(SILModule &) const; // in SILType.cpp
2939+
ValueOwnershipKind
2940+
getOwnershipKind(SILModule &,
2941+
CanGenericSignature sig = nullptr) const; // in SILType.cpp
29402942

29412943
bool operator==(SILResultInfo rhs) const {
29422944
return TypeAndConvention == rhs.TypeAndConvention;

lib/SIL/SILOwnershipVerifier.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -352,15 +352,17 @@ OwnershipUseCheckerResult
352352
OwnershipCompatibilityUseChecker::visitReturnInst(ReturnInst *RI) {
353353
SILModule &M = RI->getModule();
354354
bool IsTrivial = RI->getOperand()->getType().isTrivial(M);
355-
auto Results =
356-
RI->getFunction()->getLoweredFunctionType()->getDirectResults();
355+
auto FnType = RI->getFunction()->getLoweredFunctionType();
356+
auto Results = FnType->getDirectResults();
357357
if (Results.empty() || IsTrivial) {
358358
return {compatibleWithOwnership(ValueOwnershipKind::Trivial), false};
359359
}
360360

361+
CanGenericSignature Sig = FnType->getGenericSignature();
362+
361363
// Find the first index where we have a trivial value.
362-
auto Iter = find_if(Results, [&M](const SILResultInfo &Info) -> bool {
363-
return Info.getOwnershipKind(M) != ValueOwnershipKind::Trivial;
364+
auto Iter = find_if(Results, [&M, &Sig](const SILResultInfo &Info) -> bool {
365+
return Info.getOwnershipKind(M, Sig) != ValueOwnershipKind::Trivial;
364366
});
365367

366368
// If we have all trivial, then we must be trivial. Why wasn't our original
@@ -370,10 +372,10 @@ OwnershipCompatibilityUseChecker::visitReturnInst(ReturnInst *RI) {
370372
llvm_unreachable("Should have already checked a trivial type?!");
371373

372374
unsigned Index = std::distance(Results.begin(), Iter);
373-
ValueOwnershipKind Base = Results[Index].getOwnershipKind(M);
375+
ValueOwnershipKind Base = Results[Index].getOwnershipKind(M, Sig);
374376

375377
for (const SILResultInfo &ResultInfo : Results.slice(Index + 1)) {
376-
auto RKind = ResultInfo.getOwnershipKind(M);
378+
auto RKind = ResultInfo.getOwnershipKind(M, Sig);
377379
// Ignore trivial types.
378380
if (RKind.merge(ValueOwnershipKind::Trivial))
379381
continue;

lib/SIL/SILType.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -586,9 +586,14 @@ SILBoxType::getFieldLoweredType(SILModule &M, unsigned index) const {
586586
return fieldTy;
587587
}
588588

589-
ValueOwnershipKind SILResultInfo::getOwnershipKind(SILModule &M) const {
590-
SILType Ty = M.Types.getLoweredType(getType());
591-
bool IsTrivial = Ty.isTrivial(M);
589+
ValueOwnershipKind
590+
SILResultInfo::getOwnershipKind(SILModule &M,
591+
CanGenericSignature signature) const {
592+
if (signature)
593+
M.Types.pushGenericContext(signature);
594+
bool IsTrivial = getSILType().isTrivial(M);
595+
if (signature)
596+
M.Types.popGenericContext(signature);
592597
switch (getConvention()) {
593598
case ResultConvention::Indirect:
594599
return ValueOwnershipKind::Trivial; // Should this be an Any?

lib/SIL/SILValue.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -489,19 +489,20 @@ ValueOwnershipKindVisitor::visitApplyInst(ApplyInst *AI) {
489489
if (Results.empty() || IsTrivial)
490490
return ValueOwnershipKind::Trivial;
491491

492+
CanGenericSignature Sig = AI->getSubstCalleeType()->getGenericSignature();
492493
// Find the first index where we have a trivial value.
493-
auto Iter = find_if(Results, [&M](const SILResultInfo &Info) -> bool {
494-
return Info.getOwnershipKind(M) != ValueOwnershipKind::Trivial;
494+
auto Iter = find_if(Results, [&M, &Sig](const SILResultInfo &Info) -> bool {
495+
return Info.getOwnershipKind(M, Sig) != ValueOwnershipKind::Trivial;
495496
});
496497
// If we have all trivial, then we must be trivial.
497498
if (Iter == Results.end())
498499
return ValueOwnershipKind::Trivial;
499500

500501
unsigned Index = std::distance(Results.begin(), Iter);
501-
ValueOwnershipKind Base = Results[Index].getOwnershipKind(M);
502+
ValueOwnershipKind Base = Results[Index].getOwnershipKind(M, Sig);
502503

503504
for (const SILResultInfo &ResultInfo : Results.slice(Index+1)) {
504-
auto RKind = ResultInfo.getOwnershipKind(M);
505+
auto RKind = ResultInfo.getOwnershipKind(M, Sig);
505506
if (RKind.merge(ValueOwnershipKind::Trivial))
506507
continue;
507508

0 commit comments

Comments
 (0)