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

Linking modules compiled with -labels and -nolabels is not safe #7432

Closed
vicuna opened this issue Dec 15, 2016 · 1 comment
Closed

Linking modules compiled with -labels and -nolabels is not safe #7432

vicuna opened this issue Dec 15, 2016 · 1 comment
Assignees

Comments

@vicuna
Copy link

vicuna commented Dec 15, 2016

Original bug ID: 7432
Reporter: @yallop
Assigned to: @garrigue
Status: resolved (set by @garrigue on 2016-12-17T01:38:18Z)
Resolution: fixed
Priority: normal
Severity: minor
Fixed in version: 4.05.0 +dev/beta1/beta2/beta3/rc1
Category: typing
Monitored by: @hcarty

Bug description

The -labels and -nolabels modes of the compiler have different views of type equality. There are some types that are considered equal with -nolabels, but incompatible with -labels.

It's possible, therefore, to pass a witness of type equality (compiled with -nolabels) to a function compiled (with -labels) under the assumption that no such witness can exist, leading to a crash.

Here's a demonstration:

$ cat a.ml 
type (_,_) eql = Refl : ('a, 'a) eql
type s = x:int -> y:float -> unit
type t = y:int -> x:float -> unit
let eql : (s, t) eql = Refl
$ cat b.ml 
open A

type silly = {silly: 'a.'a}

let f : [`L of (s, t) eql | `R of silly] -> 'a =
   function `R {silly} -> silly
let () = print_endline (f (`L A.eql))
$ ocamlopt -c -nolabels a.ml  && ocamlopt -c  b.ml && ocamlopt a.cmx b.cmx -o a.out
$ ./a.out 
Segmentation fault
@vicuna
Copy link
Author

vicuna commented Dec 17, 2016

Comment author: @garrigue

Fixed by commit 6e694c6.

mcomp was already doing the right thing (ignoring labels for non-optional arguments), but unify has to do the same thing when in Pattern mode.

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