OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 import 'dart:collection'; | 5 import 'dart:collection'; |
6 | 6 |
7 import 'package:js_runtime/shared/embedded_names.dart'; | 7 import 'package:js_runtime/shared/embedded_names.dart'; |
8 | 8 |
9 import '../closure.dart'; | 9 import '../closure.dart'; |
10 import '../common.dart'; | 10 import '../common.dart'; |
(...skipping 19 matching lines...) Expand all Loading... |
30 import '../resolution/operators.dart'; | 30 import '../resolution/operators.dart'; |
31 import '../resolution/semantic_visitor.dart'; | 31 import '../resolution/semantic_visitor.dart'; |
32 import '../resolution/tree_elements.dart' show TreeElements; | 32 import '../resolution/tree_elements.dart' show TreeElements; |
33 import '../tree/tree.dart' as ast; | 33 import '../tree/tree.dart' as ast; |
34 import '../types/types.dart'; | 34 import '../types/types.dart'; |
35 import '../universe/call_structure.dart' show CallStructure; | 35 import '../universe/call_structure.dart' show CallStructure; |
36 import '../universe/selector.dart' show Selector; | 36 import '../universe/selector.dart' show Selector; |
37 import '../universe/side_effects.dart' show SideEffects; | 37 import '../universe/side_effects.dart' show SideEffects; |
38 import '../universe/use.dart' show DynamicUse, StaticUse, TypeUse; | 38 import '../universe/use.dart' show DynamicUse, StaticUse, TypeUse; |
39 import '../util/util.dart'; | 39 import '../util/util.dart'; |
40 import '../world.dart' show ClassWorld; | 40 import '../world.dart' show ClosedWorld; |
41 | 41 |
42 import 'graph_builder.dart'; | 42 import 'graph_builder.dart'; |
43 import 'jump_handler.dart'; | 43 import 'jump_handler.dart'; |
44 import 'locals_handler.dart'; | 44 import 'locals_handler.dart'; |
45 import 'loop_handler.dart'; | 45 import 'loop_handler.dart'; |
46 import 'nodes.dart'; | 46 import 'nodes.dart'; |
47 import 'optimize.dart'; | 47 import 'optimize.dart'; |
48 import 'ssa_branch_builder.dart'; | 48 import 'ssa_branch_builder.dart'; |
49 import 'types.dart'; | 49 import 'types.dart'; |
50 | 50 |
(...skipping 3308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3359 } | 3359 } |
3360 | 3360 |
3361 void handleInvalidSuperInvoke(ast.Send node, ast.NodeList arguments) { | 3361 void handleInvalidSuperInvoke(ast.Send node, ast.NodeList arguments) { |
3362 Selector selector = elements.getSelector(node); | 3362 Selector selector = elements.getSelector(node); |
3363 List<HInstruction> inputs = <HInstruction>[]; | 3363 List<HInstruction> inputs = <HInstruction>[]; |
3364 addGenericSendArgumentsToList(arguments.nodes, inputs); | 3364 addGenericSendArgumentsToList(arguments.nodes, inputs); |
3365 generateSuperNoSuchMethodSend(node, selector, inputs); | 3365 generateSuperNoSuchMethodSend(node, selector, inputs); |
3366 } | 3366 } |
3367 | 3367 |
3368 bool needsSubstitutionForTypeVariableAccess(ClassElement cls) { | 3368 bool needsSubstitutionForTypeVariableAccess(ClassElement cls) { |
3369 ClassWorld classWorld = compiler.closedWorld; | 3369 ClosedWorld closedWorld = compiler.closedWorld; |
3370 if (classWorld.isUsedAsMixin(cls)) return true; | 3370 if (closedWorld.isUsedAsMixin(cls)) return true; |
3371 | 3371 |
3372 return compiler.closedWorld.anyStrictSubclassOf(cls, | 3372 return compiler.closedWorld.anyStrictSubclassOf(cls, |
3373 (ClassElement subclass) { | 3373 (ClassElement subclass) { |
3374 return !rti.isTrivialSubstitution(subclass, cls); | 3374 return !rti.isTrivialSubstitution(subclass, cls); |
3375 }); | 3375 }); |
3376 } | 3376 } |
3377 | 3377 |
3378 /** | 3378 /** |
3379 * Generate code to extract the type argument from the object. | 3379 * Generate code to extract the type argument from the object. |
3380 */ | 3380 */ |
(...skipping 2271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5652 // instead of allocating an iterator object. | 5652 // instead of allocating an iterator object. |
5653 | 5653 |
5654 // This scheme recognizes for-in on direct lists. It does not recognize all | 5654 // This scheme recognizes for-in on direct lists. It does not recognize all |
5655 // uses of ArrayIterator. They still occur when the receiver is an Iterable | 5655 // uses of ArrayIterator. They still occur when the receiver is an Iterable |
5656 // with a `get iterator` method that delegate to another Iterable and the | 5656 // with a `get iterator` method that delegate to another Iterable and the |
5657 // method is inlined. We would require full scalar replacement in that | 5657 // method is inlined. We would require full scalar replacement in that |
5658 // case. | 5658 // case. |
5659 | 5659 |
5660 TypeMask mask = inferenceResults.typeOfIterator(node, elements); | 5660 TypeMask mask = inferenceResults.typeOfIterator(node, elements); |
5661 | 5661 |
5662 ClassWorld classWorld = compiler.closedWorld; | 5662 ClosedWorld closedWorld = compiler.closedWorld; |
5663 if (mask != null && | 5663 if (mask != null && |
5664 mask.satisfies(helpers.jsIndexableClass, classWorld) && | 5664 mask.satisfies(helpers.jsIndexableClass, closedWorld) && |
5665 // String is indexable but not iterable. | 5665 // String is indexable but not iterable. |
5666 !mask.satisfies(helpers.jsStringClass, classWorld)) { | 5666 !mask.satisfies(helpers.jsStringClass, closedWorld)) { |
5667 return buildSyncForInIndexable(node, mask); | 5667 return buildSyncForInIndexable(node, mask); |
5668 } | 5668 } |
5669 buildSyncForInIterator(node); | 5669 buildSyncForInIterator(node); |
5670 } | 5670 } |
5671 | 5671 |
5672 buildSyncForInIterator(ast.SyncForIn node) { | 5672 buildSyncForInIterator(ast.SyncForIn node) { |
5673 // Generate a structure equivalent to: | 5673 // Generate a structure equivalent to: |
5674 // Iterator<E> $iter = <iterable>.iterator; | 5674 // Iterator<E> $iter = <iterable>.iterator; |
5675 // while ($iter.moveNext()) { | 5675 // while ($iter.moveNext()) { |
5676 // <declaredIdentifier> = $iter.current; | 5676 // <declaredIdentifier> = $iter.current; |
(...skipping 1298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6975 this.oldReturnType, | 6975 this.oldReturnType, |
6976 this.oldResolvedAst, | 6976 this.oldResolvedAst, |
6977 this.oldStack, | 6977 this.oldStack, |
6978 this.oldLocalsHandler, | 6978 this.oldLocalsHandler, |
6979 this.inTryStatement, | 6979 this.inTryStatement, |
6980 this.allFunctionsCalledOnce) | 6980 this.allFunctionsCalledOnce) |
6981 : super(function); | 6981 : super(function); |
6982 } | 6982 } |
6983 | 6983 |
6984 class TypeBuilder implements DartTypeVisitor<dynamic, SsaBuilder> { | 6984 class TypeBuilder implements DartTypeVisitor<dynamic, SsaBuilder> { |
6985 final ClassWorld classWorld; | 6985 final ClosedWorld closedWorld; |
6986 | 6986 |
6987 TypeBuilder(this.classWorld); | 6987 TypeBuilder(this.closedWorld); |
6988 | 6988 |
6989 void visit(DartType type, SsaBuilder builder) => type.accept(this, builder); | 6989 void visit(DartType type, SsaBuilder builder) => type.accept(this, builder); |
6990 | 6990 |
6991 void visitVoidType(VoidType type, SsaBuilder builder) { | 6991 void visitVoidType(VoidType type, SsaBuilder builder) { |
6992 ClassElement cls = builder.backend.helpers.VoidRuntimeType; | 6992 ClassElement cls = builder.backend.helpers.VoidRuntimeType; |
6993 builder.push(new HVoidType(type, new TypeMask.exact(cls, classWorld))); | 6993 builder.push(new HVoidType(type, new TypeMask.exact(cls, closedWorld))); |
6994 } | 6994 } |
6995 | 6995 |
6996 void visitTypeVariableType(TypeVariableType type, SsaBuilder builder) { | 6996 void visitTypeVariableType(TypeVariableType type, SsaBuilder builder) { |
6997 ClassElement cls = builder.backend.helpers.RuntimeType; | 6997 ClassElement cls = builder.backend.helpers.RuntimeType; |
6998 TypeMask instructionType = new TypeMask.subclass(cls, classWorld); | 6998 TypeMask instructionType = new TypeMask.subclass(cls, closedWorld); |
6999 if (!builder.sourceElement.enclosingElement.isClosure && | 6999 if (!builder.sourceElement.enclosingElement.isClosure && |
7000 builder.sourceElement.isInstanceMember) { | 7000 builder.sourceElement.isInstanceMember) { |
7001 HInstruction receiver = builder.localsHandler.readThis(); | 7001 HInstruction receiver = builder.localsHandler.readThis(); |
7002 builder.push(new HReadTypeVariable(type, receiver, instructionType)); | 7002 builder.push(new HReadTypeVariable(type, receiver, instructionType)); |
7003 } else { | 7003 } else { |
7004 builder.push(new HReadTypeVariable.noReceiver( | 7004 builder.push(new HReadTypeVariable.noReceiver( |
7005 type, builder.addTypeVariableReference(type), instructionType)); | 7005 type, builder.addTypeVariableReference(type), instructionType)); |
7006 } | 7006 } |
7007 } | 7007 } |
7008 | 7008 |
(...skipping 16 matching lines...) Expand all Loading... |
7025 List<String> names = type.namedParameters; | 7025 List<String> names = type.namedParameters; |
7026 for (int index = 0; index < names.length; index++) { | 7026 for (int index = 0; index < names.length; index++) { |
7027 ast.DartString dartString = new ast.DartString.literal(names[index]); | 7027 ast.DartString dartString = new ast.DartString.literal(names[index]); |
7028 inputs.add(builder.graph.addConstantString(dartString, builder.compiler)); | 7028 inputs.add(builder.graph.addConstantString(dartString, builder.compiler)); |
7029 namedParameterTypes[index].accept(this, builder); | 7029 namedParameterTypes[index].accept(this, builder); |
7030 inputs.add(builder.pop()); | 7030 inputs.add(builder.pop()); |
7031 } | 7031 } |
7032 | 7032 |
7033 ClassElement cls = builder.backend.helpers.RuntimeFunctionType; | 7033 ClassElement cls = builder.backend.helpers.RuntimeFunctionType; |
7034 builder.push( | 7034 builder.push( |
7035 new HFunctionType(inputs, type, new TypeMask.exact(cls, classWorld))); | 7035 new HFunctionType(inputs, type, new TypeMask.exact(cls, closedWorld))); |
7036 } | 7036 } |
7037 | 7037 |
7038 void visitMalformedType(MalformedType type, SsaBuilder builder) { | 7038 void visitMalformedType(MalformedType type, SsaBuilder builder) { |
7039 visitDynamicType(const DynamicType(), builder); | 7039 visitDynamicType(const DynamicType(), builder); |
7040 } | 7040 } |
7041 | 7041 |
7042 void visitStatementType(StatementType type, SsaBuilder builder) { | 7042 void visitStatementType(StatementType type, SsaBuilder builder) { |
7043 throw 'not implemented visitStatementType($type)'; | 7043 throw 'not implemented visitStatementType($type)'; |
7044 } | 7044 } |
7045 | 7045 |
7046 void visitInterfaceType(InterfaceType type, SsaBuilder builder) { | 7046 void visitInterfaceType(InterfaceType type, SsaBuilder builder) { |
7047 List<HInstruction> inputs = <HInstruction>[]; | 7047 List<HInstruction> inputs = <HInstruction>[]; |
7048 for (DartType typeArgument in type.typeArguments) { | 7048 for (DartType typeArgument in type.typeArguments) { |
7049 typeArgument.accept(this, builder); | 7049 typeArgument.accept(this, builder); |
7050 inputs.add(builder.pop()); | 7050 inputs.add(builder.pop()); |
7051 } | 7051 } |
7052 ClassElement cls; | 7052 ClassElement cls; |
7053 if (type.typeArguments.isEmpty) { | 7053 if (type.typeArguments.isEmpty) { |
7054 cls = builder.backend.helpers.RuntimeTypePlain; | 7054 cls = builder.backend.helpers.RuntimeTypePlain; |
7055 } else { | 7055 } else { |
7056 cls = builder.backend.helpers.RuntimeTypeGeneric; | 7056 cls = builder.backend.helpers.RuntimeTypeGeneric; |
7057 } | 7057 } |
7058 builder.push( | 7058 builder.push( |
7059 new HInterfaceType(inputs, type, new TypeMask.exact(cls, classWorld))); | 7059 new HInterfaceType(inputs, type, new TypeMask.exact(cls, closedWorld))); |
7060 } | 7060 } |
7061 | 7061 |
7062 void visitTypedefType(TypedefType type, SsaBuilder builder) { | 7062 void visitTypedefType(TypedefType type, SsaBuilder builder) { |
7063 DartType unaliased = type.unaliased; | 7063 DartType unaliased = type.unaliased; |
7064 if (unaliased is TypedefType) throw 'unable to unalias $type'; | 7064 if (unaliased is TypedefType) throw 'unable to unalias $type'; |
7065 unaliased.accept(this, builder); | 7065 unaliased.accept(this, builder); |
7066 } | 7066 } |
7067 | 7067 |
7068 void visitDynamicType(DynamicType type, SsaBuilder builder) { | 7068 void visitDynamicType(DynamicType type, SsaBuilder builder) { |
7069 JavaScriptBackend backend = builder.compiler.backend; | 7069 JavaScriptBackend backend = builder.compiler.backend; |
7070 ClassElement cls = backend.helpers.DynamicRuntimeType; | 7070 ClassElement cls = backend.helpers.DynamicRuntimeType; |
7071 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld))); | 7071 builder.push(new HDynamicType(type, new TypeMask.exact(cls, closedWorld))); |
7072 } | 7072 } |
7073 } | 7073 } |
OLD | NEW |