Chromium Code Reviews| Index: lib/compiler/implementation/compiler.dart |
| diff --git a/lib/compiler/implementation/compiler.dart b/lib/compiler/implementation/compiler.dart |
| index 110d9d70608650a030bc9aa81822086d5f6a87b8..46f56c5392ade2c0e7d44168a472135f5123ee49 100644 |
| --- a/lib/compiler/implementation/compiler.dart |
| +++ b/lib/compiler/implementation/compiler.dart |
| @@ -56,6 +56,8 @@ class JavaScriptBackend extends Backend { |
| SsaOptimizerTask optimizer; |
| SsaCodeGeneratorTask generator; |
| CodeEmitterTask emitter; |
| + final Map<Element, Map<Element, HType>> fieldInitializers; |
| + final Map<Element, Map<Element, bool>> fieldIntegerSetters; |
| List<CompilerTask> get tasks() { |
| return <CompilerTask>[builder, optimizer, generator, emitter]; |
| @@ -63,6 +65,8 @@ class JavaScriptBackend extends Backend { |
| JavaScriptBackend(Compiler compiler) |
| : emitter = new CodeEmitterTask(compiler), |
| + fieldInitializers = new Map<Element, Map<Element, HType>>(), |
| + fieldIntegerSetters = new Map<Element, Map<Element, bool>>(), |
| super(compiler) { |
| builder = new SsaBuilderTask(this); |
| optimizer = new SsaOptimizerTask(this); |
| @@ -101,6 +105,76 @@ class JavaScriptBackend extends Backend { |
| void assembleProgram() { |
| emitter.assembleProgram(); |
| } |
| + |
| + void updateFieldInitializers(Type type, |
| + Element field, |
| + HType propagatedType) { |
| + assert(field.isField()); |
| + Map<Element, HType> fields = |
| + fieldInitializers.putIfAbsent( |
| + type.element, () => new Map<Element, HType>()); |
| + if (!fields.containsKey(field)) { |
| + fields[field] = propagatedType; |
| + } else { |
| + if (fields[field] != propagatedType) fields[field] = HType.UNKNOWN; |
|
floitsch
2012/06/20 10:20:33
can't you just union the types?
Søren Gjesse
2012/06/21 08:51:35
Done, that should also be better.
|
| + } |
| + } |
| + |
| + bool couldHaveFieldSingleTypeInitializers(Type type, |
| + Element field, |
| + HType requestedType) { |
| + assert(field.isField()); |
| + if (type == null) return false; |
| + // If there is no information on the initializer it might still be |
| + // initialized to integers only. |
| + if (!fieldInitializers.containsKey(type.element)) return true; |
| + Map<Element, HType> fields = fieldInitializers[type.element]; |
| + HType propagatedType = fields[field]; |
| + if (propagatedType == null) return true; |
| + return propagatedType == requestedType; |
| + } |
| + |
| + bool hasFieldSingleTypeInitializers(Type type, |
| + Element field, |
| + HType requestedType) { |
| + assert(field.isField()); |
| + if (type == null) return false; |
| + if (!fieldInitializers.containsKey(type.element)) return false; |
| + Map<Element, HType> fields = fieldInitializers[type.element]; |
| + HType propagatedType = fields[field]; |
| + if (propagatedType == null) return false; |
| + return propagatedType == requestedType; |
| + } |
| + |
| + void updateFieldIntegerSetters(Type type, Element field, bool isInteger) { |
| + assert(field.isField()); |
| + Map<Element, bool> fields = |
| + fieldIntegerSetters.putIfAbsent( |
| + type.element, () => new Map<Element, bool>()); |
| + if (!fields.containsKey(field)) { |
| + fields[field] = isInteger; |
| + } else { |
| + fields[field] = fields[field] && isInteger; |
| + } |
| + } |
| + |
| + bool couldHaveFieldOnlyIntegerSetters(Type type, Element field) { |
|
floitsch
2012/06/20 10:20:33
Doesn't the field element contain the enclosing c
Søren Gjesse
2012/06/21 08:51:35
It does. The element of the type can be a sub-clas
|
| + assert(field.isField()); |
| + if (type == null) return false; |
| + if (!fieldIntegerSetters.containsKey(type.element)) return true; |
| + Map<Element, bool> fields = fieldIntegerSetters[type.element]; |
| + if (!fields.containsKey(field)) return false; |
| + return fields[field]; |
| + } |
| + |
| + bool hasFieldOnlyIntegerSetters(Type type, Element field) { |
|
floitsch
2012/06/20 10:20:33
I would remove this method. It is identical to the
Søren Gjesse
2012/06/21 08:51:35
Changed the name to onlyFieldIntegerSettersSoFar (
|
| + assert(field.isField()); |
| + if (type == null) return false; |
| + if (!fieldIntegerSetters.containsKey(type.element)) return true; |
| + Map<Element, bool> fields = fieldIntegerSetters[type.element]; |
| + if (!fields.containsKey(field)) return false; |
| + return fields[field]; |
| + } |
| } |
| class Compiler implements DiagnosticListener { |
| @@ -549,7 +623,7 @@ class Compiler implements DiagnosticListener { |
| // TODO(ahe): Add structured diagnostics to the compiler API and |
| // use it to separate this from the --verbose option. |
| if (phase == PHASE_RESOLVING) { |
| - log('Resolved ${enqueuer.resolution.resolvedElements.length}' |
| + log('Resolved ${enqueuer.resolution.resolvedElements.length} ' |
| 'elements.'); |
| progress.reset(); |
| } |