Skip to content

Commit d1d842e

Browse files
committed
Fix tests
1 parent a153518 commit d1d842e

File tree

4 files changed

+37
-30
lines changed

4 files changed

+37
-30
lines changed

base/reflection.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,23 @@ function _fieldnames(@nospecialize t)
207207
return t.name.names
208208
end
209209

210+
const BINDING_KIND_GLOBAL = 0x0
211+
const BINDING_KIND_CONST = 0x1
212+
const BINDING_KIND_CONST_IMPORT = 0x2
213+
const BINDING_KIND_IMPLICIT = 0x3
214+
const BINDING_KIND_EXPLICIT = 0x4
215+
const BINDING_KIND_IMPORTED = 0x5
216+
const BINDING_KIND_FAILED = 0x6
217+
const BINDING_KIND_DECLARED = 0x7
218+
const BINDING_KIND_GUARD = 0x8
219+
220+
function lookup_binding_partition(world::UInt, b::Union{GlobalRef, Core.Binding})
221+
ccall(:jl_get_binding_partition, Ref{Core.BindingPartition}, (Any, UInt), b, world)
222+
end
223+
224+
binding_kind(bpart::Core.BindingPartition) = bpart.flags & 0xf
225+
binding_kind(m::Module, s::Symbol) = binding_kind(lookup_binding_partition(get_world_counter(), GlobalRef(m, s)))
226+
210227
"""
211228
fieldname(x::DataType, i::Integer)
212229

src/julia_internal.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,9 @@ STATIC_INLINE int jl_bpart_is_some_guard(jl_binding_partition_t *b) JL_NOTSAFEPO
855855
return b->kind == BINDING_KIND_FAILED || b->kind == BINDING_KIND_GUARD || b->kind == BINDING_KIND_DECLARED;
856856
}
857857

858-
STATIC_INLINE jl_binding_partition_t *jl_get_binding_partition(jl_binding_t *b, size_t world) JL_NOTSAFEPOINT {
858+
JL_DLLEXPORT inline jl_binding_partition_t *jl_get_binding_partition(jl_binding_t *b, size_t world) JL_NOTSAFEPOINT {
859+
if (b && jl_is_globalref(b))
860+
b = ((jl_globalref_t*)b)->binding;
859861
if (!b)
860862
return NULL;
861863
assert(jl_is_binding(b));

src/module.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
extern "C" {
1313
#endif
1414

15+
// In this translation unit and this translation unit only emit this symbol `extern` for use by julia
16+
extern JL_DLLEXPORT jl_binding_partition_t *jl_get_binding_partition(jl_binding_t *b, size_t world) JL_NOTSAFEPOINT;
17+
1518
JL_DLLEXPORT jl_module_t *jl_new_module_(jl_sym_t *name, jl_module_t *parent, uint8_t default_names)
1619
{
1720
jl_task_t *ct = jl_current_task;
@@ -175,6 +178,7 @@ static jl_binding_partition_t *new_binding_partition(void)
175178
jl_atomic_store_relaxed(&bpart->max_world, (size_t)-1);
176179
jl_atomic_store_relaxed(&bpart->next, NULL);
177180
bpart->kind = BINDING_KIND_GUARD;
181+
bpart->padding = 0;
178182
return bpart;
179183
}
180184

@@ -1080,7 +1084,7 @@ void append_module_names(jl_array_t* a, jl_module_t *m, int all, int imported, i
10801084
jl_binding_partition_t *bpart = jl_get_binding_partition(b, jl_current_task->world_age);
10811085
if (((b->publicp) ||
10821086
(imported && (bpart->kind == BINDING_KIND_CONST_IMPORT || bpart->kind == BINDING_KIND_IMPORTED)) ||
1083-
(usings && bpart->kind == BINDING_KIND_IMPLICIT) ||
1087+
(usings && bpart->kind == BINDING_KIND_EXPLICIT) ||
10841088
((bpart->kind == BINDING_KIND_GLOBAL || bpart->kind == BINDING_KIND_CONST) && (all || main_public))) &&
10851089
(all || (!b->deprecated && !hidden)))
10861090
_append_symbol_to_bindings_array(a, asname);

stdlib/REPL/src/REPL.jl

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,35 +33,19 @@ function UndefVarError_hint(io::IO, ex::UndefVarError)
3333
if isdefined(ex, :scope)
3434
scope = ex.scope
3535
if scope isa Module
36-
bnd = ccall(:jl_get_module_binding, Any, (Any, Any, Cint), scope, var, true)::Core.Binding
37-
if isdefined(bnd, :owner)
38-
owner = bnd.owner
39-
if owner === bnd
40-
print(io, "\nSuggestion: add an appropriate import or assignment. This global was declared but not assigned.")
41-
end
36+
bpart = Base.lookup_binding_partition(Base.get_world_counter(), GlobalRef(scope, var))
37+
kind = Base.binding_kind(bpart)
38+
if kind === Base.BINDING_KIND_GLOBAL || kind === Base.BINDING_KIND_CONST || kind == Base.BINDING_KIND_DECLARED
39+
print(io, "\nSuggestion: add an appropriate import or assignment. This global was declared but not assigned.")
40+
elseif kind === Base.BINDING_KIND_FAILED
41+
print(io, "\nHint: It looks like two or more modules export different ",
42+
"bindings with this name, resulting in ambiguity. Try explicitly ",
43+
"importing it from a particular module, or qualifying the name ",
44+
"with the module it should come from.")
45+
elseif kind === Base.BINDING_KIND_GUARD
46+
print(io, "\nSuggestion: check for spelling errors or missing imports.")
4247
else
43-
owner = ccall(:jl_binding_owner, Ptr{Cvoid}, (Any, Any), scope, var)
44-
if C_NULL == owner
45-
# No global of this name exists in this module.
46-
# This is the common case, so do not print that information.
47-
# It could be the binding was exported by two modules, which we can detect
48-
# by the `usingfailed` flag in the binding:
49-
if false # TODO: #isdefined(bnd, :flags) && Bool(bnd.flags >> 4 & 1) # magic location of the `usingfailed` flag
50-
print(io, "\nHint: It looks like two or more modules export different ",
51-
"bindings with this name, resulting in ambiguity. Try explicitly ",
52-
"importing it from a particular module, or qualifying the name ",
53-
"with the module it should come from.")
54-
else
55-
print(io, "\nSuggestion: check for spelling errors or missing imports.")
56-
end
57-
owner = bnd
58-
else
59-
owner = unsafe_pointer_to_objref(owner)::Core.Binding
60-
end
61-
end
62-
if owner !== bnd
63-
# this could use jl_binding_dbgmodule for the exported location in the message too
64-
print(io, "\nSuggestion: this global was defined as `$(owner.globalref)` but not assigned a value.")
48+
print(io, "\nSuggestion: this global was defined as `$(bpart.restriction.globalref)` but not assigned a value.")
6549
end
6650
elseif scope === :static_parameter
6751
print(io, "\nSuggestion: run Test.detect_unbound_args to detect method arguments that do not fully constrain a type parameter.")

0 commit comments

Comments
 (0)