Skip to content

Commit

Permalink
Revert some test changes not required for this PR
Browse files Browse the repository at this point in the history
  • Loading branch information
Keno committed Aug 20, 2024
1 parent d5e5f28 commit 1bfe075
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 41 deletions.
4 changes: 0 additions & 4 deletions base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -532,10 +532,6 @@ The thrown errors are collected in a stack of exceptions.
"""
global err = nothing

# For numbered REPL prompt
global Out::Any
export Out

# weakly exposes ans and err variables to Main
export ans, err
end
Expand Down
22 changes: 0 additions & 22 deletions src/method.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,28 +215,6 @@ static jl_value_t *resolve_globals(jl_value_t *expr, jl_module_t *module, jl_sve
if (e->head == jl_method_sym || e->head == jl_module_sym || e->head == jl_throw_undef_if_not_sym) {
i++;
}
if (e->head == jl_assign_sym && binding_effects) {
jl_value_t *lhs = jl_exprarg(e, 0);
if (jl_is_globalref(lhs) || jl_is_symbol(lhs)) {
jl_module_t *mod = jl_is_globalref(lhs) ? jl_globalref_mod(lhs) : module;
jl_sym_t *name = jl_is_globalref(lhs) ? jl_globalref_name(lhs) : (jl_sym_t*)lhs;
if (mod == module) {
// Assignment does not create bindings in foreign modules (#54678)
jl_binding_t *b = jl_get_module_binding(mod, name, 1);
jl_binding_partition_t *bpart = jl_get_binding_partition(b, jl_current_task->world_age);
jl_ptr_kind_union_t pku = jl_atomic_load_relaxed(&bpart->restriction);
while (1) {
if (!jl_bkind_is_some_guard(decode_restriction_kind(pku)))
break;
jl_ptr_kind_union_t new_pku = encode_restriction((jl_value_t*)jl_any_type, BINDING_KIND_GLOBAL);
if (jl_atomic_cmpswap(&bpart->restriction, &pku, new_pku)) {
jl_gc_wb(bpart, jl_any_type);
break;
}
}
}
}
}
for (; i < nargs; i++) {
// TODO: this should be making a copy, not mutating the source
jl_exprargset(e, i, resolve_globals(jl_exprarg(e, i), module, sparam_vals, binding_effects, eager_resolve));
Expand Down
6 changes: 3 additions & 3 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ static jl_binding_t *new_binding(jl_module_t *mod, jl_sym_t *name)

extern jl_mutex_t jl_modules_mutex;

static void check_safe_newbinding(jl_module_t *m, jl_sym_t *var)
extern void check_safe_newbinding(jl_module_t *m, jl_sym_t *var)
{
if (jl_current_task->ptls->in_pure_callback)
jl_errorf("new globals cannot be created in a generated function");
Expand Down Expand Up @@ -475,7 +475,7 @@ static jl_binding_t *jl_resolve_owner(jl_binding_t *b/*optional*/, jl_module_t *
if (decode_restriction_kind(pku) == BINDING_KIND_FAILED)
return NULL;
if (decode_restriction_kind(pku) == BINDING_KIND_DECLARED) {
return NULL;
return b;
}
if (decode_restriction_kind(pku) == BINDING_KIND_GUARD) {
jl_binding_t *b2 = NULL;
Expand Down Expand Up @@ -1126,7 +1126,7 @@ void append_module_names(jl_array_t* a, jl_module_t *m, int all, int imported, i
if (((b->publicp) ||
(imported && (kind == BINDING_KIND_CONST_IMPORT || kind == BINDING_KIND_IMPORTED)) ||
(usings && kind == BINDING_KIND_EXPLICIT) ||
((kind == BINDING_KIND_GLOBAL || kind == BINDING_KIND_CONST) && (all || main_public))) &&
((kind == BINDING_KIND_GLOBAL || kind == BINDING_KIND_CONST || kind == BINDING_KIND_DECLARED) && (all || main_public))) &&
(all || (!b->deprecated && !hidden)))
_append_symbol_to_bindings_array(a, asname);
}
Expand Down
2 changes: 2 additions & 0 deletions src/toplevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ void jl_binding_set_type(jl_binding_t *b, jl_value_t *ty)
jl_gc_wb(bpart, ty);
}

extern void check_safe_newbinding(jl_module_t *m, jl_sym_t *var);
void jl_declare_global(jl_module_t *m, jl_value_t *arg, jl_value_t *set_type) {
// create uninitialized mutable binding for "global x" decl sometimes or probably
jl_module_t *gm;
Expand All @@ -342,6 +343,7 @@ void jl_declare_global(jl_module_t *m, jl_value_t *arg, jl_value_t *set_type) {
jl_binding_partition_t *bpart = jl_get_binding_partition(b, jl_current_task->world_age);
jl_ptr_kind_union_t pku = jl_atomic_load_relaxed(&bpart->restriction);
while (decode_restriction_kind(pku) == BINDING_KIND_GUARD || decode_restriction_kind(pku) == BINDING_KIND_FAILED) {
check_safe_newbinding(gm, gs);
if (jl_atomic_cmpswap(&bpart->restriction, &pku, encode_restriction(NULL, BINDING_KIND_DECLARED)))
break;
}
Expand Down
2 changes: 2 additions & 0 deletions stdlib/REPL/src/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1820,6 +1820,8 @@ function capture_result(n::Ref{Int}, @nospecialize(x))
n = n[]
mod = Base.MainInclude
if !isdefined(mod, :Out)
@eval mod global Out
@eval mod export Out
setglobal!(mod, :Out, Dict{Int, Any}())
end
if x !== getglobal(mod, :Out) && x !== nothing # remove this?
Expand Down
2 changes: 1 addition & 1 deletion stdlib/REPL/test/repl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ end

# Issue 39427
@test occursin("does not exist.", sprint(show, help_result(":=")))
global some_undef_global::Any
global some_undef_global
@test occursin("exists,", sprint(show, help_result("some_undef_global", @__MODULE__)))

# Issue #40563
Expand Down
11 changes: 8 additions & 3 deletions test/compiler/effects.jl
Original file line number Diff line number Diff line change
Expand Up @@ -376,18 +376,23 @@ end
# as the cached effects can be easily wrong otherwise
# since the inference currently doesn't track "world-age" of global variables
@eval global_assignment_undefinedyet() = $(GlobalRef(@__MODULE__, :UNDEFINEDYET)) = 42
setglobal!_nothrow_undefinedyet() = setglobal!(@__MODULE__, :UNDEFINEDYET2, 42)
setglobal!_nothrow_undefinedyet() = setglobal!(@__MODULE__, :UNDEFINEDYET, 42)
let effects = Base.infer_effects() do
global_assignment_undefinedyet()
end
@test Core.Compiler.is_nothrow(effects)
@test !Core.Compiler.is_nothrow(effects)
end
let effects = Base.infer_effects() do
setglobal!_nothrow_undefinedyet()
end
@test !Core.Compiler.is_nothrow(effects)
end
global UNDEFINEDYET2::String = "0"
global UNDEFINEDYET::String = "0"
let effects = Base.infer_effects() do
global_assignment_undefinedyet()
end
@test !Core.Compiler.is_nothrow(effects)
end
let effects = Base.infer_effects() do
setglobal!_nothrow_undefinedyet()
end
Expand Down
6 changes: 2 additions & 4 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ end
# timing macros

# test that they don't introduce global vars
global v11801::Any, t11801::Any, names_before_timing::Any
global v11801, t11801, names_before_timing
names_before_timing = names(@__MODULE__, all = true)

let t = @elapsed 1+1
Expand Down Expand Up @@ -318,9 +318,7 @@ v11801, t11801 = @timed sin(1)
@test v11801 == sin(1)
@test isa(t11801,Real) && t11801 >= 0

let diff = setdiff(names(@__MODULE__, all = true), names_before_timing)
@test isempty(diff)
end
@test names(@__MODULE__, all = true) == names_before_timing

redirect_stdout(devnull) do # suppress time prints

Expand Down
4 changes: 2 additions & 2 deletions test/staged.jl
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ end
@generated function f33243()
:(global x33243 = 2)
end
@test_skip(@test_throws ErrorException f33243())
global x33243::Any
@test_throws ErrorException f33243()
global x33243
@test f33243() === 2
@test x33243 === 2

Expand Down
4 changes: 2 additions & 2 deletions test/syntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2595,7 +2595,7 @@ using Test

module Mod
const x = 1
global maybe_undef::Any, always_undef::Any
global maybe_undef, always_undef
export always_undef
def() = (global maybe_undef = 0)
func(x) = 2x + 1
Expand Down Expand Up @@ -3719,7 +3719,7 @@ module Foreign54607
end
@test_throws ErrorException (Foreign54607.foo = 1)
@test_throws ErrorException Foreign54607.try_to_create_binding1()
Foreign54607.try_to_create_binding2()
@test_throws ErrorException Foreign54607.try_to_create_binding2()
function assign_in_foreign_module()
(Foreign54607.foo = 1)
nothing
Expand Down

0 comments on commit 1bfe075

Please sign in to comment.