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

Side by Side Diff: pkg/front_end/lib/src/fasta/kernel/kernel_target.dart

Issue 2862223002: Rewrite mixin application handling in Fasta. (Closed)
Patch Set: Created 3 years, 7 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 file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library fasta.kernel_target; 5 library fasta.kernel_target;
6 6
7 import 'dart:async' show Future; 7 import 'dart:async' show Future;
8 8
9 import 'dart:io' show File, IOSink; 9 import 'dart:io' show File, IOSink;
10 10
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 show 76 show
77 Builder, 77 Builder,
78 ClassBuilder, 78 ClassBuilder,
79 InvalidTypeBuilder, 79 InvalidTypeBuilder,
80 KernelClassBuilder, 80 KernelClassBuilder,
81 KernelLibraryBuilder, 81 KernelLibraryBuilder,
82 KernelNamedTypeBuilder, 82 KernelNamedTypeBuilder,
83 KernelProcedureBuilder, 83 KernelProcedureBuilder,
84 LibraryBuilder, 84 LibraryBuilder,
85 MemberBuilder, 85 MemberBuilder,
86 MixinApplicationBuilder,
87 NamedMixinApplicationBuilder,
88 NamedTypeBuilder, 86 NamedTypeBuilder,
89 TypeBuilder, 87 TypeBuilder,
88 TypeDeclarationBuilder,
90 TypeVariableBuilder; 89 TypeVariableBuilder;
91 90
92 import 'verifier.dart' show verifyProgram; 91 import 'verifier.dart' show verifyProgram;
93 92
94 class KernelTarget extends TargetImplementation { 93 class KernelTarget extends TargetImplementation {
95 final bool strongMode; 94 final bool strongMode;
96 95
97 final DillTarget dillTarget; 96 final DillTarget dillTarget;
98 97
99 /// Shared with [CompilerContext]. 98 /// Shared with [CompilerContext].
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 LibraryBuilder createLibraryBuilder(Uri uri, Uri fileUri) { 138 LibraryBuilder createLibraryBuilder(Uri uri, Uri fileUri) {
140 if (dillTarget.isLoaded) { 139 if (dillTarget.isLoaded) {
141 var builder = dillTarget.loader.builders[uri]; 140 var builder = dillTarget.loader.builders[uri];
142 if (builder != null) { 141 if (builder != null) {
143 return builder; 142 return builder;
144 } 143 }
145 } 144 }
146 return new KernelLibraryBuilder(uri, fileUri, loader); 145 return new KernelLibraryBuilder(uri, fileUri, loader);
147 } 146 }
148 147
148 void forEachDirectSupertype(ClassBuilder cls, void f(NamedTypeBuilder type)) {
149 TypeBuilder supertype = cls.supertype;
150 if (supertype is NamedTypeBuilder) {
151 f(supertype);
152 } else if (supertype != null) {
153 internalError("Unhandled: ${supertype.runtimeType}");
154 }
155 if (cls.interfaces != null) {
156 for (NamedTypeBuilder t in cls.interfaces) {
157 f(t);
158 }
159 }
160 if (cls.library.loader == loader &&
161 // TODO(ahe): Implement DillClassBuilder.mixedInType and remove the
162 // above check.
163 cls.mixedInType != null) {
164 f(cls.mixedInType);
165 }
166 }
167
149 void addDirectSupertype(ClassBuilder cls, Set<ClassBuilder> set) { 168 void addDirectSupertype(ClassBuilder cls, Set<ClassBuilder> set) {
150 if (cls == null) return; 169 if (cls == null) return;
151 TypeBuilder supertype = cls.supertype; 170 forEachDirectSupertype(cls, (NamedTypeBuilder type) {
152 add(NamedTypeBuilder type) {
153 Builder builder = type.builder; 171 Builder builder = type.builder;
154 if (builder is ClassBuilder) { 172 if (builder is ClassBuilder) {
155 set.add(builder); 173 set.add(builder);
156 } 174 }
157 } 175 });
158
159 if (supertype == null) {
160 // OK.
161 } else if (supertype is MixinApplicationBuilder) {
162 add(supertype.supertype);
163 for (NamedTypeBuilder t in supertype.mixins) {
164 add(t);
165 }
166 } else if (supertype is NamedTypeBuilder) {
167 add(supertype);
168 } else {
169 internalError("Unhandled: ${supertype.runtimeType}");
170 }
171 if (cls.interfaces != null) {
172 for (NamedTypeBuilder t in cls.interfaces) {
173 add(t);
174 }
175 }
176 } 176 }
177 177
178 List<ClassBuilder> collectAllClasses() { 178 List<ClassBuilder> collectAllClasses() {
179 List<ClassBuilder> result = <ClassBuilder>[]; 179 List<ClassBuilder> result = <ClassBuilder>[];
180 loader.builders.forEach((Uri uri, LibraryBuilder library) { 180 loader.builders.forEach((Uri uri, LibraryBuilder library) {
181 library.forEach((String name, Builder member) { 181 library.forEach((String name, Builder member) {
182 if (member is KernelClassBuilder) { 182 if (member is KernelClassBuilder) {
183 result.add(member); 183 result.add(member);
184 } 184 }
185 }); 185 });
(...skipping 19 matching lines...) Expand all
205 205
206 void breakCycle(ClassBuilder builder) { 206 void breakCycle(ClassBuilder builder) {
207 Class cls = builder.target; 207 Class cls = builder.target;
208 cls.implementedTypes.clear(); 208 cls.implementedTypes.clear();
209 cls.supertype = null; 209 cls.supertype = null;
210 cls.mixedInType = null; 210 cls.mixedInType = null;
211 builder.supertype = new KernelNamedTypeBuilder("Object", null, 211 builder.supertype = new KernelNamedTypeBuilder("Object", null,
212 builder.charOffset, builder.fileUri ?? Uri.parse(cls.fileUri)) 212 builder.charOffset, builder.fileUri ?? Uri.parse(cls.fileUri))
213 ..builder = objectClassBuilder; 213 ..builder = objectClassBuilder;
214 builder.interfaces = null; 214 builder.interfaces = null;
215 builder.mixedInType = null;
215 } 216 }
216 217
217 Future<Program> handleInputError(Uri uri, InputError error, 218 Future<Program> handleInputError(Uri uri, InputError error,
218 {bool isFullProgram}) { 219 {bool isFullProgram}) {
219 if (error != null) { 220 if (error != null) {
220 String message = error.format(); 221 String message = error.format();
221 print(message); 222 print(message);
222 errors.add(message); 223 errors.add(message);
223 } 224 }
224 program = erroneousProgram(isFullProgram); 225 program = erroneousProgram(isFullProgram);
(...skipping 13 matching lines...) Expand all
238 loader.computeLibraryScopes(); 239 loader.computeLibraryScopes();
239 loader.resolveTypes(); 240 loader.resolveTypes();
240 loader.checkSemantics(); 241 loader.checkSemantics();
241 loader.buildProgram(); 242 loader.buildProgram();
242 List<SourceClassBuilder> sourceClasses = collectAllSourceClasses(); 243 List<SourceClassBuilder> sourceClasses = collectAllSourceClasses();
243 installDefaultSupertypes(); 244 installDefaultSupertypes();
244 installDefaultConstructors(sourceClasses); 245 installDefaultConstructors(sourceClasses);
245 loader.resolveConstructors(); 246 loader.resolveConstructors();
246 loader.finishTypeVariables(objectClassBuilder); 247 loader.finishTypeVariables(objectClassBuilder);
247 program = link(new List<Library>.from(loader.libraries)); 248 program = link(new List<Library>.from(loader.libraries));
248 dumpIr();
249 loader.computeHierarchy(program); 249 loader.computeHierarchy(program);
250 loader.checkOverrides(sourceClasses); 250 loader.checkOverrides(sourceClasses);
251 if (uri == null) return program; 251 if (uri == null) return program;
252 return await writeLinkedProgram(uri, program, isFullProgram: false); 252 return await writeLinkedProgram(uri, program, isFullProgram: false);
253 } on InputError catch (e) { 253 } on InputError catch (e) {
254 return handleInputError(uri, e, isFullProgram: false); 254 return handleInputError(uri, e, isFullProgram: false);
255 } catch (e, s) { 255 } catch (e, s) {
256 return reportCrash(e, s, loader?.currentUriForCrashReporting); 256 return reportCrash(e, s, loader?.currentUriForCrashReporting);
257 } 257 }
258 } 258 }
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 } 438 }
439 ticker.logMs("Installed default constructors"); 439 ticker.logMs("Installed default constructors");
440 } 440 }
441 441
442 KernelClassBuilder get objectClassBuilder => loader.coreLibrary["Object"]; 442 KernelClassBuilder get objectClassBuilder => loader.coreLibrary["Object"];
443 443
444 Class get objectClass => objectClassBuilder.cls; 444 Class get objectClass => objectClassBuilder.cls;
445 445
446 /// If [builder] doesn't have a constructors, install the defaults. 446 /// If [builder] doesn't have a constructors, install the defaults.
447 void installDefaultConstructor(SourceClassBuilder builder) { 447 void installDefaultConstructor(SourceClassBuilder builder) {
448 if (builder.cls.isMixinApplication) { 448 if (builder.isMixinApplication && !builder.isNamedMixinApplication) return;
449 // We have to test if builder.cls is a mixin application. [builder] may
450 // think it's a mixin application, but if its mixed-in type couldn't be
451 // resolved, the target class won't be a mixin application and we need
452 // to add a default constructor to complete error recovery.
453 return;
454 }
455 if (builder.constructors.local.isNotEmpty) return; 449 if (builder.constructors.local.isNotEmpty) return;
456 450
457 /// Quotes below are from [Dart Programming Language Specification, 4th 451 /// Quotes below are from [Dart Programming Language Specification, 4th
458 /// Edition]( 452 /// Edition](
459 /// https://ecma-international.org/publications/files/ECMA-ST/ECMA-408.pdf): 453 /// https://ecma-international.org/publications/files/ECMA-ST/ECMA-408.pdf):
460 if (builder is NamedMixinApplicationBuilder) { 454 if (builder.isNamedMixinApplication) {
461 /// >A mixin application of the form S with M; defines a class C with 455 /// >A mixin application of the form S with M; defines a class C with
462 /// >superclass S. 456 /// >superclass S.
463 /// >... 457 /// >...
464 458
465 /// >Let LM be the library in which M is declared. For each generative 459 /// >Let LM be the library in which M is declared. For each generative
466 /// >constructor named qi(Ti1 ai1, . . . , Tiki aiki), i in 1..n of S 460 /// >constructor named qi(Ti1 ai1, . . . , Tiki aiki), i in 1..n of S
467 /// >that is accessible to LM , C has an implicitly declared constructor 461 /// >that is accessible to LM , C has an implicitly declared constructor
468 /// >named q'i = [C/S]qi of the form q'i(ai1,...,aiki) : 462 /// >named q'i = [C/S]qi of the form q'i(ai1,...,aiki) :
469 /// >super(ai1,...,aiki);. 463 /// >super(ai1,...,aiki);.
470 Builder supertype = builder; 464 TypeDeclarationBuilder supertype = builder;
471 while (supertype is NamedMixinApplicationBuilder) { 465 while (supertype.isMixinApplication) {
472 NamedMixinApplicationBuilder named = supertype; 466 SourceClassBuilder named = supertype;
473 TypeBuilder type = named.mixinApplication; 467 TypeBuilder type = named.supertype;
474 if (type is MixinApplicationBuilder) {
475 MixinApplicationBuilder t = type;
476 type = t.supertype;
477 }
478 if (type is NamedTypeBuilder) { 468 if (type is NamedTypeBuilder) {
479 supertype = type.builder; 469 supertype = type.builder;
480 } else { 470 } else {
481 internalError("Unhandled: ${type.runtimeType}"); 471 internalError("Unhandled: ${type.runtimeType}");
482 } 472 }
483 } 473 }
484 if (supertype is KernelClassBuilder) { 474 if (supertype is KernelClassBuilder) {
485 Map<TypeParameter, DartType> substitutionMap = 475 Map<TypeParameter, DartType> substitutionMap =
486 computeKernelSubstitutionMap( 476 computeKernelSubstitutionMap(
487 builder.getSubstitutionMap(supertype, builder.fileUri, 477 builder.getSubstitutionMap(supertype, builder.fileUri,
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 } 707 }
718 for (Constructor constructor in superclass.constructors) { 708 for (Constructor constructor in superclass.constructors) {
719 if (constructor.name.name.isEmpty) { 709 if (constructor.name.name.isEmpty) {
720 return constructor.function.requiredParameterCount == 0 710 return constructor.function.requiredParameterCount == 0
721 ? constructor 711 ? constructor
722 : null; 712 : null;
723 } 713 }
724 } 714 }
725 return null; 715 return null;
726 } 716 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698