Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

various globals cleanups #56750

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions base/float.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,16 @@ significand_mask(::Type{Float16}) = 0x03ff
mantissa(x::T) where {T} = reinterpret(Unsigned, x) & significand_mask(T)

for T in (Float16, Float32, Float64)
@eval significand_bits(::Type{$T}) = $(trailing_ones(significand_mask(T)))
@eval exponent_bits(::Type{$T}) = $(sizeof(T)*8 - significand_bits(T) - 1)
@eval exponent_bias(::Type{$T}) = $(Int(exponent_one(T) >> significand_bits(T)))
sb = trailing_ones(significand_mask(T))
em = exponent_mask(T)
eb = Int(exponent_one(T) >> sb)
@eval significand_bits(::Type{$T}) = $(sb)
@eval exponent_bits(::Type{$T}) = $(sizeof(T)*8 - sb - 1)
@eval exponent_bias(::Type{$T}) = $(eb)
# maximum float exponent
@eval exponent_max(::Type{$T}) = $(Int(exponent_mask(T) >> significand_bits(T)) - exponent_bias(T) - 1)
@eval exponent_max(::Type{$T}) = $(Int(em >> sb) - eb - 1)
# maximum float exponent without bias
@eval exponent_raw_max(::Type{$T}) = $(Int(exponent_mask(T) >> significand_bits(T)))
@eval exponent_raw_max(::Type{$T}) = $(Int(em >> sb))
end

"""
Expand Down
2 changes: 1 addition & 1 deletion base/range.jl
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ function _getindex(v::UnitRange{T}, i::Integer) where {T<:OverflowSafe}
end

let BitInteger64 = Union{Int8,Int16,Int32,Int64,UInt8,UInt16,UInt32,UInt64} # for bootstrapping
function checkbounds(::Type{Bool}, v::StepRange{<:BitInteger64, <:BitInteger64}, i::BitInteger64)
global function checkbounds(::Type{Bool}, v::StepRange{<:BitInteger64, <:BitInteger64}, i::BitInteger64)
res = widemul(step(v), i-oneunit(i)) + first(v)
(0 < i) & ifelse(0 < step(v), res <= last(v), res >= last(v))
end
Expand Down
2 changes: 2 additions & 0 deletions src/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,8 @@ static jl_value_t *scm_to_julia_(fl_context_t *fl_ctx, value_t e, jl_module_t *m
if (iscvalue(e) && cv_class((cvalue_t*)ptr(e)) == jl_ast_ctx(fl_ctx)->jvtype) {
return *(jl_value_t**)cv_data((cvalue_t*)ptr(e));
}
fl_print(fl_ctx, ios_stderr, e);
ios_putc('\n', ios_stderr);
jl_error("malformed tree");
}

Expand Down
3 changes: 0 additions & 3 deletions src/interpreter.c
Original file line number Diff line number Diff line change
Expand Up @@ -893,10 +893,7 @@ jl_value_t *NOINLINE jl_interpret_toplevel_thunk(jl_module_t *m, jl_code_info_t
s->mi = NULL;
s->ci = NULL;
JL_GC_ENABLEFRAME(s);
jl_task_t *ct = jl_current_task;
size_t last_age = ct->world_age;
jl_value_t *r = eval_body(stmts, s, 0, 1);
ct->world_age = last_age;
JL_GC_POP();
return r;
}
Expand Down
25 changes: 12 additions & 13 deletions src/toplevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,10 @@ JL_DLLEXPORT jl_value_t *jl_toplevel_eval_flex(jl_module_t *JL_NONNULL m, jl_val
if (has_opaque) {
jl_resolve_globals_in_ir((jl_array_t*)thk->code, m, NULL, 0);
}
size_t world = jl_atomic_load_acquire(&jl_world_counter);
ct->world_age = world;
result = jl_interpret_toplevel_thunk(m, thk);
ct->world_age = last_age;
}

JL_GC_POP();
Expand All @@ -1075,8 +1078,8 @@ JL_DLLEXPORT jl_value_t *jl_toplevel_eval_flex(jl_module_t *JL_NONNULL m, jl_val
JL_DLLEXPORT jl_value_t *jl_toplevel_eval(jl_module_t *m, jl_value_t *v)
{
const char *filename = jl_filename;
int lieno = jl_lineno;
return jl_toplevel_eval_flex(m, v, 1, 0, &filename, &lieno);
int lineno = jl_lineno;
return jl_toplevel_eval_flex(m, v, 1, 0, &filename, &lineno);
}

// Check module `m` is open for `eval/include`, or throw an error.
Expand Down Expand Up @@ -1177,14 +1180,13 @@ static jl_value_t *jl_parse_eval_all(jl_module_t *module, jl_value_t *text,
jl_task_t *ct = jl_current_task;
int last_lineno = jl_lineno;
const char *last_filename = jl_filename;
size_t last_age = ct->world_age;
int lineno = 0;
jl_lineno = 0;
const char *filename_str = jl_string_data(filename);
jl_filename = filename_str;
int err = 0;

JL_TRY {
size_t last_age = ct->world_age;
ct->world_age = jl_atomic_load_acquire(&jl_world_counter);
for (size_t i = 0; i < jl_expr_nargs(ast); i++) {
expression = jl_exprarg(ast, i);
Expand All @@ -1200,23 +1202,20 @@ static jl_value_t *jl_parse_eval_all(jl_module_t *module, jl_value_t *text,
ct->world_age = jl_atomic_load_relaxed(&jl_world_counter);
result = jl_toplevel_eval_flex(module, expression, 1, 1, &filename_str, &lineno);
}
ct->world_age = last_age;
}
JL_CATCH {
result = jl_box_long(jl_lineno); // (ab)use result to root error line
err = 1;
goto finally; // skip jl_restore_excstack
}
finally:
ct->world_age = last_age;
jl_lineno = last_lineno;
jl_filename = last_filename;
if (err) {
result = jl_box_long(lineno); // (ab)use result to root error line
jl_lineno = last_lineno;
jl_filename = last_filename;
if (jl_loaderror_type == NULL)
jl_rethrow();
else
jl_rethrow_other(jl_new_struct(jl_loaderror_type, filename, result,
jl_current_exception(ct)));
}
jl_lineno = last_lineno;
jl_filename = last_filename;
JL_GC_POP();
return result;
}
Expand Down
Loading