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

Rework how overriden otp types are compiled and loaded #191

Merged
merged 2 commits into from
Sep 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ matrix:
# At that point, update otp_release in the corresponding list below

- env: TEST=".travis/travis_has_latest_otp_version"
otp_release: 21.2
otp_release: 22.1

# Run make target specialized for the checks we want to make in Travis for
# the latest OTP release.
Expand All @@ -36,9 +36,9 @@ matrix:
# The latest OTP version is special and therefore explicitly
# included above instead.
otp_release:

- 21.0
- 22.0
# Last minor version of older OTP releases
- 21.3
- 20.3
- 19.3

Expand Down
17 changes: 2 additions & 15 deletions src/gradualizer_db.erl
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ import_module(Module) ->

-type opts() :: #{autoimport => boolean()}.
-define(default_opts, #{autoimport => true}).
-define(prelude_erl, filename:join(code:priv_dir(gradualizer),
"otp_spec_fix.erl")).

-record(state, {specs = #{} :: #{mfa() => [type()]},
types = #{} :: #{mfa() => #typeinfo{}},
Expand Down Expand Up @@ -256,19 +254,8 @@ code_change(_OldVsn, State, _Extra) ->

-spec import_prelude(state()) -> state().
import_prelude(State) ->
%% Read the beam from file system or from escript archive
case code:which(gradualizer_prelude) of
cover_compiled ->
%% Cover messes with the code server. Hopefully we're not
%% using cover when running as an escript.
ErlFile = filename:join(filename:dirname(?FILE),
"gradualizer_prelude.erl"),
import_erl_files([ErlFile], State);
Filename when is_list(Filename) ->
{ok, BeamCode, _Filename} = erl_prim_loader:get_file(Filename),
{ok, State1 = #state{}} = import_beam_files([BeamCode], State),
State1
end.
Forms = gradualizer_prelude:get_prelude(),
_NewState1 = import_absform(gradualizer_prelude, Forms, State).

%% @doc ensure DB server is started
call(Request) ->
Expand Down
2 changes: 2 additions & 0 deletions src/gradualizer_prelude.erl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
-module(gradualizer_prelude).

-compile({parse_transform, gradualizer_prelude_parse_trans}).

%% This module contains specs to replace incorrect or inexact specs in OTP.

-spec erlang:apply(function(), [any()]) -> any().
Expand Down
15 changes: 15 additions & 0 deletions src/gradualizer_prelude_parse_trans.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-module(gradualizer_prelude_parse_trans).

-export([parse_transform/2]).

parse_transform(Forms, _Options) ->
[{attribute, _, file, _} = File,
{attribute, _, module, _} = Mod
|SpecForms] = Forms,

[File,
Mod,
{attribute,2,export,[{get_prelude,0}]},
{function,3,get_prelude,0,
[{clause,3,[],[],
[erl_parse:abstract(SpecForms)]}]}].