Skip to content
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

order of evaluation vs the ! operator #7346

Closed
vicuna opened this issue Sep 8, 2016 · 1 comment
Closed

order of evaluation vs the ! operator #7346

vicuna opened this issue Sep 8, 2016 · 1 comment

Comments

@vicuna
Copy link

vicuna commented Sep 8, 2016

Original bug ID: 7346
Reporter: @damiendoligez
Assigned to: @mshinwell
Status: closed (set by @mshinwell on 2016-12-13T10:22:18Z)
Resolution: duplicate
Priority: normal
Severity: major
Version: 4.04.0 +dev / +beta1 / +beta2
Target version: 4.05.0 +dev/beta1/beta2/beta3/rc1
Category: middle end (typedtree to clambda)
Related to: #4072 #6136
Monitored by: @gasche @yallop @hcarty

Bug description

With ocamlopt, the order of evaluation of function arguments depends on the code generated for the argument after inlining.

With ocamlc and ocamlopt+flambda, the order is always the same.

Steps to reproduce

Try this with ocamlc and ocamlopt:

let get r = !r [@@inline never]

let i = ref 0
let incr_i () = incr i; !i

let f (x, y) = Printf.printf "%d %d\n" x y [@@inline never]
let _ = f (incr_i (), get i)

let g x y = Printf.printf "%d %d\n" x y [@@inline never]
let () = g (incr_i ()) (get i)

They give the same result, all is well.
Remove the [@@inline never] annotation on the first line and they give different results.
Now make the function more complex (let get r = !r + (let rec f x = if x < 1 then 0 else 1 + f (x-1) in f 0)) and the result changes again.

@vicuna
Copy link
Author

vicuna commented Dec 13, 2016

Comment author: @mshinwell

Superceded by #966

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants