Commit 9f127c9
analyzer: Tidy strict-inference-in-parameters check
The existing code had two local functions which were an unnecessary
structuring of the check. The story might be hard to read in the diff.
1. The previous method body for `_checkStrictInferenceInParameters`
first declared a variable `usedParameterVisitor` which may or not be
ever used, and then created two local functions.
2. The first function, `isParameterReferenced`, is only called from the
second function. It has a lot of complexity because it is responsible
for maybe instantiating that local variable, only once, to cache the
results of visiting the function body.
3. The second function is called twice, which is why it was nice to
encapsulate it in a function.
4. _After_ those things are declared, we check if we're even using
`strict-inference`, or that the parameter list is null. This results
in many null-asserts on the parameter list.
5. The code that extracts out a NormalFormalParameter from a
DefaultFormalParameter is a little complicated.
The changes sort of unwind the complexity from the bottom up:
* We can move the `strict-inference` check and the parameter list null-
check to the tippy top, returning early (4). This removes many
null-asserts.
* We can simplify the code that extracts the NormalFormalParameter from
any DefaultFormalParameter (5), which means there would only be one
call to `checkParameterTypeIsKnown`. With only one call site, the
encapsulation is silly (3), and we can inline the function, removing
`checkParameterTypeIsKnown`.
* Most of the complexity of the first function, `isParameterReferenced`
is around initializing this expensive visitor, so that we only visit
the function body once. But it turns out, we only do that if we cannot
know whether the parameters are used, because `initializers` is null,
and the `body` is null or empty. But none of that knowledge is per-
parameter, so it can be computed outside this function. So we
introduce `parameterReferenceIsUnknown`. We never need to call
`isParameterReferenced` if `parameterReferenceIsUnknown`. Or, put
another way, we only need to call `isParameterReferenced` if we know
we need that visitor. So we can now computer the visitor outside the
function, after which the function is so simple (a single returned
expression), it can be removed.
All in all, here are the broad simplifications:
* We return early in a few common scenarios, in which case we neither
declare that visitor variable, nor declare the local functions.
* We compute `parameterReferenceIsUnknown` once, not per parameter.
* We simplify how inner `NormalFormalParameters` are extracted.
* We simplify instantiating the visitor, rather than in a local
function.
* We inline simple local functions.
Change-Id: I308f328940f809f10cad884e68f064dd0a468a95
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/442280
Commit-Queue: Samuel Rawlins <[email protected]>
Reviewed-by: Konstantin Shcheglov <[email protected]>1 parent 6610e5c commit 9f127c9
1 file changed
+40
-44
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1428 | 1428 | | |
1429 | 1429 | | |
1430 | 1430 | | |
1431 | | - | |
1432 | | - | |
| 1431 | + | |
| 1432 | + | |
1433 | 1433 | | |
1434 | 1434 | | |
1435 | 1435 | | |
1436 | 1436 | | |
1437 | 1437 | | |
1438 | 1438 | | |
1439 | | - | |
| 1439 | + | |
1440 | 1440 | | |
1441 | 1441 | | |
1442 | 1442 | | |
1443 | | - | |
| 1443 | + | |
| 1444 | + | |
| 1445 | + | |
1444 | 1446 | | |
1445 | | - | |
1446 | | - | |
1447 | | - | |
1448 | | - | |
1449 | | - | |
1450 | | - | |
1451 | | - | |
1452 | | - | |
1453 | | - | |
1454 | | - | |
1455 | | - | |
1456 | | - | |
1457 | | - | |
1458 | | - | |
1459 | | - | |
1460 | | - | |
1461 | | - | |
1462 | | - | |
1463 | | - | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
1464 | 1453 | | |
1465 | | - | |
1466 | | - | |
| 1454 | + | |
1467 | 1455 | | |
1468 | | - | |
1469 | | - | |
1470 | | - | |
1471 | | - | |
1472 | | - | |
1473 | | - | |
1474 | | - | |
1475 | | - | |
1476 | | - | |
1477 | | - | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + | |
| 1459 | + | |
1478 | 1460 | | |
1479 | | - | |
1480 | | - | |
1481 | | - | |
1482 | | - | |
1483 | | - | |
1484 | | - | |
1485 | | - | |
1486 | | - | |
1487 | | - | |
| 1461 | + | |
| 1462 | + | |
| 1463 | + | |
| 1464 | + | |
| 1465 | + | |
| 1466 | + | |
| 1467 | + | |
| 1468 | + | |
| 1469 | + | |
| 1470 | + | |
1488 | 1471 | | |
1489 | 1472 | | |
| 1473 | + | |
| 1474 | + | |
| 1475 | + | |
| 1476 | + | |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
| 1481 | + | |
| 1482 | + | |
| 1483 | + | |
| 1484 | + | |
| 1485 | + | |
1490 | 1486 | | |
1491 | 1487 | | |
1492 | 1488 | | |
| |||
0 commit comments