You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Mar 20, 2024. It is now read-only.
From our GlobalContext we create a raw LLVM module (global_cx.llvm_cx.create_module), then pass a reference to that module into various other contexts. From comments in the code:
// FIXME: this should be handled with lifetimes.
// Context (global_cx) must outlive llvm module (entry_llmod).
drop(entry_llmod);
drop(global_cx);
This is true of all calls to create_module - the lifetime of the llvm module is manually ensured to be less than the GlobalContext.
The obvious solution is to have one of the existing other contexts own the llvm module, but this doesn't work because it would require self-referential lifetimes, e.g.:
In the above it would nice to convert llvm_module from &'up Module to just Module. This can't be done though because the RttyContext contains a reference to llvm_module that must be named in EntrypointGenerator.
Without doing significant restructuring, the best way I can think of to ensure the LLVM module goes out of scope before GlobalContext is to introduce a new type responsible just for containing both the GlobalContext lifetime and the llvm Module:
LlvmContext exists just to tie the lifetime of the LLVM module and GlobalContext through a stack variable. It doesn't need to be passed anywhere else, just live on the stack. Then a reference to the LLVM module can continue to be passed everywhere it already is.
This only works if GlobalContext never needs accessed through a mutable reference, which appears to be the case, since this will hold an immutable reference to it.
From our GlobalContext we create a raw LLVM module (global_cx.llvm_cx.create_module), then pass a reference to that module into various other contexts. From comments in the code:
This is true of all calls to
create_module
- the lifetime of the llvm module is manually ensured to be less than the GlobalContext.The obvious solution is to have one of the existing other contexts own the llvm module, but this doesn't work because it would require self-referential lifetimes, e.g.:
In the above it would nice to convert
llvm_module
from&'up Module
to justModule
. This can't be done though because theRttyContext
contains a reference tollvm_module
that must be named inEntrypointGenerator
.Without doing significant restructuring, the best way I can think of to ensure the LLVM module goes out of scope before GlobalContext is to introduce a new type responsible just for containing both the GlobalContext lifetime and the llvm Module:
LlvmContext exists just to tie the lifetime of the LLVM module and GlobalContext through a stack variable. It doesn't need to be passed anywhere else, just live on the stack. Then a reference to the LLVM module can continue to be passed everywhere it already is.
This only works if GlobalContext never needs accessed through a mutable reference, which appears to be the case, since this will hold an immutable reference to it.
cc https://github.com/solana-labs/move/pull/374/files#r1330870435
The text was updated successfully, but these errors were encountered: