-
Notifications
You must be signed in to change notification settings - Fork 45
Refactor: make prepend ordering explicit for imperative calls in expression position #1130
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
base: main2
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -139,13 +139,9 @@ procedure addProcCaller(): int | |
| { | ||
| var x: int := 0; | ||
| var y: int := addProc({x := 1; x}, {x := x + 10; x}); | ||
| assert y == 11 | ||
|
|
||
| // The next statement is not translated correctly. | ||
| // I think it's a bug in the handling of StaticCall | ||
| // Where a reference is substituted when it should not be | ||
| // var z: int := addProc({x := 1; x}, {x := x + 10; x}) + (x := 3); | ||
| // assert z == 14 | ||
| assert y == 11; | ||
| var z: int := addProc({x := 1; x}, {x := x + 10; x}) + (x := 3); | ||
| assert z == 15 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: the PR description says the commented-out |
||
| }; | ||
| " | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The uncommented test only exercises the code path with a
pureimperative procedure (addProchas no side effects beyond producingr). With such a procedure, both the current order (argPrepends ++ prePrepends ++ liftedCall) and the alternative order (argPrepends ++ liftedCall ++ prePrepends) are observationally identical — neitherx's final value nor$c_0's value depend on which one runs first.Please add a companion test that uses a procedure with observable side-effects, so that whichever ordering the transform picks is locked in by the test:
composite Counter { var value: int } procedure bumpAndGet(c: Counter) returns (r: int) opaque modifies c { c#value := c#value + 100; return c#value }; procedure bumpCaller(): int opaque { var c: Counter := new Counter; c#value := 1; var y: int := 0; // Semantic (left-to-right): bumpAndGet(c) runs first -> c#value=101, // returns 101; then y:=7 runs -> y=7. Final z = 101+7 = 108. // With `argPrepends ++ prePrepends ++ liftedCall`, (y:=7) runs before // the call and c#value ends up unchanged at the point $c_0 is assigned, // but $c_0 still reflects the post-call value so the numeric result is // the same. However, the heap-seen ordering *is* observable in more // complex examples; please add one. var z: int := bumpAndGet(c) + (y := 7); assert z == 108; assert y == 7; assert c#value == 101 };A stronger version would involve the sibling expression also reading
c#valueafter the call, which would genuinely differentiate the two orderings — but if the transform ordering stays as-is, that test would fail, which is exactly the point of #39 that this PR claims to close.