| Index: sdk/lib/_internal/compiler/implementation/compile_time_constants.dart
|
| diff --git a/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart b/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart
|
| index ecc8645823df3bf0d40b733657bf6dc2bac1a783..8fa9e9890655a75d5c5d3943157597d31a3c2130 100644
|
| --- a/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart
|
| +++ b/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart
|
| @@ -32,6 +32,9 @@ class ConstantHandler extends CompilerTask {
|
| /** Caches the createRuntimeType function if registered. */
|
| Element createRuntimeTypeFunction = null;
|
|
|
| + /** Caches the setRuntimeTypeInfo function if registered. */
|
| + Element setRuntimeTypeInfoFunction = null;
|
| +
|
| ConstantHandler(Compiler compiler, this.constantSystem,
|
| { bool this.isMetadata: false })
|
| : initialVariableValues = new Map<VariableElement, dynamic>(),
|
| @@ -43,21 +46,26 @@ class ConstantHandler extends CompilerTask {
|
| String get name => 'ConstantHandler';
|
|
|
| void registerCompileTimeConstant(Constant constant, TreeElements elements) {
|
| - registerInstantiatedClass(constant.computeType(compiler).element, elements);
|
| + registerInstantiatedType(constant.computeType(compiler), elements);
|
| if (constant.isFunction()) {
|
| FunctionConstant function = constant;
|
| registerGetOfStaticFunction(function.element);
|
| } else if (constant.isInterceptor()) {
|
| // An interceptor constant references the class's prototype chain.
|
| InterceptorConstant interceptor = constant;
|
| - registerInstantiatedClass(interceptor.dispatchedType.element, elements);
|
| + registerInstantiatedType(interceptor.dispatchedType, elements);
|
| }
|
| compiledConstants.add(constant);
|
| }
|
|
|
| - void registerInstantiatedClass(ClassElement element, TreeElements elements) {
|
| + void registerInstantiatedType(DartType type, TreeElements elements) {
|
| if (isMetadata) return;
|
| - compiler.enqueuer.codegen.registerInstantiatedClass(element, elements);
|
| + compiler.enqueuer.codegen.registerInstantiatedType(type, elements);
|
| + if (type is InterfaceType &&
|
| + !type.isRaw &&
|
| + compiler.backend.needsRti(type.element)) {
|
| + registerSetRuntimeTypeInfoFunction();
|
| + }
|
| }
|
|
|
| void registerStaticUse(Element element) {
|
| @@ -73,7 +81,14 @@ class ConstantHandler extends CompilerTask {
|
| }
|
|
|
| void registerStringInstance(TreeElements elements) {
|
| - registerInstantiatedClass(compiler.stringClass, elements);
|
| + registerInstantiatedType(compiler.stringClass.rawType, elements);
|
| + }
|
| +
|
| + void registerSetRuntimeTypeInfoFunction() {
|
| + if (setRuntimeTypeInfoFunction != null) return;
|
| + SourceString helperName = const SourceString('setRuntimeTypeInfo');
|
| + setRuntimeTypeInfoFunction = compiler.findHelper(helperName);
|
| + registerStaticUse(setRuntimeTypeInfoFunction);
|
| }
|
|
|
| void registerCreateRuntimeTypeFunction() {
|
| @@ -318,17 +333,17 @@ class CompileTimeConstantEvaluator extends Visitor {
|
| }
|
|
|
| Constant visitLiteralBool(LiteralBool node) {
|
| - handler.registerInstantiatedClass(compiler.boolClass, elements);
|
| + handler.registerInstantiatedType(compiler.boolClass.rawType, elements);
|
| return constantSystem.createBool(node.value);
|
| }
|
|
|
| Constant visitLiteralDouble(LiteralDouble node) {
|
| - handler.registerInstantiatedClass(compiler.doubleClass, elements);
|
| + handler.registerInstantiatedType(compiler.doubleClass.rawType, elements);
|
| return constantSystem.createDouble(node.value);
|
| }
|
|
|
| Constant visitLiteralInt(LiteralInt node) {
|
| - handler.registerInstantiatedClass(compiler.intClass, elements);
|
| + handler.registerInstantiatedType(compiler.intClass.rawType, elements);
|
| return constantSystem.createInt(node.value);
|
| }
|
|
|
| @@ -342,9 +357,8 @@ class CompileTimeConstantEvaluator extends Visitor {
|
| link = link.tail) {
|
| arguments.add(evaluateConstant(link.head));
|
| }
|
| - // TODO(9476): get type parameters.
|
| - compiler.listClass.computeType(compiler);
|
| - DartType type = compiler.listClass.rawType;
|
| + DartType type = elements.getType(node);
|
| + handler.registerInstantiatedType(type, elements);
|
| Constant constant = new ListConstant(type, arguments);
|
| handler.registerCompileTimeConstant(constant, elements);
|
| return constant;
|
| @@ -379,9 +393,10 @@ class CompileTimeConstantEvaluator extends Visitor {
|
| }
|
| }
|
| bool hasProtoKey = (protoValue != null);
|
| - // TODO(9476): this should be a List<String> type.
|
| - compiler.listClass.computeType(compiler);
|
| - DartType keysType = compiler.listClass.rawType;
|
| + InterfaceType sourceType = elements.getType(node);
|
| + Link<DartType> arguments =
|
| + new Link<DartType>.fromList([compiler.stringClass.rawType]);
|
| + DartType keysType = new InterfaceType(compiler.listClass, arguments);
|
| ListConstant keysList = new ListConstant(keysType, keys);
|
| handler.registerCompileTimeConstant(keysList, elements);
|
| SourceString className = hasProtoKey
|
| @@ -389,9 +404,9 @@ class CompileTimeConstantEvaluator extends Visitor {
|
| : MapConstant.DART_CLASS;
|
| ClassElement classElement = compiler.jsHelperLibrary.find(className);
|
| classElement.ensureResolved(compiler);
|
| - // TODO(9476): copy over the generic type.
|
| - DartType type = classElement.rawType;
|
| - handler.registerInstantiatedClass(classElement, elements);
|
| + Link<DartType> typeArgument = sourceType.typeArguments.tail;
|
| + InterfaceType type = new InterfaceType(classElement, typeArgument);
|
| + handler.registerInstantiatedType(type, elements);
|
| Constant constant = new MapConstant(type, keysList, values, protoValue);
|
| handler.registerCompileTimeConstant(constant, elements);
|
| return constant;
|
| @@ -445,7 +460,7 @@ class CompileTimeConstantEvaluator extends Visitor {
|
| Constant makeTypeConstant(Element element) {
|
| DartType elementType = element.computeType(compiler).asRaw();
|
| if (compiler.mirrorsEnabled) {
|
| - handler.registerInstantiatedClass(element, elements);
|
| + handler.registerInstantiatedType(elementType, elements);
|
| }
|
| DartType constantType =
|
| compiler.backend.typeImplementation.computeType(compiler);
|
| @@ -654,6 +669,12 @@ class CompileTimeConstantEvaluator extends Visitor {
|
| // constructor to ensure the redirectionTarget has been computed
|
| // correctly. Find a way to avoid this.
|
| compiler.analyzeElement(constructor.declaration);
|
| +
|
| + InterfaceType type = elements.getType(node);
|
| + if ( constructor.isRedirectingFactory) {
|
| + type = constructor.computeTargetType(compiler, type);
|
| + }
|
| +
|
| constructor = constructor.redirectionTarget;
|
| ClassElement classElement = constructor.getEnclosingClass();
|
| // The constructor must be an implementation to ensure that field
|
| @@ -669,10 +690,7 @@ class CompileTimeConstantEvaluator extends Visitor {
|
| evaluator.evaluateConstructorFieldValues(arguments);
|
| List<Constant> jsNewArguments = evaluator.buildJsNewArguments(classElement);
|
|
|
| - handler.registerInstantiatedClass(classElement, elements);
|
| - // TODO(9476): take generic types into account.
|
| - classElement.computeType(compiler);
|
| - DartType type = classElement.rawType;
|
| + handler.registerInstantiatedType(type, elements);
|
| Constant constant = new ConstructedConstant(type, jsNewArguments);
|
| handler.registerCompileTimeConstant(constant, elements);
|
| return constant;
|
|
|