Chromium Code Reviews| 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.library_updater; | 5 library fletchc_incremental.library_updater; |
| 6 | 6 |
| 7 import 'dart:async' show | 7 import 'dart:async' show |
| 8 Future; | 8 Future; |
| 9 | 9 |
| 10 import 'dart:convert' show | 10 import 'dart:convert' show |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 FunctionExpression, | 53 FunctionExpression, |
| 54 LibraryTag, | 54 LibraryTag, |
| 55 NodeList, | 55 NodeList, |
| 56 Part, | 56 Part, |
| 57 StringNode, | 57 StringNode, |
| 58 unparse; | 58 unparse; |
| 59 | 59 |
| 60 import '../src/fletch_backend.dart' show | 60 import '../src/fletch_backend.dart' show |
| 61 FletchBackend; | 61 FletchBackend; |
| 62 | 62 |
| 63 import '../src/compiled_class.dart' show | 63 import '../src/fletch_class_builder.dart' show |
| 64 CompiledClass; | 64 FletchClassBuilder; |
| 65 | 65 |
| 66 import '../commands.dart' show | 66 import '../commands.dart' show |
| 67 Command, | 67 Command, |
| 68 MapId; | 68 MapId; |
| 69 | 69 |
| 70 import '../commands.dart' as commands_lib; | 70 import '../commands.dart' as commands_lib; |
| 71 | 71 |
| 72 import 'package:compiler/src/util/util.dart' show | 72 import 'package:compiler/src/util/util.dart' show |
| 73 Link, | 73 Link, |
| 74 LinkBuilder; | 74 LinkBuilder; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 91 TagState; | 91 TagState; |
| 92 | 92 |
| 93 import 'diff.dart' show | 93 import 'diff.dart' show |
| 94 Difference, | 94 Difference, |
| 95 computeDifference; | 95 computeDifference; |
| 96 | 96 |
| 97 import 'fletchc_incremental.dart' show | 97 import 'fletchc_incremental.dart' show |
| 98 IncrementalCompilationFailed, | 98 IncrementalCompilationFailed, |
| 99 IncrementalCompiler; | 99 IncrementalCompiler; |
| 100 | 100 |
| 101 import '../src/compiled_function.dart' show | 101 import '../src/fletch_function_builder.dart' show |
| 102 CompiledFunction; | 102 FletchFunctionBuilder; |
| 103 | 103 |
| 104 typedef void Logger(message); | 104 typedef void Logger(message); |
| 105 | 105 |
| 106 typedef bool Reuser( | 106 typedef bool Reuser( |
| 107 Token diffToken, | 107 Token diffToken, |
| 108 PartialElement before, | 108 PartialElement before, |
| 109 PartialElement after); | 109 PartialElement after); |
| 110 | 110 |
| 111 class FailedUpdate { | 111 class FailedUpdate { |
| 112 /// Either an [Element] or a [Difference]. | 112 /// Either an [Element] or a [Difference]. |
| (...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 855 updates.add(new commands_lib.PopToMap(MapId.constants, id)); | 855 updates.add(new commands_lib.PopToMap(MapId.constants, id)); |
| 856 } | 856 } |
| 857 }); | 857 }); |
| 858 | 858 |
| 859 for (Function action in deferredActions) { | 859 for (Function action in deferredActions) { |
| 860 action(); | 860 action(); |
| 861 changes++; | 861 changes++; |
| 862 } | 862 } |
| 863 | 863 |
| 864 for (ClassElementX element in _classesWithSchemaChanges) { | 864 for (ClassElementX element in _classesWithSchemaChanges) { |
| 865 CompiledClass compiledClass = backend.compiledClasses[element]; | 865 FletchClassBuilder classBuilder = backend.classBuilderes[element]; |
|
Johnni Winther
2015/06/09 09:24:32
classBuilderes -> classBuilders (throughout)
Anders Johnsen
2015/06/09 10:15:40
Done.
| |
| 866 int id = compiledClass.id; | 866 int id = classBuilder.id; |
| 867 updates.add(new commands_lib.PushFromMap(MapId.classes, id)); | 867 updates.add(new commands_lib.PushFromMap(MapId.classes, id)); |
| 868 | 868 |
| 869 compiledClass.createImplicitAccessors(backend); | 869 classBuilder.createImplicitAccessors(backend); |
| 870 Map<int, int> methodTable = compiledClass.computeMethodTable(backend); | 870 Map<int, int> methodTable = classBuilder.computeMethodTable(backend); |
| 871 | 871 |
| 872 methodTable.forEach((int selector, int methodId) { | 872 methodTable.forEach((int selector, int methodId) { |
| 873 updates.add(new commands_lib.PushNewInteger(selector)); | 873 updates.add(new commands_lib.PushNewInteger(selector)); |
| 874 updates.add(new commands_lib.PushFromMap(MapId.methods, methodId)); | 874 updates.add(new commands_lib.PushFromMap(MapId.methods, methodId)); |
| 875 }); | 875 }); |
| 876 | 876 |
| 877 updates.add(new commands_lib.ChangeMethodTable(methodTable.length)); | 877 updates.add(new commands_lib.ChangeMethodTable(methodTable.length)); |
| 878 changes++; | 878 changes++; |
| 879 } | 879 } |
| 880 | 880 |
| 881 for (ClassElementX element in _classesWithSchemaChanges) { | 881 for (ClassElementX element in _classesWithSchemaChanges) { |
| 882 computeSchemaChange(element, beforeFields[element], updates); | 882 computeSchemaChange(element, beforeFields[element], updates); |
| 883 changes++; | 883 changes++; |
| 884 } | 884 } |
| 885 | 885 |
| 886 updates.add(new commands_lib.CommitChanges(changes)); | 886 updates.add(new commands_lib.CommitChanges(changes)); |
| 887 | 887 |
| 888 return updates; | 888 return updates; |
| 889 } | 889 } |
| 890 | 890 |
| 891 void computeFieldUpdateFletch(FieldElementX element, List<Command> commands) { | 891 void computeFieldUpdateFletch(FieldElementX element, List<Command> commands) { |
| 892 throw new IncrementalCompilationFailed("Not implemented yet."); | 892 throw new IncrementalCompilationFailed("Not implemented yet."); |
| 893 } | 893 } |
| 894 | 894 |
| 895 void computeMethodUpdateFletch(Element element, List<Command> commands) { | 895 void computeMethodUpdateFletch(Element element, List<Command> commands) { |
| 896 CompiledFunction function = lookupCompiledFunction(element); | 896 FletchFunctionBuilder function = lookupFletchFunctionBuilder(element); |
| 897 backend.pushNewFunction(function, commands, deferredActions); | 897 backend.pushNewFunction(function, commands, deferredActions); |
| 898 if (element == backend.context.compiler.mainFunction) { | 898 if (element == backend.context.compiler.mainFunction) { |
| 899 deferredActions.add(() { | 899 deferredActions.add(() { |
| 900 CompiledFunction callMain = | 900 FletchFunctionBuilder callMain = |
| 901 lookupCompiledFunction( | 901 lookupFletchFunctionBuilder( |
| 902 backend.fletchSystemLibrary.findLocal('callMain')); | 902 backend.fletchSystemLibrary.findLocal('callMain')); |
| 903 commands.add( | 903 commands.add( |
| 904 new commands_lib.PushFromMap(MapId.methods, callMain.methodId)); | 904 new commands_lib.PushFromMap(MapId.methods, callMain.methodId)); |
| 905 commands.add( | 905 commands.add( |
| 906 new commands_lib.PushFromMap(MapId.methods, function.methodId)); | 906 new commands_lib.PushFromMap(MapId.methods, function.methodId)); |
| 907 commands.add(new commands_lib.ChangeMethodLiteral(0)); | 907 commands.add(new commands_lib.ChangeMethodLiteral(0)); |
| 908 }); | 908 }); |
| 909 } | 909 } |
| 910 } | 910 } |
| 911 | 911 |
| 912 void computeSchemaChange(ClassElementX element, | 912 void computeSchemaChange(ClassElementX element, |
| 913 Map<FieldElementX, int> beforeFields, | 913 Map<FieldElementX, int> beforeFields, |
| 914 List<Command> commands) { | 914 List<Command> commands) { |
| 915 CompiledClass compiledClass = backend.compiledClasses[element]; | 915 FletchClassBuilder classBuilder = backend.classBuilderes[element]; |
| 916 | 916 |
| 917 // Collect the list of fields as they should exist after the transformation. | 917 // Collect the list of fields as they should exist after the transformation. |
| 918 List<FieldElementX> afterFields = []; | 918 List<FieldElementX> afterFields = []; |
| 919 forEachField(element, (field) { | 919 forEachField(element, (field) { |
| 920 afterFields.add(field); | 920 afterFields.add(field); |
| 921 }); | 921 }); |
| 922 | 922 |
| 923 // First, we push all the classes we want to change the schema of. This | 923 // First, we push all the classes we want to change the schema of. This |
| 924 // includes all subclasses. | 924 // includes all subclasses. |
| 925 int numberOfClasses = 0; | 925 int numberOfClasses = 0; |
| 926 Queue<ClassElementX> workQueue = new Queue<ClassElementX>()..add(element); | 926 Queue<ClassElementX> workQueue = new Queue<ClassElementX>()..add(element); |
| 927 while (workQueue.isNotEmpty) { | 927 while (workQueue.isNotEmpty) { |
| 928 ClassElementX current = workQueue.removeFirst(); | 928 ClassElementX current = workQueue.removeFirst(); |
| 929 int id = backend.compiledClasses[current].id; | 929 int id = backend.classBuilderes[current].id; |
| 930 commands.add(new commands_lib.PushFromMap(MapId.classes, id)); | 930 commands.add(new commands_lib.PushFromMap(MapId.classes, id)); |
| 931 numberOfClasses++; | 931 numberOfClasses++; |
| 932 // Add all subclasses that aren't schema change target themselves to | 932 // Add all subclasses that aren't schema change target themselves to |
| 933 // the work queue. | 933 // the work queue. |
| 934 for (ClassElementX subclass in backend.directSubclasses[current]) { | 934 for (ClassElementX subclass in backend.directSubclasses[current]) { |
| 935 if (!_classesWithSchemaChanges.contains(subclass)) { | 935 if (!_classesWithSchemaChanges.contains(subclass)) { |
| 936 workQueue.add(subclass); | 936 workQueue.add(subclass); |
| 937 } | 937 } |
| 938 } | 938 } |
| 939 } | 939 } |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1145 | 1145 |
| 1146 throw new IncrementalCompilationFailed("Not implemented yet."); | 1146 throw new IncrementalCompilationFailed("Not implemented yet."); |
| 1147 } | 1147 } |
| 1148 } | 1148 } |
| 1149 | 1149 |
| 1150 class RemovedFieldUpdate extends RemovalUpdate with FletchFeatures { | 1150 class RemovedFieldUpdate extends RemovalUpdate with FletchFeatures { |
| 1151 final FieldElementX element; | 1151 final FieldElementX element; |
| 1152 | 1152 |
| 1153 bool wasStateCaptured = false; | 1153 bool wasStateCaptured = false; |
| 1154 | 1154 |
| 1155 CompiledClass beforeCompiledClass; | 1155 FletchClassBuilder beforeFletchClassBuilder; |
| 1156 Map<FieldElement, int> beforeFields; | 1156 Map<FieldElement, int> beforeFields; |
| 1157 | 1157 |
| 1158 RemovedFieldUpdate(Compiler compiler, this.element) | 1158 RemovedFieldUpdate(Compiler compiler, this.element) |
| 1159 : super(compiler); | 1159 : super(compiler); |
| 1160 | 1160 |
| 1161 PartialFieldList get before => element.declarationSite; | 1161 PartialFieldList get before => element.declarationSite; |
| 1162 | 1162 |
| 1163 PartialFieldList get after => null; | 1163 PartialFieldList get after => null; |
| 1164 | 1164 |
| 1165 void captureState() { | 1165 void captureState() { |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1369 return element is ElementX ? element.declarationSite : null; | 1369 return element is ElementX ? element.declarationSite : null; |
| 1370 } | 1370 } |
| 1371 | 1371 |
| 1372 abstract class FletchFeatures { | 1372 abstract class FletchFeatures { |
| 1373 Compiler get compiler; | 1373 Compiler get compiler; |
| 1374 | 1374 |
| 1375 FletchBackend get backend => compiler.backend; | 1375 FletchBackend get backend => compiler.backend; |
| 1376 | 1376 |
| 1377 EnqueueTask get enqueuer => compiler.enqueuer; | 1377 EnqueueTask get enqueuer => compiler.enqueuer; |
| 1378 | 1378 |
| 1379 CompiledFunction lookupCompiledFunction(FunctionElement function) { | 1379 FletchFunctionBuilder lookupFletchFunctionBuilder(FunctionElement function) { |
| 1380 return backend.compiledFunctions[function]; | 1380 return backend.functionBuilders[function]; |
| 1381 } | 1381 } |
| 1382 } | 1382 } |
| 1383 | 1383 |
| 1384 // TODO(ahe): Remove this method. | 1384 // TODO(ahe): Remove this method. |
| 1385 NO_WARN(x) => x; | 1385 NO_WARN(x) => x; |
| OLD | NEW |