Skip to content

Commit

Permalink
incremental deserializer: extract mt correctly
Browse files Browse the repository at this point in the history
fix #16905
  • Loading branch information
vtjnash committed Jun 14, 2016
1 parent 8aa1d5c commit a6d092e
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -1534,7 +1534,7 @@ JL_DLLEXPORT size_t jl_static_show(JL_STREAM *out, jl_value_t *v)

JL_DLLEXPORT size_t jl_static_show_func_sig(JL_STREAM *s, jl_value_t *type)
{
jl_value_t *ftype = jl_first_argument_datatype(type);
jl_value_t *ftype = (jl_value_t*)jl_first_argument_datatype(type);
if (ftype == NULL)
return jl_static_show(s, type);
size_t n = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -1691,8 +1691,8 @@ static void jl_deserialize_lambdas_from_mod(ios_t *s)
if (meth == NULL)
return;
jl_tupletype_t *simpletype = (jl_tupletype_t*)jl_deserialize_value(s, NULL);
jl_datatype_t *gf = (jl_datatype_t*)jl_tparam0(meth->sig);
assert(jl_is_datatype(gf));
jl_datatype_t *gf = jl_first_argument_datatype((jl_value_t*)meth->sig);
assert(jl_is_datatype(gf) && gf->name->mt);
jl_method_table_insert(gf->name->mt, meth, simpletype);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/julia_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ jl_lambda_info_t *jl_method_lookup_by_type(jl_methtable_t *mt, jl_tupletype_t *t
jl_lambda_info_t *jl_method_lookup(jl_methtable_t *mt, jl_value_t **args, size_t nargs, int cache);
jl_value_t *jl_gf_invoke(jl_tupletype_t *types, jl_value_t **args, size_t nargs);

jl_value_t *jl_first_argument_datatype(jl_value_t *argtypes);
jl_datatype_t *jl_first_argument_datatype(jl_value_t *argtypes);
int jl_has_intrinsics(jl_lambda_info_t *li, jl_value_t *v, jl_module_t *m);

jl_value_t *jl_nth_slot_type(jl_tupletype_t *sig, size_t i);
Expand Down
18 changes: 9 additions & 9 deletions src/toplevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ JL_DLLEXPORT jl_value_t *jl_generic_function_def(jl_sym_t *name, jl_value_t **bp
return gf;
}

jl_datatype_t *first_arg_datatype(jl_value_t *a, int got_tuple1)
static jl_datatype_t *first_arg_datatype(jl_value_t *a, int got_tuple1)
{
if (jl_is_datatype(a)) {
if (got_tuple1)
Expand Down Expand Up @@ -696,9 +696,9 @@ jl_datatype_t *first_arg_datatype(jl_value_t *a, int got_tuple1)
}

// get DataType of first tuple element, or NULL if cannot be determined
jl_value_t *jl_first_argument_datatype(jl_value_t *argtypes)
jl_datatype_t *jl_first_argument_datatype(jl_value_t *argtypes)
{
return (jl_value_t*)first_arg_datatype(argtypes, 0);
return first_arg_datatype(argtypes, 0);
}

extern tracer_cb jl_newmeth_tracer;
Expand Down Expand Up @@ -726,17 +726,17 @@ JL_DLLEXPORT void jl_method_def(jl_svec_t *argdata, jl_lambda_info_t *f, jl_valu

if (jl_is_tuple_type(argtypes) && jl_nparams(argtypes) > 0 && !jl_is_type(jl_tparam0(argtypes)))
jl_error("function type in method definition is not a type");
jl_value_t *ftype = jl_first_argument_datatype((jl_value_t*)argtypes);
jl_datatype_t *ftype = jl_first_argument_datatype((jl_value_t*)argtypes);
if (ftype == NULL ||
!(jl_is_type_type(ftype) ||
!(jl_is_type_type((jl_value_t*)ftype) ||
(jl_is_datatype(ftype) &&
(!((jl_datatype_t*)ftype)->abstract || jl_is_leaf_type(ftype)) &&
((jl_datatype_t*)ftype)->name->mt != NULL)))
(!ftype->abstract || jl_is_leaf_type((jl_value_t*)ftype)) &&
ftype->name->mt != NULL)))
jl_error("cannot add methods to an abstract type");
mt = ((jl_datatype_t*)ftype)->name->mt;
mt = ftype->name->mt;
name = mt->name;

if (jl_subtype(ftype, (jl_value_t*)jl_builtin_type, 0))
if (jl_subtype((jl_value_t*)ftype, (jl_value_t*)jl_builtin_type, 0))
jl_error("cannot add methods to a builtin function");

m = jl_new_method(f, name, argtypes, tvars, isstaged == jl_true);
Expand Down
37 changes: 36 additions & 1 deletion test/compile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ try
"""
__precompile__(true)
# test that docs get reconnected
module $Foo_module
# test that docs get reconnected
@doc "foo function" foo(x) = x + 1
include_dependency("foo.jl")
include_dependency("foo.jl")
Expand All @@ -39,6 +39,30 @@ try
Base.Test.@test_throws ErrorException Core.kwfunc(Base.nothing)
Base.nothing(::UInt8, ::UInt16, ::UInt32; x = 52) = x
const nothingkw = Core.kwfunc(Base.nothing)
# issue 16908 (some complicated types and external method definitions)
abstract CategoricalPool{T, R <: Integer, V}
abstract CategoricalValue{T, R <: Integer}
immutable NominalPool{T, R <: Integer, V} <: CategoricalPool{T, R, V}
index::Vector{T}
invindex::Dict{T, R}
order::Vector{R}
ordered::Vector{T}
valindex::Vector{V}
end
immutable NominalValue{T, R <: Integer} <: CategoricalValue{T, R}
level::R
pool::NominalPool{T, R, NominalValue{T, R}}
end
immutable OrdinalValue{T, R <: Integer} <: CategoricalValue{T, R}
level::R
pool::NominalPool{T, R, NominalValue{T, R}}
end
(::Union{Type{NominalValue}, Type{OrdinalValue}})() = 1
(::Union{Type{NominalValue{T}}, Type{OrdinalValue{T}}}){T}() = 2
(::Type{Vector{NominalValue{T, R}}}){T, R}() = 3
(::Type{Vector{NominalValue{T, T}}}){T}() = 4
(::Type{Vector{NominalValue{Int, Int}}})() = 5
end
""")
@test_throws ErrorException Core.kwfunc(Base.nothing) # make sure `nothing` didn't have a kwfunc (which would invalidate the attempted test)
Expand Down Expand Up @@ -75,6 +99,17 @@ try
@test nothing(0x01, 0x4000, 0x30031234) == 52
@test nothing(0x01, 0x4000, 0x30031234; x = 9142) == 9142
@test Foo.nothingkw === Core.kwfunc(Base.nothing)

@test Foo.NominalValue() == 1
@test Foo.OrdinalValue() == 1
@test Foo.NominalValue{Int}() == 2
@test Foo.OrdinalValue{Int}() == 2
let T = Vector{Foo.NominalValue{Int}}
@test isa(T(), T)
end
@test Vector{Foo.NominalValue{Int32, Int64}}() == 3
@test Vector{Foo.NominalValue{UInt, UInt}}() == 4
@test Vector{Foo.NominalValue{Int, Int}}() == 5
end

Baz_file = joinpath(dir, "Baz.jl")
Expand Down

0 comments on commit a6d092e

Please sign in to comment.