interpreter: reload libraries when new @[Link] annotations appear in REPL#16845
Open
calospoimen wants to merge 1 commit intocrystal-lang:masterfrom
Open
interpreter: reload libraries when new @[Link] annotations appear in REPL#16845calospoimen wants to merge 1 commit intocrystal-lang:masterfrom
calospoimen wants to merge 1 commit intocrystal-lang:masterfrom
Conversation
…REPL In incremental REPL evaluation, new @[Link] annotations (e.g. pcre2 on first Regex use) are added to lib_flags after the loader is already initialized. Add update_loader to sync new libraries into the running loader, and track @loader_lib_flags to detect changes. On MinGW, also populate dll_search_paths with the crystal.exe directory and PATH so that DLLs can be located by the loader at runtime.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
In the Crystal REPL (
crystal i), libraries referenced by@[Link]annotations are not always present when the loader is first initialized.
For example,
Regex/pcre2is only added tolib_flagson the firstuse of a regular expression — after the loader has already been set up
with the prelude's libraries.
This causes a
Crystal::Loader::LoadError(undefined reference to 'pcre2_compile_8') when using regex in the interpreter on Windows MinGW,and could affect other platforms or libraries in the same scenario.
Solution
@loader_lib_flagsto record which flags were used at loaderinitialization.
update_loaderto diff the currentlib_flagsagainst the trackedvalue and load any newly-appearing libraries into the running loader.
update_loaderfromc_functionbefore each symbol lookup, sonew libraries are always available.
On MinGW, also populate
dll_search_pathswith thecrystal.exedirectory and the
PATHentries so that the loader can locate DLLs atruntime.
Testing
Tested on Windows MinGW UCRT64 (Crystal 1.19.1 portable installation):