Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(577)

Unified Diff: lib/src/codegen/reify_coercions.dart

Issue 1038213003: Downward inference (Closed) Base URL: git@github.com:dart-lang/dart-dev-compiler.git@master
Patch Set: Rebase Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/checker/rules.dart ('k') | lib/src/info.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/codegen/reify_coercions.dart
diff --git a/lib/src/codegen/reify_coercions.dart b/lib/src/codegen/reify_coercions.dart
index fbedd451b83c84aeddc04820fb19284ee34ce818..8bbace34346931b1efc5d30ead419d2aa40d48ae 100644
--- a/lib/src/codegen/reify_coercions.dart
+++ b/lib/src/codegen/reify_coercions.dart
@@ -33,6 +33,40 @@ class _LocatedWrapper {
_LocatedWrapper(this.wrapper, this.loc);
}
+class _Inference extends DownwardsInference {
+ TypeManager _tm;
+
+ _Inference(TypeRules rules, this._tm) : super(rules);
+
+ @override
+ void annotateListLiteral(ListLiteral e, List<DartType> targs) {
+ var tNames = targs.map(_tm.typeNameFromDartType).toList();
+ e.typeArguments = AstBuilder.typeArgumentList(tNames);
+ var listT = rules.provider.listType.substitute4(targs);
+ e.staticType = listT;
+ }
+
+ @override
+ void annotateMapLiteral(MapLiteral e, List<DartType> targs) {
+ var tNames = targs.map(_tm.typeNameFromDartType).toList();
+ e.typeArguments = AstBuilder.typeArgumentList(tNames);
+ var mapT = rules.provider.mapType.substitute4(targs);
+ e.staticType = mapT;
+ }
+
+ @override
+ void annotateInstanceCreationExpression(
+ InstanceCreationExpression e, List<DartType> targs) {
+ var tNames = targs.map(_tm.typeNameFromDartType).toList();
+ var cName = e.constructorName;
+ var id = cName.type.name;
+ var typeName = AstBuilder.typeName(id, tNames);
+ cName.type = typeName;
+ var rawType = (e.staticType.element as ClassElement).type;
+ e.staticType = rawType.substitute4(targs);
+ }
+}
+
// This class implements a pass which modifies (in place) the ast replacing
// abstract coercion nodes with their dart implementations.
class UnitCoercionReifier extends analyzer.GeneralizingAstVisitor<Object>
@@ -43,9 +77,11 @@ class UnitCoercionReifier extends analyzer.GeneralizingAstVisitor<Object>
SourceFile _file;
bool _skipCoercions = false;
final TypeRules _rules;
+ _Inference _inferrer;
UnitCoercionReifier(this._tm, this._vm, this._rules) {
_cm = new CoercionManager(_vm, _tm, _rules);
+ _inferrer = new _Inference(_rules, _tm);
}
// This should be the entry point for this class. Entering via the
@@ -78,9 +114,7 @@ class UnitCoercionReifier extends analyzer.GeneralizingAstVisitor<Object>
if (node is ClosureWrap) return "Wrap";
if (node is DynamicCast) return "DynamicCast";
if (node is AssignmentCast) return "AssignmentCast";
- if (node is InferableLiteral) return "InferableLiteral";
if (node is InferableClosure) return "InferableClosure";
- if (node is InferableAllocation) return "InferableAllocation";
if (node is DownCastComposite) return "CompositeCast";
if (node is DownCastImplicit) return "ImplicitCast";
assert(false);
@@ -101,6 +135,18 @@ class UnitCoercionReifier extends analyzer.GeneralizingAstVisitor<Object>
}
@override
+ Object visitInferredTypeBase(InferredTypeBase node) {
+ var expr = node.node;
+ var b = _inferrer.inferExpression(expr, node.type);
+ assert(b);
+ if (!NodeReplacer.replace(node, expr)) {
+ _log.severe("Failed to replace node for InferredType");
+ }
+ expr.accept(this);
+ return null;
+ }
+
+ @override
Object visitDownCast(DownCast node) {
if (_skipCoercions) {
_log.severe("Skipping runtime downcast in constant context");
« no previous file with comments | « lib/src/checker/rules.dart ('k') | lib/src/info.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698