@@ -209,20 +209,21 @@ class SourceLoader<L> extends Loader<L> {
209
209
void resolveParts () {
210
210
List <Uri > parts = < Uri > [];
211
211
builders.forEach ((Uri uri, LibraryBuilder library) {
212
- if (library is SourceLibraryBuilder ) {
213
- if (library.isPart) {
214
- library.validatePart ();
212
+ if (library.loader == this ) {
213
+ SourceLibraryBuilder sourceLibrary = library;
214
+ if (sourceLibrary.isPart) {
215
+ sourceLibrary.validatePart ();
215
216
parts.add (uri);
216
217
} else {
217
- library .includeParts ();
218
+ sourceLibrary .includeParts ();
218
219
}
219
220
}
220
221
});
221
222
parts.forEach (builders.remove);
222
223
ticker.logMs ("Resolved parts" );
223
224
224
225
builders.forEach ((Uri uri, LibraryBuilder library) {
225
- if (library is SourceLibraryBuilder ) {
226
+ if (library.loader == this ) {
226
227
library.applyPatches ();
227
228
}
228
229
});
@@ -233,8 +234,9 @@ class SourceLoader<L> extends Loader<L> {
233
234
Set <LibraryBuilder > exporters = new Set <LibraryBuilder >();
234
235
Set <LibraryBuilder > exportees = new Set <LibraryBuilder >();
235
236
builders.forEach ((Uri uri, LibraryBuilder library) {
236
- if (library is SourceLibraryBuilder ) {
237
- library.buildInitialScopes ();
237
+ if (library.loader == this ) {
238
+ SourceLibraryBuilder sourceLibrary = library;
239
+ sourceLibrary.buildInitialScopes ();
238
240
}
239
241
if (library.exporters.isNotEmpty) {
240
242
exportees.add (library);
@@ -266,10 +268,18 @@ class SourceLoader<L> extends Loader<L> {
266
268
}
267
269
} while (wasChanged);
268
270
builders.forEach ((Uri uri, LibraryBuilder library) {
269
- if (library is SourceLibraryBuilder ) {
270
- library.addImportsToScope ();
271
+ if (library.loader == this ) {
272
+ SourceLibraryBuilder sourceLibrary = library;
273
+ sourceLibrary.addImportsToScope ();
271
274
}
272
275
});
276
+ for (LibraryBuilder exportee in exportees) {
277
+ // TODO(ahe): Change how we track exporters. Currently, when a library
278
+ // (exporter) exports another library (exportee) we add a reference to
279
+ // exporter to exportee. This creates a reference in the wrong direction
280
+ // and can lead to memory leaks.
281
+ exportee.exporters.clear ();
282
+ }
273
283
ticker.logMs ("Computed library scopes" );
274
284
// debugPrintExports();
275
285
}
@@ -314,47 +324,59 @@ class SourceLoader<L> extends Loader<L> {
314
324
void finishDeferredLoadTearoffs () {
315
325
int count = 0 ;
316
326
builders.forEach ((Uri uri, LibraryBuilder library) {
317
- count += library.finishDeferredLoadTearoffs ();
327
+ if (library.loader == this ) {
328
+ count += library.finishDeferredLoadTearoffs ();
329
+ }
318
330
});
319
331
ticker.logMs ("Finished deferred load tearoffs $count " );
320
332
}
321
333
322
334
void finishStaticInvocations () {
323
335
int count = 0 ;
324
336
builders.forEach ((Uri uri, LibraryBuilder library) {
325
- count += library.finishStaticInvocations ();
337
+ if (library.loader == this ) {
338
+ count += library.finishStaticInvocations ();
339
+ }
326
340
});
327
341
ticker.logMs ("Finished static invocations $count " );
328
342
}
329
343
330
344
void resolveConstructors () {
331
345
int count = 0 ;
332
346
builders.forEach ((Uri uri, LibraryBuilder library) {
333
- count += library.resolveConstructors (null );
347
+ if (library.loader == this ) {
348
+ count += library.resolveConstructors (null );
349
+ }
334
350
});
335
351
ticker.logMs ("Resolved $count constructors" );
336
352
}
337
353
338
354
void finishTypeVariables (ClassBuilder object) {
339
355
int count = 0 ;
340
356
builders.forEach ((Uri uri, LibraryBuilder library) {
341
- count += library.finishTypeVariables (object);
357
+ if (library.loader == this ) {
358
+ count += library.finishTypeVariables (object);
359
+ }
342
360
});
343
361
ticker.logMs ("Resolved $count type-variable bounds" );
344
362
}
345
363
346
364
void finishNativeMethods () {
347
365
int count = 0 ;
348
366
builders.forEach ((Uri uri, LibraryBuilder library) {
349
- count += library.finishNativeMethods ();
367
+ if (library.loader == this ) {
368
+ count += library.finishNativeMethods ();
369
+ }
350
370
});
351
371
ticker.logMs ("Finished $count native methods" );
352
372
}
353
373
354
374
void finishPatchMethods () {
355
375
int count = 0 ;
356
376
builders.forEach ((Uri uri, LibraryBuilder library) {
357
- count += library.finishPatchMethods ();
377
+ if (library.loader == this ) {
378
+ count += library.finishPatchMethods ();
379
+ }
358
380
});
359
381
ticker.logMs ("Finished $count patch methods" );
360
382
}
@@ -497,8 +519,9 @@ class SourceLoader<L> extends Loader<L> {
497
519
498
520
void buildProgram () {
499
521
builders.forEach ((Uri uri, LibraryBuilder library) {
500
- if (library is SourceLibraryBuilder ) {
501
- L target = library.build (coreLibrary);
522
+ if (library.loader == this ) {
523
+ SourceLibraryBuilder sourceLibrary = library;
524
+ L target = sourceLibrary.build (coreLibrary);
502
525
if (! library.isPatch) {
503
526
libraries.add (target);
504
527
}
@@ -517,7 +540,9 @@ class SourceLoader<L> extends Loader<L> {
517
540
void checkOverrides (List <SourceClassBuilder > sourceClasses) {
518
541
assert (hierarchy != null );
519
542
for (SourceClassBuilder builder in sourceClasses) {
520
- builder.checkOverrides (hierarchy);
543
+ if (builder.library.loader == this ) {
544
+ builder.checkOverrides (hierarchy);
545
+ }
521
546
}
522
547
ticker.logMs ("Checked overrides" );
523
548
}
@@ -539,7 +564,7 @@ class SourceLoader<L> extends Loader<L> {
539
564
instrumentation,
540
565
target.strongMode);
541
566
builders.forEach ((Uri uri, LibraryBuilder library) {
542
- if (library is SourceLibraryBuilder ) {
567
+ if (library.loader == this ) {
543
568
library.prepareTopLevelInference (library, null );
544
569
}
545
570
});
@@ -574,7 +599,7 @@ class SourceLoader<L> extends Loader<L> {
574
599
typeInferenceEngine.finishTopLevelInitializingFormals ();
575
600
if (instrumentation != null ) {
576
601
builders.forEach ((Uri uri, LibraryBuilder library) {
577
- if (library is SourceLibraryBuilder ) {
602
+ if (library.loader == this ) {
578
603
library.instrumentTopLevelInference (instrumentation);
579
604
}
580
605
});
0 commit comments