Skip to content

Unboxed returns (multiple return values) #1248

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
wants to merge 12 commits into from

Conversation

Ekdohibs
Copy link
Contributor

This is a rebase of #1170, together with an attribute [@unboxed] that can be added on the definition of a function to decide to have an unboxed result. It does not trigger automatically, as that would require thinking about a probably complex strategy to avoid reallocations (leading to two test failures).

@mshinwell mshinwell added flambda2 Prerequisite for, or part of, flambda2 backend labels Mar 23, 2023
@Gbury
Copy link
Contributor

Gbury commented Mar 23, 2023

I've found a bug ! Compiling and executing the following code:

let[@inline never][@unboxed] f x =
  ( (* each line has 20 elements *)
    x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
    x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
    x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
    x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
    x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x
  )

let () =
  let (
    _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
    _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
    _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
    _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
    _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, y, _, _, _
  )
    = f 5
  in
  print_int y;
  print_newline ()

Results in the output 0 instead of 5.

The cause seems to be that after the call, the stack pointer is moved before moving the result into a register.

It might be useful to add a few tests exercising unboxed result somewhere.

@Gbury
Copy link
Contributor

Gbury commented Mar 23, 2023

the bug above is fixed by f50cb88

@Ekdohibs
Copy link
Contributor Author

Ekdohibs commented Apr 4, 2023

Subsumed by #1271.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
backend flambda2 Prerequisite for, or part of, flambda2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for multiple return values (not user-visible)
4 participants