Skip to content

[sil-opaque-values] Allow open_existential_addr to be loaded (post-ownership). #11858

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 2 commits into from
Sep 11, 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
8 changes: 4 additions & 4 deletions lib/SIL/SILVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2367,8 +2367,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
break;
case ValueKind::LoadInst:
// A 'non-taking' value load is harmless.
return cast<LoadInst>(inst)->getOwnershipQualifier() !=
LoadOwnershipQualifier::Copy;
return cast<LoadInst>(inst)->getOwnershipQualifier() ==
LoadOwnershipQualifier::Take;
break;
case ValueKind::DebugValueAddrInst:
// Harmless use.
Expand All @@ -2380,8 +2380,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
}
return false;
};
require(!isMutatingOrConsuming(OEI) ||
allowedAccessKind == OpenedExistentialAccess::Mutable,
require(allowedAccessKind == OpenedExistentialAccess::Mutable
|| !isMutatingOrConsuming(OEI),
"open_existential_addr uses that consumes or mutates but is not "
"opened for mutation");
}
Expand Down
23 changes: 23 additions & 0 deletions test/SILOptimizer/opaque-verify.sil
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// RUN: %target-sil-opt -enable-sil-opaque-values -assume-parsing-unqualified-ownership-sil %s

// REQUIRES: asserts

protocol P {
func foo()
}

// Ensure that open_existential_addr can be used by an unqualified load.
sil @loadFromExis : $@convention(thin) (@in P) -> () {
bb(%0 : $P):
%tempP = alloc_stack $P, var
store %0 to %tempP : $*P
%opened = open_existential_addr immutable_access %tempP : $*P to $*@opened("295A5344-9728-11E7-B89E-38C9860EC692") P
%val = load %opened : $*@opened("295A5344-9728-11E7-B89E-38C9860EC692") P
%copy = copy_value %val : $@opened("295A5344-9728-11E7-B89E-38C9860EC692") P
%wm = witness_method $@opened("295A5344-9728-11E7-B89E-38C9860EC692") P, #P.foo!1 : <Self where Self : P> (Self) -> () -> (), %opened : $*@opened("295A5344-9728-11E7-B89E-38C9860EC692") P : $@convention(witness_method) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> ()
%call = apply %wm<@opened("295A5344-9728-11E7-B89E-38C9860EC692") P>(%copy) : $@convention(witness_method) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> ()
destroy_value %val : $@opened("295A5344-9728-11E7-B89E-38C9860EC692") P
dealloc_stack %tempP : $*P
%void = tuple ()
return %void : $()
}