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

Side by Side Diff: pkg/compiler/lib/src/ssa/builder_kernel.dart

Issue 2933363003: Add ClosureRepresentationInfo, the new public face of ClosureClassMap (Closed)
Patch Set: . Created 3 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
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 'package:kernel/ast.dart' as ir; 5 import 'package:kernel/ast.dart' as ir;
6 6
7 import '../closure.dart'; 7 import '../closure.dart';
8 import '../common.dart'; 8 import '../common.dart';
9 import '../common/codegen.dart' show CodegenRegistry; 9 import '../common/codegen.dart' show CodegenRegistry;
10 import '../common/names.dart'; 10 import '../common/names.dart';
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 localsHandler.updateLocal(parameter, argument); 587 localsHandler.updateLocal(parameter, argument);
588 } 588 }
589 589
590 constructor.function.positionalParameters.forEach(handleParameter); 590 constructor.function.positionalParameters.forEach(handleParameter);
591 constructor.function.namedParameters.toList() 591 constructor.function.namedParameters.toList()
592 ..sort(namedOrdering) 592 ..sort(namedOrdering)
593 ..forEach(handleParameter); 593 ..forEach(handleParameter);
594 594
595 // Set the locals handler state as if we were inlining the constructor. 595 // Set the locals handler state as if we were inlining the constructor.
596 ConstructorEntity astElement = _elementMap.getConstructor(constructor); 596 ConstructorEntity astElement = _elementMap.getConstructor(constructor);
597 ClosureClassMap oldClosureData = localsHandler.closureData; 597 ClosureRepresentationInfo oldClosureData = localsHandler.closureData;
598 ClosureClassMap newClosureData = 598 ClosureRepresentationInfo newClosureData =
599 closureToClassMapper.getMemberMap(astElement); 599 closureToClassMapper.getClosureRepresentationInfo(astElement);
600 if (astElement is ConstructorElement) { 600 if (astElement is ConstructorElement) {
601 // TODO(johnniwinther): Support constructor (body) entities. 601 // TODO(johnniwinther): Support constructor (body) entities.
602 ResolvedAst resolvedAst = astElement.resolvedAst; 602 ResolvedAst resolvedAst = astElement.resolvedAst;
603 localsHandler.closureData = newClosureData; 603 localsHandler.closureData = newClosureData;
604 if (resolvedAst.kind == ResolvedAstKind.PARSED) { 604 if (resolvedAst.kind == ResolvedAstKind.PARSED) {
605 // TODO(efortuna): Take out the test below for null once we are no 605 localsHandler.enterScope(
606 // longer dealing with the ClosureClassMap interface directly. 606 closureToClassMapper.getClosureAnalysisInfo(resolvedAst.node),
607 if (newClosureData.capturingScopes[resolvedAst.node] != null) { 607 forGenerativeConstructorBody:
608 localsHandler.enterScope( 608 astElement.isGenerativeConstructorBody);
609 newClosureData.capturingScopes[resolvedAst.node],
610 forGenerativeConstructorBody:
611 astElement.isGenerativeConstructorBody);
612 }
613 } 609 }
614 } 610 }
615 inlinedFrom(astElement, () { 611 inlinedFrom(astElement, () {
616 _buildInitializers(constructor, constructorChain, fieldValues); 612 _buildInitializers(constructor, constructorChain, fieldValues);
617 }); 613 });
618 localsHandler.closureData = oldClosureData; 614 localsHandler.closureData = oldClosureData;
619 } 615 }
620 616
621 /// Builds generative constructor body. 617 /// Builds generative constructor body.
622 void buildConstructorBody(ir.Constructor constructor) { 618 void buildConstructorBody(ir.Constructor constructor) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 685
690 function.positionalParameters.forEach(handleParameter); 686 function.positionalParameters.forEach(handleParameter);
691 function.namedParameters.toList() 687 function.namedParameters.toList()
692 ..sort(namedOrdering) 688 ..sort(namedOrdering)
693 ..forEach(handleParameter); 689 ..forEach(handleParameter);
694 } 690 }
695 691
696 HBasicBlock block = graph.addNewBlock(); 692 HBasicBlock block = graph.addNewBlock();
697 open(graph.entry); 693 open(graph.entry);
698 694
699 ClosureClassMap closureData = 695 localsHandler.startFunction(
700 closureToClassMapper.getMemberMap(targetElement); 696 targetElement,
701 localsHandler.startFunction(targetElement, closureData, 697 closureToClassMapper.getClosureRepresentationInfo(targetElement),
702 closureData.capturingScopes[functionNode], parameterMap, 698 closureToClassMapper.getClosureAnalysisInfo(functionNode),
699 parameterMap,
703 isGenerativeConstructorBody: _targetIsConstructorBody); 700 isGenerativeConstructorBody: _targetIsConstructorBody);
704 close(new HGoto()).addSuccessor(block); 701 close(new HGoto()).addSuccessor(block);
705 702
706 open(block); 703 open(block);
707 } 704 }
708 705
709 void closeFunction() { 706 void closeFunction() {
710 if (!isAborted()) closeAndGotoExit(new HGoto()); 707 if (!isAborted()) closeAndGotoExit(new HGoto());
711 graph.finalize(); 708 graph.finalize();
712 } 709 }
(...skipping 2115 matching lines...) Expand 10 before | Expand all | Expand 10 after
2828 push(new HInvokeDynamicSetter(selector, mask, null, inputs, type)); 2825 push(new HInvokeDynamicSetter(selector, mask, null, inputs, type));
2829 } else { 2826 } else {
2830 push(new HInvokeDynamicMethod( 2827 push(new HInvokeDynamicMethod(
2831 selector, mask, inputs, type, isIntercepted)); 2828 selector, mask, inputs, type, isIntercepted));
2832 } 2829 }
2833 } 2830 }
2834 2831
2835 @override 2832 @override
2836 visitFunctionNode(ir.FunctionNode node) { 2833 visitFunctionNode(ir.FunctionNode node) {
2837 Local methodElement = _elementMap.getLocalFunction(node); 2834 Local methodElement = _elementMap.getLocalFunction(node);
2838 ClosureClassMap nestedClosureData = 2835 ClosureRepresentationInfo closureInfo =
2839 closureToClassMapper.getLocalFunctionMap(methodElement); 2836 closureToClassMapper.getClosureRepresentationInfo(methodElement);
2840 assert(nestedClosureData != null); 2837 ClassEntity closureClassEntity = closureInfo.closureClassEntity;
2841 assert(nestedClosureData.closureClassElement != null);
2842 ClosureClassElement closureClassElement =
2843 nestedClosureData.closureClassElement;
2844 MethodElement callElement = nestedClosureData.callElement;
2845 2838
2846 List<HInstruction> capturedVariables = <HInstruction>[]; 2839 List<HInstruction> capturedVariables = <HInstruction>[];
2847 closureClassElement.closureFields.forEach((ClosureFieldElement field) { 2840 closureInfo.createdFieldEntities.forEach((Local capturedLocal) {
2848 Local capturedLocal =
2849 nestedClosureData.getLocalVariableForClosureField(field);
2850 assert(capturedLocal != null); 2841 assert(capturedLocal != null);
2851 capturedVariables.add(localsHandler.readLocal(capturedLocal)); 2842 capturedVariables.add(localsHandler.readLocal(capturedLocal));
2852 }); 2843 });
2853 2844
2854 TypeMask type = new TypeMask.nonNullExact(closureClassElement, closedWorld); 2845 TypeMask type = new TypeMask.nonNullExact(closureClassEntity, closedWorld);
2855 // TODO(efortuna): Add source information here. 2846 // TODO(efortuna): Add source information here.
2856 push(new HCreate(closureClassElement, capturedVariables, type, 2847 push(new HCreate(closureClassEntity, capturedVariables, type,
2857 callMethod: callElement, localFunction: methodElement)); 2848 callMethod: closureInfo.callEntity, localFunction: methodElement));
2858 } 2849 }
2859 2850
2860 @override 2851 @override
2861 visitFunctionDeclaration(ir.FunctionDeclaration declaration) { 2852 visitFunctionDeclaration(ir.FunctionDeclaration declaration) {
2862 assert(isReachable); 2853 assert(isReachable);
2863 declaration.function.accept(this); 2854 declaration.function.accept(this);
2864 Local localFunction = _elementMap.getLocalFunction(declaration.function); 2855 Local localFunction = _elementMap.getLocalFunction(declaration.function);
2865 localsHandler.updateLocal(localFunction, pop()); 2856 localsHandler.updateLocal(localFunction, pop());
2866 } 2857 }
2867 2858
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after
3479 enterBlock.setBlockFlow( 3470 enterBlock.setBlockFlow(
3480 new HTryBlockInformation( 3471 new HTryBlockInformation(
3481 kernelBuilder.wrapStatementGraph(bodyGraph), 3472 kernelBuilder.wrapStatementGraph(bodyGraph),
3482 exception, 3473 exception,
3483 kernelBuilder.wrapStatementGraph(catchGraph), 3474 kernelBuilder.wrapStatementGraph(catchGraph),
3484 kernelBuilder.wrapStatementGraph(finallyGraph)), 3475 kernelBuilder.wrapStatementGraph(finallyGraph)),
3485 exitBlock); 3476 exitBlock);
3486 kernelBuilder.inTryStatement = previouslyInTryStatement; 3477 kernelBuilder.inTryStatement = previouslyInTryStatement;
3487 } 3478 }
3488 } 3479 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698