Skip to content

allow redefinition of egal parametric types #17618

New issue

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

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

Already on GitHub? # to your account

Merged
merged 1 commit into from
Aug 8, 2016
Merged
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
36 changes: 24 additions & 12 deletions src/interpreter.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,35 @@ extern int jl_boot_file_loaded;
extern int inside_typedef;

// this is a heuristic for allowing "redefining" a type to something identical
static int equiv_svec_dt(jl_svec_t *sa, jl_svec_t *sb)
{
size_t i, l = jl_svec_len(sa);
if (l != jl_svec_len(sb)) return 0;
for (i = 0; i < l; i++) {
jl_value_t *a = jl_svecref(sa, i);
jl_value_t *b = jl_svecref(sb, i);
if (jl_typeof(a) != jl_typeof(b))
return 0;
if (jl_is_typevar(a) && ((jl_tvar_t*)a)->name != ((jl_tvar_t*)b)->name)
return 0;
if (!jl_subtype(a, b, 0) || !jl_subtype(b, a, 0))
return 0;
}
return 1;
}
static int equiv_type(jl_datatype_t *dta, jl_datatype_t *dtb)
{
return (jl_typeof(dta) == jl_typeof(dtb) &&
// TODO: can't yet handle parametric types due to how constructors work
dta->parameters == jl_emptysvec &&
dta->name->name == dtb->name->name &&
jl_egal((jl_value_t*)dta->types, (jl_value_t*)dtb->types) &&
dta->abstract == dtb->abstract &&
dta->mutabl == dtb->mutabl &&
dta->size == dtb->size &&
dta->ninitialized == dtb->ninitialized &&
jl_egal((jl_value_t*)dta->super, (jl_value_t*)dtb->super) &&
jl_egal((jl_value_t*)dta->name->names, (jl_value_t*)dtb->name->names) &&
jl_egal((jl_value_t*)dta->parameters, (jl_value_t*)dtb->parameters));
equiv_svec_dt(dta->parameters, dtb->parameters) &&
equiv_svec_dt(dta->types, dtb->types) &&
jl_subtype((jl_value_t*)dta->super, (jl_value_t*)dtb->super, 0) &&
jl_subtype((jl_value_t*)dtb->super, (jl_value_t*)dta->super, 0) &&
jl_egal((jl_value_t*)dta->name->names, (jl_value_t*)dtb->name->names));
}

static void check_can_assign_type(jl_binding_t *b)
Expand Down Expand Up @@ -297,7 +312,7 @@ static jl_value_t *eval(jl_value_t *e, interpreter_state *s)
jl_rethrow();
}
b->value = temp;
if (temp==NULL || !equiv_type(dt, (jl_datatype_t*)temp)) {
if (temp == NULL || !equiv_type(dt, (jl_datatype_t*)temp)) {
jl_checked_assignment(b, (jl_value_t*)dt);
}
JL_GC_POP();
Expand Down Expand Up @@ -339,7 +354,7 @@ static jl_value_t *eval(jl_value_t *e, interpreter_state *s)
jl_rethrow();
}
b->value = temp;
if (temp==NULL || !equiv_type(dt, (jl_datatype_t*)temp)) {
if (temp == NULL || !equiv_type(dt, (jl_datatype_t*)temp)) {
jl_checked_assignment(b, (jl_value_t*)dt);
}
JL_GC_POP();
Expand Down Expand Up @@ -405,12 +420,9 @@ static jl_value_t *eval(jl_value_t *e, interpreter_state *s)
}

b->value = temp;
if (temp==NULL || !equiv_type(dt, (jl_datatype_t*)temp)) {
if (temp == NULL || !equiv_type(dt, (jl_datatype_t*)temp)) {
jl_checked_assignment(b, (jl_value_t*)dt);
}
else {
// TODO: remove all old ctors and set temp->name->ctor_factory = dt->name->ctor_factory
}

JL_GC_POP();
return (jl_value_t*)jl_nothing;
Expand Down