- DownCastExact : Cases where the static type of rhs is exact
List<int> l = [1, 2, 3];
- DownCastDynamic : Cases where the static type of the rhs is a subtype (in Dart) of the static type of lhs:
List l = ...;
List<int> l2 = l;
R=jacobr@google.com
Review URL: https://chromereviews.googleplex.com/141647013
This CL adds a general reification pass which makes abstract coercions concrete by modifiying the ast. Casts are reified as "as" expressions, and wrappers are reified by creating functions which take the old function as arguments and produce a new wrapped function. There are a number of known issues not yet addressed:
1) No distinction between dart "as" and our special "as" is made yet.
2) Wrapper generation functions do not check for null arguments yet.
3) Types introduced via wrappers and "as" expressions are not yet added to the set of types for which new imports may be required.
4) Wrapper functions for non-literals can't be guaranteed not to change the runtime type without more backend support, since we only have their static type.
This CL also adds support for rewriting import directives in the dart backend to reflect the directory structure that we currently use for output. Probably this should be rethought. Currently I just use absolute file URIs, which is not what we want.
This CL also adds support for adding in the import directives needed to account for type names added via inference. This is not yet correct for "part of" files, since we need to add the imports to the main library file.
BUG=
R=vsm@google.com
Review URL: https://chromereviews.googleplex.com/137957013
This CL adds composite coercions which reify the choices made by the typechecker in allowing a closure wrapping as explicit casts and wrappers. The code generators should now be able to just walk the coercion generating the appropriate code. Thoughts or suggestions about the design of this very welcome.
The closure wrapping decision process has changed as well. Instead of simply checking reverse subtyping (which allowed some closure wrapping which would change the runtime type), we now essentially do a more extended subtype check which allows downcasts (and a few other conversions) on arguments, and attempts to wrap or downcast the body. This enables wrapping for a common pattern we have encountered in which an untyped (and hence dynamically typed) lambda is passed into a typed context. It also allows closure wrapping for some cases that we may (or may not) prefer to reject, such as allowing an int -> int to be coerced to an Object -> Object and vice versa.
In follow up CLs, I will add a reifier which translates coercions to ast nodes, and will add some flags to try out different closure wrapping strategies.
BUG=
R=vsm@google.com
Review URL: https://chromereviews.googleplex.com/132147015
This adds some checker tests for subtyping generics. One test checks that generics are invariant in various ways, another checks that raw type subtyping works, and the last test covers multiple raw type subtyping for multiple parameter generics.
For the last test, it's not clear that this is the behavior that we want, but it's what's currently implemented.
BUG=
R=vsm@google.com
Review URL: https://chromereviews.googleplex.com/130137014
We were getting some corner cases of function subtyping in the presence of named and optional parameters wrong. This CL fixes the function subtyping method, and adds a test for a range of cases.
BUG=
R=vsm@google.com
Review URL: https://chromereviews.googleplex.com/134847013
For now I ripped out the temp machinery. With the current writer there's no easy way to put the variable declaration in the right place. We can revive it when we have something, like the NestedPrinter from source_maps pkg. For now cascades are only generated when the target is a simple identifier. (That too is wrong in the case of getters, with multiple evaluations, but it's less wrong. At least we don't mess up the syntactic structure of the generated output.)
R=vsm@google.com
Review URL: https://chromereviews.googleplex.com/128587013