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

Side by Side Diff: pkg/compiler/lib/src/kernel/element_map_impl.dart

Issue 2992763002: Add boxed fields in closure classes. (Closed)
Patch Set: . Created 3 years, 4 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) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 dart2js.kernel.element_map; 5 library dart2js.kernel.element_map;
6 6
7 import 'package:kernel/ast.dart' as ir; 7 import 'package:kernel/ast.dart' as ir;
8 8
9 import '../closure.dart' show BoxLocal;
9 import '../common.dart'; 10 import '../common.dart';
10 import '../common/names.dart' show Identifiers; 11 import '../common/names.dart' show Identifiers;
11 import '../common/resolution.dart'; 12 import '../common/resolution.dart';
12 import '../compile_time_constants.dart'; 13 import '../compile_time_constants.dart';
13 import '../constants/constant_system.dart'; 14 import '../constants/constant_system.dart';
14 import '../constants/constructors.dart'; 15 import '../constants/constructors.dart';
15 import '../constants/evaluation.dart'; 16 import '../constants/evaluation.dart';
16 import '../constants/expressions.dart'; 17 import '../constants/expressions.dart';
17 import '../constants/values.dart'; 18 import '../constants/values.dart';
18 import '../common_elements.dart'; 19 import '../common_elements.dart';
(...skipping 1970 matching lines...) Expand 10 before | Expand all | Expand 10 after
1989 1990
1990 KernelClosureClass constructClosureClass( 1991 KernelClosureClass constructClosureClass(
1991 MemberEntity member, 1992 MemberEntity member,
1992 ir.FunctionNode node, 1993 ir.FunctionNode node,
1993 JLibrary enclosingLibrary, 1994 JLibrary enclosingLibrary,
1994 KernelScopeInfo info, 1995 KernelScopeInfo info,
1995 ir.Location location, 1996 ir.Location location,
1996 KernelToLocalsMap localsMap, 1997 KernelToLocalsMap localsMap,
1997 InterfaceType supertype) { 1998 InterfaceType supertype) {
1998 String name = _computeClosureName(node); 1999 String name = _computeClosureName(node);
1999 KernelClosureClass cls = new KernelClosureClass.fromScopeInfo( 2000 KernelClosureClass cls = new KernelClosureClass.fromScopeInfo(node, name,
2000 name, _classEnvs.length, enclosingLibrary, info, location, localsMap); 2001 _classEnvs.length, enclosingLibrary, info, location, localsMap);
2001 _classList.add(cls); 2002 _classList.add(cls);
2002 _classEnvs.add(new ClassEnv.closureClass()); 2003 _classEnvs.add(new ClassEnv.closureClass());
2003 2004
2004 // Create a classData and set up the interfaces and subclass 2005 // Create a classData and set up the interfaces and subclass
2005 // relationships that _ensureSupertypes and _ensureThisAndRawType are doing 2006 // relationships that _ensureSupertypes and _ensureThisAndRawType are doing
2006 var closureData = 2007 var closureData =
2007 new ClassData(null, new ClosureClassDefinition(cls, cls.location)); 2008 new ClassData(null, new ClosureClassDefinition(cls, cls.location));
2008 closureData 2009 closureData
2009 ..isMixinApplication = false 2010 ..isMixinApplication = false
2010 ..thisType = 2011 ..thisType =
2011 closureData.rawType = new InterfaceType(cls, const/*<DartType>*/ []) 2012 closureData.rawType = new InterfaceType(cls, const/*<DartType>*/ [])
2012 ..supertype = supertype 2013 ..supertype = supertype
2013 ..interfaces = const <InterfaceType>[]; 2014 ..interfaces = const <InterfaceType>[];
2014 var setBuilder = new _KernelOrderedTypeSetBuilder(this, cls); 2015 var setBuilder = new _KernelOrderedTypeSetBuilder(this, cls);
2015 _classData.add(closureData); 2016 _classData.add(closureData);
2016 closureData.orderedTypeSet = setBuilder.createOrderedTypeSet( 2017 closureData.orderedTypeSet = setBuilder.createOrderedTypeSet(
2017 closureData.supertype, const Link<InterfaceType>()); 2018 closureData.supertype, const Link<InterfaceType>());
2018 2019
2019 int i = 0; 2020 int i = 0;
2020 for (ir.VariableDeclaration variable in info.freeVariables) { 2021 for (ir.VariableDeclaration variable in info.freeVariables) {
2021 // Make a corresponding field entity in this closure class for every 2022 // Make a corresponding field entity in this closure class for every
2022 // single freeVariable in the KernelScopeInfo.freeVariable. 2023 // single freeVariable in the KernelScopeInfo.freeVariable.
2023 _constructClosureFields(cls, variable, i, localsMap); 2024 _constructClosureFields(
2025 cls, variable, i, info.capturedVariablesAccessor, localsMap);
2024 i++; 2026 i++;
2025 } 2027 }
2026 2028
2027 cls.callMethod = new JClosureCallMethod(_memberData.length, cls, member); 2029 cls.callMethod = new JClosureCallMethod(_memberData.length, cls, member);
2028 _memberList.add(cls.callMethod); 2030 _memberList.add(cls.callMethod);
2029 _memberData.add(new MemberData( 2031 _memberData.add(new MemberData(
2030 null, 2032 null,
2031 new ClosureMemberDefinition( 2033 new ClosureMemberDefinition(
2032 member, cls.location, MemberKind.closureCall, node.parent))); 2034 member, cls.location, MemberKind.closureCall, node.parent)));
2033 2035
2034 // TODO(efortuna): Does getMetadata get called in ClassData for this object? 2036 // TODO(efortuna): Does getMetadata get called in ClassData for this object?
2035 return cls; 2037 return cls;
2036 } 2038 }
2037 2039
2038 _constructClosureFields( 2040 _constructClosureFields(
2039 KernelClosureClass cls, 2041 KernelClosureClass cls,
2040 ir.VariableDeclaration variable, 2042 ir.VariableDeclaration variable,
2041 int fieldNumber, 2043 int fieldNumber,
2044 NodeBox box,
2042 KernelToLocalsMap localsMap) { 2045 KernelToLocalsMap localsMap) {
2043 // NOTE: This construction order may be slightly different than the 2046 // NOTE: This construction order may be slightly different than the
2044 // old Element version. The old version did all the boxed items and then 2047 // old Element version. The old version did all the boxed items and then
2045 // all the others. 2048 // all the others.
2046 Local capturedLocal = localsMap.getLocalVariable(variable); 2049 Local capturedLocal = localsMap.getLocalVariable(variable);
2047 if (cls.isBoxed(capturedLocal)) { 2050 if (cls.isBoxed(capturedLocal)) {
2048 // TODO(efortuna): Coming soon. 2051 var boxedField = new JBoxedField(
2052 _getClosureVariableName(capturedLocal.name, fieldNumber),
2053 _memberData.length,
2054 new BoxLocal(
2055 box.name,
2056 localsMap.getLocalVariable(box.executableContext),
Johnni Winther 2017/08/01 09:09:10 The `Local.executableContext` is actually not need
Emily Fortuna 2017/08/01 19:30:06 Acknowledged.
2057 getMember(box.memberContext)),
Johnni Winther 2017/08/01 09:09:10 The member is always the member passed to [constru
Emily Fortuna 2017/08/01 19:30:06 Done.
2058 cls,
2059 variable.isConst,
2060 variable.isFinal || variable.isConst);
2061 cls.localToFieldMap[capturedLocal] = boxedField;
2062 _memberList.add(boxedField);
2063 _memberData.add(new MemberData(
2064 null,
2065 new ClosureMemberDefinition(boxedField, variable.location,
2066 MemberKind.closureField, variable)));
2049 } else { 2067 } else {
2050 var closureField = new JClosureField( 2068 var closureField = new JClosureField(
2051 _getClosureVariableName(capturedLocal.name, fieldNumber), 2069 _getClosureVariableName(capturedLocal.name, fieldNumber),
2052 _memberData.length, 2070 _memberData.length,
2053 cls, 2071 cls,
2054 variable.isConst, 2072 variable.isConst,
2055 variable.isFinal || variable.isConst); 2073 variable.isFinal || variable.isConst);
2056 cls.localToFieldMap[capturedLocal] = closureField; 2074 cls.localToFieldMap[capturedLocal] = closureField;
2057 _memberList.add(closureField); 2075 _memberList.add(closureField);
2058 _memberData.add(new MemberData( 2076 _memberData.add(new MemberData(
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
2116 /// 2134 ///
2117 /// These names are not used in generated code, just as element name. 2135 /// These names are not used in generated code, just as element name.
2118 String _getClosureVariableName(String name, int id) { 2136 String _getClosureVariableName(String name, int id) {
2119 return "_captured_${name}_$id"; 2137 return "_captured_${name}_$id";
2120 } 2138 }
2121 2139
2122 String getDeferredUri(ir.LibraryDependency node) { 2140 String getDeferredUri(ir.LibraryDependency node) {
2123 throw new UnimplementedError('JsKernelToElementMap.getDeferredUri'); 2141 throw new UnimplementedError('JsKernelToElementMap.getDeferredUri');
2124 } 2142 }
2125 } 2143 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698