-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add type tracking to type inference logging.
This commit updates the type inference logging logic introduced in https://dart-review.googlesource.com/c/sdk/+/369788 so that it additionally tracks the context and static type for each inferred expression. Tracking the context for each expression is easy, since it is an input to the type inference algorithm, passed in to each `visit` method of `ResolverVisitor` through the named parameter `contextType`. However, there were a few expression types for which the context type *wasn't* passed in, because it wasn't used (for example `ResolverVisitor.visitBooleanLiteral`, since boolean literals always have the same meaning regardless of their context). `contextType` parameters have been added to these `visit` methods for consistency with the other expression visit methods, so that the type inference log shows the context for all expressions, whether it makes a difference to inference or not. Tracking the static type for each expression is a little trickier, since it's not an explicit output of the type inference algorithm, but rather the static type of each expression is set as a side effect of the type inference mechanism. To make things more tractable, the `ExpressionImpl.staticType` field is made private, and instead of setting it directly, the resolver must set it by either calling `recordStaticType` or `setPseudoExpressionStaticType`. The former is used when resolving a real expression; the latter is used for situations where the analyzer assigns a static type to an AST node even though that AST node isn't really serving as an expression according to the official language specification. (For example, when analyzing the method invocation `x.foo()`, the analyzer stores a static type on the SimpleIdentifier `foo`, even though according to the language spec, `foo` in this context actually isn't an expression in its own right). Splitting the code paths that set static types into `recordStaticType` and `setPseudoExpressionStaticType` allows for the type inference logging mechanism to check some useful invariants: it verifies that every expression that the resolver visits is either assigned a static type exactly once through a call to `recordStaticType`, or it's determined to not be a true expression (and hence not assigned a static type at all); I believe the latter happens mostly when analyzing erroneous code, or when the resolver visitor is called upon to assign a type to an identifier that's in a declaration context. Change-Id: Icdf023d03fba3c87dbec3a72d00d0e9c7d1da5fa Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/370322 Reviewed-by: Chloe Stefantsova <[email protected]> Commit-Queue: Paul Berry <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
- Loading branch information
1 parent
8e219fc
commit 172bbe0
Showing
26 changed files
with
423 additions
and
334 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.