@@ -847,14 +847,14 @@ JL_DLLEXPORT jl_value_t *jl_type_unionall(jl_tvar_t *v, jl_value_t *body)
847847 if (T_has_tv ) {
848848 jl_value_t * wrapped = jl_type_unionall (v , vm -> T );
849849 JL_GC_PUSH1 (& wrapped );
850- wrapped = (jl_value_t * )jl_wrap_vararg (wrapped , vm -> N );
850+ wrapped = (jl_value_t * )jl_wrap_vararg (wrapped , vm -> N , 1 );
851851 JL_GC_POP ();
852852 return wrapped ;
853853 }
854854 else {
855855 assert (N_has_tv );
856856 assert (vm -> N == (jl_value_t * )v );
857- return (jl_value_t * )jl_wrap_vararg (vm -> T , NULL );
857+ return (jl_value_t * )jl_wrap_vararg (vm -> T , NULL , 1 );
858858 }
859859 }
860860 if (!jl_is_type (body ) && !jl_is_typevar (body ))
@@ -1889,7 +1889,7 @@ static jl_value_t *inst_datatype_inner(jl_datatype_t *dt, jl_svec_t *p, jl_value
18891889 }
18901890 // if some normalization might be needed, do that now
18911891 // it is probably okay to mutate iparams, and we only store globally rooted objects here
1892- if (check && cacheable ) {
1892+ if (check ) {
18931893 size_t i ;
18941894 for (i = 0 ; i < ntp ; i ++ ) {
18951895 jl_value_t * pi = iparams [i ];
@@ -1898,8 +1898,7 @@ static jl_value_t *inst_datatype_inner(jl_datatype_t *dt, jl_svec_t *p, jl_value
18981898 if (jl_is_datatype (pi ))
18991899 continue ;
19001900 if (jl_is_vararg (pi ))
1901- // This would require some special handling, but is not needed
1902- // at the moment (and might be better handled in jl_wrap_vararg instead).
1901+ // This is already handled in jl_wrap_vararg instead
19031902 continue ;
19041903 if (!cacheable && jl_has_free_typevars (pi ))
19051904 continue ;
@@ -2327,7 +2326,7 @@ static jl_value_t *inst_type_w_(jl_value_t *t, jl_typeenv_t *env, jl_typestack_t
23272326 N = inst_type_w_ (v -> N , env , stack , check );
23282327 }
23292328 if (T != v -> T || N != v -> N ) {
2330- t = (jl_value_t * )jl_wrap_vararg (T , N );
2329+ t = (jl_value_t * )jl_wrap_vararg (T , N , check );
23312330 }
23322331 JL_GC_POP ();
23332332 return t ;
@@ -2400,36 +2399,44 @@ jl_datatype_t *jl_wrap_Type(jl_value_t *t)
24002399 return (jl_datatype_t * )jl_instantiate_unionall (jl_type_type , t );
24012400}
24022401
2403- jl_vararg_t * jl_wrap_vararg (jl_value_t * t , jl_value_t * n )
2402+ jl_vararg_t * jl_wrap_vararg (jl_value_t * t , jl_value_t * n , int check )
24042403{
2405- if (n ) {
2406- if (jl_is_typevar (n ) || jl_is_uniontype (jl_unwrap_unionall (n ))) {
2407- // TODO: this is disabled due to #39698; it is also inconsistent
2408- // with other similar checks, where we usually only check substituted
2409- // values and not the bounds of variables.
2410- /*
2411- jl_tvar_t *N = (jl_tvar_t*)n;
2412- if (!(N->lb == jl_bottom_type && N->ub == (jl_value_t*)jl_any_type))
2413- jl_error("TypeVar in Vararg length must have bounds Union{} and Any");
2414- */
2415- }
2416- else if (!jl_is_long (n )) {
2417- jl_type_error_rt ("Vararg" , "count" , (jl_value_t * )jl_long_type , n );
2418- }
2419- else if (jl_unbox_long (n ) < 0 ) {
2420- jl_errorf ("Vararg length is negative: %zd" , jl_unbox_long (n ));
2404+ jl_task_t * ct = jl_current_task ;
2405+ JL_GC_PUSH1 (& t );
2406+ if (check ) {
2407+ if (n ) {
2408+ if (jl_is_typevar (n ) || jl_is_uniontype (jl_unwrap_unionall (n ))) {
2409+ // TODO: this is disabled due to #39698; it is also inconsistent
2410+ // with other similar checks, where we usually only check substituted
2411+ // values and not the bounds of variables.
2412+ /*
2413+ jl_tvar_t *N = (jl_tvar_t*)n;
2414+ if (!(N->lb == jl_bottom_type && N->ub == (jl_value_t*)jl_any_type))
2415+ jl_error("TypeVar in Vararg length must have bounds Union{} and Any");
2416+ */
2417+ }
2418+ else if (!jl_is_long (n )) {
2419+ jl_type_error_rt ("Vararg" , "count" , (jl_value_t * )jl_long_type , n );
2420+ }
2421+ else if (jl_unbox_long (n ) < 0 ) {
2422+ jl_errorf ("Vararg length is negative: %zd" , jl_unbox_long (n ));
2423+ }
24212424 }
2422- }
2423- if (t ) {
2424- if (!jl_valid_type_param (t )) {
2425- jl_type_error_rt ("Vararg" , "type" , (jl_value_t * )jl_type_type , t );
2425+ if (t ) {
2426+ if (!jl_valid_type_param (t )) {
2427+ jl_type_error_rt ("Vararg" , "type" , (jl_value_t * )jl_type_type , t );
2428+ }
2429+ t = normalize_unionalls (t );
2430+ jl_value_t * tw = extract_wrapper (t );
2431+ if (tw && t != tw && jl_types_equal (t , tw ))
2432+ t = tw ;
24262433 }
24272434 }
2428- jl_task_t * ct = jl_current_task ;
24292435 jl_vararg_t * vm = (jl_vararg_t * )jl_gc_alloc (ct -> ptls , sizeof (jl_vararg_t ), jl_vararg_type );
24302436 jl_set_typetagof (vm , jl_vararg_tag , 0 );
24312437 vm -> T = t ;
24322438 vm -> N = n ;
2439+ JL_GC_POP ();
24332440 return vm ;
24342441}
24352442
@@ -2712,7 +2719,7 @@ void jl_init_types(void) JL_GC_DISABLED
27122719 // It seems like we probably usually end up needing the box for kinds (often used in an Any context), so force it to exist
27132720 jl_vararg_type -> name -> mayinlinealloc = 0 ;
27142721
2715- jl_svec_t * anytuple_params = jl_svec (1 , jl_wrap_vararg ((jl_value_t * )jl_any_type , (jl_value_t * )NULL ));
2722+ jl_svec_t * anytuple_params = jl_svec (1 , jl_wrap_vararg ((jl_value_t * )jl_any_type , (jl_value_t * )NULL , 0 ));
27162723 jl_anytuple_type = jl_new_datatype (jl_symbol ("Tuple" ), core , jl_any_type , anytuple_params ,
27172724 jl_emptysvec , anytuple_params , jl_emptysvec , 0 , 0 , 0 );
27182725 jl_tuple_typename = jl_anytuple_type -> name ;
0 commit comments