Skip to content

Commit 4e5767e

Browse files
committed
Merge pull request #11632 from yuyichao/revert-11606-delay-cache-type
Revert "Do not cache the type before we finish constructing it."
2 parents bfc74b2 + 3eb76ef commit 4e5767e

File tree

1 file changed

+21
-30
lines changed

1 file changed

+21
-30
lines changed

src/jltypes.c

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,26 +1951,6 @@ static jl_value_t *inst_type_w_(jl_value_t *t, jl_value_t **env, size_t n,
19511951
static jl_svec_t *inst_all(jl_svec_t *p, jl_value_t **env, size_t n,
19521952
jl_typestack_t *stack, int check);
19531953

1954-
static jl_value_t*
1955-
lookup_type_stack(jl_typestack_t *stack, jl_datatype_t *tt, size_t ntp,
1956-
jl_value_t **iparams)
1957-
{
1958-
// if an identical instantiation is already in process somewhere
1959-
// up the stack, return it. this computes a fixed point for
1960-
// recursive types.
1961-
jl_typename_t *tn = tt->name;
1962-
while (stack != NULL) {
1963-
if (stack->tt->name == tn &&
1964-
ntp == jl_svec_len(stack->tt->parameters) &&
1965-
typekey_eq(stack->tt, iparams, ntp)) {
1966-
jl_value_t *lkup = (jl_value_t*)stack->tt;
1967-
return lkup == tn->primary ? NULL : lkup;
1968-
}
1969-
stack = stack->prev;
1970-
}
1971-
return NULL;
1972-
}
1973-
19741954
static jl_value_t *inst_datatype(jl_datatype_t *dt, jl_svec_t *p, jl_value_t **iparams, size_t ntp,
19751955
int cacheable, int isabstract, jl_typestack_t *stack,
19761956
jl_value_t **env, size_t n)
@@ -1985,10 +1965,6 @@ static jl_value_t *inst_datatype(jl_datatype_t *dt, jl_svec_t *p, jl_value_t **i
19851965
if (lkup != NULL)
19861966
return lkup;
19871967
}
1988-
jl_value_t *stack_lkup = lookup_type_stack(stack, dt, ntp, iparams);
1989-
if (stack_lkup) {
1990-
return stack_lkup;
1991-
}
19921968

19931969
// always use original type constructor
19941970
if (!istuple) {
@@ -2032,6 +2008,8 @@ static jl_value_t *inst_datatype(jl_datatype_t *dt, jl_svec_t *p, jl_value_t **i
20322008
ndt->size = 0;
20332009
ndt->alignment = 1;
20342010

2011+
if (cacheable) jl_cache_type_(ndt);
2012+
20352013
if (istuple)
20362014
ndt->super = jl_any_type;
20372015
else
@@ -2069,10 +2047,6 @@ static jl_value_t *inst_datatype(jl_datatype_t *dt, jl_svec_t *p, jl_value_t **i
20692047
ndt->ninitialized = ntp;
20702048
else
20712049
ndt->ninitialized = dt->ninitialized;
2072-
2073-
if (cacheable)
2074-
jl_cache_type_(ndt);
2075-
20762050
JL_GC_POP();
20772051
return (jl_value_t*)ndt;
20782052
}
@@ -2239,8 +2213,25 @@ static jl_value_t *inst_type_w_(jl_value_t *t, jl_value_t **env, size_t n,
22392213
// if t's parameters are not bound in the environment, return it uncopied (#9378)
22402214
if (!bound && t == tc) { JL_GC_POP(); return (jl_value_t*)t; }
22412215

2242-
jl_value_t *result = inst_datatype(tt, NULL, iparams, ntp, cacheable,
2243-
isabstract, stack, env, n);
2216+
// if an identical instantiation is already in process somewhere
2217+
// up the stack, return it. this computes a fixed point for
2218+
// recursive types.
2219+
jl_typestack_t *tmp = stack;
2220+
jl_value_t *lkup = NULL;
2221+
while (tmp != NULL) {
2222+
if (tmp->tt->name==tn && ntp==jl_svec_len(tmp->tt->parameters) &&
2223+
typekey_eq(tmp->tt, iparams, ntp)) {
2224+
lkup = (jl_value_t*)tmp->tt;
2225+
break;
2226+
}
2227+
tmp = tmp->prev;
2228+
}
2229+
if (lkup != NULL && lkup != (jl_value_t*)tc) {
2230+
JL_GC_POP();
2231+
return lkup;
2232+
}
2233+
jl_value_t *result = inst_datatype((jl_datatype_t*)tt, NULL, iparams, ntp, cacheable, isabstract,
2234+
stack, env, n);
22442235
JL_GC_POP();
22452236
return result;
22462237
}

0 commit comments

Comments
 (0)