Skip to content

Commit d8f7a50

Browse files
committed
Revert "Re-enable property tests on fully static types"
This reverts commit 1a992f537c97289454dc9f8ecf3c17746b221947.
1 parent b7c0d6b commit d8f7a50

File tree

2 files changed

+43
-88
lines changed

2 files changed

+43
-88
lines changed

crates/ty_python_semantic/src/types/property_tests.rs

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,9 @@ macro_rules! type_property_test {
5050
$property
5151
}
5252
};
53-
($test_name:ident, $db:ident, forall fully_static_types $($types:ident),+ . $property:expr) => {
54-
#[quickcheck_macros::quickcheck]
55-
#[ignore]
56-
fn $test_name($($types: crate::types::property_tests::type_generation::FullyStaticTy),+) -> bool {
57-
let $db = &crate::types::property_tests::setup::get_cached_db();
58-
$(let $types = $types.into_type($db);)+
59-
60-
$property
61-
}
62-
};
6353
// A property test with a logical implication.
64-
($name:ident, $db:ident, forall $typekind:ident $($types:ident),+ . $premise:expr => $conclusion:expr) => {
65-
type_property_test!($name, $db, forall $typekind $($types),+ . !($premise) || ($conclusion));
54+
($name:ident, $db:ident, forall types $($types:ident),+ . $premise:expr => $conclusion:expr) => {
55+
type_property_test!($name, $db, forall types $($types),+ . !($premise) || ($conclusion));
6656
};
6757
}
6858

@@ -172,18 +162,6 @@ mod stable {
172162
all_type_pairs_are_assignable_to_their_union, db,
173163
forall types s, t. s.is_assignable_to(db, union(db, [s, t])) && t.is_assignable_to(db, union(db, [s, t]))
174164
);
175-
176-
// A fully static type `T` is a subtype of itself.
177-
type_property_test!(
178-
subtype_of_is_reflexive_for_fully_static_types, db,
179-
forall fully_static_types t. t.is_subtype_of(db, t)
180-
);
181-
182-
// For any two fully static types, each type in the pair must be a subtype of their union.
183-
type_property_test!(
184-
all_fully_static_type_pairs_are_subtype_of_their_union, db,
185-
forall fully_static_types s, t. s.is_subtype_of(db, union(db, [s, t])) && t.is_subtype_of(db, union(db, [s, t]))
186-
);
187165
}
188166

189167
/// This module contains property tests that currently lead to many false positives.
@@ -198,6 +176,22 @@ mod flaky {
198176

199177
use super::{intersection, union};
200178

179+
// --- These only apply to fully static types; need a way to generate fully-static types only.
180+
181+
// A type `T` is a subtype of itself.
182+
type_property_test!(
183+
subtype_of_is_reflexive, db,
184+
forall types t. t.is_subtype_of(db, t)
185+
);
186+
187+
// For any two types, each type in the pair must be a subtype of their union.
188+
type_property_test!(
189+
all_type_pairs_are_subtype_of_their_union, db,
190+
forall types s, t. s.is_subtype_of(db, union(db, [s, t])) && t.is_subtype_of(db, union(db, [s, t]))
191+
);
192+
193+
// ---
194+
201195
// Negating `T` twice is equivalent to `T`.
202196
type_property_test!(
203197
double_negation_is_identity, db,

crates/ty_python_semantic/src/types/property_tests/type_generation.rs

Lines changed: 25 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -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> {
416388
impl 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-
494455
pub(crate) fn intersection<'db>(
495456
db: &'db TestDb,
496457
tys: impl IntoIterator<Item = Type<'db>>,

0 commit comments

Comments
 (0)