Skip to content

Flambda2 layouts: Fix partial application wrapper result arity #1551

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

Merged
merged 2 commits into from
Jul 12, 2023

Conversation

ccasin
Copy link
Contributor

@ccasin ccasin commented Jul 8, 2023

This fixes an issue where an incorrect result arity on a partial application wrapper will trip a couple asserts in flambda2 (and would generate incorrect code without the asserts). The basic issue is two places where the result arity of a partial application (which is always value) is incorrectly used as the result arity of the fully applied version after wrapping (which might not be value).

I don't think this error can be observed on the current main branch because you need alternate layouts. But I can see it in #1528 on programs like this:

external of_float : (float[@local_opt]) -> float# = "%unbox_float"

let[@inline never] myapp f (x : float#) = f x

let id_float = myapp (fun x -> x)

let make_pi =
  let x = id_float (of_float 3.14) in ()

Both places are in Closure_conversion.wrap_partial_application - the rest of this is just plumbing to get the correct result arity to that function.

I haven't added a test here because I'm not sure it's possible without another layout, but I have tested applying this diff to #1528, which gets the tests to pass on flambda2 on my machine. I've just pushed it there and we'll see if the CI validates that.

@ccasin ccasin requested review from lthls and mshinwell as code owners July 8, 2023 17:33
@ccasin ccasin added flambda2 Prerequisite for, or part of, flambda2 middle end unboxed types labels Jul 8, 2023
@goldfirere
Copy link
Collaborator

Merging with @Ekdohibs 's approval and in @mshinwell's absence.

@goldfirere goldfirere merged commit 6739d76 into ocaml-flambda:main Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flambda2 Prerequisite for, or part of, flambda2 middle end unboxed types
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants