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

FIP analysis does not handle boxing of value types correctly #576

Open
anfelor opened this issue Sep 4, 2024 · 0 comments
Open

FIP analysis does not handle boxing of value types correctly #576

anfelor opened this issue Sep 4, 2024 · 0 comments

Comments

@anfelor
Copy link
Collaborator

anfelor commented Sep 4, 2024

In Koka 3.1.2, the following program is accepted:

fip fun test( b : bool ) : maybe<(int, int)>
  if b then Just((1, 2)) else Nothing

but it is compiled to the following code:

kk_std_core_types__maybe kk_test7_test(bool b, kk_context_t* _ctx) { /* (b : bool) -> maybe<(int, int)> */ 
  if (b) {
    kk_box_t _x_x6;
    kk_std_core_types__tuple2 _x_x7 = kk_std_core_types__new_Tuple2(kk_integer_box(kk_integer_from_small(1), _ctx), kk_integer_box(kk_integer_from_small(2), _ctx), _ctx); /*(1038, 1039)*/
    _x_x6 = kk_std_core_types__tuple2_box(_x_x7, _ctx); /*1027*/
    return kk_std_core_types__new_Just(_x_x6, _ctx);
  }
  {
    return kk_std_core_types__new_Nothing(_ctx);
  }
}

Since the tuple in the Just constructor is boxed, this example allocates and is in fact not fip.

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