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

Replace regex package module checks with actual code checks #55824

Merged

Conversation

IanButterworth
Copy link
Sponsor Member

Fixes #55792
Replaces #55822
Improves what #51635 was trying to do

ERROR: LoadError: `using/import Printf` outside of a Module detected. Importing a package outside of a module is not allowed during package precompilation.
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:44
  [2] require(into::Module, mod::Symbol)
    @ Base ./loading.jl:2220
  [3] include
    @ ./Base.jl:582 [inlined]
  [4] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt128}}, source::String)
    @ Base ./loading.jl:2822
  [5] top-level scope
    @ stdin:5
  [6] eval
    @ ./boot.jl:439 [inlined]
  [7] include_string(mapexpr::typeof(identity), mod::Module, code::String, filename::String)
    @ Base ./loading.jl:2675
  [8] include_string
    @ ./loading.jl:2685 [inlined]
  [9] exec_options(opts::Base.JLOptions)
    @ Base ./client.jl:327
 [10] _start()
    @ Base ./client.jl:558
in expression starting at /var/folders/1z/jf841bdj73bdj3vk7kc7f_3w0000gn/T/jl_zoGR1X/ImportBeforeMod.jl:1
in expression starting at stdin:5

cc. @barucden

@IanButterworth
Copy link
Sponsor Member Author

Perhaps the part of #51635 that this doesn't do is flag when a module is completely missing and the package has no imports.

@IanButterworth
Copy link
Sponsor Member Author

@JeffBezanson would you mind a second look. I added detecting a missing package module.

@giordano
Copy link
Contributor

Should this PR include the tests added to #55822? Unless I'm missing it, I don't see a new test which actually catches the issue described in #55792.

@IanButterworth
Copy link
Sponsor Member Author

We could add that test but this is more correct by design. For a comment to be parsed as julia code and trigger an import would require quite a bigger breakage.

Though, more tests is better. So I'll add it.

@IanButterworth
Copy link
Sponsor Member Author

There's actually a similar check on the loading side that this now gets ahead of.. But I need to check that the error is still throwing with a nice message because this looks vague:


Test Failed at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-XC9YQX9HH2.0/build/default-honeycrisp-XC9YQX9HH2-0/julialang/julia-master/julia-3c844c65d7/share/julia/test/loading.jl:865
--
  | 2024-09-20 16:26:50 EDT | Expression: #= /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-XC9YQX9HH2.0/build/default-honeycrisp-XC9YQX9HH2-0/julialang/julia-master/julia-3c844c65d7/share/julia/test/loading.jl:866 =# @eval using BadCase
  | 2024-09-20 16:26:50 EDT | Expected: ErrorException("package `BadCase` did not define the expected module `BadCase`, check for typos in package module name")
  | 2024-09-20 16:26:50 EDT | Thrown: ErrorException("Failed to precompile BadCase [top-level] to \"/private/var/tmp/agent-tempdirs/default-honeycrisp-XC9YQX9HH2.0/tmp/jl_eWFKxn/compiled/v1.12/jl_HYOeLk\".")
  | 2024-09-20 16:26:50 EDT | Failed to precompile BadCase [top-level] to "/private/var/tmp/agent-tempdirs/default-honeycrisp-XC9YQX9HH2.0/tmp/jl_eWFKxn/compiled/v1.12/jl_HYOeLk".
  | 2024-09-20 16:26:50 EDT | Stacktrace:
  | 2024-09-20 16:26:50 EDT | [1] error(s::String)
  | 2024-09-20 16:26:50 EDT | @ Base ./error.jl:44
  | 2024-09-20 16:26:50 EDT | [2] compilecache(pkg::Base.PkgId, path::String, internal_stderr::IO, internal_stdout::IO, keep_loaded_modules::Bool; flags::Cmd, cacheflags::Base.CacheFlags, reasons::Dict{String, Int64})


@IanButterworth IanButterworth changed the title Handle outside package module import check in require Replace regex package module checks with actual code checks Sep 23, 2024
@IanButterworth IanButterworth merged commit 0fade45 into JuliaLang:master Sep 23, 2024
8 checks passed
@IanButterworth IanButterworth deleted the ib/redo_outside_import_check branch September 23, 2024 15:39
@IanButterworth IanButterworth added the backport 1.11 Change should be backported to release-1.11 label Sep 23, 2024
@KristofferC KristofferC mentioned this pull request Sep 24, 2024
30 tasks
KristofferC added a commit that referenced this pull request Sep 25, 2024
Backported PRs:
- [x] #55773 <!-- Add compat entry for `Base.donotdelete` -->
- [x] #41244 <!-- Fix shell `cd` error when working dir has been deleted
-->
- [x] #55795 <!-- fix #52986, regression in `@doc` of macro without REPL
loaded -->
- [x] #55829 <!-- [Dates] Make test more robust against non-UTC
timezones -->
- [x] #55641 <!-- fall back to slower stat filesize if optimized
filesize fails -->
- [x] #55744 <!-- fix #45494, error in ssa conversion with complex type
decl -->
- [x] #55783 <!-- use `inferencebarrier` instead of `invokelatest` for
1-arg `@assert` -->
- [x] #55739 <!-- Add `invokelatest` barrier to `string(...)` in
`@assert` -->

Need manual backport:
- [ ] #55798 <!-- Broadcast binary ops involving strided triangular -->

Contains multiple commits, manual intervention needed:
- [ ] #55509 <!-- Fix cong implementation to be properly random and not
just cycling. -->
- [ ] #55569 <!-- Add a docs section about loading/precomp/ttfx time
tuning -->
- [ ] #55824 <!-- Replace regex package module checks with actual code
checks -->

Non-merged PRs with backport label:
- [ ] #55845 <!-- privatize annotated string API, take two -->
- [ ] #55828 <!-- Fix some corner cases of `isapprox` with unsigned
integers -->
- [ ] #55813 <!-- Check for conflicting `@ccallable` name before JIT
registration -->
- [ ] #55743 <!-- doc: heap snapshot viewing -->
- [ ] #55741 <!-- Change annotations to use a NamedTuple -->
- [ ] #55534 <!-- Set stdlib sources as read-only during installation
-->
- [ ] #55499 <!-- propagate the terminal's `displaysize` to the
`IOContext` used by the REPL -->
- [ ] #55458 <!-- Allow for generically extracting unannotated string
-->
- [ ] #55457 <!-- Make AnnotateChar equality consider annotations -->
- [ ] #55453 <!-- Privatise the annotations API, for StyledStrings -->
- [ ] #55355 <!-- relocation: account for trailing path separator in
depot paths -->
- [ ] #55220 <!-- `isfile_casesensitive` fixes on Windows -->
- [ ] #55169 <!-- `propertynames` for SVD respects private argument -->
- [ ] #54457 <!-- Make `String(::Memory)` copy -->
- [ ] #53957 <!-- tweak how filtering is done for what packages should
be precompiled -->
- [ ] #51479 <!-- prevent code loading from lookin in the versioned
environment when building Julia -->
- [ ] #50813 <!-- More doctests for Sockets and capitalization fix -->
- [ ] #50157 <!-- improve docs for `@inbounds` and
`Base.@propagate_inbounds` -->
@KristofferC KristofferC mentioned this pull request Sep 30, 2024
39 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 1.11 Change should be backported to release-1.11
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multiline comment parsing error on 1.11-rc3
3 participants