Skip to content

Commit 2051368

Browse files
stereotype441Commit Queue
authored andcommitted
[flow analysis] Change unit tests to match new promotion chain representation.
In https://dart-review.googlesource.com/c/sdk/+/443540, the representation for promotion chains in flow analysis was changed so that an empty promotion chain is now represented by an empty list rather than `null`, but to reduce the risk of mistakes, only minimal changes were made to flow analysis unit tests. This CL updates the unit tests to follow the same convention. This change also fixes a previously unnoticed bug in the flow analysis unit tests. Previously, there were several test cases that passed a `null` value to `_matchVariableModel`'s `chain` parameter, with the intention of checking that the promotion chain was empty. However, `_matchVariableModel` converts a `null` value of `chain` to `anything` (to handle test cases where the promotion chain isn't of interest), so as a result, these test cases accidentally failed to check that the promotion chain was empty. These test cases have been changed to pass `isEmpty`, so these unit tests are actually stronger now. Change-Id: Ibf19d1ff64075d9f37fa85f85e11df417c0a68e1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/443541 Commit-Queue: Paul Berry <[email protected]> Reviewed-by: Erik Ernst <[email protected]>
1 parent 1b95cf1 commit 2051368

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

pkg/_fe_analyzer_shared/test/flow_analysis/flow_analysis_test.dart

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3721,7 +3721,7 @@ main() {
37213721
expect(
37223722
s2._infoFor(h, objectQVar),
37233723
_matchVariableModel(
3724-
chain: null,
3724+
chain: isEmpty,
37253725
ofInterest: isEmpty,
37263726
assigned: true,
37273727
unassigned: false,
@@ -3744,7 +3744,7 @@ main() {
37443744
expect(
37453745
s2._infoFor(h, objectQVar),
37463746
_matchVariableModel(
3747-
chain: null,
3747+
chain: isEmpty,
37483748
ofInterest: isEmpty,
37493749
assigned: true,
37503750
unassigned: false,
@@ -3772,7 +3772,7 @@ main() {
37723772
expect(s2.reachable.overallReachable, true);
37733773
expect(s2.promotionInfo.unwrap(h), {
37743774
h.promotionKeyStore.keyForVariable(objectQVar): _matchVariableModel(
3775-
chain: null,
3775+
chain: isEmpty,
37763776
ofInterest: [Type('int')],
37773777
assigned: true,
37783778
unassigned: false,
@@ -3929,7 +3929,7 @@ main() {
39293929
)._declare(h, x, true);
39303930
expect(s1.promotionInfo.unwrap(h), {
39313931
h.promotionKeyStore.keyForVariable(x): _matchVariableModel(
3932-
chain: null,
3932+
chain: isEmpty,
39333933
),
39343934
});
39353935

@@ -3955,14 +3955,14 @@ main() {
39553955
)._declare(h, x, true);
39563956
expect(s1.promotionInfo.unwrap(h), {
39573957
h.promotionKeyStore.keyForVariable(x): _matchVariableModel(
3958-
chain: null,
3958+
chain: isEmpty,
39593959
),
39603960
});
39613961

39623962
var s2 = s1._conservativeJoin(h, [], [x]);
39633963
expect(s2.promotionInfo.unwrap(h), {
39643964
h.promotionKeyStore.keyForVariable(x): _matchVariableModel(
3965-
chain: null,
3965+
chain: isEmpty,
39663966
writeCaptured: true,
39673967
),
39683968
});
@@ -3977,7 +3977,7 @@ main() {
39773977
);
39783978
expect(s3.promotionInfo.unwrap(h), {
39793979
h.promotionKeyStore.keyForVariable(x): _matchVariableModel(
3980-
chain: null,
3980+
chain: isEmpty,
39813981
writeCaptured: true,
39823982
),
39833983
});
@@ -4408,7 +4408,7 @@ main() {
44084408
ofInterest: ['int'],
44094409
),
44104410
h.promotionKeyStore.keyForVariable(intQVar): _matchVariableModel(
4411-
chain: null,
4411+
chain: isEmpty,
44124412
ofInterest: [],
44134413
),
44144414
});
@@ -4429,7 +4429,7 @@ main() {
44294429
ofInterest: ['int'],
44304430
),
44314431
h.promotionKeyStore.keyForVariable(intQVar): _matchVariableModel(
4432-
chain: null,
4432+
chain: isEmpty,
44334433
ofInterest: ['int'],
44344434
),
44354435
});
@@ -4450,7 +4450,7 @@ main() {
44504450
ofInterest: ['int'],
44514451
),
44524452
h.promotionKeyStore.keyForVariable(intQVar): _matchVariableModel(
4453-
chain: null,
4453+
chain: isEmpty,
44544454
ofInterest: isEmpty,
44554455
unassigned: false,
44564456
),
@@ -5021,12 +5021,12 @@ main() {
50215021
});
50225022

50235023
PromotionModel<SharedTypeView> model(
5024-
List<SharedTypeView>? promotionChain, {
5024+
List<SharedTypeView> promotionChain, {
50255025
List<SharedTypeView>? typesOfInterest,
50265026
bool assigned = false,
50275027
}) => PromotionModel<SharedTypeView>(
5028-
promotedTypes: promotionChain ?? const [],
5029-
tested: typesOfInterest ?? promotionChain ?? [],
5028+
promotedTypes: promotionChain,
5029+
tested: typesOfInterest ?? promotionChain,
50305030
assigned: assigned,
50315031
unassigned: !assigned,
50325032
ssaNode: new SsaNode<SharedTypeView>(null),
@@ -5037,15 +5037,15 @@ main() {
50375037
var s0 = FlowModel<SharedTypeView>(Reachability.initial);
50385038
var s1 = s0._setInfo(h, {
50395039
x: model([SharedTypeView(intType)]),
5040-
y: model(null),
5040+
y: model(const []),
50415041
});
50425042
var s2 = s0._setInfo(h, {
5043-
x: model(null),
5043+
x: model(const []),
50445044
y: model([SharedTypeView(intType)]),
50455045
});
50465046
expect(FlowModel.joinPromotionInfo(h, s1, s2).promotionInfo.unwrap(h), {
5047-
x: _matchVariableModel(chain: null, ofInterest: ['int']),
5048-
y: _matchVariableModel(chain: null, ofInterest: ['int']),
5047+
x: _matchVariableModel(chain: isEmpty, ofInterest: ['int']),
5048+
y: _matchVariableModel(chain: isEmpty, ofInterest: ['int']),
50495049
});
50505050
});
50515051
});
@@ -5082,9 +5082,9 @@ main() {
50825082
var s1 = s0._setInfo(h, {
50835083
x: model([SharedTypeView(intType)]),
50845084
});
5085-
var s2 = s0._setInfo(h, {x: model(null)});
5085+
var s2 = s0._setInfo(h, {x: model(const [])});
50865086
var expected = {
5087-
x: _matchVariableModel(chain: null, ofInterest: ['int']),
5087+
x: _matchVariableModel(chain: isEmpty, ofInterest: ['int']),
50885088
};
50895089
expect(
50905090
FlowModel.joinPromotionInfo(h, s1, s2).promotionInfo.unwrap(h),
@@ -5126,7 +5126,7 @@ main() {
51265126
x: model([SharedTypeView(stringType)]),
51275127
});
51285128
var expected = {
5129-
x: _matchVariableModel(chain: null, ofInterest: ['String', 'int']),
5129+
x: _matchVariableModel(chain: isEmpty, ofInterest: ['String', 'int']),
51305130
};
51315131
expect(
51325132
FlowModel.joinPromotionInfo(h, s1, s2).promotionInfo.unwrap(h),
@@ -5203,8 +5203,8 @@ main() {
52035203

52045204
test('assigned', () {
52055205
var s0 = FlowModel<SharedTypeView>(Reachability.initial);
5206-
var unassigned = model(null, assigned: false);
5207-
var assigned = model(null, assigned: true);
5206+
var unassigned = model(const [], assigned: false);
5207+
var assigned = model(const [], assigned: true);
52085208
var s1 = s0._setInfo(h, {
52095209
x: assigned,
52105210
y: assigned,
@@ -5221,12 +5221,12 @@ main() {
52215221
expect(joined.promotionInfo.unwrap(h), {
52225222
x: same(assigned),
52235223
y: _matchVariableModel(
5224-
chain: null,
5224+
chain: isEmpty,
52255225
assigned: false,
52265226
unassigned: false,
52275227
),
52285228
z: _matchVariableModel(
5229-
chain: null,
5229+
chain: isEmpty,
52305230
assigned: false,
52315231
unassigned: false,
52325232
),
@@ -12786,8 +12786,7 @@ Matcher _matchOfInterestSet(List<String> expectedTypes) {
1278612786
);
1278712787
}
1278812788

12789-
Matcher _matchPromotionChain(List<String>? expectedTypes) {
12790-
if (expectedTypes == null) return isEmpty;
12789+
Matcher _matchPromotionChain(List<String> expectedTypes) {
1279112790
return predicate(
1279212791
(List<SharedTypeView> x) => equals(
1279312792
expectedTypes,

0 commit comments

Comments
 (0)