From fc3c5eff7556f2a8fc7a3b58710db1642cbb2e8e Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Thu, 16 May 2019 16:03:59 -0400 Subject: [PATCH] In person review changes --- base/compiler/typelimits.jl | 2 +- src/subtype.c | 34 +++++++++++++++++----------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/base/compiler/typelimits.jl b/base/compiler/typelimits.jl index 450c77df4bfe7..48f38ff7980aa 100644 --- a/base/compiler/typelimits.jl +++ b/base/compiler/typelimits.jl @@ -94,7 +94,7 @@ function _limit_type_size(@nospecialize(t), @nospecialize(c), sources::SimpleVec return t # fast path: unparameterized are always simple else ut = unwrap_unionall(t) - if isa(ut, DataType) && ut.name !== unwrap_unionall(Vararg).name && isa(c, Type) && c !== Union{} && c <: t + if isa(ut, DataType) && ut.name !== _va_typename && isa(c, Type) && c !== Union{} && c <: t return t # t is already wider than the comparison in the type lattice elseif is_derived_type_from_any(ut, sources, depth) return t # t isn't something new diff --git a/src/subtype.c b/src/subtype.c index 85d363c9cd16a..e979a91c426d5 100644 --- a/src/subtype.c +++ b/src/subtype.c @@ -753,7 +753,8 @@ static int with_tvar(tvar_callback callback, void *context, jl_unionall_t *u, in return ans; } -static jl_unionall_t *unalias_unionall(jl_unionall_t *u, jl_stenv_t *e) { +static jl_unionall_t *unalias_unionall(jl_unionall_t *u, jl_stenv_t *e) +{ jl_varbinding_t *btemp = e->vars; // if the var for this unionall (based on identity) already appears somewhere // in the environment, rename to get a fresh var. @@ -868,9 +869,9 @@ static int subtype_tuple_varargs(struct subtype_tuple_env *env, jl_stenv_t *e, i } if (jl_is_long(xl)) { if (jl_unbox_long(xl) + 1 == env->vx) { - // LHS is exhausted. We're a subtype if the LHS is either + // LHS is exhausted. We're a subtype if the RHS is either // exhausted as well or unbounded (in which case we need to - // set it to 0. + // set it to 0). if (jl_is_datatype(env->vty)) { jl_value_t *yl = jl_tparam1(env->vty); if (jl_is_typevar(yl)) { @@ -899,10 +900,6 @@ static int subtype_tuple_varargs(struct subtype_tuple_env *env, jl_stenv_t *e, i if (!subtype(xp0, yp0, e, 1)) return 0; constrain_length: - if (jl_is_long(xp1) && jl_is_long(yp1)) { - return env->lx + jl_unbox_long(xp1) == env->ly + jl_unbox_long(yp1); - } - if (!jl_is_datatype(env->vtx)) { jl_value_t *yl = yp1; if (jl_is_typevar(yl)) { @@ -920,11 +917,13 @@ static int subtype_tuple_varargs(struct subtype_tuple_env *env, jl_stenv_t *e, i // Vararg{T,N} <: Vararg{T2,N2}; equate N and N2 e->invdepth++; + JL_GC_PUSH2(xp1, yp1); if (jl_is_long(xp1) && env->vx != 1) xp1 = jl_box_long(jl_unbox_long(xp1) - env->vx + 1); if (jl_is_long(yp1) && env->vy != 1) yp1 = jl_box_long(jl_unbox_long(yp1) - env->vy + 1); int ans = forall_exists_equal(xp1, yp1, e); + JL_GC_POP(); e->invdepth--; return ans; } @@ -941,7 +940,7 @@ static int subtype_tuple_tail(struct subtype_tuple_env *env, int8_t R, jl_stenv_ if (env->i == env->lx-1 && env->vvx) { if (!env->vtx) { xi = jl_tparam(env->xd, env->i); - // Unbounded vararg on the LHS without vararg on the LHS should + // Unbounded vararg on the LHS without vararg on the RHS should // have been caught earlier. assert(env->vvy || !jl_is_unionall(xi)); if (jl_is_unionall(xi)) { @@ -1027,7 +1026,6 @@ static int subtype_tuple_tail(struct subtype_tuple_env *env, int8_t R, jl_stenv_ // } (from loop:) done: - // TODO: handle Vararg with explicit integer length parameter if (!env->vy && env->j < env->ly && jl_is_vararg_type(jl_tparam(env->yd, env->j))) env->vy += 1; if (env->vy && !env->vx && env->lx+1 >= env->ly) { @@ -1041,12 +1039,14 @@ static int subtype_tuple_tail(struct subtype_tuple_env *env, int8_t R, jl_stenv_ static int subtype_tuple(jl_datatype_t *xd, jl_datatype_t *yd, jl_stenv_t *e, int param) { struct subtype_tuple_env env; - env.xd = xd; env.yd = yd; - env.lx = jl_nparams(xd); env.ly = jl_nparams(yd); + env.xd = xd; + env.yd = yd; + env.lx = jl_nparams(xd); + env.ly = jl_nparams(yd); if (env.lx == 0 && env.ly == 0) return 1; - env.i=0; env.j=0; - env.vx=0; env.vy=0; + env.i = env.j = 0; + env.vx = env.vy = 0; env.vvx = env.vvy = JL_VARARG_NONE; if (env.lx > 0) env.vvx = jl_vararg_kind(jl_tparam(env.xd, env.lx-1)); @@ -1089,8 +1089,8 @@ static int subtype_tuple(jl_datatype_t *xd, jl_datatype_t *yd, jl_stenv_t *e, in } param = (param == 0 ? 1 : param); - env.lastx=NULL; env.lasty=NULL; - env.vtx=NULL; env.vty=NULL; + env.lastx = env.lasty=NULL; + env.vtx = env.vty=NULL; return subtype_tuple_tail(&env, 0, e, param); } @@ -1519,8 +1519,8 @@ JL_DLLEXPORT int jl_obvious_subtype(jl_value_t *x, jl_value_t *y, int *subtype) *subtype = 0; return 1; } - if ((vx == JL_VARARG_NONE || vx == JL_VARARG_INT) && nparams_expanded_x < npy - vy) - { + if ((vx == JL_VARARG_NONE || vx == JL_VARARG_INT) && + nparams_expanded_x < npy - vy) { *subtype = 0; return 1; // number of fixed parameters in x could be fewer than in y }