@@ -171,21 +171,31 @@ compile(Meta, Module, ModuleAsCharlist, Block, Vars, Prune, E) ->
171171        NifsAttribute  =  lists :keyfind (nifs , 1 , Attributes ),
172172        validate_nifs_attribute (NifsAttribute , AllDefinitions , Line , E ),
173173        elixir_import :ensure_no_local_conflict (Module , AllDefinitions , E ),
174- 
175174        make_readonly (Module ),
176175
177176        (not  elixir_config :is_bootstrap ()) andalso 
178177         'Elixir.Module' :'__check_attributes__' (E , DataSet , DataBag ),
179178
180-         RawCompileOpts  =  bag_lookup_element (DataBag , {accumulate , compile }, 2 ),
181-         CompileOpts  =  validate_compile_opts (RawCompileOpts , AllDefinitions , Line , E ),
182-         Impls  =  bag_lookup_element (DataBag , impls , 2 ),
183- 
184179        AfterVerify  =  bag_lookup_element (DataBag , {accumulate , after_verify }, 2 ),
185180        [elixir_env :trace ({remote_function , [], VerifyMod , VerifyFun , 1 }, CallbackE ) ||
186181         {VerifyMod , VerifyFun } <-  AfterVerify ],
187182
188-         PartialModuleMap  =  #{
183+         % % Ensure there are no errors before we infer types
184+         compile_error_if_tainted (DataSet , E ),
185+ 
186+         {Signatures , Unreachable } = 
187+           case  elixir_config :is_bootstrap () of 
188+             true  -> {#{}, []};
189+             false  ->
190+               Used  =  bag_lookup_element (DataBag , macro_private_calls , 2 ),
191+               'Elixir.Module.Types' :infer (Module , File , AllDefinitions , NewPrivate , Used , E )
192+           end ,
193+ 
194+         RawCompileOpts  =  bag_lookup_element (DataBag , {accumulate , compile }, 2 ),
195+         CompileOpts  =  validate_compile_opts (RawCompileOpts , AllDefinitions , Unreachable , Line , E ),
196+         Impls  =  bag_lookup_element (DataBag , impls , 2 ),
197+ 
198+         ModuleMap  =  #{
189199          struct  =>  get_struct (DataSet ),
190200          module  =>  Module ,
191201          anno  =>  Anno ,
@@ -198,17 +208,14 @@ compile(Meta, Module, ModuleAsCharlist, Block, Vars, Prune, E) ->
198208          deprecated  =>  get_deprecated (DataBag ),
199209          defines_behaviour  =>  defines_behaviour (DataBag ),
200210          impls  =>  Impls ,
201-           unreachable  =>  [] ,
202-           signatures  =>  #{} 
211+           unreachable  =>  Unreachable ,
212+           signatures  =>  Signatures 
203213        },
204214
205-         % % Compute signatures only if the module is valid.
206-         compile_error_if_tainted (DataSet , E ),
207-         ModuleMap  =  spawn_parallel_checker (DataBag , CheckerInfo , PartialModuleMap , NewPrivate , E ),
208215        compile_error_if_tainted (DataSet , E ),
209- 
210216        Binary  =  elixir_erl :compile (ModuleMap ),
211217        Autoload  =  proplists :get_value (autoload , CompileOpts , true ),
218+         spawn_parallel_checker (CheckerInfo , Module , ModuleMap ),
212219        {Binary , PersistedAttributes , Autoload }
213220      end ),
214221
@@ -218,7 +225,7 @@ compile(Meta, Module, ModuleAsCharlist, Block, Vars, Prune, E) ->
218225    elixir_env :trace ({on_module , Binary , none }, ModuleE ),
219226    warn_unused_attributes (DataSet , DataBag , PersistedAttributes , E ),
220227    make_module_available (Module , Binary ),
221-     (CheckerInfo  ==  nil ) andalso 
228+     (CheckerInfo  ==  undefined ) andalso 
222229      [VerifyMod :VerifyFun (Module ) ||
223230       {VerifyMod , VerifyFun } <-  bag_lookup_element (DataBag , {accumulate , after_verify }, 2 )],
224231    {module , Module , Binary , Result }
@@ -245,27 +252,41 @@ compile_error_if_tainted(DataSet, E) ->
245252    false  -> ok 
246253  end .
247254
248- validate_compile_opts (Opts , Defs , Line , E ) -> 
249-   lists :flatmap (fun  (Opt ) -> validate_compile_opt (Opt , Defs , Line , E ) end , Opts ).
255+ validate_compile_opts (Opts , Defs , Unreachable ,  Line , E ) -> 
256+   lists :flatmap (fun  (Opt ) -> validate_compile_opt (Opt , Defs , Unreachable ,  Line , E ) end , Opts ).
250257
251258% % TODO: Make this an error on v2.0
252- validate_compile_opt ({parse_transform , Module } =  Opt , _Defs , Line , E ) -> 
259+ validate_compile_opt ({parse_transform , Module } =  Opt , _Defs , _Unreachable ,  Line , E ) -> 
253260  elixir_errors :file_warn ([{line , Line }], E , ? MODULE , {parse_transform , Module }),
254261  [Opt ];
255- validate_compile_opt ({inline , Inlines } =  Opt , Defs , Line , E ) -> 
256-   [case  lists :keyfind (Inline , 1 , Defs ) of 
262+ validate_compile_opt ({inline , Inlines }, Defs , Unreachable , Line , E ) -> 
263+   case  validate_inlines (Inlines , Defs , Unreachable , []) of 
264+     {ok , []} ->
265+       [];
266+     {ok , FilteredInlines } ->
267+       [{inline , FilteredInlines }];
268+     {error , Reason } ->
269+       elixir_errors :module_error ([{line , Line }], E , ? MODULE , Reason ),
270+       []
271+   end ;
272+ validate_compile_opt (Opt , Defs , Unreachable , Line , E ) when  is_list (Opt ) -> 
273+   validate_compile_opts (Opt , Defs , Unreachable , Line , E );
274+ validate_compile_opt (Opt , _Defs , _Unreachable , _Line , _E ) -> 
275+   [Opt ].
276+ 
277+ validate_inlines ([Inline  | Inlines ], Defs , Unreachable , Acc ) -> 
278+   case  lists :keyfind (Inline , 1 , Defs ) of 
257279    false  ->
258-       elixir_errors : module_error ([{ line ,  Line }],  E ,  ? MODULE ,  {undefined_function , {compile , inline }, Inline }) ;
280+       { error ,  {undefined_function , {compile , inline }, Inline }} ;
259281    {_Def , Type , _Meta , _Clauses } when  Type  ==  defmacro ; Type  ==  defmacrop  ->
260-       elixir_errors : module_error ([{ line ,  Line }],  E ,  ? MODULE ,  {bad_macro , {compile , inline }, Inline }) ;
282+       { error ,  {bad_macro , {compile , inline }, Inline }} ;
261283    _  ->
262-       ok 
263-   end  || Inline  <-  Inlines ],
264-   [Opt ];
265- validate_compile_opt (Opt , Defs , Line , E ) when  is_list (Opt ) -> 
266-   validate_compile_opts (Opt , Defs , Line , E );
267- validate_compile_opt (Opt , _Defs , _Line , _E ) -> 
268-   [Opt ].
284+       case  lists :member (Inline , Unreachable ) of 
285+         true  -> validate_inlines (Inlines , Defs , Unreachable , Acc );
286+         false  -> validate_inlines (Inlines , Defs , Unreachable , [Inline  | Acc ])
287+       end 
288+   end ;
289+ validate_inlines ([], _Defs , _Unreachable , Acc ) ->  {ok , Acc }.
269290
270291validate_on_load_attribute ({on_load , Def }, Defs , Private , Line , E ) -> 
271292  case  lists :keyfind (Def , 1 , Defs ) of 
@@ -534,23 +555,19 @@ beam_location(ModuleAsCharlist) ->
534555
535556checker_info () -> 
536557  case  get (elixir_checker_info ) of 
537-     undefined  -> nil ;
558+     undefined  -> undefined ;
538559    _  -> 'Elixir.Module.ParallelChecker' :get ()
539560  end .
540561
541- spawn_parallel_checker (DataBag , CheckerInfo , ModuleMap , Private , E ) -> 
562+ spawn_parallel_checker (undefined , _Module , _ModuleMap ) -> 
563+   ok ;
564+ spawn_parallel_checker (CheckerInfo , Module , ModuleMap ) -> 
542565  Log  = 
543566    case  erlang :get (elixir_code_diagnostics ) of 
544567      {_ , false } -> false ;
545568      _  -> true 
546569    end ,
547- 
548-   Used  =  bag_lookup_element (DataBag , macro_private_calls , 2 ),
549- 
550-   case  elixir_config :is_bootstrap () of 
551-     true  -> ModuleMap ;
552-     false  -> 'Elixir.Module.ParallelChecker' :spawn (CheckerInfo , ModuleMap , Log , Private , Used , E )
553-   end .
570+   'Elixir.Module.ParallelChecker' :spawn (CheckerInfo , Module , ModuleMap , Log ).
554571
555572make_module_available (Module , Binary ) -> 
556573  case  get (elixir_module_binaries ) of 
0 commit comments