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

__precompile__(false) does not work #28384

Open
timholy opened this issue Aug 1, 2018 · 12 comments
Open

__precompile__(false) does not work #28384

timholy opened this issue Aug 1, 2018 · 12 comments
Assignees
Labels
compiler:precompilation Precompilation of modules

Comments

@timholy
Copy link
Member

timholy commented Aug 1, 2018

julia> mkpath("/tmp/pkgs/NPC/src")
"/tmp/pkgs/NPC/src"

julia> open("/tmp/pkgs/NPC/src/NPC.jl", "w") do io
           println(io, """
           __precompile__(false)
           module NPC
           
           foo() = 1
           
           end
           """)
       end

julia> push!(LOAD_PATH, "/tmp/pkgs")
4-element Array{String,1}:
 "@"        
 "@v#.#"    
 "@stdlib"  
 "/tmp/pkgs"

julia> using NPC
[ Info: Precompiling module NPC
ERROR: LoadError: Declaring __precompile__(false) is not allowed in files that are being precompiled.
Stacktrace:
 [1] __precompile__(::Bool) at ./loading.jl:780
 [2] top-level scope at none:0
 [3] include at ./boot.jl:317 [inlined]
 [4] include_relative(::Module, ::String) at ./loading.jl:1034
 [5] include(::Module, ::String) at ./sysimg.jl:29
 [6] top-level scope at none:0
 [7] eval at ./boot.jl:319 [inlined]
 [8] eval(::Expr) at ./client.jl:399
 [9] top-level scope at ./none:3
in expression starting at /tmp/pkgs/NPC/src/NPC.jl:1
ERROR: Failed to precompile NPC to /home/tim/.julia/compiled/v0.7/NPC.ji.
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] macro expansion at ./logging.jl:310 [inlined]
 [3] compilecache(::Base.PkgId) at ./loading.jl:1173
 [4] _require(::Base.PkgId) at ./logging.jl:311
 [5] require(::Base.PkgId) at ./loading.jl:852
 [6] macro expansion at ./logging.jl:311 [inlined]
 [7] require(::Module, ::Symbol) at ./loading.jl:834

I'm on a branch that includes #28366.

@KristofferC
Copy link
Member

What if you rm -rf ~/.julia/compiled? I seem to remember that if there is an old precompile file there for the name of the package it will just precompile anyway.

@timholy
Copy link
Member Author

timholy commented Aug 1, 2018

Nope, same problem.

Turns out our tests checked whether __precompile__(false) properly generated an error if the file was being used by something that was __precompile__(true), but AFAICT we had no tests of __precompile__(false) on its own 😢 :

diff --git a/test/precompile.jl b/test/precompile.jl
index f834e029a2..6c47416a75 100644
--- a/test/precompile.jl
+++ b/test/precompile.jl
@@ -281,6 +281,7 @@ try
           """
           __precompile__(false)
           module Baz
+          baz() = 1
           end
           """)
 
@@ -291,6 +292,8 @@ try
         isa(exc, ErrorException) || rethrow(exc)
         occursin("__precompile__(false)", exc.msg) && rethrow(exc)
     end
+    @eval using Baz
+    @test Baz.baz() == 1
 
     # Issue #12720
     FooBar1_file = joinpath(dir, "FooBar1.jl")

leads to a test failure. Work around coming.

@timholy timholy modified the milestones: 1.0, 0.7 Aug 1, 2018
@timholy timholy added priority This should be addressed urgently bug Indicates an unexpected problem or unintended behavior labels Aug 1, 2018
@JeffBezanson JeffBezanson modified the milestones: 1.0, 0.7 Aug 1, 2018
vtjnash pushed a commit that referenced this issue Aug 1, 2018
And make it equivalent to `exit(125)`

Fixes #28384
Keno pushed a commit that referenced this issue Aug 2, 2018
And make it equivalent to `exit(125)`

Fixes #28384
@Keno Keno closed this as completed in 8cd383e Aug 2, 2018
@IanButterworth
Copy link
Member

IanButterworth commented Nov 14, 2018

I still see this issue in 1.0.2 and 1.1.0-DEV.655
For me, the below module produces the repeated precompilation with every new session

__precompile__(false)

module DevPackage
greet() = "Hello world!"
end

@IanButterworth
Copy link
Member

Also, rm -rf ~/.julia/compiled dosen't fix the issue for me

@ufechner7
Copy link

Same problem for me with a newly created package and Julia 1.0.2 on Ubuntu.

@tbole
Copy link
Contributor

tbole commented Nov 26, 2018

I can also confirm this bug on 1.0.2. Disabling precompilation is not possible __precompile__(false) is ignored. Reopen?

@StefanKarpinski
Copy link
Member

@vtjnash, this seems unfixed for many people...

@StefanKarpinski StefanKarpinski modified the milestones: 0.7, 1.0.x Nov 26, 2018
@IanButterworth
Copy link
Member

While this remains unfixed, is there another way to disable precompilation of a package? I'm developing a package with a dependency that doesn't precompile (VideoIO) and have to go through the attempted precompillation repeatedly

@andyljones
Copy link

andyljones commented Jan 10, 2019

Browsing the code, I think the issue is that the call to jl_generating_output here returns 0, because in my IJulia at least all four of the options or'd are 0 (you can get the options struct with Base.JLOptions()). Doing some Googling, I think these correspond to compiler switches? Presumably one of them was true in the past?

e: Realised I could test this theory by sticking throw(Base.PrecompilableError()) at the top of my file. No such luck - I get further than with __precompile__(false) alone, but run into the same ERROR: LoadError: Declaring __precompile__(false) is not allowed in files that are being precompiled. that @timholy got back in August.

@vtjnash
Copy link
Member

vtjnash commented Jan 10, 2019

c.f. #30064

we could also perhaps early-parse the file to look for an obvious __precompile__(false) statement at the top if we don't already have a cache file (passing that parse result to eval a bit later in the function if the precompile fails)

KristofferC pushed a commit that referenced this issue Feb 11, 2019
And make it equivalent to `exit(125)`

Fixes #28384
@vtjnash vtjnash removed bug Indicates an unexpected problem or unintended behavior priority This should be addressed urgently labels Feb 18, 2020
@vtjnash vtjnash removed this from the 1.x.y milestone Feb 18, 2020
@ngam
Copy link

ngam commented Dec 23, 2021

I believe this is resurfacing again: #43535

@brenhinkeller brenhinkeller added compiler:precompilation Precompilation of modules heisenbug This bug occurs unpredictably and removed heisenbug This bug occurs unpredictably labels Nov 21, 2022
@brenhinkeller
Copy link
Contributor

Seems fixed for me, but does seem to be a bit of a heisenbug

julia> mkpath("/tmp/pkgs/NPC/src")
"/tmp/pkgs/NPC/src"

julia> open("/tmp/pkgs/NPC/src/NPC.jl", "w") do io
           println(io, """
           __precompile__(false)
           module NPC

           foo() = 1

           end
           """)
       end

julia> push!(LOAD_PATH, "/tmp/pkgs")
4-element Vector{String}:
 "@"
 "@v#.#"
 "@stdlib"
 "/tmp/pkgs"

julia> using NPC
[ Info: Precompiling NPC [top-level]
[ Info: Skipping precompilation since __precompile__(false). Importing NPC [top-level].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:precompilation Precompilation of modules
Projects
None yet
Development

Successfully merging a pull request may close this issue.