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

Side by Side Diff: pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart

Issue 1388473003: dart2js cps_ir: Use interceptors for is-checks. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 months 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 library dart2js.ir_nodes; 4 library dart2js.ir_nodes;
5 5
6 import 'dart:collection'; 6 import 'dart:collection';
7 import '../constants/values.dart' as values; 7 import '../constants/values.dart' as values;
8 import '../dart_types.dart' show DartType, InterfaceType, TypeVariableType; 8 import '../dart_types.dart' show DartType, InterfaceType, TypeVariableType;
9 import '../elements/elements.dart'; 9 import '../elements/elements.dart';
10 import '../io/source_information.dart' show SourceInformation; 10 import '../io/source_information.dart' show SourceInformation;
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 580
581 /// An "is" type test. 581 /// An "is" type test.
582 /// 582 ///
583 /// Returns `true` if [value] is an instance of [type]. 583 /// Returns `true` if [value] is an instance of [type].
584 /// 584 ///
585 /// [type] must not be the [Object], `dynamic` or [Null] types (though it might 585 /// [type] must not be the [Object], `dynamic` or [Null] types (though it might
586 /// be a type variable containing one of these types). This design is chosen 586 /// be a type variable containing one of these types). This design is chosen
587 /// to simplify code generation for type tests. 587 /// to simplify code generation for type tests.
588 class TypeTest extends Primitive { 588 class TypeTest extends Primitive {
589 Reference<Primitive> value; 589 Reference<Primitive> value;
590
590 final DartType dartType; 591 final DartType dartType;
591 592
592 /// If [type] is an [InterfaceType], this holds the internal representation of 593 /// If [type] is an [InterfaceType], this holds the internal representation of
593 /// the type arguments to [type]. Since these may reference type variables 594 /// the type arguments to [type]. Since these may reference type variables
594 /// from the enclosing class, they are not constant. 595 /// from the enclosing class, they are not constant.
595 /// 596 ///
596 /// If [type] is a [TypeVariableType], this is a singleton list with 597 /// If [type] is a [TypeVariableType], this is a singleton list with
597 /// the internal representation of the type held in that type variable. 598 /// the internal representation of the type held in that type variable.
598 /// 599 ///
599 /// If [type] is a [FunctionType], this is a singleton list with the 600 /// If [type] is a [FunctionType], this is a singleton list with the
600 /// internal representation of that type, 601 /// internal representation of that type,
601 /// 602 ///
602 /// Otherwise the list is empty. 603 /// Otherwise the list is empty.
603 final List<Reference<Primitive>> typeArguments; 604 final List<Reference<Primitive>> typeArguments;
604 605
605 TypeTest(Primitive value, 606 TypeTest(Primitive value,
606 this.dartType, 607 this.dartType,
607 List<Primitive> typeArguments) 608 List<Primitive> typeArguments)
608 : this.value = new Reference<Primitive>(value), 609 : this.value = new Reference<Primitive>(value),
609 this.typeArguments = _referenceList(typeArguments); 610 this.typeArguments = _referenceList(typeArguments);
610 611
611 accept(Visitor visitor) => visitor.visitTypeTest(this); 612 accept(Visitor visitor) => visitor.visitTypeTest(this);
612 613
613 bool get isSafeForElimination => true; 614 bool get isSafeForElimination => true;
614 bool get isSafeForReordering => true; 615 bool get isSafeForReordering => true;
615 } 616 }
616 617
618 /// An "is" type test for a raw type.
619 ///
620 /// Returns `true` if [value] is an instance of [type].
621 ///
622 /// [type] must not be the [Object], `dynamic` or [Null] types (though it might
623 /// be a type variable containing one of these types). This design is chosen
624 /// to simplify code generation for type tests.
625 class TypeTestRaw extends Primitive {
626 //
627 Reference<Primitive> value;
628
629 // Some tests can be performed on the interceptor by testing a property. May
630 // be null for other tests. The interceptor may have been optimized via the
631 // self-interceptor rule to [value].
632 Reference<Primitive> interceptor;
633
634 final DartType dartType;
635
636 bool usePropertyTest = false;
637
638 TypeTestRaw(Primitive value, this.dartType)
639 : this.value = new Reference<Primitive>(value);
640
641 accept(Visitor visitor) => visitor.visitTypeTestRaw(this);
642
643 bool get isSafeForElimination => true;
644 bool get isSafeForReordering => true;
645 }
646
617 /// An "as" type cast. 647 /// An "as" type cast.
618 /// 648 ///
619 /// If [value] is `null` or is an instance of [type], [continuation] is invoked 649 /// If [value] is `null` or is an instance of [type], [continuation] is invoked
620 /// with [value] as argument. Otherwise, a [CastError] is thrown. 650 /// with [value] as argument. Otherwise, a [CastError] is thrown.
621 /// 651 ///
622 /// Discussion: 652 /// Discussion:
623 /// The parameter to [continuation] is redundant since it will always equal 653 /// The parameter to [continuation] is redundant since it will always equal
624 /// [value], which is typically in scope in the continuation. However, it might 654 /// [value], which is typically in scope in the continuation. However, it might
625 /// simplify type propagation, since a better type can be computed for the 655 /// simplify type propagation, since a better type can be computed for the
626 /// continuation parameter without needing flow-sensitive analysis. 656 /// continuation parameter without needing flow-sensitive analysis.
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after
1364 T visitGetStatic(GetStatic node); 1394 T visitGetStatic(GetStatic node);
1365 T visitInterceptor(Interceptor node); 1395 T visitInterceptor(Interceptor node);
1366 T visitCreateInstance(CreateInstance node); 1396 T visitCreateInstance(CreateInstance node);
1367 T visitGetField(GetField node); 1397 T visitGetField(GetField node);
1368 T visitCreateBox(CreateBox node); 1398 T visitCreateBox(CreateBox node);
1369 T visitReifyRuntimeType(ReifyRuntimeType node); 1399 T visitReifyRuntimeType(ReifyRuntimeType node);
1370 T visitReadTypeVariable(ReadTypeVariable node); 1400 T visitReadTypeVariable(ReadTypeVariable node);
1371 T visitTypeExpression(TypeExpression node); 1401 T visitTypeExpression(TypeExpression node);
1372 T visitCreateInvocationMirror(CreateInvocationMirror node); 1402 T visitCreateInvocationMirror(CreateInvocationMirror node);
1373 T visitTypeTest(TypeTest node); 1403 T visitTypeTest(TypeTest node);
1404 T visitTypeTestRaw(TypeTestRaw node);
1374 T visitApplyBuiltinOperator(ApplyBuiltinOperator node); 1405 T visitApplyBuiltinOperator(ApplyBuiltinOperator node);
1375 T visitApplyBuiltinMethod(ApplyBuiltinMethod node); 1406 T visitApplyBuiltinMethod(ApplyBuiltinMethod node);
1376 T visitGetLength(GetLength node); 1407 T visitGetLength(GetLength node);
1377 T visitGetIndex(GetIndex node); 1408 T visitGetIndex(GetIndex node);
1378 T visitSetIndex(SetIndex node); 1409 T visitSetIndex(SetIndex node);
1379 T visitRefinement(Refinement node); 1410 T visitRefinement(Refinement node);
1380 1411
1381 // Support for literal foreign code. 1412 // Support for literal foreign code.
1382 T visitForeignCode(ForeignCode node); 1413 T visitForeignCode(ForeignCode node);
1383 } 1414 }
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1492 node.typeArguments.forEach(processReference); 1523 node.typeArguments.forEach(processReference);
1493 } 1524 }
1494 1525
1495 processTypeTest(TypeTest node) {} 1526 processTypeTest(TypeTest node) {}
1496 visitTypeTest(TypeTest node) { 1527 visitTypeTest(TypeTest node) {
1497 processTypeTest(node); 1528 processTypeTest(node);
1498 processReference(node.value); 1529 processReference(node.value);
1499 node.typeArguments.forEach(processReference); 1530 node.typeArguments.forEach(processReference);
1500 } 1531 }
1501 1532
1533 processTypeTestRaw(TypeTestRaw node) {}
1534 visitTypeTestRaw(TypeTestRaw node) {
1535 processTypeTestRaw(node);
1536 processReference(node.value);
1537 if (node.interceptor != null) processReference(node.interceptor);
1538 }
1539
1502 processSetMutable(SetMutable node) {} 1540 processSetMutable(SetMutable node) {}
1503 visitSetMutable(SetMutable node) { 1541 visitSetMutable(SetMutable node) {
1504 processSetMutable(node); 1542 processSetMutable(node);
1505 processReference(node.variable); 1543 processReference(node.variable);
1506 processReference(node.value); 1544 processReference(node.value);
1507 } 1545 }
1508 1546
1509 processGetLazyStatic(GetLazyStatic node) {} 1547 processGetLazyStatic(GetLazyStatic node) {}
1510 visitGetLazyStatic(GetLazyStatic node) { 1548 visitGetLazyStatic(GetLazyStatic node) {
1511 processGetLazyStatic(node); 1549 processGetLazyStatic(node);
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
1817 /// Visit a just-deleted subterm and unlink all [Reference]s in it. 1855 /// Visit a just-deleted subterm and unlink all [Reference]s in it.
1818 class RemovalVisitor extends RecursiveVisitor { 1856 class RemovalVisitor extends RecursiveVisitor {
1819 processReference(Reference reference) { 1857 processReference(Reference reference) {
1820 reference.unlink(); 1858 reference.unlink();
1821 } 1859 }
1822 1860
1823 static void remove(Node node) { 1861 static void remove(Node node) {
1824 (new RemovalVisitor()).visit(node); 1862 (new RemovalVisitor()).visit(node);
1825 } 1863 }
1826 } 1864 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698