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

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

Issue 2984263002: Make the ClosedWorld build the closure class on the kernel side. (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 '../common.dart'; 9 import '../common.dart';
10 import '../common/names.dart' show Identifiers; 10 import '../common/names.dart' show Identifiers;
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 name = path.substring(path.lastIndexOf('/') + 1); 656 name = path.substring(path.lastIndexOf('/') + 1);
657 } 657 }
658 LibraryEntity library = 658 LibraryEntity library =
659 createLibrary(_libraryMap.length, name, canonicalUri); 659 createLibrary(_libraryMap.length, name, canonicalUri);
660 _libraryList.add(library); 660 _libraryList.add(library);
661 _libraryData.add(new LibraryData(node)); 661 _libraryData.add(new LibraryData(node));
662 return library; 662 return library;
663 }); 663 });
664 } 664 }
665 665
666 // TODO(johnniwinther,efortuna): Create the class index and data together with
667 // the [KernelClosureClass].
668 void addClosureClass(KernelClosureClass cls, InterfaceType supertype) {
669 cls.classIndex = _classEnvs.length;
670 _classEnvs.add(new ClassEnv.closureClass());
671 _classList.add(cls);
672
673 // Create a classData and set up the interfaces and subclass
674 // relationships that _ensureSupertypes and _ensureThisAndRawType are doing
675 var closureData =
676 new ClassData(null, new ClosureClassDefinition(cls, cls.location));
677 closureData
678 ..isMixinApplication = false
679 ..thisType =
680 closureData.rawType = new InterfaceType(cls, const/*<DartType>*/ [])
681 ..supertype = supertype
682 ..interfaces = const <InterfaceType>[];
683 var setBuilder =
684 new _KernelOrderedTypeSetBuilder((this as KernelToElementMapBase), cls);
685 _classData.add(closureData);
686 closureData.orderedTypeSet = setBuilder.createOrderedTypeSet(
687 closureData.supertype, const Link<InterfaceType>());
688
689 cls.forEachCapturedVariable((Local local, JField field) {
690 field.setClosureMemberIndex = _memberData.length;
691 // TODO(efortuna): Uncomment this line after Johnni's added in his CL
692 // about Class/MemberDefinition.
693 //_memberData.add(field);
694 });
695 // TODO(efortuna): Does getMetadata get called in ClassData for this object?
696 }
697
698 ClassEntity _getClass(ir.Class node, [ClassEnv classEnv]) { 666 ClassEntity _getClass(ir.Class node, [ClassEnv classEnv]) {
699 return _classMap.putIfAbsent(node, () { 667 return _classMap.putIfAbsent(node, () {
700 KLibrary library = _getLibrary(node.enclosingLibrary); 668 KLibrary library = _getLibrary(node.enclosingLibrary);
701 if (classEnv == null) { 669 if (classEnv == null) {
702 classEnv = _libraryEnvs[library.libraryIndex].lookupClass(node.name); 670 classEnv = _libraryEnvs[library.libraryIndex].lookupClass(node.name);
703 } 671 }
704 _classEnvs.add(classEnv); 672 _classEnvs.add(classEnv);
705 ClassEntity cls = createClass(library, _classList.length, node.name, 673 ClassEntity cls = createClass(library, _classList.length, node.name,
706 isAbstract: node.isAbstract); 674 isAbstract: node.isAbstract);
707 _classData 675 _classData
(...skipping 1282 matching lines...) Expand 10 before | Expand all | Expand 10 after
1990 // The constructor is not live. 1958 // The constructor is not live.
1991 return; 1959 return;
1992 } 1960 }
1993 ConstructorData data = _memberData[constructor.memberIndex]; 1961 ConstructorData data = _memberData[constructor.memberIndex];
1994 if (data.constructorBody != null) { 1962 if (data.constructorBody != null) {
1995 f(data.constructorBody); 1963 f(data.constructorBody);
1996 } 1964 }
1997 }); 1965 });
1998 } 1966 }
1999 1967
1968 KernelClosureClass constructClosureClass(
1969 String name,
1970 JLibrary enclosingLibrary,
1971 KernelScopeInfo info,
1972 ir.Location location,
1973 KernelToLocalsMap localsMap,
1974 InterfaceType supertype) {
1975 KernelClosureClass cls = new KernelClosureClass.fromScopeInfo(
1976 name, _classEnvs.length, enclosingLibrary, info, location, localsMap);
1977 _classList.add(cls);
1978 _classEnvs.add(new ClassEnv.closureClass());
1979
1980 // Create a classData and set up the interfaces and subclass
1981 // relationships that _ensureSupertypes and _ensureThisAndRawType are doing
1982 var closureData =
1983 new ClassData(null, new ClosureClassDefinition(cls, cls.location));
1984 closureData
1985 ..isMixinApplication = false
1986 ..thisType =
1987 closureData.rawType = new InterfaceType(cls, const/*<DartType>*/ [])
1988 ..supertype = supertype
1989 ..interfaces = const <InterfaceType>[];
1990 var setBuilder = new _KernelOrderedTypeSetBuilder(this, cls);
1991 _classData.add(closureData);
1992 closureData.orderedTypeSet = setBuilder.createOrderedTypeSet(
1993 closureData.supertype, const Link<InterfaceType>());
1994
1995 int i = 0;
1996 for (ir.VariableDeclaration variable in info.freeVariables) {
1997 // Make a corresponding field entity in this closure class for every
1998 // single freeVariable in the KernelScopeInfo.freeVariable.
1999 _constructClosureFields(cls, variable, i, localsMap);
2000 i++;
2001 }
2002
2003 // TODO(efortuna): Does getMetadata get called in ClassData for this object?
2004 return cls;
2005 }
2006
2007 _constructClosureFields(
2008 KernelClosureClass cls,
2009 ir.VariableDeclaration variable,
2010 int fieldNumber,
2011 KernelToLocalsMap localsMap) {
2012 // NOTE: This construction order may be slightly different than the
2013 // old Element version. The old version did all the boxed items and then
2014 // all the others.
2015 Local capturedLocal = localsMap.getLocalVariable(variable);
2016 if (cls.isBoxed(capturedLocal)) {
2017 // TODO(efortuna): Coming soon.
2018 } else {
2019 var closureField = new ClosureField(
2020 _getClosureVariableName(capturedLocal.name, fieldNumber),
2021 _memberData.length,
2022 cls,
2023 variable.isConst,
2024 variable.isFinal || variable.isConst);
2025 cls.localToFieldMap[capturedLocal] = closureField;
2026 _memberList.add(closureField);
2027 _memberData.add(new MemberData(
2028 null,
2029 new ClosureMemberDefinition(cls.localToFieldMap[capturedLocal],
2030 variable.location, MemberKind.closureField, variable)));
2031 }
2032 }
2033
2034 /// Generate a unique name for the [id]th closure field, with proposed name
2035 /// [name].
2036 ///
2037 /// The result is used as the name of [ClosureFieldElement]s, and must
2038 /// therefore be unique to avoid breaking an invariant in the element model
2039 /// (classes cannot declare multiple fields with the same name).
2040 ///
2041 /// Also, the names should be distinct from real field names to prevent
2042 /// clashes with selectors for those fields.
2043 ///
2044 /// These names are not used in generated code, just as element name.
2045 String _getClosureVariableName(String name, int id) {
2046 return "_captured_${name}_$id";
2047 }
2048
2000 String getDeferredUri(ir.LibraryDependency node) { 2049 String getDeferredUri(ir.LibraryDependency node) {
2001 throw new UnimplementedError('JsKernelToElementMap.getDeferredUri'); 2050 throw new UnimplementedError('JsKernelToElementMap.getDeferredUri');
2002 } 2051 }
2003 } 2052 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/kernel/element_map.dart ('k') | pkg/compiler/lib/src/ssa/builder_kernel.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698