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

Elixir support #73

Closed
lpil opened this issue Nov 5, 2018 · 6 comments
Closed

Elixir support #73

lpil opened this issue Nov 5, 2018 · 6 comments

Comments

@lpil
Copy link

lpil commented Nov 5, 2018

Hello!

I was wondering if there would be any interest in/possibility of adding Elixir support to Gradualizer?

Semantically they are near identical languages that use the same typespecs, so I feel the same tool could be applied to both. I can think of two main differences:

  1. Elixir has Lisp style macros. To handle this type checking could be performed after macro resolution so no knowledge of that system is required.

  2. Elixir has protocols, which are slightly similar to Haskell's typeclasses and have no equivalent in Erlang. This could be ignored, at least to start.

I've not yet read any of the Gradualizer source- does this feature seem realistic and achiveable?

Cheers,
Louis

@josefs
Copy link
Owner

josefs commented Nov 5, 2018

People have already experimented with running the Gradualizer on Elixir programs! The way we can currently support this is as follows: beam files compiled with the debug_info flag includes an "abstract form" of the program, which Gradualizer can use as a basis for typechecking. As luck would have it, the Elixir compiler includes the abstract form when compiling programs. So the Gradualizer can easily be run on beam files originating from Elixir programs.

Now, I haven't tried to type check any Elixir programs myself. But from what I understand it is already possible to typecheck quite a few programs although there are a few wrinkles that need to be sorted out for full Elixir support. Don't take my work for it though.

I'd love to see people trying out Gradualizer for Elixir and reporting any success and/or problems they have. Ideally, also submitting patches to fix any encountered problems. Unfortunately, I don't have any bandwidth to work on Elixir support and the main contributors are focused on finalizing typechecking for Erlang so that we can make a beta release. But I'd be happy to have people contribute Elixir support as well.

@OvermindDL1
Copy link

Now, I haven't tried to type check any Elixir programs myself. But from what I understand it is already possible to typecheck quite a few programs although there are a few wrinkles that need to be sorted out for full Elixir support. Don't take my work for it though.

I've done it, it works well enough sans Gradualizer is still missing some types but those are being added over time. :-)

I've been waiting for someone to make a mix plugin to use Gradualizer, then you could do it all at once and built-in'ish, I might get around to it sometime when I get some free time. :-)

@lpil
Copy link
Author

lpil commented Nov 5, 2018

Makes sense! Is there an option for languages such as LFE? It compiles to Core directly and I believe do not have the same abstract form as Erlang and Elixir as a result.

@OvermindDL1
Copy link

I've not actually checked about LFE, @rvirding would be the one to ask there, but from my understanding the abstract form's should be the same for everything that compiles to the BEAM via any method as long as they add in the debug chunk (which I'm not sure if LFE does, but I would expect it to do so considering LFE is made by @rvirding?).

@jeremyowensboggs
Copy link

jeremyowensboggs commented Nov 19, 2018

@OvermindDL1 How did you get it running with Elixir? I have it compiled, but when I try to use it my elixir directory, I get:

~/d/blaster2 (BV2-66-display-on-screen-for-technical-issues)> ../Gradualizer/gradualizer _build/dev/lib/blaster/ebin/Elixir.Blaster.Cart.beam
escript: exception error: undefined function elixir_erl:debug_info/4
  in function  beam_lib:chunks_to_data/7 (beam_lib.erl, line 652)
  in call from beam_lib:read_chunk_data/3 (beam_lib.erl, line 521)
  in call from beam_lib:read_chunk_data/2 (beam_lib.erl, line 509)
  in call from gradualizer_file_utils:get_forms_from_beam/1 (/Users/jowens/dev/Gradualizer/_build/default/lib/gradualizer/src/gradualizer_file_utils.erl, line 36)
  in call from gradualizer:type_check_file/2 (/Users/jowens/dev/Gradualizer/_build/default/lib/gradualizer/src/gradualizer.erl, line 40)
  in call from gradualizer:'-type_check_files/2-fun-0-'/4 (/Users/jowens/dev/Gradualizer/_build/default/lib/gradualizer/src/gradualizer.erl, line 99)
  in call from lists:foldl/3 (lists.erl, line 1263)

@OvermindDL1
Copy link

@jeremyowensboggs I made a mix plugin at: https://github.com/overminddl1/gradualixir

That error means that you didn't link in the Elixir library location (-pa .../path/to/elixir/ebin).

I plan to PR my plugin here sometime, just not got around to it yet, way busy in real life. ^.^;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants