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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/closure.dart

Issue 17262003: Fix type variables in closures. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Handle is!. Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
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 library closureToClassMapper; 5 library closureToClassMapper;
6 6
7 import "elements/elements.dart"; 7 import "elements/elements.dart";
8 import "dart2jslib.dart"; 8 import "dart2jslib.dart";
9 import "dart_types.dart"; 9 import "dart_types.dart";
10 import "scanner/scannerlib.dart" show Token; 10 import "scanner/scannerlib.dart" show Token;
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 502
503 visitSend(Send node) { 503 visitSend(Send node) {
504 Element element = elements[node]; 504 Element element = elements[node];
505 if (Elements.isLocal(element)) { 505 if (Elements.isLocal(element)) {
506 useLocal(element); 506 useLocal(element);
507 } else if (node.receiver == null && 507 } else if (node.receiver == null &&
508 Elements.isInstanceSend(node, elements)) { 508 Elements.isInstanceSend(node, elements)) {
509 registerNeedsThis(); 509 registerNeedsThis();
510 } else if (node.isSuperCall) { 510 } else if (node.isSuperCall) {
511 registerNeedsThis(); 511 registerNeedsThis();
512 } else if (node.isIsCheck || node.isIsNotCheck) {
ngeoffray 2013/06/18 08:00:43 Why isn't visiting the right hand side of the expr
karlklose 2013/06/18 11:05:00 It is not enough because we only recorded the depe
513 TypeAnnotation annotation = node.typeAnnotationFromIsCheck;
514 DartType type = elements.getType(annotation);
515 if (type != null && type.containsTypeVariables) {
516 registerNeedsThis();
517 }
512 } else if (node.isParameterCheck) { 518 } else if (node.isParameterCheck) {
513 Element parameter = elements[node.receiver]; 519 Element parameter = elements[node.receiver];
514 FunctionElement enclosing = parameter.enclosingElement; 520 FunctionElement enclosing = parameter.enclosingElement;
515 FunctionExpression function = enclosing.parseNode(compiler); 521 FunctionExpression function = enclosing.parseNode(compiler);
516 ClosureClassMap cached = closureMappingCache[function]; 522 ClosureClassMap cached = closureMappingCache[function];
517 if (!cached.parametersWithSentinel.containsKey(parameter)) { 523 if (!cached.parametersWithSentinel.containsKey(parameter)) {
518 SourceString parameterName = parameter.name; 524 SourceString parameterName = parameter.name;
519 String name = '${parameterName.slowToString()}_check'; 525 String name = '${parameterName.slowToString()}_check';
520 Element newElement = new CheckVariableElement(new SourceString(name), 526 Element newElement = new CheckVariableElement(new SourceString(name),
521 parameter, 527 parameter,
(...skipping 13 matching lines...) Expand all
535 if (Elements.isLocal(element) && 541 if (Elements.isLocal(element) &&
536 element.computeType(compiler).containsTypeVariables) { 542 element.computeType(compiler).containsTypeVariables) {
537 registerNeedsThis(); 543 registerNeedsThis();
538 } 544 }
539 super.visitSendSet(node); 545 super.visitSendSet(node);
540 } 546 }
541 547
542 visitNewExpression(NewExpression node) { 548 visitNewExpression(NewExpression node) {
543 DartType type = elements.getType(node); 549 DartType type = elements.getType(node);
544 550
545 bool hasTypeVariable(DartType type) {
546 if (type is TypeVariableType) {
547 return true;
548 } else if (type is InterfaceType) {
549 InterfaceType ifcType = type;
550 for (DartType argument in ifcType.typeArguments) {
551 if (hasTypeVariable(argument)) {
552 return true;
553 }
554 }
555 }
556 return false;
557 }
558
559 void analyzeTypeVariables(DartType type) { 551 void analyzeTypeVariables(DartType type) {
560 if (type is TypeVariableType) { 552 if (type is TypeVariableType) {
561 useLocal(type.element); 553 useLocal(type.element);
554 if (outermostElement.isConstructor()) {
ngeoffray 2013/06/18 08:00:43 Why is it only for constructor? Please add a comme
karlklose 2013/06/18 11:05:00 Added comment and changed to !isField.
555 registerNeedsThis();
556 }
562 } else if (type is InterfaceType) { 557 } else if (type is InterfaceType) {
563 InterfaceType ifcType = type; 558 InterfaceType ifcType = type;
564 for (DartType argument in ifcType.typeArguments) { 559 for (DartType argument in ifcType.typeArguments) {
565 analyzeTypeVariables(argument); 560 analyzeTypeVariables(argument);
566 } 561 }
567 } 562 }
568 } 563 }
569 564
570 if (outermostElement.isMember() && 565 if (outermostElement.isMember() &&
571 compiler.backend.needsRti(outermostElement.getEnclosingClass())) { 566 compiler.backend.needsRti(outermostElement.getEnclosingClass())) {
572 if (outermostElement.isConstructor() || outermostElement.isField()) { 567 if (outermostElement.isConstructor() || outermostElement.isField()) {
573 analyzeTypeVariables(type); 568 analyzeTypeVariables(type);
574 } else if (outermostElement.isInstanceMember()) { 569 } else if (outermostElement.isInstanceMember()) {
575 if (hasTypeVariable(type)) { 570 if (type.containsTypeVariables) {
576 registerNeedsThis(); 571 registerNeedsThis();
577 } 572 }
578 } 573 }
579 } 574 }
580 575
581 node.visitChildren(this); 576 node.visitChildren(this);
582 } 577 }
583 578
584 // If variables that are declared in the [node] scope are captured and need 579 // If variables that are declared in the [node] scope are captured and need
585 // to be boxed create a box-element and update the [capturingScopes] in the 580 // to be boxed create a box-element and update the [capturingScopes] in the
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 } 797 }
803 798
804 visitTryStatement(TryStatement node) { 799 visitTryStatement(TryStatement node) {
805 // TODO(ngeoffray): implement finer grain state. 800 // TODO(ngeoffray): implement finer grain state.
806 bool oldInTryStatement = inTryStatement; 801 bool oldInTryStatement = inTryStatement;
807 inTryStatement = true; 802 inTryStatement = true;
808 node.visitChildren(this); 803 node.visitChildren(this);
809 inTryStatement = oldInTryStatement; 804 inTryStatement = oldInTryStatement;
810 } 805 }
811 } 806 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698