Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006322OCamlOCaml backend (code generation)public2014-02-05 21:252014-02-07 00:45
Reporterchambart 
Assigned Tomaranget 
PrioritynormalSeverityminorReproducibilityalways
StatusresolvedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0006322: match branches wrongly merged
DescriptionThis code fails:

let g x = match x with (* branch are merged *)
  | true -> "a"
  | false -> "a"

let f x = match x with (* branch are not merged *)
  | true -> (); "a"
  | false -> "a"

let () =
  let s1 = f true in
  let s2 = f false in
  let s3 = g true in
  let s4 = g false in
  s1.[0] <- 'p';
  s3.[0] <- 'p';
  assert(s2 = s4) (* s2 is "p" and s4 is still "a" *)

This is due to Lambda.same considering constant strings as equal terms.
Tagspatch
Attached Filespatch file icon 0001-Fix-Lambda.same-considering-identical-strings-as-equ.patch [^] (1,678 bytes) 2014-02-05 21:25 [Show Content]

- Relationships

-  Notes
(0010887)
frisch (developer)
2014-02-05 21:36

Is this really a bug? The "sharing" semantics of string literals is not really specified. The manual says (http://caml.inria.fr/pub/docs/manual-ocaml/libref/String.html [^]):

[...] both the OCaml compiler and most OCaml libraries share strings as if they were immutable, rather than copying them.
(0010888)
chambart (developer)
2014-02-05 22:44

I am not sure of which semantics we really want, but I consider that adding '();' shouldn't change the semantics
(0010892)
garrigue (manager)
2014-02-06 05:12

If the semantics is undefined, anything can change the result...
(0010893)
frisch (developer)
2014-02-06 09:30

For OS which support read-only pages, I'm wondering if it would be feasible to make string literals read-only. Any attempt to modify them would trigger a trap (which one could hopefully turn into an OCaml exception).
(0010899)
shinwell (developer)
2014-02-06 12:21

Making them read-only seems like a potentially good idea.
(0010901)
maranget (manager)
2014-02-06 14:05

I would tend to correct this misbehaviour, as it is rather surprising.
However, the patch does not correct the misbehaviour. I am working on it.
(0010902)
maranget (manager)
2014-02-06 14:33

The misbehaviour is now fixed in trunk.

--Luc

- Issue History
Date Modified Username Field Change
2014-02-05 21:25 chambart New Issue
2014-02-05 21:25 chambart File Added: 0001-Fix-Lambda.same-considering-identical-strings-as-equ.patch
2014-02-05 21:27 chambart Tag Attached: patch
2014-02-05 21:36 frisch Note Added: 0010887
2014-02-05 22:44 chambart Note Added: 0010888
2014-02-06 05:12 garrigue Note Added: 0010892
2014-02-06 09:30 frisch Note Added: 0010893
2014-02-06 12:21 shinwell Note Added: 0010899
2014-02-06 14:05 maranget Note Added: 0010901
2014-02-06 14:06 maranget Assigned To => maranget
2014-02-06 14:06 maranget Status new => assigned
2014-02-06 14:32 maranget Status assigned => resolved
2014-02-06 14:32 maranget Resolution open => fixed
2014-02-06 14:33 maranget Note Added: 0010902


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker