Skip to content

Commit 4374754

Browse files
committed
[sil] Teach the verifier that open_existential_addr immutable is safe to pass as Indirect_InoutAliasable.
We do not consider inout_aliasable to be "truly mutating" since today it is just used as a way to mark a captured argument and not that something truly has mutating semantics. The reason why this is safe is that the typechecker guarantees that if our value was immutable, then the use in the closure must be immutable as well. In a future SIL, we want to remove Inout_Aliasable in favor of just using inout/in_guaranteed using the capture info from the type checker. rdar://50212579
1 parent fd2cf65 commit 4374754

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

lib/SIL/SILVerifier.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2885,11 +2885,20 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
28852885
case SILArgumentConvention::Indirect_In_Guaranteed:
28862886
return false;
28872887

2888+
case SILArgumentConvention::Indirect_InoutAliasable:
2889+
// DISCUSSION: We do not consider inout_aliasable to be "truly mutating"
2890+
// since today it is just used as a way to mark a captured argument and
2891+
// not that something truly has mutating semantics. The reason why this
2892+
// is safe is that the typechecker guarantees that if our value was
2893+
// immutable, then the use in the closure must be immutable as well.
2894+
//
2895+
// TODO: Remove this in favor of using Inout and In_Guaranteed.
2896+
return false;
2897+
28882898
case SILArgumentConvention::Indirect_Out:
28892899
case SILArgumentConvention::Indirect_In:
28902900
case SILArgumentConvention::Indirect_In_Constant:
28912901
case SILArgumentConvention::Indirect_Inout:
2892-
case SILArgumentConvention::Indirect_InoutAliasable:
28932902
return true;
28942903

28952904
case SILArgumentConvention::Direct_Unowned:

test/SIL/verifier_nofail.sil

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %target-sil-opt -enable-sil-verify-all %s
2+
3+
// This file contains a collection of tests that ensure that the verifier does
4+
// not fail on specific segments of code. The idea is to ensure that changing
5+
// the verifier does not cause these to start asserting. When one adds a new
6+
// check to the verifier, add a test case to make sure normal cases do not
7+
// crash.
8+
9+
sil_stage canonical
10+
11+
import Builtin
12+
13+
protocol P {
14+
}
15+
16+
sil @generic_user : $@convention(thin) <τ_0_0 where τ_0_0 : P> (@inout_aliasable τ_0_0) -> ()
17+
18+
sil @open_existential_immutable_access_to_inout_aliasable : $@convention(thin) (@in_guaranteed P) -> () {
19+
bb0(%0 : $*P):
20+
%1 = open_existential_addr immutable_access %0 : $*P to $*@opened("4E16CBC0-FD9F-11E8-A311-D0817AD9F6DD") P
21+
%2 = function_ref @generic_user : $@convention(thin) <τ_0_0 where τ_0_0 : P> (@inout_aliasable τ_0_0) -> ()
22+
apply %2<@opened("4E16CBC0-FD9F-11E8-A311-D0817AD9F6DD") P>(%1) : $@convention(thin) <τ_0_0 where τ_0_0 : P> (@inout_aliasable τ_0_0) -> ()
23+
%9999 = tuple()
24+
return %9999 : $()
25+
}

0 commit comments

Comments
 (0)