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

Constants emitted several times #6337

Closed
vicuna opened this issue Mar 5, 2014 · 2 comments
Closed

Constants emitted several times #6337

vicuna opened this issue Mar 5, 2014 · 2 comments
Assignees

Comments

@vicuna
Copy link

vicuna commented Mar 5, 2014

Original bug ID: 6337
Reporter: @alainfrisch
Assigned to: @alainfrisch
Status: closed (set by @xavierleroy on 2015-12-11T18:25:45Z)
Resolution: fixed
Priority: normal
Severity: minor
Fixed in version: 4.02.0+dev
Category: back end (clambda to assembly)
Related to: #5779
Monitored by: @gasche

Bug description

The 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 (#5779), this will still apply because of string literals (which won't be shared, since they are mutable).

@vicuna
Copy link
Author

vicuna commented Mar 6, 2014

Comment author: @alainfrisch

This is fixed in the *_v6 patch on #5779.

@vicuna
Copy link
Author

vicuna commented Mar 6, 2014

Comment author: @alainfrisch

Fixed by commit 14444 on trunk (cf #5779).

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