Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix loaded native code execution #959

Merged
merged 5 commits into from Jan 20, 2022
Merged

Conversation

Kha
Copy link
Member

@Kha Kha commented Jan 17, 2022

This PR fixes two related bugs:

  • When using --plugin, [init] functions might be run twice: once when loading the plugin, and once in [init]'s afterImport
  • When using --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 flag builtin that prevents --load-dynlib from running builtin_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.

@leodemoura
Copy link
Member

@Kha Could you please copy the PR comment in the code itself? I am not sure what the best place it, but I think lean_run_mod_init is a good spot. What do you think?

@Kha
Copy link
Member Author

Kha commented Jan 18, 2022

Yes, there's no perfect place in the code. I extended the initializers section in ffi.md instead, since that one already describes parts of the Lean ABI not strictly relevant for FFI. What do you think?

@Kha Kha merged commit f0f2672 into leanprover:master Jan 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants