Skip to content

[semantic-sil] Change SILResultInfo::getOwnershipKind(SILModule &) to also take a Generic Signature. #6871

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -2936,7 +2936,9 @@ class SILResultInfo {
return out;
}

ValueOwnershipKind getOwnershipKind(SILModule &) const; // in SILType.cpp
ValueOwnershipKind
getOwnershipKind(SILModule &,
CanGenericSignature sig = nullptr) const; // in SILType.cpp

bool operator==(SILResultInfo rhs) const {
return TypeAndConvention == rhs.TypeAndConvention;
Expand Down
14 changes: 8 additions & 6 deletions lib/SIL/SILOwnershipVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,15 +352,17 @@ OwnershipUseCheckerResult
OwnershipCompatibilityUseChecker::visitReturnInst(ReturnInst *RI) {
SILModule &M = RI->getModule();
bool IsTrivial = RI->getOperand()->getType().isTrivial(M);
auto Results =
RI->getFunction()->getLoweredFunctionType()->getDirectResults();
auto FnType = RI->getFunction()->getLoweredFunctionType();
auto Results = FnType->getDirectResults();
if (Results.empty() || IsTrivial) {
return {compatibleWithOwnership(ValueOwnershipKind::Trivial), false};
}

CanGenericSignature Sig = FnType->getGenericSignature();

// Find the first index where we have a trivial value.
auto Iter = find_if(Results, [&M](const SILResultInfo &Info) -> bool {
return Info.getOwnershipKind(M) != ValueOwnershipKind::Trivial;
auto Iter = find_if(Results, [&M, &Sig](const SILResultInfo &Info) -> bool {
return Info.getOwnershipKind(M, Sig) != ValueOwnershipKind::Trivial;
});

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

unsigned Index = std::distance(Results.begin(), Iter);
ValueOwnershipKind Base = Results[Index].getOwnershipKind(M);
ValueOwnershipKind Base = Results[Index].getOwnershipKind(M, Sig);

for (const SILResultInfo &ResultInfo : Results.slice(Index + 1)) {
auto RKind = ResultInfo.getOwnershipKind(M);
auto RKind = ResultInfo.getOwnershipKind(M, Sig);
// Ignore trivial types.
if (RKind.merge(ValueOwnershipKind::Trivial))
continue;
Expand Down
11 changes: 8 additions & 3 deletions lib/SIL/SILType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,14 @@ SILBoxType::getFieldLoweredType(SILModule &M, unsigned index) const {
return fieldTy;
}

ValueOwnershipKind SILResultInfo::getOwnershipKind(SILModule &M) const {
SILType Ty = M.Types.getLoweredType(getType());
bool IsTrivial = Ty.isTrivial(M);
ValueOwnershipKind
SILResultInfo::getOwnershipKind(SILModule &M,
CanGenericSignature signature) const {
if (signature)
M.Types.pushGenericContext(signature);
bool IsTrivial = getSILType().isTrivial(M);
if (signature)
M.Types.popGenericContext(signature);
switch (getConvention()) {
case ResultConvention::Indirect:
return ValueOwnershipKind::Trivial; // Should this be an Any?
Expand Down
9 changes: 5 additions & 4 deletions lib/SIL/SILValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,19 +489,20 @@ ValueOwnershipKindVisitor::visitApplyInst(ApplyInst *AI) {
if (Results.empty() || IsTrivial)
return ValueOwnershipKind::Trivial;

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

unsigned Index = std::distance(Results.begin(), Iter);
ValueOwnershipKind Base = Results[Index].getOwnershipKind(M);
ValueOwnershipKind Base = Results[Index].getOwnershipKind(M, Sig);

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

Expand Down