Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006337OCamlOCaml backend (code generation)public2014-03-05 11:102014-03-06 18:04
Reporterfrisch 
Assigned Tofrisch 
PrioritynormalSeverityminorReproducibilityhave not tried
StatusresolvedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version4.02.0+dev 
Summary0006337: Constants emitted several times
DescriptionThe following code:
let g () =
  let r = ref 0 in
  let rec f () =
    incr r;
    print_endline "foo";
  in
  f


results in the string constant "foo" to be emitted twice. ocamlopt -dcmm shows:

(data int 1024 global "camlFoo" "camlFoo": skip 8)
(data int 2295 "camlFoo__3": addr "camlFoo__g_1010" int 3)
(data global "camlFoo__1" int 1276 "camlFoo__1": string "foo" skip 4 byte 
4)
(data global "camlFoo__2" int 1276 "camlFoo__2": string "foo" skip 4 byte 
4)
...


Note the presence of camlFoo_1 and camlFoo_2. Only the second one is actually used.

This comes from Closure.close_functions, which tries to compile first the functions under the assumption that their environment is not used, and do it again if this assumption is invalidated. Since structured constants are now allocated during this pass, they can be allocated several times.

One possible fix is to backtrack the list of allocated structured constants when a second pass is required.

Note that even if the sharing of constants is added (0005779), this will still apply because of string literals (which won't be shared, since they are mutable).
TagsNo tags attached.
Attached Files

- Relationships
related to 0005779resolvedfrisch static data structures allocated on the GC heap 

-  Notes
(0011008)
frisch (developer)
2014-03-06 14:54

This is fixed in the *_v6 patch on 0005779.
(0011014)
frisch (developer)
2014-03-06 18:04

Fixed by commit 14444 on trunk (cf 0005779).

- Issue History
Date Modified Username Field Change
2014-03-05 11:10 frisch New Issue
2014-03-05 11:27 frisch Description Updated View Revisions
2014-03-05 11:27 frisch Description Updated View Revisions
2014-03-05 11:32 frisch Description Updated View Revisions
2014-03-05 17:33 frisch Relationship added related to 0005779
2014-03-06 14:54 frisch Note Added: 0011008
2014-03-06 18:04 frisch Note Added: 0011014
2014-03-06 18:04 frisch Status new => resolved
2014-03-06 18:04 frisch Fixed in Version => 4.02.0+dev
2014-03-06 18:04 frisch Resolution open => fixed
2014-03-06 18:04 frisch Assigned To => frisch
2014-03-06 18:04 frisch Description Updated View Revisions


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker