Skip to content

Unboxed returns (multiple return values)#1248

Closed
Ekdohibs wants to merge 12 commits intooxcaml:mainfrom
Ekdohibs:unboxed-returns
Closed

Unboxed returns (multiple return values)#1248
Ekdohibs wants to merge 12 commits intooxcaml:mainfrom
Ekdohibs:unboxed-returns

Conversation

@Ekdohibs
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

Gbury commented Mar 23, 2023

the bug above is fixed by f50cb88

@Ekdohibs
Copy link
Copy Markdown
Contributor Author

Ekdohibs commented Apr 4, 2023

Subsumed by #1271.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in 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