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

Unified Diff: pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart

Issue 819993003: dart2js OldEmitter: inline FinishClasses. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
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 side-by-side diff with in-line comments
Download patch
Index: pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart
diff --git a/pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart b/pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart
index e5983d60808a9aee67176a7283c5164473183719..f61517aa435af90076fb5cc7762e41fd4405173c 100644
--- a/pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart
+++ b/pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart
@@ -21,7 +21,7 @@ class OldEmitter implements Emitter {
final Map<Element, ClassBuilder> cachedClassBuilders;
final Set<Element> cachedElements;
- bool needsDefineClass = false;
+ bool hasClasses = false;
floitsch 2014/12/29 18:00:22 I prefer to stay consistent: needsClassSupport ?
zarah 2014/12/30 14:02:43 Done.
bool needsMixinSupport = false;
bool needsLazyInitializer = false;
final Namer namer;
@@ -147,14 +147,6 @@ class OldEmitter implements Emitter {
String get name => 'CodeEmitter';
- String get currentGenerateAccessorName
- => '${namer.currentIsolate}.\$generateAccessor';
- String get generateAccessorHolder
- => '$isolatePropertiesName.\$generateAccessor';
- String get finishClassesProperty
- => r'$finishClasses';
- String get finishClassesName
- => '${namer.isolateName}.$finishClassesProperty';
String get finishIsolateConstructorName
=> '${namer.isolateName}.\$finishIsolateConstructor';
String get isolatePropertiesName
@@ -221,6 +213,10 @@ class OldEmitter implements Emitter {
return globalPropertyAccess(element);
}
+ List<jsAst.Statement> buildTrivialNsmHandlers(){
+ return nsmEmitter.buildTrivialNsmHandlers();
+ }
+
jsAst.FunctionDeclaration get generateAccessorFunction {
const RANGE1_SIZE = RANGE1_LAST - RANGE1_FIRST + 1;
const RANGE2_SIZE = RANGE2_LAST - RANGE2_FIRST + 1;
@@ -344,12 +340,10 @@ class OldEmitter implements Emitter {
return str;
}''', { 'hasIsolateSupport': hasIsolateSupport });
-
floitsch 2014/12/29 18:00:21 nit. I would keep this new line.
zarah 2014/12/30 14:02:43 Done.
// Declare a function called "generateAccessor". This is used in
- // defineClassFunction (it's a local declaration in init()).
+ // defineClassFunction.
List result = <jsAst.Node>[
generateAccessorFunction,
- js('$generateAccessorHolder = generateAccessor'),
new jsAst.FunctionDeclaration(
new jsAst.VariableDeclaration('defineClass'), defineClass) ];
@@ -443,9 +437,9 @@ class OldEmitter implements Emitter {
return js(r'var inheritFrom = #', [result]);
}
- /// Code that needs to be run before first invocation of
- /// [finishClassesFunction], but should only be run once.
- jsAst.Expression get initFinishClasses {
+ /// Code that needs to be run before processing reflection data,
+ /// but should only be run once.
floitsch 2014/12/29 18:00:21 specify that the "once" refers to deferred librari
zarah 2014/12/30 14:02:43 Done.
+ jsAst.Expression get initProcessStatics {
floitsch 2014/12/29 18:00:21 was already a bad name: "initX" looks/sounds like
zarah 2014/12/30 14:02:43 Done.
jsAst.Expression allClassesAccess =
generateEmbeddedGlobalAccess(embeddedNames.ALL_CLASSES);
jsAst.Expression interceptorsByTagAccess =
@@ -468,131 +462,6 @@ class OldEmitter implements Emitter {
finishedClassesAccess]);
}
- jsAst.Fun get finishClassesFunction {
- // Class descriptions are collected in a JS object.
- // 'finishClasses' takes all collected descriptions and sets up
- // the prototype.
- // Once set up, the constructors prototype field satisfy:
- // - it contains all (local) members.
- // - its internal prototype (__proto__) points to the superclass'
- // prototype field.
- // - the prototype's constructor field points to the JavaScript
- // constructor.
- // For engines where we have access to the '__proto__' we can manipulate
- // the object literal directly. For other engines we have to create a new
- // object and copy over the members.
-
- String reflectableField = namer.reflectableField;
- jsAst.Expression allClassesAccess =
- generateEmbeddedGlobalAccess(embeddedNames.ALL_CLASSES);
- jsAst.Expression metadataAccess =
- generateEmbeddedGlobalAccess(embeddedNames.METADATA);
- String signaturePropertyName = namer.operatorSignature;
-
- return js('''
- function(collectedClasses, isolateProperties, existingIsolateProperties) {
- var pendingClasses = Object.create(null);
- var allClasses = #allClasses;
- var constructors;
-
- if (#debugFastObjects)
- print("Number of classes: " +
- Object.getOwnPropertyNames(\$\$).length);
-
- var hasOwnProperty = Object.prototype.hasOwnProperty;
-
- if (#inCspMode) {
- constructors = dart_precompiled(collectedClasses);
- }
-
- if (#notInCspMode) {
- var combinedConstructorFunction =
- "function \$reflectable(fn){fn.$reflectableField=1;return fn};\\n"+
- "var \$desc;\\n";
- var constructorsList = [];
- }
-
- for (var cls in collectedClasses) {
- var desc = collectedClasses[cls];
- if (desc instanceof Array) desc = desc[1];
-
- /* The 'fields' are either a constructor function or a
- * string encoding fields, constructor and superclass. Gets the
- * superclass and fields in the format
- * 'Super;field1,field2'
- * from the CLASS_DESCRIPTOR_PROPERTY property on the descriptor.
- */
- var classData = desc["${namer.classDescriptorProperty}"],
- supr, fields = classData;
- if (#hasRetainedMetadata)
- if (typeof classData == "object" &&
- classData instanceof Array) {
- classData = fields = classData[0];
- }
- // ${ClassBuilder.fieldEncodingDescription}.
- var s = fields.split(";");
- fields = s[1] == "" ? [] : s[1].split(",");
- supr = s[0];
- // ${ClassBuilder.functionTypeEncodingDescription}.
- split = supr.split(":");
- if (split.length == 2) {
- supr = split[0];
- var functionSignature = split[1];
- if (functionSignature)
- desc.$signaturePropertyName = (function(s) {
- return function(){ return #metadata[s]; };
- })(functionSignature);
- }
-
- if (#notInCspMode) {
- combinedConstructorFunction += defineClass(cls, fields);
- constructorsList.push(cls);
- }
- if (supr) pendingClasses[cls] = supr;
- }
-
- if (#notInCspMode) {
- combinedConstructorFunction +=
- "return [\\n " + constructorsList.join(",\\n ") + "\\n]";
- var constructors =
- new Function("\$collectedClasses", combinedConstructorFunction)
- (collectedClasses);
- combinedConstructorFunction = null;
- }
-
- for (var i = 0; i < constructors.length; i++) {
- var constructor = constructors[i];
- var cls = constructor.name;
- var desc = collectedClasses[cls];
- var globalObject = isolateProperties;
- if (desc instanceof Array) {
- globalObject = desc[0] || isolateProperties;
- desc = desc[1];
- }
- if (#isTreeShakingDisabled)
- constructor["${namer.metadataField}"] = desc;
- allClasses[cls] = constructor;
- globalObject[cls] = constructor;
- }
-
- constructors = null;
-
- #finishClassFunction;
-
- #trivialNsmHandlers;
-
- for (var cls in pendingClasses) finishClass(cls);
- }''', { 'allClasses': allClassesAccess,
- 'debugFastObjects': DEBUG_FAST_OBJECTS,
- 'hasRetainedMetadata': backend.hasRetainedMetadata,
- 'metadata': metadataAccess,
- 'isTreeShakingDisabled': backend.isTreeShakingDisabled,
- 'finishClassFunction': buildFinishClass(),
- 'trivialNsmHandlers': nsmEmitter.buildTrivialNsmHandlers(),
- 'inCspMode': compiler.useContentSecurityPolicy,
- 'notInCspMode': !compiler.useContentSecurityPolicy});
- }
-
jsAst.Node optional(bool condition, jsAst.Node node) {
return condition ? node : new jsAst.EmptyStatement();
}
@@ -616,7 +485,7 @@ class OldEmitter implements Emitter {
if (finishedClasses[cls]) return;
finishedClasses[cls] = true;
- var superclass = pendingClasses[cls];
+ var superclass = processedClasses.pending[cls];
if (#needsMixinSupport) {
if (superclass && superclass.indexOf("+") > 0) {
@@ -757,8 +626,6 @@ class OldEmitter implements Emitter {
Isolate.prototype = oldIsolate.prototype;
Isolate.prototype.constructor = Isolate;
Isolate.#isolatePropertiesName = isolateProperties;
- if (#needsDefineClass)
- Isolate.#finishClassesProperty = oldIsolate.#finishClassesProperty;
if (#outputContainsConstantList)
Isolate.#makeConstListProperty = oldIsolate.#makeConstListProperty;
if (#hasIncrementalSupport)
@@ -768,8 +635,6 @@ class OldEmitter implements Emitter {
}
""",
{ 'isolatePropertiesName': namer.isolatePropertiesName,
- 'needsDefineClass': needsDefineClass,
- 'finishClassesProperty': finishClassesProperty,
'outputContainsConstantList': task.outputContainsConstantList,
'makeConstListProperty': makeConstListProperty,
'hasIncrementalSupport': compiler.hasIncrementalSupport,
@@ -823,14 +688,6 @@ class OldEmitter implements Emitter {
cyclicThrow]);
}
- List buildDefineClassAndFinishClassFunctionsIfNecessary() {
- if (!needsDefineClass) return [];
- return defineClassFunction
- ..add(buildInheritFrom())
- ..add(js('$finishClassesName = #', finishClassesFunction))
- ..add(initFinishClasses);
- }
-
List buildLazyInitializerFunctionIfNecessary() {
if (!needsLazyInitializer) return [];
@@ -1017,17 +874,6 @@ class OldEmitter implements Emitter {
});
}
- void emitFinishClassesInvocationIfNecessary(CodeBuffer buffer) {
- if (needsDefineClass) {
- buffer.write('$finishClassesName($classesCollector,'
- '$_$isolateProperties,'
- '${_}null)$N');
-
- // Reset the map.
- buffer.write("$classesCollector$_=${_}null$N$n");
- }
- }
-
void emitStaticFunctions(List<Element> staticFunctions) {
for (Element element in staticFunctions) {
ClassBuilder builder = new ClassBuilder(element, namer);
@@ -1350,7 +1196,7 @@ class OldEmitter implements Emitter {
$isolateProperties = Object.create(null);
#; #; #;
}''', [
- buildDefineClassAndFinishClassFunctionsIfNecessary(),
+ initProcessStatics,
buildLazyInitializerFunctionIfNecessary(),
floitsch 2014/12/29 18:00:21 just inline all three functions. Use "if (#) ..."
zarah 2014/12/30 14:02:43 Done.
buildFinishIsolateConstructor()]);
@@ -1674,17 +1520,6 @@ class OldEmitter implements Emitter {
emitStaticFunctions(task.outputStaticLists[mainOutputUnit]);
- // Only output the classesCollector if we actually have any classes.
- if (needsDefineClass ||
- !(nativeClasses.isEmpty &&
- compiler.codegenWorld.staticFunctionsNeedingGetter.isEmpty &&
- outputClassLists.values.every((classList) => classList.isEmpty) &&
- typedefsNeededForReflection.isEmpty)) {
- // Shorten the code by using "$$" as temporary.
- classesCollector = r"$$";
- mainBuffer.add('var $classesCollector$_=${_}Object.create(null)$N$n');
- }
-
if (!nativeClasses.isEmpty) {
addComment('Native classes', mainBuffer);
}
@@ -1720,14 +1555,12 @@ class OldEmitter implements Emitter {
..write('(')
..write(
jsAst.prettyPrint(
- getReflectionDataParser(classesCollector, backend),
+ getReflectionDataParser(this, backend),
compiler))
..write(')')
..write('([$n')
..add(libraryBuffer)
..write('])$N');
-
- emitFinishClassesInvocationIfNecessary(mainBuffer);
}
interceptorEmitter.emitGetInterceptorMethods(mainBuffer);
@@ -2020,8 +1853,6 @@ function(originalDescriptor, name, holder, isStatic, globalFunctionsAccess) {
// Shorten the code by using [namer.currentIsolate] as temporary.
isolateProperties = namer.currentIsolate;
- classesCollector = r"$$";
-
// Emit deferred units first, so we have their hashes.
// Map from OutputUnit to a hash of its content. The hash uniquely
// identifies the code of the output-unit. It does not include
@@ -2170,24 +2001,16 @@ function(originalDescriptor, name, holder, isStatic, globalFunctionsAccess) {
// to Isolate.$finishIsolateConstructor.
outputBuffer
..write('var ${namer.currentIsolate}$_=$_$isolatePropertiesName$N')
- // The classesCollector object ($$).
- ..write('$classesCollector$_=${_}Object.create(null);$n')
..write('(')
..write(
jsAst.prettyPrint(
- getReflectionDataParser(classesCollector, backend),
+ getReflectionDataParser(this, backend),
compiler, monitor: compiler.dumpInfoTask))
..write(')')
..write('([$n')
..addBuffer(libraryDescriptorBuffer)
..write('])$N');
- if (outputClassLists.containsKey(outputUnit)) {
- outputBuffer.write(
- '$finishClassesName($classesCollector,$_${namer.currentIsolate},'
- '$_$isolatePropertiesName)$N');
- }
-
}
// Set the currentIsolate variable to the current isolate (which is
@@ -2196,9 +2019,9 @@ function(originalDescriptor, name, holder, isStatic, globalFunctionsAccess) {
// the isolate-properties and for storing the current isolate. During
// the setup (the code above this lines) we must set the variable to
// the isolate-properties.
- // After we have done the setup (finishing with `finishClasses`) it must
- // point to the current Isolate. Otherwise all methods/functions
- // accessing isolate variables will access the wrong object.
+ // After we have done the setup it must point to the current Isolate.
+ // Otherwise all methods/functions accessing isolate variables will
+ // access the wrong object.
outputBuffer.write("${namer.currentIsolate}$_=${_}arguments[1]$N");
emitCompileTimeConstants(outputBuffer, outputUnit);

Powered by Google App Engine
This is Rietveld 408576698