Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0007292OCamlback end (clambda to assembly)public2016-07-18 16:182017-09-24 17:33
Assigned Toshinwell 
PrioritynormalSeverityminorReproducibilityhave not tried
PlatformOSOS Version
Product Version 
Target Version4.04.0 +dev / +beta1 / +beta2Fixed in Version4.04.0 +dev / +beta1 / +beta2 
Summary0007292: CamlinternalLazy not flambda-proof?
DescriptionCompiling the following:

let _ = Lazy.force (lazy (fun _ -> assert false))

with flambda and O3 prints the following error message 9 times:

File "", line 0, characters 0-0:
Warning 59: A potential assignment to a non-mutable value was detected
in this source file.  Such assignments may generate incorrect code
when using Flambda.

(Note that the error message refers to while we are compiling another unit.)
TagsNo tags attached.
Attached Files

- Relationships
related to 0007301closedshinwell Segfault with flambda -03, perhaps related to lazy values 

-  Notes
frisch (developer)
2016-07-18 16:51

For now, we compile with this local change:

---      (revision 95085)
+++      (working copy)
@@ -1017,6 +1017,7 @@
       | (Psetfield _ | Parraysetu _ | Parraysets _),
           _block::_, block_approx::_ ->
         if A.is_definitely_immutable block_approx then begin
+          if dbg.Debuginfo.dinfo_file <> "" then (* LEXIFI, see OCaml 
PR#7292 *)
           Location.prerr_warning (Debuginfo.to_location dbg)

I don't know if this is safe (i.e. if the "unsafe set_field" in camlinternalLazy cannot break anything), but it is better than disabling that warning globally. (Due to our local "lazy let rec" construction, we end up with a lot of "lazy functions".)
frisch (developer)
2016-07-20 19:26
edited on: 2016-07-20 19:32

We get a segfault on a piece of code with flambda -O3; this code uses Lazy and the segfault disappears with simple changes such as (lazy x --> Lazy.from_val x) (where x is an identifier). So I'm wondering if the warning reported in this PR could be related. Could it be that "unsafe" mutations done in camlinternalLazy are really unsafe with flambda -O3?

More details: the 'x' refers in fact to a function, but hidden behind an abstract type. So for "lazy x", Translcore produces a forward block (because it doesn't know the definition of the abstract type and if it were "float", it could be compile the expression as "x"). For "Lazy.from_val x", flambda inlines the called function; since it knows that "x" refers to a closure, this removes the tag check in Lazy.from_val, and this produces simply a reference to "x".

(Optimization note: Perhaps in flambda mode, Translcore should compile "lazy x" to "Lazy.from_val x" instead of producing the forward block itself, in order to benefit from further optimization. Alternatively flambda should optimize away forward blocks pointing to values of non-float types.)

frisch (developer)
2016-07-21 17:39

Segfaulting program reduced and reported in 0007301.
shinwell (developer)
2016-07-25 12:33

I am looking at this
shinwell (developer)
2016-07-25 13:01

Please see [^]
frisch (developer)
2016-07-31 15:28

And [^]
shinwell (developer)
2016-08-01 16:22

Fixed for 4.04

- Issue History
Date Modified Username Field Change
2016-07-18 16:18 frisch New Issue
2016-07-18 16:51 frisch Note Added: 0016080
2016-07-20 19:26 frisch Note Added: 0016106
2016-07-20 19:32 frisch Note Edited: 0016106 View Revisions
2016-07-21 17:39 frisch Note Added: 0016111
2016-07-21 17:39 frisch Relationship added related to 0007301
2016-07-25 12:33 shinwell Note Added: 0016124
2016-07-25 13:01 shinwell Note Added: 0016125
2016-07-31 15:28 frisch Note Added: 0016153
2016-08-01 16:22 shinwell Note Added: 0016159
2016-08-01 16:23 shinwell Status new => resolved
2016-08-01 16:23 shinwell Fixed in Version => 4.04.0 +dev / +beta1 / +beta2
2016-08-01 16:23 shinwell Resolution open => fixed
2016-08-01 16:23 shinwell Assigned To => shinwell
2017-02-23 16:35 doligez Category OCaml backend (code generation) => Back end (clambda to assembly)
2017-02-23 16:44 doligez Category Back end (clambda to assembly) => back end (clambda to assembly)
2017-09-24 17:33 xleroy Status resolved => closed

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker