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

Function references have the wrong arity #10

Closed
leostera opened this issue Oct 10, 2020 · 0 comments
Closed

Function references have the wrong arity #10

leostera opened this issue Oct 10, 2020 · 0 comments
Labels
bug Something isn't working compiler Related to the OCaml to Erlang compiler help wanted Extra attention is needed

Comments

@leostera
Copy link
Owner

After the last refactor of the Erlang printer, we no longer look up the arity of a function at print time, and thus the default arity that's set to zero here is always printed out.

So this OCaml:

let f g = g ()
let rec g _ = f g

that should compile to this Erlang:

f(G) -> G().
g(_) -> f(fun g/1).

Compiles instead to this erlang:

f(G) -> G().
g(_) -> f(fun g/0).

Note the arity of g is obviously 1 since it takes one parameter, but the function reference does not have this information anymore.

To fix this we should change the way that function references are being created here and use the identifier found to lookup the arity of the function.

This could be done by:

  • Adding a Hashtbl.t from function name's to their a copy of the Erlang AST values
  • Carrying around an assoc. list of the functions that we've transformed so far.

The second approach would be a little cleaner (considering we've gone so far without any mutable state in the translation), and it happily relies on the assumption that every function will be defined before it is used.

The first approach might be easier to hack on.

@leostera leostera added bug Something isn't working help wanted Extra attention is needed compiler Related to the OCaml to Erlang compiler labels Oct 10, 2020
@leostera leostera added this to the v0.1 milestone Oct 10, 2020
@leostera leostera mentioned this issue Oct 10, 2020
61 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler Related to the OCaml to Erlang compiler help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant