@@ -79,26 +79,6 @@ int jl_is_type(jl_value_t *v)
7979 return jl_is_nontuple_type (v );
8080}
8181
82- int jl_has_typevars_ (jl_value_t * v , int incl_wildcard );
83-
84- DLLEXPORT int jl_is_leaf_type (jl_value_t * v )
85- {
86- if (jl_is_tuple (v )) {
87- jl_tuple_t * t = (jl_tuple_t * )v ;
88- size_t i ;
89- for (i = 0 ; i < t -> length ; i ++ ) {
90- if (!jl_is_leaf_type (jl_tupleref (t , i )))
91- return 0 ;
92- }
93- return 1 ;
94- }
95- if (jl_is_type_type (v ) && !jl_has_typevars_ (jl_tparam0 (v ),1 ))
96- return 1 ;
97- if (!jl_is_struct_type (v ) && !jl_is_func_type (v ) && !jl_is_bits_type (v ))
98- return 0 ;
99- return !jl_has_typevars_ (v ,1 );
100- }
101-
10282int jl_has_typevars_ (jl_value_t * v , int incl_wildcard )
10383{
10484 size_t i ;
@@ -141,6 +121,34 @@ int jl_has_typevars(jl_value_t *v)
141121 return jl_has_typevars_ (v , 0 );
142122}
143123
124+ DLLEXPORT int jl_is_leaf_type (jl_value_t * v )
125+ {
126+ if (jl_is_struct_type (v ) || jl_is_bits_type (v )) {
127+ jl_tuple_t * t = ((jl_tag_type_t * )v )-> parameters ;
128+ for (int i = 0 ; i < t -> length ; i ++ ) {
129+ if (jl_is_typevar (jl_tupleref (t ,i )))
130+ return 0 ;
131+ }
132+ return 1 ;
133+ }
134+ if (jl_is_tuple (v )) {
135+ jl_tuple_t * t = (jl_tuple_t * )v ;
136+ for (int i = 0 ; i < t -> length ; i ++ ) {
137+ if (!jl_is_leaf_type (jl_tupleref (t , i )))
138+ return 0 ;
139+ }
140+ return 1 ;
141+ }
142+ if (jl_is_type_type (v )) {
143+ return !jl_is_typevar (jl_tparam0 (v ));
144+ }
145+ if (jl_is_func_type (v )) {
146+ return !jl_is_typevar (((jl_func_type_t * )v )-> from ) &&
147+ !jl_is_typevar (((jl_func_type_t * )v )-> to );
148+ }
149+ return 0 ;
150+ }
151+
144152// construct the full type of a value, possibly making a tuple type
145153jl_value_t * jl_full_type (jl_value_t * v )
146154{
@@ -1314,9 +1322,18 @@ int jl_assign_type_uid(void)
13141322static void cache_type_ (jl_type_t * type )
13151323{
13161324 // only cache concrete types
1317- if (jl_has_typevars_ ((jl_value_t * )type ,1 ) ||
1318- ((jl_tag_type_t * )type )-> parameters -> length == 0 )
1319- return ;
1325+ jl_tuple_t * t = ((jl_tag_type_t * )type )-> parameters ;
1326+ if (t -> length == 0 ) return ;
1327+ if (jl_is_tag_type (type )) {
1328+ if (jl_has_typevars_ ((jl_value_t * )type ,1 ))
1329+ return ;
1330+ }
1331+ else {
1332+ for (int i = 0 ; i < t -> length ; i ++ ) {
1333+ if (jl_is_typevar (jl_tupleref (t ,i )))
1334+ return ;
1335+ }
1336+ }
13201337 // assign uid
13211338 if (jl_is_struct_type (type ) && ((jl_struct_type_t * )type )-> uid == 0 )
13221339 ((jl_struct_type_t * )type )-> uid = jl_assign_type_uid ();
0 commit comments