@@ -200,31 +200,16 @@ impl Ty {
200200 }
201201}
202202
203- #[ derive( Debug , Clone , PartialEq ) ]
204- pub ( crate ) struct FullyStaticTy ( Ty ) ;
205-
206- impl FullyStaticTy {
207- pub ( crate ) fn into_type ( self , db : & TestDb ) -> Type < ' _ > {
208- self . 0 . into_type ( db)
209- }
210- }
211-
212- fn arbitrary_core_type ( g : & mut Gen , fully_static : bool ) -> Ty {
203+ fn arbitrary_core_type ( g : & mut Gen ) -> Ty {
213204 // We could select a random integer here, but this would make it much less
214205 // likely to explore interesting edge cases:
215206 let int_lit = Ty :: IntLiteral ( * g. choose ( & [ -2 , -1 , 0 , 1 , 2 ] ) . unwrap ( ) ) ;
216207 let bool_lit = Ty :: BooleanLiteral ( bool:: arbitrary ( g) ) ;
217-
218- // Update this if new non-fully-static types are added below.
219- let fully_static_index = 3 ;
220- let types = & [
221- Ty :: Any ,
222- Ty :: Unknown ,
223- Ty :: SubclassOfAny ,
224- // Add fully static types below, dynamic types above.
225- // Update `fully_static_index` above if adding new dynamic types!
208+ g. choose ( & [
226209 Ty :: Never ,
210+ Ty :: Unknown ,
227211 Ty :: None ,
212+ Ty :: Any ,
228213 int_lit,
229214 bool_lit,
230215 Ty :: StringLiteral ( "" ) ,
@@ -249,6 +234,7 @@ fn arbitrary_core_type(g: &mut Gen, fully_static: bool) -> Ty {
249234 Ty :: BuiltinInstance ( "type" ) ,
250235 Ty :: AbcInstance ( "ABC" ) ,
251236 Ty :: AbcInstance ( "ABCMeta" ) ,
237+ Ty :: SubclassOfAny ,
252238 Ty :: SubclassOfBuiltinClass ( "object" ) ,
253239 Ty :: SubclassOfBuiltinClass ( "str" ) ,
254240 Ty :: SubclassOfBuiltinClass ( "type" ) ,
@@ -268,59 +254,54 @@ fn arbitrary_core_type(g: &mut Gen, fully_static: bool) -> Ty {
268254 class : "int" ,
269255 method : "bit_length" ,
270256 } ,
271- ] ;
272- let types = if fully_static {
273- & types[ fully_static_index..]
274- } else {
275- types
276- } ;
277- g. choose ( types) . unwrap ( ) . clone ( )
257+ ] )
258+ . unwrap ( )
259+ . clone ( )
278260}
279261
280262/// Constructs an arbitrary type.
281263///
282264/// The `size` parameter controls the depth of the type tree. For example,
283265/// a simple type like `int` has a size of 0, `Union[int, str]` has a size
284266/// of 1, `tuple[int, Union[str, bytes]]` has a size of 2, etc.
285- ///
286- /// The `fully_static` parameter, if `true`, limits generation to fully static types.
287- fn arbitrary_type ( g : & mut Gen , size : u32 , fully_static : bool ) -> Ty {
267+ fn arbitrary_type ( g : & mut Gen , size : u32 ) -> Ty {
288268 if size == 0 {
289- arbitrary_core_type ( g, fully_static )
269+ arbitrary_core_type ( g)
290270 } else {
291271 match u32:: arbitrary ( g) % 5 {
292- 0 => arbitrary_core_type ( g, fully_static ) ,
272+ 0 => arbitrary_core_type ( g) ,
293273 1 => Ty :: Union (
294274 ( 0 ..* g. choose ( & [ 2 , 3 ] ) . unwrap ( ) )
295- . map ( |_| arbitrary_type ( g, size - 1 , fully_static ) )
275+ . map ( |_| arbitrary_type ( g, size - 1 ) )
296276 . collect ( ) ,
297277 ) ,
298278 2 => Ty :: Tuple (
299279 ( 0 ..* g. choose ( & [ 0 , 1 , 2 ] ) . unwrap ( ) )
300- . map ( |_| arbitrary_type ( g, size - 1 , fully_static ) )
280+ . map ( |_| arbitrary_type ( g, size - 1 ) )
301281 . collect ( ) ,
302282 ) ,
303283 3 => Ty :: Intersection {
304284 pos : ( 0 ..* g. choose ( & [ 0 , 1 , 2 ] ) . unwrap ( ) )
305- . map ( |_| arbitrary_type ( g, size - 1 , fully_static ) )
285+ . map ( |_| arbitrary_type ( g, size - 1 ) )
306286 . collect ( ) ,
307287 neg : ( 0 ..* g. choose ( & [ 0 , 1 , 2 ] ) . unwrap ( ) )
308- . map ( |_| arbitrary_type ( g, size - 1 , fully_static ) )
288+ . map ( |_| arbitrary_type ( g, size - 1 ) )
309289 . collect ( ) ,
310290 } ,
311291 4 => Ty :: Callable {
312292 params : match u32:: arbitrary ( g) % 2 {
313- 0 if !fully_static => CallableParams :: GradualForm ,
314- _ => CallableParams :: List ( arbitrary_parameter_list ( g, size, fully_static) ) ,
293+ 0 => CallableParams :: GradualForm ,
294+ 1 => CallableParams :: List ( arbitrary_parameter_list ( g, size) ) ,
295+ _ => unreachable ! ( ) ,
315296 } ,
316- returns : arbitrary_annotation ( g, size - 1 , fully_static ) . map ( Box :: new) ,
297+ returns : arbitrary_optional_type ( g, size - 1 ) . map ( Box :: new) ,
317298 } ,
318299 _ => unreachable ! ( ) ,
319300 }
320301 }
321302}
322303
323- fn arbitrary_parameter_list ( g : & mut Gen , size : u32 , fully_static : bool ) -> Vec < Param > {
304+ fn arbitrary_parameter_list ( g : & mut Gen , size : u32 ) -> Vec < Param > {
324305 let mut params: Vec < Param > = vec ! [ ] ;
325306 let mut used_names = HashSet :: new ( ) ;
326307
@@ -372,31 +353,22 @@ fn arbitrary_parameter_list(g: &mut Gen, size: u32, fully_static: bool) -> Vec<P
372353 params. push ( Param {
373354 kind : next_kind,
374355 name,
375- annotated_ty : arbitrary_annotation ( g, size, fully_static ) ,
356+ annotated_ty : arbitrary_optional_type ( g, size) ,
376357 default_ty : if matches ! ( next_kind, ParamKind :: Variadic | ParamKind :: KeywordVariadic ) {
377358 None
378359 } else {
379- arbitrary_optional_type ( g, size, fully_static )
360+ arbitrary_optional_type ( g, size)
380361 } ,
381362 } ) ;
382363 }
383364
384365 params
385366}
386367
387- /// An arbitrary optional type, always `Some` if fully static.
388- fn arbitrary_annotation ( g : & mut Gen , size : u32 , fully_static : bool ) -> Option < Ty > {
389- if fully_static {
390- Some ( arbitrary_type ( g, size, true ) )
391- } else {
392- arbitrary_optional_type ( g, size, false )
393- }
394- }
395-
396- fn arbitrary_optional_type ( g : & mut Gen , size : u32 , fully_static : bool ) -> Option < Ty > {
368+ fn arbitrary_optional_type ( g : & mut Gen , size : u32 ) -> Option < Ty > {
397369 match u32:: arbitrary ( g) % 2 {
398370 0 => None ,
399- 1 => Some ( arbitrary_type ( g, size, fully_static ) ) ,
371+ 1 => Some ( arbitrary_type ( g, size) ) ,
400372 _ => unreachable ! ( ) ,
401373 }
402374}
@@ -416,7 +388,7 @@ fn arbitrary_optional_name(g: &mut Gen) -> Option<Name> {
416388impl Arbitrary for Ty {
417389 fn arbitrary ( g : & mut Gen ) -> Ty {
418390 const MAX_SIZE : u32 = 2 ;
419- arbitrary_type ( g, MAX_SIZE , false )
391+ arbitrary_type ( g, MAX_SIZE )
420392 }
421393
422394 fn shrink ( & self ) -> Box < dyn Iterator < Item = Self > > {
@@ -480,17 +452,6 @@ impl Arbitrary for Ty {
480452 }
481453}
482454
483- impl Arbitrary for FullyStaticTy {
484- fn arbitrary ( g : & mut Gen ) -> FullyStaticTy {
485- const MAX_SIZE : u32 = 2 ;
486- FullyStaticTy ( arbitrary_type ( g, MAX_SIZE , true ) )
487- }
488-
489- fn shrink ( & self ) -> Box < dyn Iterator < Item = Self > > {
490- Box :: new ( self . 0 . shrink ( ) . map ( FullyStaticTy ) )
491- }
492- }
493-
494455pub ( crate ) fn intersection < ' db > (
495456 db : & ' db TestDb ,
496457 tys : impl IntoIterator < Item = Type < ' db > > ,
0 commit comments