| OLD | NEW |
| 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 fletchc_incremental; | 5 library dartino_compiler_incremental; |
| 6 | 6 |
| 7 import 'dart:async' show | 7 import 'dart:async' show |
| 8 EventSink, | 8 EventSink, |
| 9 Future; | 9 Future; |
| 10 | 10 |
| 11 import 'dart:developer' show | 11 import 'dart:developer' show |
| 12 UserTag; | 12 UserTag; |
| 13 | 13 |
| 14 import 'package:compiler/src/apiimpl.dart' show | 14 import 'package:compiler/src/apiimpl.dart' show |
| 15 CompilerImpl; | 15 CompilerImpl; |
| 16 | 16 |
| 17 import 'package:compiler/compiler_new.dart' show | 17 import 'package:compiler/compiler_new.dart' show |
| 18 CompilerDiagnostics, | 18 CompilerDiagnostics, |
| 19 CompilerInput, | 19 CompilerInput, |
| 20 CompilerOutput, | 20 CompilerOutput, |
| 21 Diagnostic; | 21 Diagnostic; |
| 22 | 22 |
| 23 import 'package:compiler/src/elements/elements.dart' show | 23 import 'package:compiler/src/elements/elements.dart' show |
| 24 ClassElement, | 24 ClassElement, |
| 25 ConstructorElement, | 25 ConstructorElement, |
| 26 Element, | 26 Element, |
| 27 FunctionElement, | 27 FunctionElement, |
| 28 LibraryElement; | 28 LibraryElement; |
| 29 | 29 |
| 30 import 'package:compiler/src/library_loader.dart' show | 30 import 'package:compiler/src/library_loader.dart' show |
| 31 ReuseLibrariesFunction; | 31 ReuseLibrariesFunction; |
| 32 | 32 |
| 33 import 'fletch_reuser.dart' show | 33 import 'dartino_reuser.dart' show |
| 34 IncrementalCompilerContext, | 34 IncrementalCompilerContext, |
| 35 FletchReuser, | 35 DartinoReuser, |
| 36 Logger; | 36 Logger; |
| 37 | 37 |
| 38 import '../fletch_compiler.dart' show | 38 import '../dartino_compiler.dart' show |
| 39 FletchCompiler; | 39 DartinoCompiler; |
| 40 | 40 |
| 41 import '../src/debug_info.dart' show | 41 import '../src/debug_info.dart' show |
| 42 DebugInfo; | 42 DebugInfo; |
| 43 | 43 |
| 44 import '../src/class_debug_info.dart' show | 44 import '../src/class_debug_info.dart' show |
| 45 ClassDebugInfo; | 45 ClassDebugInfo; |
| 46 | 46 |
| 47 import '../src/fletch_selector.dart' show | 47 import '../src/dartino_selector.dart' show |
| 48 FletchSelector; | 48 DartinoSelector; |
| 49 | 49 |
| 50 import '../src/fletch_compiler_implementation.dart' show | 50 import '../src/dartino_compiler_implementation.dart' show |
| 51 FletchCompilerImplementation, | 51 DartinoCompilerImplementation, |
| 52 OutputProvider; | 52 OutputProvider; |
| 53 | 53 |
| 54 import '../fletch_system.dart'; | 54 import '../dartino_system.dart'; |
| 55 | 55 |
| 56 import '../src/fletch_backend.dart' show | 56 import '../src/dartino_backend.dart' show |
| 57 FletchBackend; | 57 DartinoBackend; |
| 58 | 58 |
| 59 import '../src/hub/exit_codes.dart' as exit_codes; | 59 import '../src/hub/exit_codes.dart' as exit_codes; |
| 60 | 60 |
| 61 import 'package:compiler/src/source_file_provider.dart' show | 61 import 'package:compiler/src/source_file_provider.dart' show |
| 62 SourceFileProvider; | 62 SourceFileProvider; |
| 63 | 63 |
| 64 import 'package:compiler/src/tokens/token.dart' show | 64 import 'package:compiler/src/tokens/token.dart' show |
| 65 Token; | 65 Token; |
| 66 | 66 |
| 67 import 'package:compiler/src/diagnostics/source_span.dart' show | 67 import 'package:compiler/src/diagnostics/source_span.dart' show |
| (...skipping 21 matching lines...) Expand all Loading... |
| 89 /// All incremental features are turned on even if we know that we don't | 89 /// All incremental features are turned on even if we know that we don't |
| 90 /// always generate correct code. Initially, this covers features such as | 90 /// always generate correct code. Initially, this covers features such as |
| 91 /// schema changes. | 91 /// schema changes. |
| 92 experimental, | 92 experimental, |
| 93 } | 93 } |
| 94 | 94 |
| 95 class IncrementalCompiler { | 95 class IncrementalCompiler { |
| 96 final Uri libraryRoot; | 96 final Uri libraryRoot; |
| 97 final Uri nativesJson; | 97 final Uri nativesJson; |
| 98 final Uri packageConfig; | 98 final Uri packageConfig; |
| 99 final Uri fletchVm; | 99 final Uri dartinoVm; |
| 100 final CompilerInput inputProvider; | 100 final CompilerInput inputProvider; |
| 101 final List<String> options; | 101 final List<String> options; |
| 102 final CompilerOutput outputProvider; | 102 final CompilerOutput outputProvider; |
| 103 final Map<String, dynamic> environment; | 103 final Map<String, dynamic> environment; |
| 104 final IncrementalCompilerContext _context; | 104 final IncrementalCompilerContext _context; |
| 105 final IncrementalMode support; | 105 final IncrementalMode support; |
| 106 final String platform; | 106 final String platform; |
| 107 final Map<Uri, Uri> _updatedFiles = new Map<Uri, Uri>(); | 107 final Map<Uri, Uri> _updatedFiles = new Map<Uri, Uri>(); |
| 108 | 108 |
| 109 FletchCompilerImplementation _compiler; | 109 DartinoCompilerImplementation _compiler; |
| 110 | 110 |
| 111 IncrementalCompiler( | 111 IncrementalCompiler( |
| 112 {this.libraryRoot, | 112 {this.libraryRoot, |
| 113 this.nativesJson, | 113 this.nativesJson, |
| 114 this.packageConfig, | 114 this.packageConfig, |
| 115 this.fletchVm, | 115 this.dartinoVm, |
| 116 this.inputProvider, | 116 this.inputProvider, |
| 117 CompilerDiagnostics diagnosticHandler, | 117 CompilerDiagnostics diagnosticHandler, |
| 118 this.options, | 118 this.options, |
| 119 this.outputProvider, | 119 this.outputProvider, |
| 120 this.environment, | 120 this.environment, |
| 121 this.support: IncrementalMode.none, | 121 this.support: IncrementalMode.none, |
| 122 this.platform}) | 122 this.platform}) |
| 123 : _context = new IncrementalCompilerContext(diagnosticHandler) { | 123 : _context = new IncrementalCompilerContext(diagnosticHandler) { |
| 124 // if (libraryRoot == null) { | 124 // if (libraryRoot == null) { |
| 125 // throw new ArgumentError('libraryRoot is null.'); | 125 // throw new ArgumentError('libraryRoot is null.'); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 143 return support == IncrementalMode.production || | 143 return support == IncrementalMode.production || |
| 144 support == IncrementalMode.experimental; | 144 support == IncrementalMode.experimental; |
| 145 } | 145 } |
| 146 | 146 |
| 147 bool get isExperimentalModeEnabled { | 147 bool get isExperimentalModeEnabled { |
| 148 return support == IncrementalMode.experimental; | 148 return support == IncrementalMode.experimental; |
| 149 } | 149 } |
| 150 | 150 |
| 151 LibraryElement get mainApp => _compiler.mainApp; | 151 LibraryElement get mainApp => _compiler.mainApp; |
| 152 | 152 |
| 153 FletchCompilerImplementation get compiler => _compiler; | 153 DartinoCompilerImplementation get compiler => _compiler; |
| 154 | 154 |
| 155 /// Perform a full compile of [script]. This will reset the incremental | 155 /// Perform a full compile of [script]. This will reset the incremental |
| 156 /// compiler. | 156 /// compiler. |
| 157 /// | 157 /// |
| 158 /// Error messages will be reported relative to [base]. | 158 /// Error messages will be reported relative to [base]. |
| 159 /// | 159 /// |
| 160 /// Notice: a full compile means not incremental. The part of the program | 160 /// Notice: a full compile means not incremental. The part of the program |
| 161 /// that is compiled is determined by tree shaking. | 161 /// that is compiled is determined by tree shaking. |
| 162 Future<bool> compile(Uri script, Uri base) { | 162 Future<bool> compile(Uri script, Uri base) { |
| 163 _compiler = null; | 163 _compiler = null; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 ? <String> [] : new List<String>.from(this.options); | 201 ? <String> [] : new List<String>.from(this.options); |
| 202 options.addAll(INCREMENTAL_OPTIONS); | 202 options.addAll(INCREMENTAL_OPTIONS); |
| 203 if (analyzeOnly) { | 203 if (analyzeOnly) { |
| 204 options.add("--analyze-only"); | 204 options.add("--analyze-only"); |
| 205 } | 205 } |
| 206 return reuseCompiler( | 206 return reuseCompiler( |
| 207 cachedCompiler: _compiler, | 207 cachedCompiler: _compiler, |
| 208 libraryRoot: libraryRoot, | 208 libraryRoot: libraryRoot, |
| 209 packageConfig: packageConfig, | 209 packageConfig: packageConfig, |
| 210 nativesJson: nativesJson, | 210 nativesJson: nativesJson, |
| 211 fletchVm: fletchVm, | 211 dartinoVm: dartinoVm, |
| 212 inputProvider: inputProvider, | 212 inputProvider: inputProvider, |
| 213 diagnosticHandler: _context, | 213 diagnosticHandler: _context, |
| 214 options: options, | 214 options: options, |
| 215 outputProvider: outputProvider, | 215 outputProvider: outputProvider, |
| 216 environment: environment, | 216 environment: environment, |
| 217 reuseLibraries: reuseLibraries, | 217 reuseLibraries: reuseLibraries, |
| 218 platform: platform, | 218 platform: platform, |
| 219 base: base, | 219 base: base, |
| 220 incrementalCompiler: this); | 220 incrementalCompiler: this); |
| 221 } | 221 } |
| 222 | 222 |
| 223 void _checkCompilationFailed() { | 223 void _checkCompilationFailed() { |
| 224 if (!isExperimentalModeEnabled && _compiler.compilationFailed) { | 224 if (!isExperimentalModeEnabled && _compiler.compilationFailed) { |
| 225 throw new IncrementalCompilationFailed( | 225 throw new IncrementalCompilationFailed( |
| 226 "Unable to reuse compiler due to compile-time errors"); | 226 "Unable to reuse compiler due to compile-time errors"); |
| 227 } | 227 } |
| 228 } | 228 } |
| 229 | 229 |
| 230 /// Perform an incremental compilation of [updatedFiles]. [compile] must have | 230 /// Perform an incremental compilation of [updatedFiles]. [compile] must have |
| 231 /// been called once before calling this method. | 231 /// been called once before calling this method. |
| 232 /// | 232 /// |
| 233 /// Error messages will be reported relative to [base], if [base] is not | 233 /// Error messages will be reported relative to [base], if [base] is not |
| 234 /// provided the previous set [base] will be used. | 234 /// provided the previous set [base] will be used. |
| 235 Future<FletchDelta> compileUpdates( | 235 Future<DartinoDelta> compileUpdates( |
| 236 FletchSystem currentSystem, | 236 DartinoSystem currentSystem, |
| 237 Map<Uri, Uri> updatedFiles, | 237 Map<Uri, Uri> updatedFiles, |
| 238 {Logger logTime, | 238 {Logger logTime, |
| 239 Logger logVerbose, | 239 Logger logVerbose, |
| 240 Uri base}) { | 240 Uri base}) { |
| 241 _checkCompilationFailed(); | 241 _checkCompilationFailed(); |
| 242 if (logTime == null) { | 242 if (logTime == null) { |
| 243 logTime = (_) {}; | 243 logTime = (_) {}; |
| 244 } | 244 } |
| 245 if (logVerbose == null) { | 245 if (logVerbose == null) { |
| 246 logVerbose = (_) {}; | 246 logVerbose = (_) {}; |
| 247 } | 247 } |
| 248 updatedFiles.forEach((Uri from, Uri to) { | 248 updatedFiles.forEach((Uri from, Uri to) { |
| 249 _updatedFiles[from] = to; | 249 _updatedFiles[from] = to; |
| 250 }); | 250 }); |
| 251 Future mappingInputProvider(Uri uri) { | 251 Future mappingInputProvider(Uri uri) { |
| 252 Uri updatedFile = _updatedFiles[uri]; | 252 Uri updatedFile = _updatedFiles[uri]; |
| 253 return inputProvider.readFromUri(updatedFile == null ? uri : updatedFile); | 253 return inputProvider.readFromUri(updatedFile == null ? uri : updatedFile); |
| 254 } | 254 } |
| 255 FletchReuser reuser = new FletchReuser( | 255 DartinoReuser reuser = new DartinoReuser( |
| 256 _compiler, | 256 _compiler, |
| 257 mappingInputProvider, | 257 mappingInputProvider, |
| 258 logTime, | 258 logTime, |
| 259 logVerbose, | 259 logVerbose, |
| 260 _context); | 260 _context); |
| 261 _context.registerUriWithUpdates(updatedFiles.keys); | 261 _context.registerUriWithUpdates(updatedFiles.keys); |
| 262 return _reuseCompiler(reuser.reuseLibraries, base: base).then( | 262 return _reuseCompiler(reuser.reuseLibraries, base: base).then( |
| 263 (CompilerImpl compiler) async { | 263 (CompilerImpl compiler) async { |
| 264 _compiler = compiler; | 264 _compiler = compiler; |
| 265 FletchDelta delta = await reuser.computeUpdateFletch(currentSystem); | 265 DartinoDelta delta = await reuser.computeUpdateDartino(currentSystem); |
| 266 _checkCompilationFailed(); | 266 _checkCompilationFailed(); |
| 267 return delta; | 267 return delta; |
| 268 }); | 268 }); |
| 269 } | 269 } |
| 270 | 270 |
| 271 FletchDelta computeInitialDelta() { | 271 DartinoDelta computeInitialDelta() { |
| 272 FletchBackend backend = _compiler.backend; | 272 DartinoBackend backend = _compiler.backend; |
| 273 return backend.computeDelta(); | 273 return backend.computeDelta(); |
| 274 } | 274 } |
| 275 | 275 |
| 276 String lookupFunctionName(FletchFunction function) { | 276 String lookupFunctionName(DartinoFunction function) { |
| 277 if (function.isParameterStub) return "<parameter stub>"; | 277 if (function.isParameterStub) return "<parameter stub>"; |
| 278 Element element = function.element; | 278 Element element = function.element; |
| 279 if (element == null) return function.name; | 279 if (element == null) return function.name; |
| 280 if (element.isConstructor) { | 280 if (element.isConstructor) { |
| 281 ConstructorElement constructor = element; | 281 ConstructorElement constructor = element; |
| 282 ClassElement enclosing = constructor.enclosingClass; | 282 ClassElement enclosing = constructor.enclosingClass; |
| 283 String name = (constructor.name == null || constructor.name.length == 0) | 283 String name = (constructor.name == null || constructor.name.length == 0) |
| 284 ? '' | 284 ? '' |
| 285 : '.${constructor.name}'; | 285 : '.${constructor.name}'; |
| 286 String postfix = function.isInitializerList ? ' initializer' : ''; | 286 String postfix = function.isInitializerList ? ' initializer' : ''; |
| 287 return '${enclosing.name}$name$postfix'; | 287 return '${enclosing.name}$name$postfix'; |
| 288 } | 288 } |
| 289 | 289 |
| 290 ClassElement enclosing = element.enclosingClass; | 290 ClassElement enclosing = element.enclosingClass; |
| 291 if (enclosing == null) return function.name; | 291 if (enclosing == null) return function.name; |
| 292 return '${enclosing.name}.${function.name}'; | 292 return '${enclosing.name}.${function.name}'; |
| 293 } | 293 } |
| 294 | 294 |
| 295 ClassDebugInfo createClassDebugInfo(FletchClass klass) { | 295 ClassDebugInfo createClassDebugInfo(DartinoClass klass) { |
| 296 return _compiler.context.backend.createClassDebugInfo(klass); | 296 return _compiler.context.backend.createClassDebugInfo(klass); |
| 297 } | 297 } |
| 298 | 298 |
| 299 String lookupFunctionNameBySelector(int selector) { | 299 String lookupFunctionNameBySelector(int selector) { |
| 300 int id = FletchSelector.decodeId(selector); | 300 int id = DartinoSelector.decodeId(selector); |
| 301 return _compiler.context.symbols[id]; | 301 return _compiler.context.symbols[id]; |
| 302 } | 302 } |
| 303 | 303 |
| 304 DebugInfo createDebugInfo( | 304 DebugInfo createDebugInfo( |
| 305 FletchFunction function, | 305 DartinoFunction function, |
| 306 FletchSystem currentSystem) { | 306 DartinoSystem currentSystem) { |
| 307 return _compiler.context.backend.createDebugInfo(function, currentSystem); | 307 return _compiler.context.backend.createDebugInfo(function, currentSystem); |
| 308 } | 308 } |
| 309 | 309 |
| 310 DebugInfo debugInfoForPosition( | 310 DebugInfo debugInfoForPosition( |
| 311 Uri file, | 311 Uri file, |
| 312 int position, | 312 int position, |
| 313 FletchSystem currentSystem) { | 313 DartinoSystem currentSystem) { |
| 314 return _compiler.debugInfoForPosition(file, position, currentSystem); | 314 return _compiler.debugInfoForPosition(file, position, currentSystem); |
| 315 } | 315 } |
| 316 | 316 |
| 317 int positionInFileFromPattern(Uri file, int line, String pattern) { | 317 int positionInFileFromPattern(Uri file, int line, String pattern) { |
| 318 return _compiler.positionInFileFromPattern(file, line, pattern); | 318 return _compiler.positionInFileFromPattern(file, line, pattern); |
| 319 } | 319 } |
| 320 | 320 |
| 321 int positionInFile(Uri file, int line, int column) { | 321 int positionInFile(Uri file, int line, int column) { |
| 322 return _compiler.positionInFile(file, line, column); | 322 return _compiler.positionInFile(file, line, column); |
| 323 } | 323 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 | 369 |
| 370 case "production": | 370 case "production": |
| 371 return IncrementalMode.production; | 371 return IncrementalMode.production; |
| 372 | 372 |
| 373 case "experimental": | 373 case "experimental": |
| 374 return IncrementalMode.experimental; | 374 return IncrementalMode.experimental; |
| 375 | 375 |
| 376 } | 376 } |
| 377 return null; | 377 return null; |
| 378 } | 378 } |
| OLD | NEW |