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

Side by Side Diff: sdk/lib/_internal/pub_generated/lib/src/dart.dart

Issue 559833004: Cache snapshots of (mostly) immutable transformer phases. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 | Annotate | Revision Log
OLDNEW
1 library pub.dart; 1 library pub.dart;
2 import 'dart:async'; 2 import 'dart:async';
3 import 'dart:io';
3 import 'dart:isolate'; 4 import 'dart:isolate';
4 import 'package:analyzer/analyzer.dart'; 5 import 'package:analyzer/analyzer.dart';
5 import 'package:path/path.dart' as path; 6 import 'package:path/path.dart' as path;
6 import 'package:stack_trace/stack_trace.dart'; 7 import 'package:stack_trace/stack_trace.dart';
7 import '../../../compiler/compiler.dart' as compiler; 8 import '../../../compiler/compiler.dart' as compiler;
8 import '../../../compiler/implementation/filenames.dart' show appendSlash; 9 import '../../../compiler/implementation/filenames.dart' show appendSlash;
9 import '../../asset/dart/serialize.dart'; 10 import '../../asset/dart/serialize.dart';
10 import 'io.dart'; 11 import 'io.dart';
12 import 'log.dart' as log;
11 import 'utils.dart'; 13 import 'utils.dart';
12 abstract class CompilerProvider { 14 abstract class CompilerProvider {
13 Uri get libraryRoot; 15 Uri get libraryRoot;
14 Future provideInput(Uri uri); 16 Future provideInput(Uri uri);
15 void handleDiagnostic(Uri uri, int begin, int end, String message, 17 void handleDiagnostic(Uri uri, int begin, int end, String message,
16 compiler.Diagnostic kind); 18 compiler.Diagnostic kind);
17 EventSink<String> provideOutput(String name, String extension); 19 EventSink<String> provideOutput(String name, String extension);
18 } 20 }
19 Future compile(String entrypoint, CompilerProvider provider, 21 Future compile(String entrypoint, CompilerProvider provider,
20 {Iterable<String> commandLineOptions, bool checked: false, bool csp: false, 22 {Iterable<String> commandLineOptions, bool checked: false, bool csp: false,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 } 67 }
66 List<UriBasedDirective> parseImportsAndExports(String contents, {String name}) { 68 List<UriBasedDirective> parseImportsAndExports(String contents, {String name}) {
67 var collector = new _DirectiveCollector(); 69 var collector = new _DirectiveCollector();
68 parseDirectives(contents, name: name).accept(collector); 70 parseDirectives(contents, name: name).accept(collector);
69 return collector.directives; 71 return collector.directives;
70 } 72 }
71 class _DirectiveCollector extends GeneralizingAstVisitor { 73 class _DirectiveCollector extends GeneralizingAstVisitor {
72 final directives = <UriBasedDirective>[]; 74 final directives = <UriBasedDirective>[];
73 visitUriBasedDirective(UriBasedDirective node) => directives.add(node); 75 visitUriBasedDirective(UriBasedDirective node) => directives.add(node);
74 } 76 }
75 Future runInIsolate(String code, message) { 77 Future runInIsolate(String code, message, {String snapshot}) {
78 if (snapshot != null && fileExists(snapshot)) {
79 log.fine("Spawning isolate from $snapshot.");
80 return Chain.track(Isolate.spawnUri(path.toUri(snapshot), [], message));
81 }
76 return withTempDir((dir) { 82 return withTempDir((dir) {
77 var dartPath = path.join(dir, 'runInIsolate.dart'); 83 var dartPath = path.join(dir, 'runInIsolate.dart');
78 writeTextFile(dartPath, code, dontLogContents: true); 84 writeTextFile(dartPath, code, dontLogContents: true);
79 var port = new ReceivePort(); 85 var port = new ReceivePort();
80 return Chain.track(Isolate.spawn(_isolateBuffer, { 86 return Chain.track(Isolate.spawn(_isolateBuffer, {
81 'replyTo': port.sendPort, 87 'replyTo': port.sendPort,
82 'uri': path.toUri(dartPath).toString(), 88 'uri': path.toUri(dartPath).toString(),
83 'message': message 89 'message': message
84 })).then((_) => port.first).then((response) { 90 })).then((_) => port.first).then((response) {
85 if (response['type'] == 'success') return null; 91 if (response['type'] == 'success') return null;
86 assert(response['type'] == 'error'); 92 assert(response['type'] == 'error');
87 return new Future.error( 93 return new Future.error(
88 new CrossIsolateException.deserialize(response['error']), 94 new CrossIsolateException.deserialize(response['error']),
89 new Chain.current()); 95 new Chain.current());
96 }).then((_) {
97 if (snapshot == null) return null;
98 ensureDir(path.dirname(snapshot));
99 return runProcess(
100 Platform.executable,
101 ['--snapshot=$snapshot', dartPath]).then((result) {
102 if (result.success) return;
103 log.warning(
104 "Failed to compile a snapshot to " "${path.relative(snapshot)}:\n" +
105 result.stderr.join("\n"));
106 });
90 }); 107 });
91 }); 108 });
92 } 109 }
93 void _isolateBuffer(message) { 110 void _isolateBuffer(message) {
94 var replyTo = message['replyTo']; 111 var replyTo = message['replyTo'];
95 Chain.track( 112 Chain.track(
96 Isolate.spawnUri( 113 Isolate.spawnUri(
97 Uri.parse(message['uri']), 114 Uri.parse(message['uri']),
98 [], 115 [],
99 message['message'])).then((_) => replyTo.send({ 116 message['message'])).then((_) => replyTo.send({
100 'type': 'success' 117 'type': 'success'
101 })).catchError((e, stack) { 118 })).catchError((e, stack) {
102 replyTo.send({ 119 replyTo.send({
103 'type': 'error', 120 'type': 'error',
104 'error': CrossIsolateException.serialize(e, stack) 121 'error': CrossIsolateException.serialize(e, stack)
105 }); 122 });
106 }); 123 });
107 } 124 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698