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

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

Issue 14698026: Revert "Enable full type-checks in checked mode." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 7 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
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/js_backend/backend.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 // TODO(ngeoffray): only do this if the variable is mutated. 383 // TODO(ngeoffray): only do this if the variable is mutated.
384 closureData.usedVariablesInTry.add(element); 384 closureData.usedVariablesInTry.add(element);
385 } 385 }
386 } 386 }
387 } 387 }
388 388
389 void declareLocal(Element element) { 389 void declareLocal(Element element) {
390 scopeVariables.add(element); 390 scopeVariables.add(element);
391 } 391 }
392 392
393 void registerNeedsThis() {
394 if (closureData.thisElement != null) {
395 useLocal(closureData.thisElement);
396 }
397 }
398
399 visit(Node node) => node.accept(this); 393 visit(Node node) => node.accept(this);
400 394
401 visitNode(Node node) => node.visitChildren(this); 395 visitNode(Node node) => node.visitChildren(this);
402 396
403 visitVariableDefinitions(VariableDefinitions node) { 397 visitVariableDefinitions(VariableDefinitions node) {
404 if (node.type != null) {
405 visit(node.type);
406 }
407 for (Link<Node> link = node.definitions.nodes; 398 for (Link<Node> link = node.definitions.nodes;
408 !link.isEmpty; 399 !link.isEmpty;
409 link = link.tail) { 400 link = link.tail) {
410 Node definition = link.head; 401 Node definition = link.head;
411 Element element = elements[definition]; 402 Element element = elements[definition];
412 assert(element != null); 403 assert(element != null);
413 declareLocal(element); 404 declareLocal(element);
414 // We still need to visit the right-hand sides of the init-assignments. 405 // We still need to visit the right-hand sides of the init-assignments.
415 // For SendSets don't visit the left again. Otherwise it would be marked 406 // For SendSets don't visit the left again. Otherwise it would be marked
416 // as mutated. 407 // as mutated.
417 if (definition is Send) { 408 if (definition is Send) {
418 Send assignment = definition; 409 Send assignment = definition;
419 Node arguments = assignment.argumentsNode; 410 Node arguments = assignment.argumentsNode;
420 if (arguments != null) { 411 if (arguments != null) {
421 visit(arguments); 412 visit(arguments);
422 } 413 }
423 } else { 414 } else {
424 visit(definition); 415 visit(definition);
425 } 416 }
426 } 417 }
427 } 418 }
428 419
429 visitTypeAnnotation(TypeAnnotation node) {
430 if (compiler.enableTypeAssertions && currentElement.isInstanceMember()) {
431 DartType type = elements.getType(node);
432 // In checked mode, using a type variable in a type annotation may lead
433 // to a runtime type check that needs to access the type argument and
434 // therefore the closure needs a this-element.
435 // TODO(karlklose,johnniwinther): if the type is null, the annotation is
436 // from a parameter which has been analyzed before the method has been
437 // resolved and the result has been thrown away.
438 if (type != null && type.containsTypeVariables) {
439 registerNeedsThis();
440 }
441 }
442 node.visitChildren(this);
443 }
444
445 visitIdentifier(Identifier node) { 420 visitIdentifier(Identifier node) {
446 if (node.isThis()) { 421 if (node.isThis()) {
447 registerNeedsThis(); 422 useLocal(closureData.thisElement);
448 } else { 423 } else {
449 Element element = elements[node]; 424 Element element = elements[node];
450 if (element != null && element.kind == ElementKind.TYPE_VARIABLE) { 425 if (element != null && element.kind == ElementKind.TYPE_VARIABLE) {
451 registerNeedsThis(); 426 useLocal(closureData.thisElement);
452 } 427 }
453 } 428 }
454 node.visitChildren(this); 429 node.visitChildren(this);
455 } 430 }
456 431
457 visitSend(Send node) { 432 visitSend(Send node) {
458 Element element = elements[node]; 433 Element element = elements[node];
459 if (Elements.isLocal(element)) { 434 if (Elements.isLocal(element)) {
460 useLocal(element); 435 useLocal(element);
461 } else if (node.receiver == null && 436 } else if (node.receiver == null &&
462 Elements.isInstanceSend(node, elements)) { 437 Elements.isInstanceSend(node, elements)) {
463 registerNeedsThis(); 438 useLocal(closureData.thisElement);
464 } else if (node.isSuperCall) { 439 } else if (node.isSuperCall) {
465 registerNeedsThis(); 440 useLocal(closureData.thisElement);
466 } else if (node.isParameterCheck) { 441 } else if (node.isParameterCheck) {
467 Element parameter = elements[node.receiver]; 442 Element parameter = elements[node.receiver];
468 FunctionElement enclosing = parameter.enclosingElement; 443 FunctionElement enclosing = parameter.enclosingElement;
469 FunctionExpression function = enclosing.parseNode(compiler); 444 FunctionExpression function = enclosing.parseNode(compiler);
470 ClosureClassMap cached = closureMappingCache[function]; 445 ClosureClassMap cached = closureMappingCache[function];
471 if (!cached.parametersWithSentinel.containsKey(parameter)) { 446 if (!cached.parametersWithSentinel.containsKey(parameter)) {
472 SourceString parameterName = parameter.name; 447 SourceString parameterName = parameter.name;
473 String name = '${parameterName.slowToString()}_check'; 448 String name = '${parameterName.slowToString()}_check';
474 Element newElement = new CheckVariableElement(new SourceString(name), 449 Element newElement = new CheckVariableElement(new SourceString(name),
475 parameter, 450 parameter,
476 enclosing); 451 enclosing);
477 useLocal(newElement); 452 useLocal(newElement);
478 cached.parametersWithSentinel[parameter] = newElement; 453 cached.parametersWithSentinel[parameter] = newElement;
479 } 454 }
480 } 455 }
481 node.visitChildren(this); 456 node.visitChildren(this);
482 } 457 }
483 458
484 visitSendSet(SendSet node) { 459 visitSendSet(SendSet node) {
485 Element element = elements[node]; 460 Element element = elements[node];
486 if (Elements.isLocal(element)) { 461 if (Elements.isLocal(element)) {
487 mutatedVariables.add(element); 462 mutatedVariables.add(element);
488 } 463 }
489 if (Elements.isLocal(element) &&
490 element.computeType(compiler).containsTypeVariables) {
491 registerNeedsThis();
492 }
493 super.visitSendSet(node); 464 super.visitSendSet(node);
494 } 465 }
495 466
496 visitNewExpression(NewExpression node) { 467 visitNewExpression(NewExpression node) {
497 DartType type = elements.getType(node); 468 DartType type = elements.getType(node);
498 469
499 bool hasTypeVariable(DartType type) { 470 bool hasTypeVariable(DartType type) {
500 if (type is TypeVariableType) { 471 if (type is TypeVariableType) {
501 return true; 472 return true;
502 } else if (type is InterfaceType) { 473 } else if (type is InterfaceType) {
(...skipping 16 matching lines...) Expand all
519 analyzeTypeVariables(argument); 490 analyzeTypeVariables(argument);
520 } 491 }
521 } 492 }
522 } 493 }
523 494
524 if (outermostElement.isMember() && 495 if (outermostElement.isMember() &&
525 compiler.backend.needsRti(outermostElement.getEnclosingClass())) { 496 compiler.backend.needsRti(outermostElement.getEnclosingClass())) {
526 if (outermostElement.isConstructor() || outermostElement.isField()) { 497 if (outermostElement.isConstructor() || outermostElement.isField()) {
527 analyzeTypeVariables(type); 498 analyzeTypeVariables(type);
528 } else if (outermostElement.isInstanceMember()) { 499 } else if (outermostElement.isInstanceMember()) {
529 if (hasTypeVariable(type)) { 500 if (hasTypeVariable(type)) useLocal(closureData.thisElement);
530 registerNeedsThis();
531 }
532 } 501 }
533 } 502 }
534 503
535 node.visitChildren(this); 504 node.visitChildren(this);
536 } 505 }
537 506
538 // If variables that are declared in the [node] scope are captured and need 507 // If variables that are declared in the [node] scope are captured and need
539 // to be boxed create a box-element and update the [capturingScopes] in the 508 // to be boxed create a box-element and update the [capturingScopes] in the
540 // current [closureData]. 509 // current [closureData].
541 // The boxed variables are updated in the [capturedVariableMapping]. 510 // The boxed variables are updated in the [capturedVariableMapping].
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 if (currentElement.isFactoryConstructor() && 662 if (currentElement.isFactoryConstructor() &&
694 compiler.backend.needsRti(currentElement.enclosingElement)) { 663 compiler.backend.needsRti(currentElement.enclosingElement)) {
695 // Declare the type parameters in the scope. Generative 664 // Declare the type parameters in the scope. Generative
696 // constructors just use 'this'. 665 // constructors just use 'this'.
697 ClassElement cls = currentElement.enclosingElement; 666 ClassElement cls = currentElement.enclosingElement;
698 cls.typeVariables.forEach((TypeVariableType typeVariable) { 667 cls.typeVariables.forEach((TypeVariableType typeVariable) {
699 declareLocal(typeVariable.element); 668 declareLocal(typeVariable.element);
700 }); 669 });
701 } 670 }
702 671
703 // Compute the function type and check for type variables in return or
704 // parameter types.
705 if (element.computeType(compiler).containsTypeVariables) {
706 registerNeedsThis();
707 }
708
709 visitChildren(); 672 visitChildren();
710 }); 673 });
711 674
712 675
713 ClosureClassMap savedClosureData = closureData; 676 ClosureClassMap savedClosureData = closureData;
714 bool savedInsideClosure = insideClosure; 677 bool savedInsideClosure = insideClosure;
715 678
716 // Restore old values. 679 // Restore old values.
717 insideClosure = oldInsideClosure; 680 insideClosure = oldInsideClosure;
718 closureData = oldClosureData; 681 closureData = oldClosureData;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 } 719 }
757 720
758 visitTryStatement(TryStatement node) { 721 visitTryStatement(TryStatement node) {
759 // TODO(ngeoffray): implement finer grain state. 722 // TODO(ngeoffray): implement finer grain state.
760 bool oldInTryStatement = inTryStatement; 723 bool oldInTryStatement = inTryStatement;
761 inTryStatement = true; 724 inTryStatement = true;
762 node.visitChildren(this); 725 node.visitChildren(this);
763 inTryStatement = oldInTryStatement; 726 inTryStatement = oldInTryStatement;
764 } 727 }
765 } 728 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/js_backend/backend.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698