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

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

Issue 2691753002: Add deferred loading to Kernel. (Closed)
Patch Set: sra's comments 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").
sra1 2017/02/14 21:55:28 Is the 'underlying' library element the current li
Emily Fortuna 2017/02/15 01:02:31 updated the comment -- imported library.
209 final Map<LibraryElement, Map<String, ir.DeferredImport>> deferredImports =
210 <LibraryElement, Map<String, ir.DeferredImport>>{};
211
205 ir.Node associateElement(ir.Node node, Element element) { 212 ir.Node associateElement(ir.Node node, Element element) {
206 kernel.nodeToElement[node] = element; 213 kernel.nodeToElement[node] = element;
207 return node; 214 return node;
208 } 215 }
209 216
210 ir.Node associateNode(ir.Node node, Node ast) { 217 ir.Node associateNode(ir.Node node, Node ast) {
211 kernel.nodeToAst[node] = ast; 218 kernel.nodeToAst[node] = ast;
212 return node; 219 return node;
213 } 220 }
214 221
215 bool isVoidContext = false; 222 bool isVoidContext = false;
216 223
224 /// If non-null, reference to a deferred library that a subsequent getter is
225 /// using.
226 ir.DeferredImport _deferredLibrary;
227
217 KernelVisitor(this.currentElement, this.elements, this.kernel); 228 KernelVisitor(this.currentElement, this.elements, this.kernel);
218 229
219 KernelVisitor get sendVisitor => this; 230 KernelVisitor get sendVisitor => this;
220 231
221 KernelVisitor get declVisitor => this; 232 KernelVisitor get declVisitor => this;
222 233
223 ir.TreeNode visitForValue(Expression node) { 234 ir.TreeNode visitForValue(Expression node) {
224 bool wasVoidContext = isVoidContext; 235 bool wasVoidContext = isVoidContext;
225 isVoidContext = false; 236 isVoidContext = false;
226 try { 237 try {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 367
357 @override 368 @override
358 ir.Expression handleError(Node node) => new ir.InvalidExpression(); 369 ir.Expression handleError(Node node) => new ir.InvalidExpression();
359 370
360 @override 371 @override
361 void apply(Node node, _) { 372 void apply(Node node, _) {
362 throw new UnsupportedError("apply"); 373 throw new UnsupportedError("apply");
363 } 374 }
364 375
365 @override 376 @override
366 void previsitDeferredAccess(Send node, PrefixElement prefix, _) {} 377 void previsitDeferredAccess(Send node, PrefixElement prefix, _) {
378 // This is visited before any element access, and if it is deferred,
379 // prefix.isDeferred = true.
380 if (prefix != null && prefix.isDeferred) {
381 _deferredLibrary = getDeferredImport(prefix);
382 } else {
383 _deferredLibrary = null;
384 }
385 }
367 386
368 @override 387 @override
369 internalError(Spannable spannable, String message) { 388 internalError(Spannable spannable, String message) {
370 kernel.internalError(spannable, message); 389 kernel.internalError(spannable, message);
371 } 390 }
372 391
373 @override 392 @override
374 applyParameters(NodeList parameters, _) { 393 applyParameters(NodeList parameters, _) {
375 throw new UnsupportedError("applyParameters"); 394 throw new UnsupportedError("applyParameters");
376 } 395 }
(...skipping 1610 matching lines...) Expand 10 before | Expand all | Expand 10 after
1987 } 2006 }
1988 2007
1989 @override 2008 @override
1990 visitStaticFieldDeclaration(VariableDefinitions node, Node definition, 2009 visitStaticFieldDeclaration(VariableDefinitions node, Node definition,
1991 FieldElement field, Node initializer, _) { 2010 FieldElement field, Node initializer, _) {
1992 // Shouldn't be called, handled by fieldToIr. 2011 // Shouldn't be called, handled by fieldToIr.
1993 return internalError(node, "StaticFieldDeclaration"); 2012 return internalError(node, "StaticFieldDeclaration");
1994 } 2013 }
1995 2014
1996 ir.Expression buildStaticGet(Element element) { 2015 ir.Expression buildStaticGet(Element element) {
1997 return buildStaticAccessor(element).buildSimpleRead(); 2016 var expression = buildStaticAccessor(element).buildSimpleRead();
2017 if (_deferredLibrary != null) {
2018 ir.Let let = new ir.Let(
2019 makeOrReuseVariable(new ir.CheckLibraryIsLoaded(_deferredLibrary)),
2020 expression);
2021 return let;
2022 }
2023 return expression;
1998 } 2024 }
1999 2025
2000 @override 2026 @override
2001 ir.Expression handleStaticFieldGet(Send node, FieldElement field, _) { 2027 ir.Expression handleStaticFieldGet(Send node, FieldElement field, _) {
2002 return associateNode(buildStaticGet(field), node); 2028 return associateNode(buildStaticGet(field), node);
2003 } 2029 }
2004 2030
2005 @override 2031 @override
2006 ir.MethodInvocation handleStaticFieldInvoke(Send node, FieldElement field, 2032 ir.MethodInvocation handleStaticFieldInvoke(Send node, FieldElement field,
2007 NodeList arguments, CallStructure callStructure, _) { 2033 NodeList arguments, CallStructure callStructure, _) {
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
2222 return buildStaticAccessor(function) 2248 return buildStaticAccessor(function)
2223 .buildAssignment(visitForValue(rhs), voidContext: isVoidContext); 2249 .buildAssignment(visitForValue(rhs), voidContext: isVoidContext);
2224 } 2250 }
2225 2251
2226 @override 2252 @override
2227 IrFunction visitStaticGetterDeclaration( 2253 IrFunction visitStaticGetterDeclaration(
2228 FunctionExpression node, MethodElement getter, Node body, _) { 2254 FunctionExpression node, MethodElement getter, Node body, _) {
2229 return buildIrFunction(ir.ProcedureKind.Getter, getter, body); 2255 return buildIrFunction(ir.ProcedureKind.Getter, getter, body);
2230 } 2256 }
2231 2257
2258 ir.DeferredImport getDeferredImport(PrefixElement prefix) {
2259 ir.DeferredImport deferredImport;
2260 var importedLibraryElement = prefix.deferredImport.importedLibrary;
2261 if (deferredImports.containsKey(importedLibraryElement)) {
2262 var prefixToDeferredImport = deferredImports[importedLibraryElement];
sra1 2017/02/14 21:55:28 Nowadays I find ??= more convenient var map = def
Emily Fortuna 2017/02/15 01:02:31 Done.
2263 deferredImport =
2264 prefixToDeferredImport.putIfAbsent(prefix.name, () {
2265 return new ir.DeferredImport(kernel.libraries[importedLibraryElement],
2266 prefix.name);
2267 });
2268 } else {
2269 deferredImport = new ir.DeferredImport(
2270 kernel.libraries[importedLibraryElement], prefix.name);
2271 deferredImports[importedLibraryElement] = {prefix.name: deferredImport};
sra1 2017/02/14 21:55:28 Type parameters on literal.
Emily Fortuna 2017/02/15 01:02:31 Done.
2272 }
2273 return deferredImport;
2274 }
2275
2232 @override 2276 @override
2233 ir.Expression handleStaticGetterGet(Send node, FunctionElement getter, _) { 2277 ir.Expression handleStaticGetterGet(Send node, FunctionElement getter, _) {
2234 if (getter.isDeferredLoaderGetter) { 2278 if (getter.isDeferredLoaderGetter) {
2235 // TODO(ahe): Support deferred load. 2279 return new ir.LoadLibrary(getDeferredImport(getter.enclosingElement));
2236 return new ir.InvalidExpression();
2237 } 2280 }
2238 return buildStaticGet(getter); 2281 var expression = buildStaticGet(getter);
2282 return expression;
2239 } 2283 }
2240 2284
2241 @override 2285 @override
2242 ir.Expression handleStaticGetterInvoke(Send node, FunctionElement getter, 2286 ir.Expression handleStaticGetterInvoke(Send node, FunctionElement getter,
2243 NodeList arguments, CallStructure callStructure, _) { 2287 NodeList arguments, CallStructure callStructure, _) {
2288 var expression;
2244 if (getter.isDeferredLoaderGetter) { 2289 if (getter.isDeferredLoaderGetter) {
2245 // TODO(ahe): Support deferred load. 2290 expression = new ir.LoadLibrary(getDeferredImport(
2246 return new ir.InvalidExpression(); 2291 getter.enclosingElement));
2292 } else {
2293 expression = buildStaticGet(getter);
2247 } 2294 }
2248 return associateNode( 2295 return associateNode(buildCall(expression, callStructure, arguments), node);
2249 buildCall(buildStaticGet(getter), callStructure, arguments), node);
2250 } 2296 }
2251 2297
2252 @override 2298 @override
2253 ir.Expression handleStaticGetterSet( 2299 ir.Expression handleStaticGetterSet(
2254 SendSet node, FunctionElement getter, Node rhs, _) { 2300 SendSet node, FunctionElement getter, Node rhs, _) {
2255 return buildStaticAccessor(getter) 2301 return buildStaticAccessor(getter)
2256 .buildAssignment(visitForValue(rhs), voidContext: isVoidContext); 2302 .buildAssignment(visitForValue(rhs), voidContext: isVoidContext);
2257 } 2303 }
2258 2304
2259 @override 2305 @override
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
2867 : this(null, true, node, initializers); 2913 : this(null, true, node, initializers);
2868 2914
2869 accept(ir.Visitor v) => throw "unsupported"; 2915 accept(ir.Visitor v) => throw "unsupported";
2870 2916
2871 visitChildren(ir.Visitor v) => throw "unsupported"; 2917 visitChildren(ir.Visitor v) => throw "unsupported";
2872 2918
2873 String toString() { 2919 String toString() {
2874 return "IrFunction($kind, $isConstructor, $node, $initializers)"; 2920 return "IrFunction($kind, $isConstructor, $node, $initializers)";
2875 } 2921 }
2876 } 2922 }
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