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

Side by Side Diff: pkg/compiler/lib/src/kernel/kernel_visitor.dart

Issue 2691753002: Add deferred loading to Kernel. (Closed)
Patch Set: . Created 3 years, 10 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 unified diff | Download patch
« no previous file with comments | « no previous file | pkg/compiler/lib/src/kernel/task.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE.md file. 3 // BSD-style license that can be found in the LICENSE.md file.
4 4
5 import 'package:kernel/ast.dart' as ir; 5 import 'package:kernel/ast.dart' as ir;
6 import 'package:kernel/frontend/accessors.dart' 6 import 'package:kernel/frontend/accessors.dart'
7 show 7 show
8 Accessor, 8 Accessor,
9 IndexAccessor, 9 IndexAccessor,
10 NullAwarePropertyAccessor, 10 NullAwarePropertyAccessor,
(...skipping 29 matching lines...) Expand all
40 AsyncMarker, 40 AsyncMarker,
41 ClassElement, 41 ClassElement,
42 ConstructorElement, 42 ConstructorElement,
43 Element, 43 Element,
44 FieldElement, 44 FieldElement,
45 FunctionElement, 45 FunctionElement,
46 FunctionSignature, 46 FunctionSignature,
47 GetterElement, 47 GetterElement,
48 InitializingFormalElement, 48 InitializingFormalElement,
49 JumpTarget, 49 JumpTarget,
50 LibraryElement,
50 LocalElement, 51 LocalElement,
51 LocalFunctionElement, 52 LocalFunctionElement,
52 LocalVariableElement, 53 LocalVariableElement,
53 MethodElement, 54 MethodElement,
54 Name, 55 Name,
55 ParameterElement, 56 ParameterElement,
56 PrefixElement, 57 PrefixElement,
57 TypeVariableElement; 58 TypeVariableElement;
58 import '../resolution/operators.dart' 59 import '../resolution/operators.dart'
59 show AssignmentOperator, BinaryOperator, IncDecOperator, UnaryOperator; 60 show AssignmentOperator, BinaryOperator, IncDecOperator, UnaryOperator;
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 196
196 final Map<JumpTarget, ir.LabeledStatement> breakTargets = 197 final Map<JumpTarget, ir.LabeledStatement> breakTargets =
197 <JumpTarget, ir.LabeledStatement>{}; 198 <JumpTarget, ir.LabeledStatement>{};
198 199
199 final Map<LocalElement, ir.VariableDeclaration> locals = 200 final Map<LocalElement, ir.VariableDeclaration> locals =
200 <LocalElement, ir.VariableDeclaration>{}; 201 <LocalElement, ir.VariableDeclaration>{};
201 202
202 final Map<CascadeReceiver, ir.VariableGet> cascadeReceivers = 203 final Map<CascadeReceiver, ir.VariableGet> cascadeReceivers =
203 <CascadeReceiver, ir.VariableGet>{}; 204 <CascadeReceiver, ir.VariableGet>{};
204 205
206 // This maps underlying Library elements to the corresponding DeferredImport
207 // object, via the prefix name (aka "bar" in
208 // "import foo.dart deferred as bar"). LibraryElement corresponds to the
209 // imported library element.
210 final Map<LibraryElement, Map<String, ir.DeferredImport>> deferredImports =
211 <LibraryElement, Map<String, ir.DeferredImport>>{};
212
205 ir.Node associateElement(ir.Node node, Element element) { 213 ir.Node associateElement(ir.Node node, Element element) {
206 kernel.nodeToElement[node] = element; 214 kernel.nodeToElement[node] = element;
207 return node; 215 return node;
208 } 216 }
209 217
210 ir.Node associateNode(ir.Node node, Node ast) { 218 ir.Node associateNode(ir.Node node, Node ast) {
211 kernel.nodeToAst[node] = ast; 219 kernel.nodeToAst[node] = ast;
212 return node; 220 return node;
213 } 221 }
214 222
215 bool isVoidContext = false; 223 bool isVoidContext = false;
216 224
225 /// If non-null, reference to a deferred library that a subsequent getter is
226 /// using.
227 ir.DeferredImport _deferredLibrary;
228
217 KernelVisitor(this.currentElement, this.elements, this.kernel); 229 KernelVisitor(this.currentElement, this.elements, this.kernel);
218 230
219 KernelVisitor get sendVisitor => this; 231 KernelVisitor get sendVisitor => this;
220 232
221 KernelVisitor get declVisitor => this; 233 KernelVisitor get declVisitor => this;
222 234
223 ir.TreeNode visitForValue(Expression node) { 235 ir.TreeNode visitForValue(Expression node) {
224 bool wasVoidContext = isVoidContext; 236 bool wasVoidContext = isVoidContext;
225 isVoidContext = false; 237 isVoidContext = false;
226 try { 238 try {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 368
357 @override 369 @override
358 ir.Expression handleError(Node node) => new ir.InvalidExpression(); 370 ir.Expression handleError(Node node) => new ir.InvalidExpression();
359 371
360 @override 372 @override
361 void apply(Node node, _) { 373 void apply(Node node, _) {
362 throw new UnsupportedError("apply"); 374 throw new UnsupportedError("apply");
363 } 375 }
364 376
365 @override 377 @override
366 void previsitDeferredAccess(Send node, PrefixElement prefix, _) {} 378 void previsitDeferredAccess(Send node, PrefixElement prefix, _) {
379 // This is visited before any element access, and if it is deferred,
380 // prefix.isDeferred = true.
381 if (prefix != null && prefix.isDeferred) {
382 _deferredLibrary = getDeferredImport(prefix);
383 } else {
384 _deferredLibrary = null;
385 }
386 }
367 387
368 @override 388 @override
369 internalError(Spannable spannable, String message) { 389 internalError(Spannable spannable, String message) {
370 kernel.internalError(spannable, message); 390 kernel.internalError(spannable, message);
371 } 391 }
372 392
373 @override 393 @override
374 applyParameters(NodeList parameters, _) { 394 applyParameters(NodeList parameters, _) {
375 throw new UnsupportedError("applyParameters"); 395 throw new UnsupportedError("applyParameters");
376 } 396 }
(...skipping 1610 matching lines...) Expand 10 before | Expand all | Expand 10 after
1987 } 2007 }
1988 2008
1989 @override 2009 @override
1990 visitStaticFieldDeclaration(VariableDefinitions node, Node definition, 2010 visitStaticFieldDeclaration(VariableDefinitions node, Node definition,
1991 FieldElement field, Node initializer, _) { 2011 FieldElement field, Node initializer, _) {
1992 // Shouldn't be called, handled by fieldToIr. 2012 // Shouldn't be called, handled by fieldToIr.
1993 return internalError(node, "StaticFieldDeclaration"); 2013 return internalError(node, "StaticFieldDeclaration");
1994 } 2014 }
1995 2015
1996 ir.Expression buildStaticGet(Element element) { 2016 ir.Expression buildStaticGet(Element element) {
1997 return buildStaticAccessor(element).buildSimpleRead(); 2017 var expression = buildStaticAccessor(element).buildSimpleRead();
2018 if (_deferredLibrary != null) {
2019 ir.Let let = new ir.Let(
2020 makeOrReuseVariable(new ir.CheckLibraryIsLoaded(_deferredLibrary)),
2021 expression);
2022 return let;
2023 }
2024 return expression;
1998 } 2025 }
1999 2026
2000 @override 2027 @override
2001 ir.Expression handleStaticFieldGet(Send node, FieldElement field, _) { 2028 ir.Expression handleStaticFieldGet(Send node, FieldElement field, _) {
2002 return associateNode(buildStaticGet(field), node); 2029 return associateNode(buildStaticGet(field), node);
2003 } 2030 }
2004 2031
2005 @override 2032 @override
2006 ir.MethodInvocation handleStaticFieldInvoke(Send node, FieldElement field, 2033 ir.MethodInvocation handleStaticFieldInvoke(Send node, FieldElement field,
2007 NodeList arguments, CallStructure callStructure, _) { 2034 NodeList arguments, CallStructure callStructure, _) {
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
2222 return buildStaticAccessor(function) 2249 return buildStaticAccessor(function)
2223 .buildAssignment(visitForValue(rhs), voidContext: isVoidContext); 2250 .buildAssignment(visitForValue(rhs), voidContext: isVoidContext);
2224 } 2251 }
2225 2252
2226 @override 2253 @override
2227 IrFunction visitStaticGetterDeclaration( 2254 IrFunction visitStaticGetterDeclaration(
2228 FunctionExpression node, MethodElement getter, Node body, _) { 2255 FunctionExpression node, MethodElement getter, Node body, _) {
2229 return buildIrFunction(ir.ProcedureKind.Getter, getter, body); 2256 return buildIrFunction(ir.ProcedureKind.Getter, getter, body);
2230 } 2257 }
2231 2258
2259 ir.DeferredImport getDeferredImport(PrefixElement prefix) {
2260 var map = deferredImports[prefix.deferredImport.importedLibrary] ??=
2261 <String, ir.DeferredImport>{};
2262 return map[prefix.name] ??= associateElement(
2263 new ir.DeferredImport(
2264 kernel.libraries[prefix.deferredImport.importedLibrary],
2265 prefix.name),
2266 prefix);
2267 }
2268
2232 @override 2269 @override
2233 ir.Expression handleStaticGetterGet(Send node, FunctionElement getter, _) { 2270 ir.Expression handleStaticGetterGet(Send node, FunctionElement getter, _) {
2234 if (getter.isDeferredLoaderGetter) { 2271 if (getter.isDeferredLoaderGetter) {
2235 // TODO(ahe): Support deferred load. 2272 return new ir.LoadLibrary(getDeferredImport(getter.enclosingElement));
2236 return new ir.InvalidExpression();
2237 } 2273 }
2238 return buildStaticGet(getter); 2274 var expression = buildStaticGet(getter);
2275 return expression;
2239 } 2276 }
2240 2277
2241 @override 2278 @override
2242 ir.Expression handleStaticGetterInvoke(Send node, FunctionElement getter, 2279 ir.Expression handleStaticGetterInvoke(Send node, FunctionElement getter,
2243 NodeList arguments, CallStructure callStructure, _) { 2280 NodeList arguments, CallStructure callStructure, _) {
2281 var expression;
2244 if (getter.isDeferredLoaderGetter) { 2282 if (getter.isDeferredLoaderGetter) {
2245 // TODO(ahe): Support deferred load. 2283 expression =
2246 return new ir.InvalidExpression(); 2284 new ir.LoadLibrary(getDeferredImport(getter.enclosingElement));
2285 } else {
2286 expression = buildStaticGet(getter);
2247 } 2287 }
2248 return associateNode( 2288 return associateNode(buildCall(expression, callStructure, arguments), node);
2249 buildCall(buildStaticGet(getter), callStructure, arguments), node);
2250 } 2289 }
2251 2290
2252 @override 2291 @override
2253 ir.Expression handleStaticGetterSet( 2292 ir.Expression handleStaticGetterSet(
2254 SendSet node, FunctionElement getter, Node rhs, _) { 2293 SendSet node, FunctionElement getter, Node rhs, _) {
2255 return buildStaticAccessor(getter) 2294 return buildStaticAccessor(getter)
2256 .buildAssignment(visitForValue(rhs), voidContext: isVoidContext); 2295 .buildAssignment(visitForValue(rhs), voidContext: isVoidContext);
2257 } 2296 }
2258 2297
2259 @override 2298 @override
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
2867 : this(null, true, node, initializers); 2906 : this(null, true, node, initializers);
2868 2907
2869 accept(ir.Visitor v) => throw "unsupported"; 2908 accept(ir.Visitor v) => throw "unsupported";
2870 2909
2871 visitChildren(ir.Visitor v) => throw "unsupported"; 2910 visitChildren(ir.Visitor v) => throw "unsupported";
2872 2911
2873 String toString() { 2912 String toString() {
2874 return "IrFunction($kind, $isConstructor, $node, $initializers)"; 2913 return "IrFunction($kind, $isConstructor, $node, $initializers)";
2875 } 2914 }
2876 } 2915 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/kernel/task.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698