@@ -847,14 +847,14 @@ JL_DLLEXPORT jl_value_t *jl_type_unionall(jl_tvar_t *v, jl_value_t *body)
847
847
if (T_has_tv ) {
848
848
jl_value_t * wrapped = jl_type_unionall (v , vm -> T );
849
849
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 );
851
851
JL_GC_POP ();
852
852
return wrapped ;
853
853
}
854
854
else {
855
855
assert (N_has_tv );
856
856
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 );
858
858
}
859
859
}
860
860
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
1889
1889
}
1890
1890
// if some normalization might be needed, do that now
1891
1891
// it is probably okay to mutate iparams, and we only store globally rooted objects here
1892
- if (check && cacheable ) {
1892
+ if (check ) {
1893
1893
size_t i ;
1894
1894
for (i = 0 ; i < ntp ; i ++ ) {
1895
1895
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
1898
1898
if (jl_is_datatype (pi ))
1899
1899
continue ;
1900
1900
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
1903
1902
continue ;
1904
1903
if (!cacheable && jl_has_free_typevars (pi ))
1905
1904
continue ;
@@ -2327,7 +2326,7 @@ static jl_value_t *inst_type_w_(jl_value_t *t, jl_typeenv_t *env, jl_typestack_t
2327
2326
N = inst_type_w_ (v -> N , env , stack , check );
2328
2327
}
2329
2328
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 );
2331
2330
}
2332
2331
JL_GC_POP ();
2333
2332
return t ;
@@ -2400,36 +2399,44 @@ jl_datatype_t *jl_wrap_Type(jl_value_t *t)
2400
2399
return (jl_datatype_t * )jl_instantiate_unionall (jl_type_type , t );
2401
2400
}
2402
2401
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 )
2404
2403
{
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
+ }
2421
2424
}
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 ;
2426
2433
}
2427
2434
}
2428
- jl_task_t * ct = jl_current_task ;
2429
2435
jl_vararg_t * vm = (jl_vararg_t * )jl_gc_alloc (ct -> ptls , sizeof (jl_vararg_t ), jl_vararg_type );
2430
2436
jl_set_typetagof (vm , jl_vararg_tag , 0 );
2431
2437
vm -> T = t ;
2432
2438
vm -> N = n ;
2439
+ JL_GC_POP ();
2433
2440
return vm ;
2434
2441
}
2435
2442
@@ -2712,7 +2719,7 @@ void jl_init_types(void) JL_GC_DISABLED
2712
2719
// It seems like we probably usually end up needing the box for kinds (often used in an Any context), so force it to exist
2713
2720
jl_vararg_type -> name -> mayinlinealloc = 0 ;
2714
2721
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 ));
2716
2723
jl_anytuple_type = jl_new_datatype (jl_symbol ("Tuple" ), core , jl_any_type , anytuple_params ,
2717
2724
jl_emptysvec , anytuple_params , jl_emptysvec , 0 , 0 , 0 );
2718
2725
jl_tuple_typename = jl_anytuple_type -> name ;
0 commit comments