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

trying eqwalizer on elixir projects #17

Open
tothlac opened this issue Jan 24, 2023 · 2 comments
Open

trying eqwalizer on elixir projects #17

tothlac opened this issue Jan 24, 2023 · 2 comments

Comments

@tothlac
Copy link

tothlac commented Jan 24, 2023

We wanted to try eqwalizer on our elixir projects. I know it would be a lot better to implement a parser for Elixir projects, but as a first step we decompiled the beam files to erlang sources, and
we were running eqwalizer on those sources.

We have found some problems:

  • in the decompiled source there is a -file attribute:
-file("lib/asdfqqqq.ex", 1).
-module('Elixir.Asdfqqqq').

When this attribute is there eqwalizer simply ignores all problems. If I manually delete this line, it works.

  • there is also an info/1 function in the source:
'__info__'(module) -> 'Elixir.Asdfqqqq';
'__info__'(functions) -> [{double, 1}];
'__info__'(macros) -> [];
'__info__'(exports_md5) -> <<"\035S8}I7\030\232\236g-\023">>;

this last function clause will cause this problem:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Utf8Error { valid_up_to: 429, error_len: Some(1) }', crates/elp/src/bin/[reporting.rs:101](http://reporting.rs:101/):78
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
  • actually, when I manually fix these problems eqwalizer works quite well, and it is able to spot the problems in the code (of course the line numbers are wrong). One remaining problem is that I could not figure out how to tell to eqwalizer where the declarations of Elixir types are. So for instance:
-spec double({error, 1}) -> 'Elixir.String':t().
double(_x@1) -> 2 * _x@1.

Elixir.String type is declared in $ELIXIR_DIR//lib/elixir/lib/string.ex. Similarly, I want to add all files where elixir types are declared. How can I add those using project.json?

I have one more question...
Let's say I have my_app application, which uses my_lib as a dependency. In my_app.erl I have the following:

-include_lib("my_lib/include/my_lib.hrl").

I've tried it with this project.json:

{
  "apps": [
    {
      "name": "my_app",
      "dir": "",
      "ebin": "_build/default/lib/my_app/ebin",
      "extra_src_dirs": [""],
      "include_dirs": ["include"],
      "macros": ["TEST"],
      "src_dirs": ["src"]
    }
  ],
  "deps": [
    {
      "name": "my_lib",
      "dir": "",
      "ebin": "_build/default/lib/my_lib/ebin",
      "extra_src_dirs": [""],
      "include_dirs": ["_build/default/lib/my_lib/include"],
      "macros": ["TEST"],
      "src_dirs": ["src"]
    }

  ],
  "root": ""
}

elp is still complaining about being not able to find the include file:

  eqWAlizing                ████████████████████ 3/3                                                                             error: parse_error
    ┌─ src/my_app.erl:3:14
    │
103 │ -include_lib("my_lib/include/my_lib.hrl").
    │              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find include lib "my_lib/include/my_lib.hrl"

Do you have an idea what should I put into my project.json ?

@tothlac
Copy link
Author

tothlac commented Jan 27, 2023

We were trying to make it work using the following project.json :

{
  "apps": [
    {
      "name": "asdfqqqq",
      "dir": "/home/joe/Projects/asdfqqqq",
      "ebin": "/home/joe/Projects/asdfqqqq/_build/dev/lib/asdfqqqq/ebin",
      "extra_src_dirs": ["test"],
      "include_dirs": ["include"],
      "macros": ["TEST"],
      "src_dirs": ["erlangized_src/"]
    }
  ],
  "deps": [
    {
      "name": "elixir",
      "dir": "/home/joe/.manager/elixir",
      "ebin": "/home/joe/.managerl/erlang-OTP-23.2.3/elixirs/elixir-v1.12.2/lib/elixir/lib/elixir/ebin",
      "extra_src_dirs": [],
      "include_dirs": [],
      "macros": [],
      "src_dirs": ["lib"]
    }

  ],
  "source_root": "/home/joe/Projects/asdfqqqq",
  "otp_lib_dir": "/home/joe/.managerl/erlang-OTP-23.2.3/lib/"
}

Elixir.String.t() type is declared in the above-mentioned folder. With these settings, it still was not able to find the declaration of this type. Is it possible that to find the declaration eqwalizer also needs the erlang source code present in the src directory, or do you have any other ideas on what's going on wrong?

@ilya-klyuchnikov
Copy link
Member

  1. We don't provide any support for type-checking Elixir projects out of the box and we don't plan to do it on our own in the near future
  2. Nevertheless, I think that it's feasible to to use it for Elixir, - but someone needs to drive it. And it's hard to estimate the amount of tech work.

Contributions are welcome.

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

2 participants