Skip to content

Prevent fatal compiler error with unboxing code and GADTs#1578

Merged
mshinwell merged 3 commits intooxcaml:mainfrom
Ekdohibs:fix-unboxing-crash
Jul 25, 2023
Merged

Prevent fatal compiler error with unboxing code and GADTs#1578
mshinwell merged 3 commits intooxcaml:mainfrom
Ekdohibs:fix-unboxing-crash

Conversation

@Ekdohibs
Copy link
Copy Markdown
Contributor

This prevents a crash on this example:

type foo =
  | A of float
  | B of int

type bar = Other

type 'a t =
  | Foo : foo -> foo t
  | Bar : bar t


let f (type a) : a t -> a = function
  | Foo x -> x
  | Bar -> Other


let baz p x z =
  let a =
    if p then (f x)
    else B z
  in
  Sys.opaque_identity a

I think we could also rewrite the code to Invalid in this case, but I'm not sure how to do that.

@Ekdohibs Ekdohibs requested review from Gbury and chambart as code owners July 19, 2023 17:03
@mshinwell mshinwell added bug Something isn't working flambda2 Prerequisite for, or part of, flambda2 labels Jul 24, 2023
@mshinwell mshinwell changed the title Prevent crash with unboxing code and GADTs Prevent fatal compiler error with unboxing code and GADTs Jul 24, 2023
Copy link
Copy Markdown
Contributor

@chambart chambart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to think about potential problems since this might be a bit tricky. But this seems sound.

It would be possible to produce invalid in that case, but it is probably too much work for quite a small benefit.

@Ekdohibs Ekdohibs requested a review from lukemaurer as a code owner July 25, 2023 09:13
@mshinwell mshinwell merged commit 83fa0b2 into oxcaml:main Jul 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working flambda2 Prerequisite for, or part of, flambda2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants