Skip to content

Commit f6b3233

Browse files
committed
Slightly more aggressive elimination of temporaries
This fixes AeneasVerif/eurydice#128 -- but this uncovered a shortcoming that ought to be fixed.
1 parent e111ce5 commit f6b3233

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

lib/Simplify.ml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,17 @@ let use_mark_to_inline_temporaries = object (self)
132132
b.node.name = "scrut" ||
133133
Structs.should_rewrite b.typ = NoCopies
134134
) &&
135-
v = AtMost 1 && (
136-
is_readonly_c_expression e1 &&
137-
safe_readonly_use e2 ||
138-
safe_pure_use e2
139-
) (* || is_readonly_and_variable_free_c_expression e1 && b.node.mut *)
135+
(v = AtMost 1 && (
136+
is_readonly_c_expression e1 &&
137+
safe_readonly_use e2 ||
138+
safe_pure_use e2
139+
) ||
140+
is_readonly_and_variable_free_c_expression e1 && not b.node.mut)
141+
(* b.node.mut is an approximation of "the address of this variable is taken"
142+
-- TODO this is somewhat incompatible with the phase that changes size-1
143+
arrays into variables who address is taken, so we should also check beore
144+
inlining that the address of this variable is not taken... this is
145+
starting to be quite an expensive check! *)
140146
then
141147
(* Don't drop a potentially useful comment into the ether *)
142148
let e1 = { e1 with meta = e1.meta @ b.meta } in

0 commit comments

Comments
 (0)