feat: basic support for reinitialization #2398
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
See Zulip for context. This allows lean to be able to call the frontend more than once per process, by keeping track of modules that have been initialized and not calling their initializers again. This is possibly duplicating state because the C code also keeps this information in
_G_initialized
private static booleans in each module, but I think only compiled modules have this, while we need it here for all modules (compiled and interpreted).Because lean already does enough accounting to avoid multiple initialization of modules, there is no need during a normal elaboration session to collect this state, so the
enableReinitialization
function lazily initializes the state when requested (e.g. by a tool that is planning to call the frontend from the interpreter, or a tool that will call the frontend many times in the same process).