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

Side by Side Diff: dart/site/try/poi/poi.dart

Issue 804903004: Refactor LibraryUpdater to prepare for parts. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 trydart.poi; 5 library trydart.poi;
6 6
7 import 'dart:async' show 7 import 'dart:async' show
8 Completer, 8 Completer,
9 Future; 9 Future;
10 10
11 import 'dart:io' as io; 11 import 'dart:io' as io;
12 12
13 import 'dart:convert' show 13 import 'dart:convert' show
14 UTF8; 14 UTF8;
15 15
16 import 'package:dart2js_incremental/dart2js_incremental.dart' show 16 import 'package:dart2js_incremental/dart2js_incremental.dart' show
17 INCREMENTAL_OPTIONS, 17 INCREMENTAL_OPTIONS,
18 reuseCompiler; 18 reuseCompiler;
19 19
20 import 'package:dart2js_incremental/library_updater.dart' show 20 import 'package:dart2js_incremental/library_updater.dart' show
21 IncrementalCompilerContext,
21 LibraryUpdater; 22 LibraryUpdater;
22 23
23 import 'package:compiler/src/source_file_provider.dart' show 24 import 'package:compiler/src/source_file_provider.dart' show
24 FormattingDiagnosticHandler; 25 FormattingDiagnosticHandler;
25 26
26 import 'package:compiler/compiler.dart' as api; 27 import 'package:compiler/compiler.dart' as api;
27 28
28 import 'package:compiler/src/dart2jslib.dart' show 29 import 'package:compiler/src/dart2jslib.dart' show
29 Compiler, 30 Compiler,
30 CompilerTask, 31 CompilerTask,
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 options.add('--minify'); 400 options.add('--minify');
400 } 401 }
401 402
402 LibraryUpdater updater; 403 LibraryUpdater updater;
403 404
404 Future<bool> reuseLibrary(LibraryElement library) { 405 Future<bool> reuseLibrary(LibraryElement library) {
405 return poiTask.measure(() => updater.reuseLibrary(library)); 406 return poiTask.measure(() => updater.reuseLibrary(library));
406 } 407 }
407 408
408 Future<Compiler> invokeReuseCompiler() { 409 Future<Compiler> invokeReuseCompiler() {
410 var context = new IncrementalCompilerContext();
409 updater = new LibraryUpdater( 411 updater = new LibraryUpdater(
410 cachedCompiler, inputProvider, script, printWallClock, printVerbose); 412 cachedCompiler, inputProvider, printWallClock, printVerbose, context);
413 context.registerUriWithUpdates([script]);
411 return reuseCompiler( 414 return reuseCompiler(
412 diagnosticHandler: handler, 415 diagnosticHandler: handler,
413 inputProvider: inputProvider, 416 inputProvider: inputProvider,
414 options: options, 417 options: options,
415 cachedCompiler: cachedCompiler, 418 cachedCompiler: cachedCompiler,
416 libraryRoot: libraryRoot, 419 libraryRoot: libraryRoot,
417 packageRoot: packageRoot, 420 packageRoot: packageRoot,
418 packagesAreImmutable: true, 421 packagesAreImmutable: true,
419 reuseLibrary: reuseLibrary); 422 reuseLibrary: reuseLibrary);
420 } 423 }
421 424
422 return invokeReuseCompiler().then((Compiler newCompiler) { 425 return invokeReuseCompiler().then((Compiler newCompiler) {
423 // TODO(ahe): Move this "then" block to [reuseCompiler]. 426 // TODO(ahe): Move this "then" block to [reuseCompiler].
424 if (updater.failed) { 427 if (updater.failed) {
425 cachedCompiler = null; 428 cachedCompiler = null;
426 return invokeReuseCompiler(); 429 return invokeReuseCompiler();
427 } else { 430 } else {
428 return newCompiler; 431 return newCompiler;
429 } 432 }
430 }).then((Compiler newCompiler) { 433 }).then((Compiler newCompiler) {
431 if (!isCompiler) { 434 if (!isCompiler) {
432 newCompiler.enqueuerFilter = new ScriptOnlyFilter(script); 435 newCompiler.enqueuerFilter = new ScriptOnlyFilter(script);
433 } 436 }
434 return runPoiInternal(newCompiler, sw, updater, position); 437 return runPoiInternal(newCompiler, sw, updater, script, position);
435 }); 438 });
436 } 439 }
437 440
438 Future<Element> runPoiInternal( 441 Future<Element> runPoiInternal(
439 Compiler newCompiler, 442 Compiler newCompiler,
440 Stopwatch sw, 443 Stopwatch sw,
441 LibraryUpdater updater, 444 LibraryUpdater updater,
445 Uri uri,
442 int position) { 446 int position) {
443 bool isFullCompile = cachedCompiler != newCompiler; 447 bool isFullCompile = cachedCompiler != newCompiler;
444 cachedCompiler = newCompiler; 448 cachedCompiler = newCompiler;
445 if (poiTask == null || poiTask.compiler != cachedCompiler) { 449 if (poiTask == null || poiTask.compiler != cachedCompiler) {
446 poiTask = new PoiTask(cachedCompiler); 450 poiTask = new PoiTask(cachedCompiler);
447 cachedCompiler.tasks.add(poiTask); 451 cachedCompiler.tasks.add(poiTask);
448 } 452 }
449 453
450 if (!isFullCompile) { 454 if (!isFullCompile) {
451 printFormattedTime( 455 printFormattedTime(
452 'Analyzing changes and updating elements took', sw.elapsedMicroseconds); 456 'Analyzing changes and updating elements took', sw.elapsedMicroseconds);
453 } 457 }
454 sw.reset(); 458 sw.reset();
455 459
456 Future<bool> compilation; 460 Future<bool> compilation;
457 461
458 if (updater.hasPendingUpdates) { 462 if (updater.hasPendingUpdates) {
459 compilation = new Future(() { 463 compilation = new Future(() {
460 var node = js.statement( 464 var node = js.statement(
461 r'var $dart_patch = #', js.escapedString(updater.computeUpdateJs())); 465 r'var $dart_patch = #', js.escapedString(updater.computeUpdateJs()));
462 print(updater.prettyPrintJs(node)); 466 print(updater.prettyPrintJs(node));
463 467
464 return !cachedCompiler.compilationFailed; 468 return !cachedCompiler.compilationFailed;
465 }); 469 });
466 } else { 470 } else {
467 compilation = cachedCompiler.run(updater.uri); 471 compilation = cachedCompiler.run(uri);
468 } 472 }
469 473
470 return compilation.then((success) { 474 return compilation.then((success) {
471 printVerbose('Compiler queue processed in ${sw.elapsedMicroseconds}us'); 475 printVerbose('Compiler queue processed in ${sw.elapsedMicroseconds}us');
472 if (isVerbose) { 476 if (isVerbose) {
473 for (final task in cachedCompiler.tasks) { 477 for (final task in cachedCompiler.tasks) {
474 int time = task.timingMicroseconds; 478 int time = task.timingMicroseconds;
475 if (time != 0) { 479 if (time != 0) {
476 printFormattedTime('${task.name} took', time); 480 printFormattedTime('${task.name} took', time);
477 } 481 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 f(work); 553 f(work);
550 printWallClock('Processed ${work.element}.'); 554 printWallClock('Processed ${work.element}.');
551 } 555 }
552 } 556 }
553 557
554 class PoiTask extends CompilerTask { 558 class PoiTask extends CompilerTask {
555 PoiTask(Compiler compiler) : super(compiler); 559 PoiTask(Compiler compiler) : super(compiler);
556 560
557 String get name => 'POI'; 561 String get name => 'POI';
558 } 562 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698