Skip to content

Commit b10ba43

Browse files
committed
add world counter to MethodError
1 parent 3e32d63 commit b10ba43

File tree

5 files changed

+23
-10
lines changed

5 files changed

+23
-10
lines changed

base/base.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ Alternatively, there is no unique most-specific method.
5757
type MethodError <: Exception
5858
f
5959
args
60+
world::UInt
61+
MethodError(f::ANY, args::ANY, world::UInt) = new(f, args, world)
6062
end
63+
MethodError(f::ANY, args::ANY) = MethodError(f, args, 0)
6164

6265
"""
6366
EOFError()

base/replutil.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ function showerror(io::IO, ex::MethodError)
341341
print(io, "you may have intended to import Base.", name)
342342
end
343343
end
344+
# TODO: world counter check
344345
if !is_arg_types
345346
# Check for row vectors used where a column vector is intended.
346347
vec_args = []
@@ -538,6 +539,7 @@ function show_method_candidates(io::IO, ex::MethodError, kwargs::Vector=Any[])
538539
end
539540
end
540541
end
542+
# TODO: indicate if it's in the wrong world
541543
push!(lines, (buf, right_matches))
542544
end
543545
end

src/ast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ value_t fl_invoke_julia_macro(fl_context_t *fl_ctx, value_t *args, uint32_t narg
156156
mfunc = jl_method_lookup(jl_gf_mtable(margs[0]), margs, nargs, 1, world);
157157
if (mfunc == NULL) {
158158
JL_GC_POP();
159-
jl_method_error((jl_function_t*)margs[0], margs, nargs);
159+
jl_method_error((jl_function_t*)margs[0], margs, nargs, world);
160160
// unreachable
161161
}
162162
margs[nargs] = result = jl_call_method_internal(mfunc, margs, nargs);

src/gf.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,14 +1070,22 @@ JL_DLLEXPORT void jl_method_table_insert(jl_methtable_t *mt, jl_method_t *method
10701070
JL_GC_POP();
10711071
}
10721072

1073-
void JL_NORETURN jl_method_error_bare(jl_function_t *f, jl_value_t *args)
1073+
void JL_NORETURN jl_method_error_bare(jl_function_t *f, jl_value_t *args, size_t world)
10741074
{
10751075
if (jl_methoderror_type) {
1076-
jl_throw(jl_new_struct(jl_methoderror_type, f, args));
1076+
jl_value_t *e = jl_new_struct_uninit(jl_methoderror_type);
1077+
struct jl_method_error {
1078+
jl_value_t *f;
1079+
jl_value_t *args;
1080+
size_t world;
1081+
} *pe = (void*)e,
1082+
ee = {f, args, world};
1083+
*pe = ee;
1084+
jl_throw(e);
10771085
}
10781086
else {
10791087
jl_printf((JL_STREAM*)STDERR_FILENO, "A method error occurred before the base MethodError type was defined. Aborting...\n");
1080-
jl_static_show((JL_STREAM*)STDERR_FILENO,(jl_value_t*)f); jl_printf((JL_STREAM*)STDERR_FILENO,"\n");
1088+
jl_static_show((JL_STREAM*)STDERR_FILENO,(jl_value_t*)f); jl_printf((JL_STREAM*)STDERR_FILENO," world %u\n", (unsigned)world);
10811089
jl_static_show((JL_STREAM*)STDERR_FILENO,args); jl_printf((JL_STREAM*)STDERR_FILENO,"\n");
10821090
jl_ptls_t ptls = jl_get_ptls_states();
10831091
ptls->bt_size = rec_backtrace(ptls->bt_data, JL_MAX_BT_SIZE);
@@ -1087,11 +1095,11 @@ void JL_NORETURN jl_method_error_bare(jl_function_t *f, jl_value_t *args)
10871095
// not reached
10881096
}
10891097

1090-
void JL_NORETURN jl_method_error(jl_function_t *f, jl_value_t **args, size_t na)
1098+
void JL_NORETURN jl_method_error(jl_function_t *f, jl_value_t **args, size_t na, size_t world)
10911099
{
10921100
jl_value_t *argtup = jl_f_tuple(NULL, args+1, na-1);
10931101
JL_GC_PUSH1(&argtup);
1094-
jl_method_error_bare(f, argtup);
1102+
jl_method_error_bare(f, argtup, world);
10951103
// not reached
10961104
}
10971105

@@ -1891,7 +1899,7 @@ JL_DLLEXPORT jl_value_t *jl_apply_generic(jl_value_t **args, uint32_t nargs)
18911899
if (error_en)
18921900
show_call(F, args, nargs);
18931901
#endif
1894-
jl_method_error((jl_function_t*)args[0], args, nargs);
1902+
jl_method_error((jl_function_t*)args[0], args, nargs, world);
18951903
// unreachable
18961904
}
18971905
}
@@ -1938,7 +1946,7 @@ jl_value_t *jl_gf_invoke(jl_tupletype_t *types0, jl_value_t **args, size_t nargs
19381946
jl_typemap_entry_t *entry = (jl_typemap_entry_t*)jl_gf_invoke_lookup(types, world);
19391947

19401948
if ((jl_value_t*)entry == jl_nothing) {
1941-
jl_method_error_bare(gf, (jl_value_t*)types0);
1949+
jl_method_error_bare(gf, (jl_value_t*)types0, world);
19421950
// unreachable
19431951
}
19441952

src/julia_internal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ void jl_set_t_uid_ctr(int i);
239239
uint32_t jl_get_gs_ctr(void);
240240
void jl_set_gs_ctr(uint32_t ctr);
241241

242-
void JL_NORETURN jl_method_error_bare(jl_function_t *f, jl_value_t *args);
243-
void JL_NORETURN jl_method_error(jl_function_t *f, jl_value_t **args, size_t na);
242+
void JL_NORETURN jl_method_error_bare(jl_function_t *f, jl_value_t *args, size_t world);
243+
void JL_NORETURN jl_method_error(jl_function_t *f, jl_value_t **args, size_t na, size_t world);
244244

245245
JL_DLLEXPORT void jl_typeassert(jl_value_t *x, jl_value_t *t);
246246

0 commit comments

Comments
 (0)