Skip to content

interpreter: reload libraries when new @[Link] annotations appear in REPL#16845

Open
calospoimen wants to merge 1 commit intocrystal-lang:masterfrom
calospoimen:fix/interpreter-repl-incremental-loader
Open

interpreter: reload libraries when new @[Link] annotations appear in REPL#16845
calospoimen wants to merge 1 commit intocrystal-lang:masterfrom
calospoimen:fix/interpreter-repl-incremental-loader

Conversation

@calospoimen
Copy link
Copy Markdown

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 / pcre2 is only added to lib_flags on the first
use 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

  • Track @loader_lib_flags to record which flags were used at loader
    initialization.
  • Add update_loader to diff the current lib_flags against the tracked
    value and load any newly-appearing libraries into the running loader.
  • Call update_loader from c_function before each symbol lookup, so
    new libraries are always available.

On MinGW, also populate dll_search_paths with the crystal.exe
directory and the PATH entries so that the loader can locate DLLs at
runtime.

Testing

Tested on Windows MinGW UCRT64 (Crystal 1.19.1 portable installation):

# Previously raised: undefined reference to `pcre2_compile_8'
result = "hello world" =~ /world/
puts result  # => 6

…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.
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.

1 participant