Fixes https://github.com/dart-lang/linter/issues/3046
The diff looks bigger than it is. The gist is:
* There is a check for if the ParenthesizedExpression is immediately
wrapped with parens. Move that check higher.
* There are broad exceptions for ConditionalExpressions and
TypeLiterals being wrapped with parens. Also move those higher.
* Add allowances for wrapped expressions which "directly" contain
whitespace, except for a few cases where the parens are still
considered unnecessary, such as an expression that is an argument.
* Add allowances for PrefixExpressions and PostfixExpressions which
are the "targets" of property access or method invocations.
Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Change-Id: I808586df874b20b064d4f4a0bd7775b2ec28442a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366891
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
The AST-to-IR conversion stage now handles the `AdjacentStrings` and
`StringInterpolation` AST nodes. This required adding the `concat`
instruction.
Although this support is not strictly necessary for the
proof-of-concept of wolf analysis, the presence of the `concat`
instruction will make testing of some later analysis stages easier,
notably SSA analysis, since it is a non-trivial operation that
produces a fresh value from one or more previous values.
Change-Id: I0915e0413db51e4c67617f61d8facc4e84909a7f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/339640
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
The AST-to-IR conversion stage now handles the AwaitExpression,
YieldStatement, and IsExpression AST nodes. This required adding the
`await_`, `yield_`, and `is_` instructions.
I believe this completes the proof-of-concept phase of AST-to-IR
conversion. I plan to move on now to implementing some lint rules
based on the IR representation.
Change-Id: I5f6e920dd04ca23d6b90d1522abf32955f757bc4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/337280
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
The AST-to-IR conversion stage now handles the DoStatement and
WhileStatement AST nodes, as well as simple ForStatement nodes (those
whose `forLoopParts` is `ForPartsWithDeclarations`). This required
adding the `loop` instruction. Unlabeled `break` and `continue`
statements are also supported.
Change-Id: Iaa46245755087e9f905988d65c4c2e0c33d283ab
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/337041
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
The AST-to-IR conversion stage now handles the MethodInvocation AST
node (which is used for both method invocations and top level function
invocations). This required adding the instruction `identical`, to
support invocations of the `identical()` function.
Change-Id: I7a4204f50c770874ff913e2cbeabb997958025c8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/336829
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
The AST-to-IR conversion stage now handles if statements, conditional
expressions, unary `!`, and binary `!=`. This required adding the
instruction `not`.
Change-Id: I2c87f95d8dfa1967ebe6c92c789c16254779c5bd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/336821
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
The AST-to-IR conversion stage now handles null-shorting property
accesses (both for reads and writes). This required adding the
following instruction types: `eq`, `block`, and `brIf`.
In order to make `eq` easier to test, support was also added for
AST-to-IR conversion of testing binary expressions using `==`.
The way null shorting is encoded in the IR is by issuing a `block`
instruction when null shorting starts, and an `end` instruction when
it terminates. Anywhere a null check appears within the null shorting
expression, the null check uses a `brIf(0)` instruction to branch to
the `end` in the case a `null` is found. To make it easier to keep
track of when `block` and `end` instructions need to be generated,
`RawIRWriter` keeps track of a count of the current nesting of control
flow contsructs.
In order for the interpreter to find to the appropriate `end`
instruction when a branch is taken, a new scope analyzer is
added. Later CLs will expand on it and use it for static analysis as
well.
Change-Id: I09ca34eaa900d47f7a4014cbc8db2a48a1d69e1e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/336800
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
The AST-to-IR conversion stage now handles reads and writes of
properties, whether through a `SimpleIdentifier` (via implicit
`this`), a `PrefixedIdentifier`, or a `PropertyAccess` AST node. In
order to make this easier to test, support was also added for
parenthesized expressions.
This required adding the following instruction types: `call` and
`shuffle`. To allow for thorough testing, support for these
instruction types was added to the interpreter and validator.
Change-Id: Ic60452422a877f358b0cad31b3c5664fd0585809
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/335701
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
This is a reland of commit b76d60340d
Original change's description:
> Add support for non-late local variables to the Wolf analysis prototype.
>
> The AST-to-IR conversion stage now handles function parameters, local
> variable declarations, `this`, and reads and writes of local
> variables. In order to make this easier to test, support was also
> added for block function bodies, expression statements, and return
> statements.
>
> This required adding the following instruction types: `alloc`, `br`,
> `drop`, `dup`, `readLocal`, `release`, and `writeLocal`. To allow for
> thorough testing, support for these instruction types was added to the
> interpreter and validator.
>
> Change-Id: Iedef6aa75297081d128e89a2ac24019a198cf948
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/335505
> Commit-Queue: Paul Berry <paulberry@google.com>
> Reviewed-by: Phil Quitslund <pquitslund@google.com>
Change-Id: I660947ff7adc6173508dcd69f625ced7e1d35721
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/336202
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
This reverts commit b76d60340d.
Reason for revert: Cbuild failures (old version of package:checks used internally)
I'll fix the internal code to use the latest package:checks before re-landing.
Original change's description:
> Add support for non-late local variables to the Wolf analysis prototype.
>
> The AST-to-IR conversion stage now handles function parameters, local
> variable declarations, `this`, and reads and writes of local
> variables. In order to make this easier to test, support was also
> added for block function bodies, expression statements, and return
> statements.
>
> This required adding the following instruction types: `alloc`, `br`,
> `drop`, `dup`, `readLocal`, `release`, and `writeLocal`. To allow for
> thorough testing, support for these instruction types was added to the
> interpreter and validator.
>
> Change-Id: Iedef6aa75297081d128e89a2ac24019a198cf948
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/335505
> Commit-Queue: Paul Berry <paulberry@google.com>
> Reviewed-by: Phil Quitslund <pquitslund@google.com>
Change-Id: I4ae22c6e0dfcd9ae7d60c994b5bde8dc24158105
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/335950
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
The AST-to-IR conversion stage now handles function parameters, local
variable declarations, `this`, and reads and writes of local
variables. In order to make this easier to test, support was also
added for block function bodies, expression statements, and return
statements.
This required adding the following instruction types: `alloc`, `br`,
`drop`, `dup`, `readLocal`, `release`, and `writeLocal`. To allow for
thorough testing, support for these instruction types was added to the
interpreter and validator.
Change-Id: Iedef6aa75297081d128e89a2ac24019a198cf948
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/335505
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Wolf analysis is an experimental part of the analyzer that I intend to
use as the basis for new, more advanced, lint rules and other
analyses. Its first phase will consist of lowering the abstract syntax
of each function or method to a stream of instructions for a minimal
stack machine.
This code implements the first few instructions for the minimal stack
machine (`function`, `end`, `literal`, and `drop`). These are
sufficient to express a simple function like:
int f() => 0;
Which maps to the following instruction stream:
function(int Function(), 0)
literal(0)
end
This code includes a validator that verifies that an instruction
stream is well-formed. In follow-up CLs I will add logic to convert an
analyzer AST to an instruction stream.
The internal representation of an instruction stream is code
genreated, because:
- I intend to add additional instructions in follow-up CLs, and I
don't want to have to remember all the boilerplate for adding an
instruction each time.
- Once the implementation is far enough along to start consuming large
amounts of real-world Dart code, I would like to be able to
investigate the performance effects of changing the internal
representation. Code generation will make this a lot easier.
Change-Id: I4bc299d31ed108f6eebf9cca913d1484dbc9a3cf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/334644
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>