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.
This PR fixes two related bugs:
--plugin
,[init]
functions might be run twice: once when loading the plugin, and once in[init]
'safterImport
--load-dynlib
, constants (nullary functions) that are not[init]
are never initialized. The interpreter does initialize constants lazily, but only when there is no native symbol for them (since it doesn't know what code has been loaded dynamically).To fix this, we now run the
[init]
functions only for modules that do not have native code, and run the module initializer function (initialize_Init
etc.) for any other imported module. We extend the module initializer with a new boolean flagbuiltin
that prevents--load-dynlib
from runningbuiltin_initialize
commands as intended.Note that the module initializer only exists in native code, so we cannot interpret it. Note also that in contrast to
--plugin
,--load-dynlib
can still accept shared libraries that contain code of multiple, possible unrelated Lean modules - it is the imported modules that determine the module initializers to be run (since code of a non-imported module should be unreachable from the interpreter). Thus we can still produce big shared libraries of entire packages and load them whenever any of their modules are imported without additional overhead other than relocation.