Skip to content

Commit 1df5033

Browse files
authored
Merge pull request #287 from JuliaIO/teh/better_precompilability
Better precompilability
2 parents 6fd2c3a + 6f009f0 commit 1df5033

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed

src/error_handling.jl

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,5 @@ handle_error(e, q) = throw(e)
8383

8484
function handle_error(e::NotInstalledError, q)
8585
println("Library \"", e.library, "\" is not installed but is recommended as a library to load format: \"", file_extension(q), "\"")
86-
!isinteractive() && rethrow(e) # if we're not in interactive mode just throw
87-
while true
88-
println("Should we install \"", e.library, "\" for you? (y/n):")
89-
input = lowercase(chomp(strip(readline(stdin))))
90-
if input == "y"
91-
@info(string("Start installing ", e.library, "..."))
92-
Pkg.add(string(e.library))
93-
return false # don't continue
94-
elseif input == "n"
95-
@info(string("Not installing ", e.library))
96-
return true # User does not install, continue going through errors.
97-
else
98-
println("$input is not a valid choice. Try typing y or n")
99-
end
100-
end
101-
true # User does not install, continue going through errors.
86+
rethrow(e)
10287
end

src/loadsave.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ function checked_import(pkg::Symbol)
3434
end
3535
end
3636

37+
applicable_error(applicable, sym) = error("No $applicable found for $sym")
3738

3839
for (applicable_, add_, dict_) in (
3940
(:applicable_loaders, :add_loader, :sym2loader),
@@ -44,7 +45,7 @@ for (applicable_, add_, dict_) in (
4445
if haskey($dict_, sym)
4546
return $dict_[sym]
4647
end
47-
error("No $($applicable_) found for $(sym)")
48+
Base.invokelatest(applicable_error, $applicable_, sym)
4849
end
4950
function $add_(@nospecialize(fmt::Type{<:DataFormat}), pkg::Symbol)
5051
sym = formatname(fmt)
@@ -182,14 +183,18 @@ end
182183
# Handlers for formatted files/streams
183184

184185
for fn in (:load, :loadstreaming, :metadata)
186+
fn_func_name = Symbol(fn, "_filename")
185187
gen2_func_name = Symbol("fileio_", fn)
186188
@eval function $fn(@nospecialize(q::Formatted), @nospecialize(args...); @nospecialize(options...))
189+
Base.invokelatest($fn_func_name, q, filename(q), args...; options...)
190+
end
191+
@eval function $fn_func_name(@nospecialize(q::Formatted), filename, @nospecialize(args...); @nospecialize(options...))
187192
if unknown(q)
188-
isfile(filename(q)) || open(filename(q)) # force systemerror
193+
isfile(filename) || open(filename) # force systemerror
189194
throw(UnknownFormat(q))
190195
end
191196
if q isa File
192-
!isfile(filename(q)) && throw(ArgumentError("No file exists at given path: $(filename(q))"))
197+
!isfile(filename) && throw(ArgumentError("No file exists at given path: $(filename)"))
193198
end
194199
libraries = applicable_loaders(q)
195200
failures = Any[]
@@ -207,7 +212,7 @@ for fn in (:load, :loadstreaming, :metadata)
207212
push!(failures, (e, q))
208213
end
209214
end
210-
handle_exceptions(failures, "loading $(repr(filename(q)))")
215+
handle_exceptions(failures, "loading $(repr(filename))")
211216
end
212217
end
213218

src/precompile.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ function _precompile_()
99
@assert precompile(Tuple{typeof(load),File})
1010
@assert precompile(Tuple{typeof(load),Formatted})
1111
@assert precompile(Tuple{typeof(load),String})
12+
@assert precompile(Tuple{typeof(FileIO.load_filename),Formatted,String})
13+
if isdefined(Base, :bodyfunction)
14+
fbody = Base.bodyfunction(which(FileIO.load_filename, (Formatted, String)))
15+
@assert precompile(fbody, (Any, typeof(FileIO.load_filename), Formatted, String))
16+
@assert precompile(fbody, (Any, typeof(FileIO.load_filename), Formatted, String, Vararg{Any,100}))
17+
end
1218

1319
@assert precompile(Tuple{typeof(query),String})
1420
@assert precompile(Tuple{typeof(query),IOStream})

0 commit comments

Comments
 (0)