Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006029OCamlOCaml backend (code generation)public2013-06-03 18:302014-07-16 20:38
Reporterppedrot 
Assigned To 
PrioritynormalSeveritytweakReproducibilityalways
StatusconfirmedResolutionopen 
PlatformOSOS Version
Product Version3.12.1 
Target Versionafter-4.02.0Fixed in Version 
Summary0006029: lazy should be primitive
DescriptionCurrently, only Lazy.force is compiled as a primitive function, while the keyword "lazy" is not. This has various drawbacks:

1. One has to explicitly put Lazy.from_val to get an efficient lifting, while the compiler could do it automatically in front of syntactical values;

2. Even doing so, there is a small penalty to pay because of the special treatment of float values, which could be inferred statically, similarly to array accesses.

3. This is unlikely to happen, but that also permits code rewriting such as "Lazy.force (lazy t)" as "t".
Steps To ReproduceThe following examples generates a lot of assembly noise:

type 'a stream = 'a node Lazy.t
and 'a node = Cons of 'a * 'a stream

let cons1 x s = lazy (Cons (x, s))
let cons2 x s = Lazy.from_val (Cons (x, s))

while they could be compiled exactly like:

let cons3 x s = Obj.magic (Cons (x, s))
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0009390)
frisch (developer)
2013-06-04 15:12

> 1. One has to explicitly put Lazy.from_val to get an efficient lifting, while the compiler could do it automatically in front of syntactical values;

There is already some code in translcore.ml to do so (see the case for Texp_lazy).
The case of pure constructors with arguments (and records) is currently not optimized. I'm not sure why, but this is easy to change without changing more deeply the way "lazy" is compiled.
(0010724)
doligez (administrator)
2013-12-16 16:40

> 2. Even doing so, there is a small penalty to pay because of the special treatment of float values, which could be inferred statically, similarly to array accesses.

Note to anyone who wants to implement this: float values cannot always be inferred statically, so be ready to have the run-time test in some cases.

- Issue History
Date Modified Username Field Change
2013-06-03 18:30 ppedrot New Issue
2013-06-04 15:12 frisch Note Added: 0009390
2013-06-18 15:50 doligez Status new => confirmed
2013-06-18 15:50 doligez Target Version => 4.02.0+dev
2013-07-12 18:15 doligez Target Version 4.02.0+dev => 4.01.1+dev
2013-12-16 16:40 doligez Note Added: 0010724
2014-05-25 20:20 doligez Target Version 4.01.1+dev => 4.02.0+dev
2014-07-16 20:38 doligez Target Version 4.02.0+dev => after-4.02.0


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker