@@ -744,46 +744,30 @@ function include_dependency(path::AbstractString)
744
744
return nothing
745
745
end
746
746
747
- # We throw PrecompilableError(true) when a module wants to be precompiled but isn't,
748
- # and PrecompilableError(false) when a module doesn't want to be precompiled but is
749
- struct PrecompilableError <: Exception
750
- isprecompilable:: Bool
751
- end
747
+ # we throw PrecompilableError when a module doesn't want to be precompiled
748
+ struct PrecompilableError <: Exception end
752
749
function show (io:: IO , ex:: PrecompilableError )
753
- if ex. isprecompilable
754
- print (io, " Declaring __precompile__(true) is only allowed in module files being imported." )
755
- else
756
- print (io, " Declaring __precompile__(false) is not allowed in files that are being precompiled." )
757
- end
750
+ print (io, " Declaring __precompile__(false) is not allowed in files that are being precompiled." )
758
751
end
759
- precompilableerror (ex:: PrecompilableError , c ) = ex . isprecompilable == c
760
- precompilableerror (ex:: WrappedException , c ) = precompilableerror (ex. error, c )
761
- precompilableerror (ex, c ) = false
752
+ precompilableerror (ex:: PrecompilableError ) = true
753
+ precompilableerror (ex:: WrappedException ) = precompilableerror (ex. error)
754
+ precompilableerror (@nospecialize ex ) = false
762
755
763
- # Call __precompile__ at the top of a file to force it to be precompiled (true), or
764
- # to be prevent it from being precompiled (false). __precompile__(true) is
765
- # ignored except within "require" call.
756
+ # Call __precompile__(false) at the top of a tile prevent it from being precompiled (false)
766
757
"""
767
- __precompile__(isprecompilable::Bool=true)
768
-
769
- Specify whether the file calling this function is precompilable. If `isprecompilable` is
770
- `true`, then `__precompile__` throws an exception when the file is loaded by
771
- `using`/`import`/`require` *unless* the file is being precompiled, and in a module file it
772
- causes the module to be automatically precompiled when it is imported. Typically,
773
- `__precompile__()` should occur before the `module` declaration in the file.
758
+ __precompile__(false)
774
759
760
+ Specify that the file calling this function is not precompilable.
775
761
If a module or file is *not* safely precompilable, it should call `__precompile__(false)` in
776
762
order to throw an error if Julia attempts to precompile it.
777
-
778
- `__precompile__()` should *not* be used in a module unless all of its dependencies are also
779
- using `__precompile__()`. Failure to do so can result in a runtime error when loading the module.
780
763
"""
781
- function __precompile__ (isprecompilable:: Bool = true )
782
- if ( JLOptions () . use_compiled_modules != 0 &&
783
- isprecompilable != ( 0 != ccall ( :jl_generating_output , Cint, ())) &&
784
- ! (isprecompilable && toplevel_load[] ))
785
- throw (PrecompilableError (isprecompilable ))
764
+ @noinline function __precompile__ (isprecompilable:: Bool = true )
765
+ if isprecompilable
766
+ depwarn ( " __precompile__() is now the default " , :__precompile__ )
767
+ elseif 0 != ccall ( :jl_generating_output , Cint, ( ))
768
+ throw (PrecompilableError ())
786
769
end
770
+ nothing
787
771
end
788
772
789
773
# require always works in Main scope and loads files from node 1
@@ -932,10 +916,9 @@ function _require(pkg::PkgId)
932
916
end
933
917
934
918
# attempt to load the module file via the precompile cache locations
935
- doneprecompile = false
936
919
if JLOptions (). use_compiled_modules != 0
937
- doneprecompile = _require_search_from_serialized (pkg, path)
938
- if ! isa (doneprecompile , Bool)
920
+ m = _require_search_from_serialized (pkg, path)
921
+ if ! isa (m , Bool)
939
922
return
940
923
end
941
924
end
@@ -948,21 +931,24 @@ function _require(pkg::PkgId)
948
931
This may mean module $name does not support precompilation but is imported by a module that does."""
949
932
if JLOptions (). incremental != 0
950
933
# during incremental precompilation, this should be fail-fast
951
- throw (PrecompilableError (false ))
934
+ throw (PrecompilableError ())
952
935
end
953
936
end
954
937
end
955
938
956
- if doneprecompile === true || JLOptions (). incremental != 0
957
- # spawn off a new incremental pre-compile task for recursive `require` calls
958
- # or if the require search declared it was pre-compiled before (and therefore is expected to still be pre-compilable)
959
- cachefile = compilecache (pkg)
960
- m = _require_from_serialized (cachefile)
961
- if isa (m, Exception)
962
- @warn " The call to compilecache failed to create a usable precompiled cache file for module $name " exception= m
963
- # fall-through, TODO : disable __precompile__(true) error so that the normal include will succeed
964
- else
965
- return
939
+ if JLOptions (). use_compiled_modules != 0
940
+ if (0 == ccall (:jl_generating_output , Cint, ())) || (JLOptions (). incremental != 0 )
941
+ # spawn off a new incremental pre-compile task for recursive `require` calls
942
+ # or if the require search declared it was pre-compiled before (and therefore is expected to still be pre-compilable)
943
+ cachefile = compilecache (pkg)
944
+ m = _require_from_serialized (cachefile)
945
+ if isa (m, Exception)
946
+ if ! precompilableerror (m)
947
+ @warn " The call to compilecache failed to create a usable precompiled cache file for module $name " exception= m
948
+ end
949
+ else
950
+ return
951
+ end
966
952
end
967
953
end
968
954
@@ -977,22 +963,6 @@ function _require(pkg::PkgId)
977
963
try
978
964
include_relative (__toplevel__, path)
979
965
return
980
- catch ex
981
- if uuid != = old_uuid
982
- ccall (:jl_set_module_uuid , Cvoid, (Any, NTuple{2 , UInt64}), __toplevel__, old_uuid)
983
- end
984
- if doneprecompile === true || JLOptions (). use_compiled_modules == 0 || ! precompilableerror (ex, true )
985
- rethrow () # rethrow non-precompilable=true errors
986
- end
987
- # the file requested `__precompile__`, so try to build a cache file and use that
988
- cachefile = compilecache (pkg)
989
- m = _require_from_serialized (cachefile)
990
- if isa (m, Exception)
991
- @warn """ Module `$name ` declares `__precompile__(true)` but `require` failed
992
- to create a usable precompiled cache file""" exception= m
993
- # TODO : disable __precompile__(true) error and do normal include instead of error
994
- error (" Module $name declares __precompile__(true) but require failed to create a usable precompiled cache file." )
995
- end
996
966
finally
997
967
if uuid != = old_uuid
998
968
ccall (:jl_set_module_uuid , Cvoid, (Any, NTuple{2 , UInt64}), __toplevel__, old_uuid)
0 commit comments