Skip to content

Commit

Permalink
Merge pull request #12725 from stevengj/precompile_path
Browse files Browse the repository at this point in the history
compilecache should use same path as require, and treat cache as stale if path changes
  • Loading branch information
stevengj committed Aug 21, 2015
2 parents 37b9a10 + 4b24670 commit 7994909
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 29 deletions.
16 changes: 11 additions & 5 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ end
compilecache(mod::Symbol) = compilecache(string(mod))
function compilecache(name::ByteString)
myid() == 1 || error("can only precompile from node 1")
path = find_in_path(name)
path = find_in_path(name, nothing)
path === nothing && throw(ArgumentError("$name not found in path"))
cachepath = LOAD_CACHE_PATH[1]
if !isdir(cachepath)
Expand Down Expand Up @@ -375,13 +375,16 @@ function cache_dependencies(cachefile::AbstractString)
end
end

function stale_cachefile(cachefile::AbstractString)
function stale_cachefile(modpath, cachefile)
io = open(cachefile, "r")
try
if !isvalid_cache_header(io)
return true # invalid cache file
end
modules, files = cache_dependencies(io)
if files[1][1] != modpath
return true # cache file was compiled from a different path
end
for (f,ftime) in files
if mtime(f) != ftime
return true
Expand All @@ -403,10 +406,13 @@ function stale_cachefile(cachefile::AbstractString)
end

function recompile_stale(mod, cachefile)
if stale_cachefile(cachefile)
path = find_in_path(string(mod), nothing)
if path === nothing
rm(cachefile)
error("module $mod not found in current path; removed orphaned cache file $cachefile")
end
if stale_cachefile(path, cachefile)
info("Recompiling stale cache file $cachefile for module $mod.")
path = find_in_path(string(mod))
path === nothing && error("module $mod not found")
if !success(create_expr_cache(path, cachefile))
error("Failed to precompile $mod to $cachefile")
end
Expand Down
44 changes: 20 additions & 24 deletions src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -1015,43 +1015,39 @@ void jl_serialize_dependency_list(ios_t *s)
static jl_array_t *deps = NULL;
if (!deps)
deps = (jl_array_t*)jl_get_global(jl_base_module, jl_symbol("_require_dependencies"));
if (deps) {
// sort!(deps) so that we can easily eliminate duplicates
static jl_value_t *sort_func = NULL;
if (!sort_func)
sort_func = jl_get_global(jl_base_module, jl_symbol("sort!"));
jl_apply((jl_function_t*)sort_func, (jl_value_t**)&deps, 1);

size_t l = jl_array_len(deps);
jl_value_t *prev = NULL;

// unique(deps) to eliminate duplicates while preserving order:
// we preserve order so that the topmost included .jl file comes first
static jl_value_t *unique_func = NULL;
if (!unique_func)
unique_func = jl_get_global(jl_base_module, jl_symbol("unique"));
jl_array_t *udeps = deps && unique_func ? (jl_array_t *) jl_apply((jl_function_t*)unique_func, (jl_value_t**)&deps, 1) : NULL;

if (udeps) {
JL_GC_PUSH(&udeps);
size_t l = jl_array_len(udeps);
for (size_t i=0; i < l; i++) {
jl_value_t *dep = jl_fieldref(jl_cellref(deps, i), 0);
jl_value_t *dep = jl_fieldref(jl_cellref(udeps, i), 0);
size_t slen = jl_string_len(dep);
if (!prev || memcmp(jl_string_data(dep), jl_string_data(prev), slen)) {
total_size += 4 + slen + 8;
}
prev = dep;
total_size += 4 + slen + 8;
}
total_size += 4;
}
// write the total size so that we can quickly seek past all of the
// dependencies if we don't need them
write_uint64(s, total_size);
if (deps) {
size_t l = jl_array_len(deps);
jl_value_t *prev = NULL;
if (udeps) {
size_t l = jl_array_len(udeps);
for (size_t i=0; i < l; i++) {
jl_value_t *deptuple = jl_cellref(deps, i);
jl_value_t *deptuple = jl_cellref(udeps, i);
jl_value_t *dep = jl_fieldref(deptuple, 0);
size_t slen = jl_string_len(dep);
if (!prev || memcmp(jl_string_data(dep), jl_string_data(prev), slen)) {
write_int32(s, slen);
ios_write(s, jl_string_data(dep), slen);
write_float64(s, jl_unbox_float64(jl_fieldref(deptuple, 1)));
}
prev = dep;
write_int32(s, slen);
ios_write(s, jl_string_data(dep), slen);
write_float64(s, jl_unbox_float64(jl_fieldref(deptuple, 1)));
}
write_int32(s, 0); // terminator, for ease of reading
JL_GC_POP();
}
}

Expand Down

0 comments on commit 7994909

Please sign in to comment.