Skip to content

Commit

Permalink
Define exports to throw informative error in Julia DEV versions (#688)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickrobinson251 authored Feb 4, 2025
1 parent 9ed5b27 commit 082691f
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 13 deletions.
14 changes: 14 additions & 0 deletions src/JET.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ const JET_DEV_MODE = Preferences.@load_preference("JET_DEV_MODE", false)

const JET_LOADABLE = JET_DEV_MODE || (get(VERSION.prerelease, 1, "") != "DEV")

# exports
# =======

export
# jetanalyzer
@report_call, report_call, @test_call, test_call,
report_file, test_file, report_package, test_package, report_text, reportkey, test_text,
watch_file,
# optanalyzer
@report_opt, report_opt, @test_opt, test_opt,
# configurations
LastFrameModule, AnyFrameModule

# Pre-release Julia versions are not supported, and we don't expect JET to even
# precompile in pre-release versions. So, instead of having JET fail to precompile, we
# simply make JET an empty module so that failure is delayed until the first time JET is
Expand All @@ -21,6 +34,7 @@ else
If you want to load JET on a nightly version, set the `JET_DEV_MODE` Preferences.jl
configuration to `true` and reload it.
"""
include("JETEmpty.jl")
end

end # module
13 changes: 0 additions & 13 deletions src/JETBase.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
# exports
# =======

export
# jetanalyzer
@report_call, report_call, @test_call, test_call,
report_file, test_file, report_package, test_package, report_text, reportkey, test_text,
watch_file,
# optanalyzer
@report_opt, report_opt, @test_opt, test_opt,
# configurations
LastFrameModule, AnyFrameModule

let README = normpath(dirname(@__DIR__), "README.md")
s = read(README, String)
s = replace(s,
Expand Down
37 changes: 37 additions & 0 deletions src/JETEmpty.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Empty stubs for the exported functions/macros of JET.jl, to provide a more informative
# error message when JET.jl is used with a pre-release version of Julia.

const err_msg = strip("""
JET.jl does not guarantee compatibility with pre-release versions of Julia and
is not be loaded on this versions by default.
Julia VERSION = $VERSION
We recommend using a stable version of Julia in order to use JET.jl.
Or to try JET with this pre-release Julia version use Preferences.jl to enable
`JET_DEV_MODE`, and then reload JET. For example create a file named
`LocalPreferences.toml` which contains the line:
JET_DEV_MODE = true
Note that JET.jl may not function properly with a pre-release versions of Julia
even with `JET_DEV_MODE` enabled.
""")

for exported_func in (
:report_call, :test_call,
:report_file, :test_file, :report_package, :test_package, :report_text, :reportkey, :test_text,
:watch_file,
# optanalyzer
:report_opt, :test_opt,
# configurations
:LastFrameModule, :AnyFrameModule
)
@eval $exported_func(args...; kws...) = error($err_msg)
end
for exported_macro in (
:report_call, :test_call,
:report_opt, :test_opt
)
@eval begin
macro $exported_macro(args...)
error($err_msg)
end
end
end

0 comments on commit 082691f

Please sign in to comment.