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

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

Powered by Google App Engine
This is Rietveld 408576698