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

match branches wrongly merged #6322

Closed
vicuna opened this issue Feb 5, 2014 · 7 comments
Closed

match branches wrongly merged #6322

vicuna opened this issue Feb 5, 2014 · 7 comments
Assignees

Comments

@vicuna
Copy link

vicuna commented Feb 5, 2014

Original bug ID: 6322
Reporter: @chambart
Assigned to: @maranget
Status: closed (set by @xavierleroy on 2015-12-11T18:25:41Z)
Resolution: fixed
Priority: normal
Severity: minor
Category: back end (clambda to assembly)
Tags: patch
Monitored by: @gasche @jmeber @hcarty

Bug description

This 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.

File attachments

@vicuna
Copy link
Author

vicuna commented Feb 5, 2014

Comment author: @alainfrisch

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.

@vicuna
Copy link
Author

vicuna commented Feb 5, 2014

Comment author: @chambart

I am not sure of which semantics we really want, but I consider that adding '();' shouldn't change the semantics

@vicuna
Copy link
Author

vicuna commented Feb 6, 2014

Comment author: @garrigue

If the semantics is undefined, anything can change the result...

@vicuna
Copy link
Author

vicuna commented Feb 6, 2014

Comment author: @alainfrisch

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).

@vicuna
Copy link
Author

vicuna commented Feb 6, 2014

Comment author: @mshinwell

Making them read-only seems like a potentially good idea.

@vicuna
Copy link
Author

vicuna commented Feb 6, 2014

Comment author: @maranget

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.

@vicuna
Copy link
Author

vicuna commented Feb 6, 2014

Comment author: @maranget

The misbehaviour is now fixed in trunk.

--Luc

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