@@ -20,6 +20,7 @@ defmodule Module.ParallelChecker do
2020 { :max_concurrency , pos_integer ( ) }
2121 | { :long_verification_threshold , pos_integer ( ) }
2222 | { :each_long_verification , ( module ( ) -> term ( ) ) | ( module ( ) , pid ( ) -> term ( ) ) }
23+ | { :profile , :time }
2324 | { atom ( ) , term ( ) }
2425 ]
2526
@@ -117,13 +118,13 @@ defmodule Module.ParallelChecker do
117118 send ( checker , { ref , :cached } )
118119
119120 receive do
120- { ^ ref , :check } ->
121+ { ^ ref , :check , profile } ->
121122 # Set the compiler info so we can collect warnings
122123 :erlang . put ( :elixir_compiler_info , { pid , self ( ) } )
123124
124125 { warnings , errors } =
125126 if module_tuple do
126- check_module ( module_tuple , { checker , table } , log? )
127+ check_module ( module_tuple , { checker , table } , log? , profile )
127128 else
128129 { [ ] , [ ] }
129130 end
@@ -262,7 +263,7 @@ defmodule Module.ParallelChecker do
262263
263264 ## Module checking
264265
265- defp check_module ( module_tuple , cache , log? ) do
266+ defp check_module ( module_tuple , cache , log? , profile ) do
266267 { module , file , line , definitions , no_warn_undefined , behaviours , impls , attrs , after_verify } =
267268 module_tuple
268269
@@ -276,9 +277,13 @@ defmodule Module.ParallelChecker do
276277 definitions
277278 )
278279
280+ type_warnings =
281+ profile ( module , profile , fn ->
282+ Module.Types . warnings ( module , file , attrs , definitions , no_warn_undefined , cache )
283+ end )
284+
279285 { warnings , errors } =
280- module
281- |> Module.Types . warnings ( file , attrs , definitions , no_warn_undefined , cache )
286+ type_warnings
282287 |> Kernel . ++ ( behaviour_warnings )
283288 |> group_diagnostics ( )
284289 |> emit_diagnostics ( file , log? )
@@ -577,6 +582,7 @@ defmodule Module.ParallelChecker do
577582 schedulers: schedulers ,
578583 threshold: threshold ,
579584 callback: callback ,
585+ profile: Keyword . get ( options , :profile ) ,
580586 protocols: [ ] ,
581587 table: table
582588 }
@@ -653,9 +659,24 @@ defmodule Module.ParallelChecker do
653659 end
654660
655661 defp run_checkers ( % { modules: [ { module , pid , ref } | modules ] } = state ) do
656- send ( pid , { ref , :check } )
662+ send ( pid , { ref , :check , state . profile } )
657663 timer = :erlang . send_after ( state . threshold , self ( ) , { __MODULE__ , :timeout , module , pid } )
658664 spawned = Map . put ( state . spawned , module , timer )
659665 run_checkers ( % { state | modules: modules , spawned: spawned } )
660666 end
667+
668+ defp profile ( module , :time , fun ) do
669+ { time , result } = :timer . tc ( fun )
670+
671+ IO . puts (
672+ :stderr ,
673+ "[profile] Type checked #{ inspect ( module ) } in #{ div ( time , 1000 ) } ms"
674+ )
675+
676+ result
677+ end
678+
679+ defp profile ( _module , _profile , fun ) do
680+ fun . ( )
681+ end
661682end
0 commit comments