Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0007535OCamlback end (clambda to assembly)public2017-05-18 22:192017-09-30 18:09
Assigned To 
PrioritynormalSeverityfeatureReproducibilityhave not tried
PlatformOSOS Version
Product Version4.04.1 
Target VersionFixed in Version 
Summary0007535: Improve sharing of values
DescriptionGiven following snippet of a code:

  type 'a id = Id of 'a

  let make (Id x) = Id x

allocation happens every time 'make' called (using flambda-enabled compiler).
Unfortunately it prevents a lot of further optimizations that could happen if it was compiled as simply

  let make (Id _ as x) = x

It seems that flambda already capable of eliminating some allocations, i.e.

  let make x =
    let f (Id x) = Id x in
    f @@ f @@ f @@ f @@ f x

allocates only one block.
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
sliquister (reporter)
2017-05-19 03:34

In this specific example, you'd be better off adding [@@unboxed] on the type definition (or using the command flag that adds it implicitely).

But it's true that sometimes, the compiler could avoid reallocating things, especially when the workaround is not expressible in the source like:

| [] -> assert false
| hd :: tl -> hd, tl

- Issue History
Date Modified Username Field Change
2017-05-18 22:19 Eugene New Issue
2017-05-19 03:34 sliquister Note Added: 0017806
2017-09-30 18:09 xleroy Status new => acknowledged

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker