檢視原始碼 Kernel.ParallelCompiler (Elixir v1.16.2)
負責並行編譯和載入檔案的模組。
摘要
類型
@type error() :: {file :: Path.t(), Code.position(), message :: String.t()}
@type info() :: %{ runtime_warnings: [Code.diagnostic(:warning)], compile_warnings: [Code.diagnostic(:warning)] }
@type warning() :: {file :: Path.t(), Code.position(), message :: String.t()}
函式
啟動平行編譯任務。
@spec compile( [Path.t()], keyword() ) :: {:ok, [atom()], [warning()] | info()} | {:error, [error()] | [Code.diagnostic(:error)], [warning()] | info()}
編譯指定的檔案。
這些檔案會平行編譯,並可自動偵測彼此之間的相依性。一旦發現相依性,目前的檔案就會停止編譯,直到相依性獲得解決。
預設會傳回 {:ok, modules, warnings}
或 {:error, errors, warnings}
,但建議使用 return_diagnostics: true
,如此便會傳回診斷資訊(以映射表示),以及編譯資訊的映射。映射的結構如下
%{
runtime_warnings: [warning],
compile_warnings: [warning]
}
選項
:each_file
- 每編譯一個檔案,就會呼叫回呼函式,傳遞檔案:each_long_compilation
- 每個編譯時間超過指定逾時時間(請參閱:long_compilation_threshold
選項)的檔案,就會呼叫此回呼函式,傳遞檔案作為其引數:each_module
- 對每個已編譯的模組,呼叫傳遞檔案、模組和模組位元組碼的回呼:each_cycle
- 在已編譯指定的檔案後,呼叫此函數,此函數應傳回下列值{:compile, modules, warnings}
- 繼續編譯,並提供要編譯的進一步模組清單{:runtime, modules, warnings}
- 停止編譯並驗證模組清單,因為相依模組已變更
:long_compilation_threshold
- 超時 (以秒為單位) 以檢查編譯時間過長的模組。對於超過閾值的每個檔案,:each_long_compilation
回呼會被呼叫。從 Elixir v1.11 開始,閾值只考慮實際編譯模組所花費的時間,不考慮等待時間。預設為10
秒。:profile
- 如果設為:time
,則會測量每個編譯週期和群組傳遞檢查器的編譯時間:dest
- BEAM 檔案的目標目錄。使用compile/2
時,此資訊只用於在將 BEAM 檔案載入記憶體之前適當地註解 BEAM 檔案。如果您希望實際將檔案寫入dest
,請改用compile_to_path/3
。:beam_timestamp
- 要提供給所有 BEAM 檔案的修改時間戳記:return_diagnostics
(自 v1.15.0 起) - 傳回包含資訊的對應,而不是警告清單,並將診斷結果傳回對應,而不是元組
@spec compile_to_path([Path.t()], Path.t(), keyword()) :: {:ok, [atom()], [warning()] | info()} | {:error, [error()] | [Code.diagnostic(:error)], [warning()] | info()}
編譯指定的檔案,並將產生的 BEAM 檔案寫入路徑。
有關更多資訊,請參閱 compile/2
。
使用 fun
平行編譯 collection
。
如果您有一個需要並行編譯其他模組的檔案,則衍生的程序需要知道編譯器環境。此函數允許開發人員執行此類任務。
@spec require( [Path.t()], keyword() ) :: {:ok, [atom()], [warning()] | info()} | {:error, [error()] | [Code.diagnostic(:error)], [warning()] | info()}
平行載入指定的檔案。
與編譯相反,檔案之間的相依性不會自動嘗試解決。
預設會傳回 {:ok, modules, warnings}
或 {:error, errors, warnings}
,但建議使用 return_diagnostics: true
,如此便會傳回診斷資訊(以映射表示),以及編譯資訊的映射。映射的結構如下
%{
runtime_warnings: [warning],
compile_warnings: [warning]
}
選項
:each_file
- 每編譯一個檔案,就會呼叫回呼函式,傳遞檔案:each_module
- 對每個已編譯的模組,呼叫傳遞檔案、模組和模組位元組碼的回呼