Chromium Code Reviews| Index: lib/compiler/implementation/js_backend/backend.dart |
| diff --git a/lib/compiler/implementation/js_backend/backend.dart b/lib/compiler/implementation/js_backend/backend.dart |
| index 392f72c5bee81b3bcb3d4749b24a31875a555354..abf2b08f3697bd8ad8c354784c07bb39b86870c2 100644 |
| --- a/lib/compiler/implementation/js_backend/backend.dart |
| +++ b/lib/compiler/implementation/js_backend/backend.dart |
| @@ -225,10 +225,13 @@ class HTypeList { |
| class ArgumentTypesRegistry { |
| final JavaScriptBackend backend; |
| + /// Invariant: Keys must be declaration elements. |
| final Map<Element, HTypeList> staticTypeMap; |
| + /// Invariant: Elements must be declaration elements. |
| final Set<Element> optimizedStaticFunctions; |
| final SelectorMap<HTypeList> selectorTypeMap; |
| final FunctionSet optimizedFunctions; |
| + /// Invariant: Keys must be declaration elements. |
| final Map<Element, HTypeList> optimizedTypes; |
| final Map<Element, OptionalParameterTypes> optimizedDefaultValueTypes; |
| @@ -246,6 +249,7 @@ class ArgumentTypesRegistry { |
| void registerStaticInvocation(HInvokeStatic node, HTypeMap types) { |
| Element element = node.element; |
| + assert(element.isDeclaration); |
| HTypeList oldTypes = staticTypeMap[element]; |
| if (oldTypes == null) { |
| staticTypeMap[element] = new HTypeList.fromStaticInvocation(node, types); |
| @@ -264,6 +268,7 @@ class ArgumentTypesRegistry { |
| // When a static is used for anything else than a call target we cannot |
| // infer anything about its parameter types. |
| Element element = node.element; |
| + assert(element.isDeclaration); |
| if (optimizedStaticFunctions.contains(element)) { |
| backend.scheduleForRecompilation(element); |
| } |
| @@ -327,6 +332,7 @@ class ArgumentTypesRegistry { |
| HTypeList parameterTypes(FunctionElement element, |
| OptionalParameterTypes defaultValueTypes) { |
| + assert(element.isDeclaration); |
| // Handle static functions separately. |
| if (Elements.isStaticOrTopLevelFunction(element) || |
| element.kind == ElementKind.GENERATIVE_CONSTRUCTOR) { |
| @@ -367,6 +373,7 @@ class ArgumentTypesRegistry { |
| void registerOptimization(Element element, |
| HTypeList parameterTypes, |
| OptionalParameterTypes defaultValueTypes) { |
| + assert(element.isDeclaration); |
| if (Elements.isStaticOrTopLevelFunction(element)) { |
| if (parameterTypes.allUnknown) { |
| optimizedStaticFunctions.remove(element); |
| @@ -427,6 +434,7 @@ class JavaScriptBackend extends Backend { |
| final Map<Element, ReturnInfo> returnInfo; |
| + /// Invariant: Elements must be declaration elements. |
| final List<Element> invalidateAfterCodegen; |
| ArgumentTypesRegistry argumentTypes; |
| @@ -613,7 +621,11 @@ class JavaScriptBackend extends Backend { |
| return fields[field]; |
| } |
| + /** |
| + * Invariant: [element] must be the declaration element. |
|
ahe
2012/09/18 11:25:54
Not documentation.
Johnni Winther
2012/09/20 08:12:23
Done.
|
| + */ |
| void scheduleForRecompilation(Element element) { |
| + assert(element.isDeclaration); |
| if (compiler.phase == Compiler.PHASE_COMPILING) { |
| invalidateAfterCodegen.add(element); |
| } |
| @@ -649,10 +661,13 @@ class JavaScriptBackend extends Backend { |
| * Retrieve the types of the parameters used for calling the [element] |
| * function. The types are optimistic in the sense as they are based on the |
| * possible invocations of the function seen so far. |
| + * |
| + * Invariant: [element] must be the declaration element. |
| */ |
| HTypeList optimisticParameterTypes( |
| FunctionElement element, |
| OptionalParameterTypes defaultValueTypes) { |
| + assert(element.isDeclaration); |
| if (element.parameterCount(compiler) == 0) return HTypeList.ALL_UNKNOWN; |
| return argumentTypes.parameterTypes(element, defaultValueTypes); |
| } |
| @@ -663,6 +678,8 @@ class JavaScriptBackend extends Backend { |
| * The passed [defaultValueTypes] holds the types of default values for |
| * the optional parameters. If this assumption fail the function will be |
| * scheduled for recompilation. |
| + * |
| + * Invariant: [element] must be the declaration element. |
| */ |
| registerParameterTypesOptimization( |
| FunctionElement element, |
| @@ -673,7 +690,11 @@ class JavaScriptBackend extends Backend { |
| element, parameterTypes, defaultValueTypes); |
| } |
| + /** |
| + * Invariant: [element] must be the declaration element. |
| + */ |
| void registerReturnType(FunctionElement element, HType returnType) { |
| + assert(element.isDeclaration); |
| ReturnInfo info = returnInfo[element]; |
| if (info != null) { |
| info.update(returnType, scheduleForRecompilation); |
| @@ -688,6 +709,8 @@ class JavaScriptBackend extends Backend { |
| * is recompiled the return type might change to someting broader. For that |
| * reason [caller] is registered for recompilation if this happens. If the |
| * function [callee] has not yet been compiled the returned type is [null]. |
| + * |
| + * Invariant: Both [caller] and [callee] must be the declaration elements. |
| */ |
| HType optimisticReturnTypesWithRecompilationOnTypeChange( |
| Element caller, FunctionElement callee) { |