Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0007657OCamltypingpublic2017-10-11 05:242017-10-19 15:25
Reportersliquister 
Assigned Tofrisch 
PrioritynormalSeveritymajorReproducibilityalways
StatusresolvedResolutionfixed 
PlatformOSOS Version
Product Version4.05.0 
Target Version4.06.0+devFixed in Version 
Summary0007657: typer can wrongly eta-expand effectful expressions
DescriptionThe following program should clearly raise:

    let foo g () = g 1; ()
    let f ?x y = ()

    let _ = foo (assert false; f)

but it doesn't (with 4.05).

I think this is because the typer rewrites the argument of foo as:

    let _ = foo (fun y -> (assert false; f) ?x:None y)

because it calls is_nonexpansive to decide if the expression is side-effect free, which doesn't work for sequences and other cases (the condition of if-then-else, patterns with lazy in them, etc).

(I didn't run into this in practice, I simply saw the call to
is_nonexpansive and thought that it couldn't be right)
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0018535)
frisch (developer)
2017-10-11 09:33

I wonder whether the compiler shouldn't be less clever and always let-bind the argument outside the eta-expanded function (as it does today when is_nonexpansive returns false). The common case where the argument is a simple identifier would be simplified by the Simplif pass anyway.
(0018538)
frisch (developer)
2017-10-11 10:22

is_nonexpansive also fails to detect reads from mutable locations, so

let foo g () = g 1; ()
let f1 ?x y = print_endline "f1"
let f2 ?x y = print_endline "f2"
let r = ref f1
let h = foo r.contents
let () = h (); r := f2; h ()


prints:

f1
f2
(0018539)
frisch (developer)
2017-10-11 10:28

https://github.com/ocaml/ocaml/pull/1424 [^]
(0018591)
xleroy (administrator)
2017-10-19 15:25

Pull request was merged in trunk and 4.06.

- Issue History
Date Modified Username Field Change
2017-10-11 05:24 sliquister New Issue
2017-10-11 09:27 frisch Assigned To => frisch
2017-10-11 09:27 frisch Status new => confirmed
2017-10-11 09:33 frisch Note Added: 0018535
2017-10-11 09:33 frisch Severity minor => major
2017-10-11 10:07 frisch Assigned To frisch =>
2017-10-11 10:22 frisch Note Added: 0018538
2017-10-11 10:28 frisch Assigned To => frisch
2017-10-11 10:28 frisch Status confirmed => assigned
2017-10-11 10:28 frisch Note Added: 0018539
2017-10-11 12:57 frisch Target Version => 4.06.0+dev
2017-10-19 15:25 xleroy Note Added: 0018591
2017-10-19 15:25 xleroy Status assigned => resolved
2017-10-19 15:25 xleroy Resolution open => fixed


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker