Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0007722OCamlback end (clambda to assembly)public2018-02-06 07:342018-02-17 18:07
Assigned To 
PlatformOSOS Version
Product Version4.06.0 
Target VersionFixed in Version 
Summary0007722: caml_modify with int type parameter in GADT
DescriptionWhen mutating a member of a record with an existential type, a caml_modify is generated even though it is know that the member can only hold immediate values.

module Kind = struct
  type _ t =
    | Int : int t

module R = struct
  type t =
    | T :
        { kind : 'a Kind.t
        ; mutable m : 'a
        } -> t

let mutate r (v : int) =
  let open R in
  let T ({ kind = Kind.Int; _} as r) = r in
  (* caml_modify is used here, even though r.m can only
     contain ints *)
  r.m <- v
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
xleroy (administrator)
2018-02-17 18:07

The compiler errs on the side of caution: it generates a caml_modify operation unless it can positively prove that it's not needed. With GADTs such proofs are delicate and very error prone. So, maybe it's for the best that we're not trying to optimize this example.

- Issue History
Date Modified Username Field Change
2018-02-06 07:34 smuenzel-js New Issue
2018-02-17 18:07 xleroy Note Added: 0018882
2018-02-17 18:07 xleroy Status new => acknowledged

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker