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

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

Issue 2338093002: Build entire program with kernel for conversion to ssa. (Closed)
Patch Set: some tweaks Created 4 years, 3 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
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 'dart:async';
5 import 'dart:collection' show Queue; 6 import 'dart:collection' show Queue;
6 7
7 import 'package:kernel/ast.dart' as ir; 8 import 'package:kernel/ast.dart' as ir;
8 import 'package:kernel/checks.dart' show CheckParentPointers; 9 import 'package:kernel/checks.dart' show CheckParentPointers;
9 10
10 import '../compiler.dart' show Compiler; 11 import '../compiler.dart' show Compiler;
11 import '../constants/expressions.dart' show TypeConstantExpression; 12 import '../constants/expressions.dart' show TypeConstantExpression;
12 import '../dart_types.dart' 13 import '../dart_types.dart'
13 show DartType, FunctionType, InterfaceType, TypeKind, TypeVariableType; 14 show DartType, FunctionType, InterfaceType, TypeKind, TypeVariableType;
14 import '../diagnostics/messages.dart' show MessageKind; 15 import '../diagnostics/messages.dart' show MessageKind;
15 import '../diagnostics/spannable.dart' show Spannable; 16 import '../diagnostics/spannable.dart' show Spannable;
16 import '../elements/elements.dart' 17 import '../elements/elements.dart'
17 show 18 show
18 ClassElement, 19 ClassElement,
19 ConstructorElement, 20 ConstructorElement,
20 Element, 21 Element,
22 ExportElement,
21 FieldElement, 23 FieldElement,
22 FunctionElement, 24 FunctionElement,
25 ImportElement,
23 LibraryElement, 26 LibraryElement,
24 MixinApplicationElement, 27 MixinApplicationElement,
25 TypeVariableElement; 28 TypeVariableElement;
26 import '../elements/modelx.dart' show ErroneousFieldElementX; 29 import '../elements/modelx.dart' show ErroneousFieldElementX;
27 import '../tree/tree.dart' show FunctionExpression, Node; 30 import '../tree/tree.dart' show FunctionExpression, Node;
28 import 'kernel_visitor.dart' show IrFunction, KernelVisitor; 31 import 'kernel_visitor.dart' show IrFunction, KernelVisitor;
29 32
30 typedef void WorkAction(); 33 typedef void WorkAction();
31 34
32 class WorkItem { 35 class WorkItem {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 ClassElement cls = element.enclosingClass; 113 ClassElement cls = element.enclosingClass;
111 if (cls != null && cls.isMixinApplication) { 114 if (cls != null && cls.isMixinApplication) {
112 MixinApplicationElement mixinApplication = cls; 115 MixinApplicationElement mixinApplication = cls;
113 element = mixinApplication.mixin; 116 element = mixinApplication.mixin;
114 } 117 }
115 irLibrary = libraryToIr(element.library); 118 irLibrary = libraryToIr(element.library);
116 } 119 }
117 return new ir.Name(name, irLibrary); 120 return new ir.Name(name, irLibrary);
118 } 121 }
119 122
123 Future<ir.Library> loadLibrary(Uri uri) async {
124 return libraryToIr(await compiler.libraryLoader.loadLibrary(uri));
125 }
126
120 ir.Library libraryToIr(LibraryElement library) { 127 ir.Library libraryToIr(LibraryElement library) {
121 library = library.declaration; 128 library = library.declaration;
122 return libraries.putIfAbsent(library, () { 129 return libraries.putIfAbsent(library, () {
123 String name = library.hasLibraryName ? library.libraryName : null; 130 String name = library.hasLibraryName ? library.libraryName : null;
124 ir.Library libraryNode = new ir.Library(library.canonicalUri, 131 ir.Library libraryNode = new ir.Library(library.canonicalUri,
125 name: name, classes: null, procedures: null, fields: null); 132 name: name, classes: null, procedures: null, fields: null);
126 addWork(library, () { 133 addWork(library, () {
127 Queue<ir.Class> classes = new Queue<ir.Class>(); 134 Queue<ir.Class> classes = new Queue<ir.Class>();
128 Queue<ir.Member> members = new Queue<ir.Member>(); 135 Queue<ir.Member> members = new Queue<ir.Member>();
129 library.implementation.forEachLocalMember((Element e) { 136 library.implementation.forEachLocalMember((Element e) {
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 void debugMessage(Spannable spannable, String message) { 489 void debugMessage(Spannable spannable, String message) {
483 compiler.reporter 490 compiler.reporter
484 .reportHintMessage(spannable, MessageKind.GENERIC, {'text': message}); 491 .reportHintMessage(spannable, MessageKind.GENERIC, {'text': message});
485 } 492 }
486 493
487 void internalError(Spannable spannable, String message) { 494 void internalError(Spannable spannable, String message) {
488 compiler.reporter.internalError(spannable, message); 495 compiler.reporter.internalError(spannable, message);
489 throw message; 496 throw message;
490 } 497 }
491 498
499 forEachLibraryElement(f(LibraryElement library)) {
500 return compiler.libraryLoader.libraries.forEach(f);
501 }
502
492 ConstructorTarget computeEffectiveTarget( 503 ConstructorTarget computeEffectiveTarget(
493 ConstructorElement constructor, DartType type) { 504 ConstructorElement constructor, DartType type) {
494 constructor = constructor.implementation; 505 constructor = constructor.implementation;
495 Set<ConstructorElement> seen = new Set<ConstructorElement>(); 506 Set<ConstructorElement> seen = new Set<ConstructorElement>();
496 functionToIr(constructor); 507 functionToIr(constructor);
497 while (constructor != constructor.effectiveTarget) { 508 while (constructor != constructor.effectiveTarget) {
498 type = constructor.computeEffectiveTargetType(type); 509 type = constructor.computeEffectiveTargetType(type);
499 if (constructor.isGenerativeConstructor) break; 510 if (constructor.isGenerativeConstructor) break;
500 if (!seen.add(constructor)) break; 511 if (!seen.add(constructor)) break;
501 constructor = constructor.effectiveTarget.implementation; 512 constructor = constructor.effectiveTarget.implementation;
502 if (isSyntheticError(constructor)) break; 513 if (isSyntheticError(constructor)) break;
503 functionToIr(constructor); 514 functionToIr(constructor);
504 } 515 }
505 return new ConstructorTarget(constructor, type); 516 return new ConstructorTarget(constructor, type);
506 } 517 }
507 518
519 /// Compute all the dependencies on the library with [uri] (including the
520 /// library itself). This is useful for creating a Kernel IR `Program`.
521 List<ir.Library> libraryDependencies(Uri uri) {
522 List<ir.Library> result = <ir.Library>[];
523 Queue<LibraryElement> notProcessed = new Queue<LibraryElement>();
524 Set<LibraryElement> seen = new Set<LibraryElement>();
525 LibraryElement library = compiler.libraryLoader.lookupLibrary(uri);
526 void processLater(LibraryElement library) {
527 if (library != null) {
528 notProcessed.addLast(library);
529 }
530 }
531
532 processLater(library);
533 seen.add(library);
534 LibraryElement core =
535 compiler.libraryLoader.lookupLibrary(Uri.parse("dart:core"));
536 if (seen.add(core)) {
537 // `dart:core` is implicitly imported by most libraries, and for some
538 // reason not included in `library.imports` below.
539 processLater(core);
540 }
541 while (notProcessed.isNotEmpty) {
542 LibraryElement library = notProcessed.removeFirst();
543 ir.Library irLibrary = libraryToIr(library);
544 for (ImportElement import in library.imports) {
545 if (seen.add(import.importedLibrary)) {
546 processLater(import.importedLibrary);
547 }
548 }
549 for (ExportElement export in library.exports) {
550 if (seen.add(export.exportedLibrary)) {
551 processLater(export.exportedLibrary);
552 }
553 }
554 for (ImportElement import in library.implementation.imports) {
555 if (seen.add(import.importedLibrary)) {
556 processLater(import.importedLibrary);
557 }
558 }
559 for (ExportElement export in library.implementation.exports) {
560 if (seen.add(export.exportedLibrary)) {
561 processLater(export.exportedLibrary);
562 }
563 }
564 if (irLibrary != null) {
565 result.add(irLibrary);
566 }
567 }
568 processWorkQueue();
569 return result;
570 }
571
508 /// Returns true if [element] is synthesized to recover or represent a 572 /// Returns true if [element] is synthesized to recover or represent a
509 /// semantic error, for example, missing, duplicated, or ambiguous elements. 573 /// semantic error, for example, missing, duplicated, or ambiguous elements.
510 /// However, returns false for elements that have an unrecoverable syntax 574 /// However, returns false for elements that have an unrecoverable syntax
511 /// error. Both kinds of element will return true from [Element.isMalformed], 575 /// error. Both kinds of element will return true from [Element.isMalformed],
512 /// but they must be handled differently. For example, a static call to 576 /// but they must be handled differently. For example, a static call to
513 /// synthetic error element should be compiled to [ir.InvalidExpression], 577 /// synthetic error element should be compiled to [ir.InvalidExpression],
514 /// whereas a static call to a method which has a syntax error should be 578 /// whereas a static call to a method which has a syntax error should be
515 /// compiled to a static call to the method. The method itself will have a 579 /// compiled to a static call to the method. The method itself will have a
516 /// method body that is [ir.InvalidStatement]. 580 /// method body that is [ir.InvalidStatement].
517 bool isSyntheticError(Element element) { 581 bool isSyntheticError(Element element) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 } 648 }
585 649
586 class ConstructorTarget { 650 class ConstructorTarget {
587 final ConstructorElement element; 651 final ConstructorElement element;
588 final DartType type; 652 final DartType type;
589 653
590 ConstructorTarget(this.element, this.type); 654 ConstructorTarget(this.element, this.type);
591 655
592 String toString() => "ConstructorTarget($element, $type)"; 656 String toString() => "ConstructorTarget($element, $type)";
593 } 657 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/kernel_task.dart ('k') | pkg/compiler/lib/src/kernel/kernel_visitor.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698