Skip to content

Commit 59ca442

Browse files
committed
Document requirement of __precompile__
Fixes #13200
1 parent 3a421c9 commit 59ca442

File tree

6 files changed

+28
-17
lines changed

6 files changed

+28
-17
lines changed

base/docs/helpdb/Base.jl

-15
Original file line numberDiff line numberDiff line change
@@ -10127,21 +10127,6 @@ no effect outside of compilation.
1012710127
"""
1012810128
include_dependency
1012910129

10130-
"""
10131-
__precompile__(isprecompilable::Bool=true)
10132-
10133-
Specify whether the file calling this function is precompilable. If `isprecompilable` is
10134-
`true`, then `__precompile__` throws an exception when the file is loaded by
10135-
`using`/`import`/`require` *unless* the file is being precompiled, and in a module file it
10136-
causes the module to be automatically precompiled when it is imported. Typically,
10137-
`__precompile__()` should occur before the `module` declaration in the file, or better yet
10138-
`VERSION >= v"0.4" && __precompile__()` in order to be backward-compatible with Julia 0.3.
10139-
10140-
If a module or file is *not* safely precompilable, it should call `__precompile__(false)` in
10141-
order to throw an error if Julia attempts to precompile it.
10142-
"""
10143-
__precompile__
10144-
1014510130
"""
1014610131
randn!([rng], A::Array{Float64,N})
1014710132

base/loading.jl

+16
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,22 @@ precompilableerror(ex, c) = false
239239
# Call __precompile__ at the top of a file to force it to be precompiled (true), or
240240
# to be prevent it from being precompiled (false). __precompile__(true) is
241241
# ignored except within "require" call.
242+
"""
243+
__precompile__(isprecompilable::Bool=true)
244+
245+
Specify whether the file calling this function is precompilable. If `isprecompilable` is
246+
`true`, then `__precompile__` throws an exception when the file is loaded by
247+
`using`/`import`/`require` *unless* the file is being precompiled, and in a module file it
248+
causes the module to be automatically precompiled when it is imported. Typically,
249+
`__precompile__()` should occur before the `module` declaration in the file, or better yet
250+
`VERSION >= v"0.4" && __precompile__()` in order to be backward-compatible with Julia 0.3.
251+
252+
If a module or file is *not* safely precompilable, it should call `__precompile__(false)` in
253+
order to throw an error if Julia attempts to precompile it.
254+
255+
`__precompile__()` should *not* be used in a module unless all of its dependencies are also
256+
using `__precompile__()`. Failure to do so can result in a runtime error when loading the module.
257+
"""
242258
function __precompile__(isprecompilable::Bool=true)
243259
if (myid() == 1 &&
244260
JLOptions().use_compilecache != 0 &&

doc/manual/modules.rst

+4
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,10 @@ therein. If you know that it is *not* safe to precompile your module
282282
throw an error (and thereby prevent the module from being imported by
283283
any other precompiled module).
284284

285+
``__precompile__()`` should *not* be used in a module unless all of its
286+
dependencies are also using ``__precompile__()``. Failure to do so can result
287+
in a runtime error when loading the module.
288+
285289
In order to make your module work with precompilation,
286290
however, you may need to change your module to explicitly separate any
287291
initialization steps that must occur at *runtime* from steps that can

doc/stdlib/base.rst

+2
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ Getting Around
142142

143143
If a module or file is *not* safely precompilable, it should call ``__precompile__(false)`` in order to throw an error if Julia attempts to precompile it.
144144

145+
``__precompile__()`` should *not* be used in a module unless all of its dependencies are also using ``__precompile__()``\ . Failure to do so can result in a runtime error when loading the module.
146+
145147
.. function:: include(path::AbstractString)
146148

147149
.. Docstring generated from Julia source

doc/stdlib/io-network.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ General I/O
150150

151151
.. Docstring generated from Julia source
152152
153-
Read binary data from a stream, filling in the argument ``array``\ .
153+
Read binary data from a stream or file, filling in the argument ``array``\ .
154154

155155
.. function:: readbytes!(stream, b::Vector{UInt8}, nb=length(b); all=true)
156156

src/dump.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -1647,7 +1647,11 @@ static int jl_deserialize_verify_mod_list(ios_t *s)
16471647
jl_errorf("invalid module path (%s does not name a module)", name);
16481648
}
16491649
if (m->uuid != uuid) {
1650-
jl_printf(JL_STDERR, "WARNING: Module %s uuid did not match cache file\n", name);
1650+
jl_printf(JL_STDERR,
1651+
"WARNING: Module %s uuid did not match cache file\n"
1652+
" This is likely because module %s does not support"
1653+
" precompilation but is imported by a module that does.\n",
1654+
name, name);
16511655
return 0;
16521656
}
16531657
}

0 commit comments

Comments
 (0)