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

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

Issue 2960633002: Split KernelToElementMap into sub-interfaces (Closed)
Patch Set: Created 3 years, 5 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 import 'package:js_runtime/shared/embedded_names.dart'; 5 import 'package:js_runtime/shared/embedded_names.dart';
6 import 'package:kernel/ast.dart' as ir; 6 import 'package:kernel/ast.dart' as ir;
7 7
8 import '../closure.dart'; 8 import '../closure.dart';
9 import '../common.dart'; 9 import '../common.dart';
10 import '../common/names.dart'; 10 import '../common/names.dart';
(...skipping 15 matching lines...) Expand all
26 import '../universe/call_structure.dart'; 26 import '../universe/call_structure.dart';
27 import '../universe/selector.dart'; 27 import '../universe/selector.dart';
28 import '../world.dart'; 28 import '../world.dart';
29 import 'kernel_debug.dart'; 29 import 'kernel_debug.dart';
30 30
31 /// Interface that translates between Kernel IR nodes and entities. 31 /// Interface that translates between Kernel IR nodes and entities.
32 abstract class KernelToElementMap { 32 abstract class KernelToElementMap {
33 /// Access to the commonly used elements and types. 33 /// Access to the commonly used elements and types.
34 CommonElements get commonElements; 34 CommonElements get commonElements;
35 35
36 /// [ElementEnvironment] for library, class and member lookup.
37 ElementEnvironment get elementEnvironment;
38
39 /// Returns the [DartType] corresponding to [type]. 36 /// Returns the [DartType] corresponding to [type].
40 DartType getDartType(ir.DartType type); 37 DartType getDartType(ir.DartType type);
41 38
42 /// Returns the [FunctionType] of the [node].
43 FunctionType getFunctionType(ir.FunctionNode node);
44
45 /// Returns the list of [DartType]s corresponding to [types].
46 List<DartType> getDartTypes(List<ir.DartType> types);
47
48 /// Returns the [InterfaceType] corresponding to [type].
49 InterfaceType getInterfaceType(ir.InterfaceType type);
50
51 /// Return the [InterfaceType] corresponding to the [cls] with the given 39 /// Return the [InterfaceType] corresponding to the [cls] with the given
52 /// [typeArguments]. 40 /// [typeArguments].
53 InterfaceType createInterfaceType( 41 InterfaceType createInterfaceType(
54 ir.Class cls, List<ir.DartType> typeArguments); 42 ir.Class cls, List<ir.DartType> typeArguments);
55 43
56 /// Returns the [CallStructure] corresponding to the [arguments].
57 CallStructure getCallStructure(ir.Arguments arguments);
58
59 /// Returns the [Selector] corresponding to the invocation or getter/setter 44 /// Returns the [Selector] corresponding to the invocation or getter/setter
60 /// access of [node]. 45 /// access of [node].
61 Selector getSelector(ir.Expression node); 46 Selector getSelector(ir.Expression node);
62 47
48 /// Returns the [MemberEntity] corresponding to the member [node].
49 MemberEntity getMember(ir.Member node);
50
51 /// Returns the [FunctionEntity] corresponding to the procedure [node].
52 FunctionEntity getMethod(ir.Procedure node);
53
63 /// Returns the [ConstructorEntity] corresponding to the generative or factory 54 /// Returns the [ConstructorEntity] corresponding to the generative or factory
64 /// constructor [node]. 55 /// constructor [node].
65 ConstructorEntity getConstructor(ir.Member node); 56 ConstructorEntity getConstructor(ir.Member node);
66 57
58 /// Returns the [FieldEntity] corresponding to the field [node].
59 FieldEntity getField(ir.Field node);
60
61 /// Returns the [Local] corresponding to the [node]. The node must be either
62 /// a [ir.FunctionDeclaration] or [ir.FunctionExpression].
63 Local getLocalFunction(ir.TreeNode node);
64
65 /// Returns the super [MemberEntity] for a super invocation, get or set of
66 /// [name] from the member [context].
67 ///
68 /// The IR doesn't always resolve super accesses to the corresponding
69 /// [target]. If not, the target is computed using [name] and [setter] from
70 /// the enclosing class of [context].
71 MemberEntity getSuperMember(ir.Member context, ir.Name name, ir.Member target,
72 {bool setter: false});
73
74 /// Returns the [Name] corresponding to [name].
75 Name getName(ir.Name name);
76
77 /// Return `true` if [node] is the `dart:_foreign_helper` library.
78 bool isForeignLibrary(ir.Library node);
79
80 /// Computes the [native.NativeBehavior] for a call to the [JS] function.
81 native.NativeBehavior getNativeBehaviorForJsCall(ir.StaticInvocation node);
82
83 /// Computes the [native.NativeBehavior] for a call to the [JS_BUILTIN]
84 /// function.
85 native.NativeBehavior getNativeBehaviorForJsBuiltinCall(
86 ir.StaticInvocation node);
87
88 /// Computes the [native.NativeBehavior] for a call to the
89 /// [JS_EMBEDDED_GLOBAL] function.
90 native.NativeBehavior getNativeBehaviorForJsEmbeddedGlobalCall(
91 ir.StaticInvocation node);
92
93 /// Returns the [js.Name] for the `JsGetName` [constant] value.
94 js.Name getNameForJsGetName(ConstantValue constant, Namer namer);
95
96 /// Computes the [ConstantValue] for the constant [expression].
97 // TODO(johnniwinther): Move to [KernelToElementMapForBuilding]. This is only used in
98 // impact builder for symbol constants.
99 ConstantValue getConstantValue(ir.Expression expression,
100 {bool requireConstant: true, bool implicitNull: false});
101 }
102
103 /// Interface that translates between Kernel IR nodes and entities used for
104 /// computing the [WorldImpact] for members.
105 abstract class KernelToElementMapForImpact implements KernelToElementMap {
Siggi Cherem (dart-lang) 2017/06/26 18:05:41 nit: any reason to use `implements` as opposed to
Johnni Winther 2017/06/27 08:26:31 Nah.
106 /// Returns the [CallStructure] corresponding to the [arguments].
107 CallStructure getCallStructure(ir.Arguments arguments);
108
67 /// Returns the [ConstructorEntity] corresponding to a super initializer in 109 /// Returns the [ConstructorEntity] corresponding to a super initializer in
68 /// [constructor]. 110 /// [constructor].
69 /// 111 ///
70 /// The IR resolves super initializers to a [target] up in the type hierarchy. 112 /// The IR resolves super initializers to a [target] up in the type hierarchy.
71 /// Most of the time, the result of this function will be the entity 113 /// Most of the time, the result of this function will be the entity
72 /// corresponding to that target. In the presence of unnamed mixins, this 114 /// corresponding to that target. In the presence of unnamed mixins, this
73 /// function returns an entity for an intermediate synthetic constructor that 115 /// function returns an entity for an intermediate synthetic constructor that
74 /// kernel doesn't explicitly represent. 116 /// kernel doesn't explicitly represent.
75 /// 117 ///
76 /// For example: 118 /// For example:
77 /// class M {} 119 /// class M {}
78 /// class C extends Object with M {} 120 /// class C extends Object with M {}
79 /// 121 ///
80 /// Kernel will say that C()'s super initializer resolves to Object(), but 122 /// Kernel will say that C()'s super initializer resolves to Object(), but
81 /// this function will return an entity representing the unnamed mixin 123 /// this function will return an entity representing the unnamed mixin
82 /// application "Object+M"'s constructor. 124 /// application "Object+M"'s constructor.
83 ConstructorEntity getSuperConstructor( 125 ConstructorEntity getSuperConstructor(
84 ir.Constructor constructor, ir.Member target); 126 ir.Constructor constructor, ir.Member target);
85 127
86 /// Returns the [MemberEntity] corresponding to the member [node].
87 MemberEntity getMember(ir.Member node);
88
89 /// Returns the kernel IR node that defines the [member].
90 ir.Node getMemberNode(covariant MemberEntity member);
91
92 /// Returns the [FunctionEntity] corresponding to the procedure [node].
93 FunctionEntity getMethod(ir.Procedure node);
94
95 /// Returns the super [MemberEntity] for a super invocation, get or set of
96 /// [name] from the member [context].
97 ///
98 /// The IR doesn't always resolve super accesses to the corresponding
99 /// [target]. If not, the target is computed using [name] and [setter] from
100 /// the enclosing class of [context].
101 MemberEntity getSuperMember(ir.Member context, ir.Name name, ir.Member target,
102 {bool setter: false});
103
104 /// Returns the [FieldEntity] corresponding to the field [node].
105 FieldEntity getField(ir.Field node);
106
107 /// Returns the [ClassEntity] corresponding to the class [node].
108 ClassEntity getClass(ir.Class node);
109
110 /// Returns the [Local] corresponding to the [node]. The node must be either
111 /// a [ir.FunctionDeclaration] or [ir.FunctionExpression].
112 Local getLocalFunction(ir.TreeNode node);
113
114 /// Returns the [LibraryEntity] corresponding to the library [node].
115 LibraryEntity getLibrary(ir.Library node);
116
117 /// Returns the [Name] corresponding to [name].
118 Name getName(ir.Name name);
119
120 /// Returns `true` is [node] has a `@Native(...)` annotation. 128 /// Returns `true` is [node] has a `@Native(...)` annotation.
121 bool isNativeClass(ir.Class node); 129 bool isNativeClass(ir.Class node);
122 130
123 /// Return `true` if [node] is the `dart:_foreign_helper` library.
124 bool isForeignLibrary(ir.Library node);
125
126 /// Computes the native behavior for reading the native [field]. 131 /// Computes the native behavior for reading the native [field].
127 native.NativeBehavior getNativeBehaviorForFieldLoad(ir.Field field, 132 native.NativeBehavior getNativeBehaviorForFieldLoad(ir.Field field,
128 {bool isJsInterop}); 133 {bool isJsInterop});
129 134
130 /// Computes the native behavior for writing to the native [field]. 135 /// Computes the native behavior for writing to the native [field].
131 native.NativeBehavior getNativeBehaviorForFieldStore(ir.Field field); 136 native.NativeBehavior getNativeBehaviorForFieldStore(ir.Field field);
132 137
133 /// Computes the native behavior for calling [procedure]. 138 /// Computes the native behavior for calling [procedure].
134 native.NativeBehavior getNativeBehaviorForMethod(ir.Procedure procedure, 139 native.NativeBehavior getNativeBehaviorForMethod(ir.Procedure procedure,
135 {bool isJsInterop}); 140 {bool isJsInterop});
136 141
137 /// Computes the [native.NativeBehavior] for a call to the [JS] function.
138 native.NativeBehavior getNativeBehaviorForJsCall(ir.StaticInvocation node);
139
140 /// Computes the [native.NativeBehavior] for a call to the [JS_BUILTIN]
141 /// function.
142 native.NativeBehavior getNativeBehaviorForJsBuiltinCall(
143 ir.StaticInvocation node);
144
145 /// Computes the [native.NativeBehavior] for a call to the
146 /// [JS_EMBEDDED_GLOBAL] function.
147 native.NativeBehavior getNativeBehaviorForJsEmbeddedGlobalCall(
148 ir.StaticInvocation node);
149
150 /// Compute the kind of foreign helper function called by [node], if any. 142 /// Compute the kind of foreign helper function called by [node], if any.
151 ForeignKind getForeignKind(ir.StaticInvocation node); 143 ForeignKind getForeignKind(ir.StaticInvocation node);
152 144
153 /// Returns the [js.Name] for the `JsGetName` [constant] value. 145 /// Computes the [InterfaceType] referenced by a call to the
154 js.Name getNameForJsGetName(ConstantValue constant, Namer namer); 146 /// [JS_INTERCEPTOR_CONSTANT] function, if any.
147 InterfaceType getInterfaceTypeForJsInterceptorCall(ir.StaticInvocation node);
148 }
149
150 /// Interface that translates between Kernel IR nodes and entities used for
151 /// global type inference and building the SSA graph for members.
152 abstract class KernelToElementMapForBuilding implements KernelToElementMap {
153 /// [ElementEnvironment] for library, class and member lookup.
154 ElementEnvironment get elementEnvironment;
155
156 /// Returns the [FunctionType] of the [node].
157 FunctionType getFunctionType(ir.FunctionNode node);
158
159 /// Returns the list of [DartType]s corresponding to [types].
160 List<DartType> getDartTypes(List<ir.DartType> types);
161
162 /// Returns the [InterfaceType] corresponding to [type].
163 InterfaceType getInterfaceType(ir.InterfaceType type);
164
165 /// Returns the kernel IR node that defines the [member].
166 ir.Node getMemberNode(covariant MemberEntity member);
167
168 /// Returns the [ClassEntity] corresponding to the class [node].
169 ClassEntity getClass(ir.Class node);
170
171 /// Returns the [LibraryEntity] corresponding to the library [node].
172 LibraryEntity getLibrary(ir.Library node);
155 173
156 /// Returns the [js.Template] for the `JsBuiltin` [constant] value. 174 /// Returns the [js.Template] for the `JsBuiltin` [constant] value.
157 js.Template getJsBuiltinTemplate( 175 js.Template getJsBuiltinTemplate(
158 ConstantValue constant, CodeEmitterTask emitter); 176 ConstantValue constant, CodeEmitterTask emitter);
159 177
160 /// Computes the [InterfaceType] referenced by a call to the
161 /// [JS_INTERCEPTOR_CONSTANT] function, if any.
162 InterfaceType getInterfaceTypeForJsInterceptorCall(ir.StaticInvocation node);
163
164 /// Computes the [ConstantValue] for the constant [expression].
165 ConstantValue getConstantValue(ir.Expression expression,
166 {bool requireConstant: true, bool implicitNull: false});
167
168 /// Return the [ConstantValue] the initial value of [field] or `null` if 178 /// Return the [ConstantValue] the initial value of [field] or `null` if
169 /// the initializer is not a constant expression. 179 /// the initializer is not a constant expression.
170 ConstantValue getFieldConstantValue(ir.Field field); 180 ConstantValue getFieldConstantValue(ir.Field field);
171 181
172 /// Returns the `noSuchMethod` [FunctionEntity] call from a 182 /// Returns the `noSuchMethod` [FunctionEntity] call from a
173 /// `super.noSuchMethod` invocation within [cls]. 183 /// `super.noSuchMethod` invocation within [cls].
174 FunctionEntity getSuperNoSuchMethod(ClassEntity cls); 184 FunctionEntity getSuperNoSuchMethod(ClassEntity cls);
175 185
176 /// Returns a [Spannable] for a message pointing to the IR [node] in the 186 /// Returns a [Spannable] for a message pointing to the IR [node] in the
177 /// context of [member]. 187 /// context of [member].
178 Spannable getSpannable(MemberEntity member, ir.Node node); 188 Spannable getSpannable(MemberEntity member, ir.Node node);
179 } 189 }
180 190
181 /// Kinds of foreign functions. 191 /// Kinds of foreign functions.
182 enum ForeignKind { 192 enum ForeignKind {
183 JS, 193 JS,
184 JS_BUILTIN, 194 JS_BUILTIN,
185 JS_EMBEDDED_GLOBAL, 195 JS_EMBEDDED_GLOBAL,
186 JS_INTERCEPTOR_CONSTANT, 196 JS_INTERCEPTOR_CONSTANT,
187 NONE, 197 NONE,
188 } 198 }
189 199
190 abstract class KernelToElementMapMixin implements KernelToElementMap { 200 abstract class KernelToElementMapMixin
201 implements KernelToElementMapForBuilding {
191 DiagnosticReporter get reporter; 202 DiagnosticReporter get reporter;
192 native.BehaviorBuilder get nativeBehaviorBuilder; 203 native.BehaviorBuilder get nativeBehaviorBuilder;
193 ConstantValue computeConstantValue(ConstantExpression constant, 204 ConstantValue computeConstantValue(ConstantExpression constant,
194 {bool requireConstant: true}); 205 {bool requireConstant: true});
195 206
196 @override 207 @override
197 Name getName(ir.Name name) { 208 Name getName(ir.Name name) {
198 return new Name( 209 return new Name(
199 name.name, name.isPrivate ? getLibrary(name.library) : null); 210 name.name, name.isPrivate ? getLibrary(name.library) : null);
200 } 211 }
201 212
202 @override
203 CallStructure getCallStructure(ir.Arguments arguments) { 213 CallStructure getCallStructure(ir.Arguments arguments) {
204 int argumentCount = arguments.positional.length + arguments.named.length; 214 int argumentCount = arguments.positional.length + arguments.named.length;
205 List<String> namedArguments = arguments.named.map((e) => e.name).toList(); 215 List<String> namedArguments = arguments.named.map((e) => e.name).toList();
206 return new CallStructure(argumentCount, namedArguments); 216 return new CallStructure(argumentCount, namedArguments);
207 } 217 }
208 218
209 @override 219 @override
210 Selector getSelector(ir.Expression node) { 220 Selector getSelector(ir.Expression node) {
211 // TODO(efortuna): This is screaming for a common interface between 221 // TODO(efortuna): This is screaming for a common interface between
212 // PropertyGet and SuperPropertyGet (and same for *Get). Talk to kernel 222 // PropertyGet and SuperPropertyGet (and same for *Get). Talk to kernel
(...skipping 903 matching lines...) Expand 10 before | Expand all | Expand 10 after
1116 /// [closureClassMaps]. 1126 /// [closureClassMaps].
1117 LoopClosureRepresentationInfo getClosureRepresentationInfoForLoop( 1127 LoopClosureRepresentationInfo getClosureRepresentationInfoForLoop(
1118 ClosureDataLookup closureLookup, ir.TreeNode node); 1128 ClosureDataLookup closureLookup, ir.TreeNode node);
1119 } 1129 }
1120 1130
1121 /// Comparator for the canonical order or named arguments. 1131 /// Comparator for the canonical order or named arguments.
1122 // TODO(johnniwinther): Remove this when named parameters are sorted in dill. 1132 // TODO(johnniwinther): Remove this when named parameters are sorted in dill.
1123 int namedOrdering(ir.VariableDeclaration a, ir.VariableDeclaration b) { 1133 int namedOrdering(ir.VariableDeclaration a, ir.VariableDeclaration b) {
1124 return a.name.compareTo(b.name); 1134 return a.name.compareTo(b.name);
1125 } 1135 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698