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

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

Issue 2971673002: Split ClassEnv into env and data to avoid copying types/constants from the k-model (Closed)
Patch Set: Updated cf. comments. 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 library dart2js.kernel.env; 5 library dart2js.kernel.env;
6 6
7 import 'package:kernel/ast.dart' as ir; 7 import 'package:kernel/ast.dart' as ir;
8 import 'package:kernel/clone.dart'; 8 import 'package:kernel/clone.dart';
9 import 'package:kernel/type_algebra.dart'; 9 import 'package:kernel/type_algebra.dart';
10 10
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 } else { 150 } else {
151 // Skip fields; these are also in _memberMap. 151 // Skip fields; these are also in _memberMap.
152 } 152 }
153 } 153 }
154 } 154 }
155 } 155 }
156 156
157 /// Environment for fast lookup of class members. 157 /// Environment for fast lookup of class members.
158 class ClassEnv { 158 class ClassEnv {
159 final ir.Class cls; 159 final ir.Class cls;
160 bool isMixinApplication;
161 final bool isUnnamedMixinApplication; 160 final bool isUnnamedMixinApplication;
162 161
163 InterfaceType thisType;
164 InterfaceType rawType;
165 InterfaceType supertype;
166 InterfaceType mixedInType;
167 List<InterfaceType> interfaces;
168 OrderedTypeSet orderedTypeSet;
169
170 Map<String, ir.Member> _constructorMap; 162 Map<String, ir.Member> _constructorMap;
171 Map<String, ir.Member> _memberMap; 163 Map<String, ir.Member> _memberMap;
172 Map<String, ir.Member> _setterMap; 164 Map<String, ir.Member> _setterMap;
173 165
174 Iterable<ConstantValue> _metadata;
175
176 ClassEnv(this.cls) 166 ClassEnv(this.cls)
177 // TODO(johnniwinther): Change this to use a property on [cls] when such 167 // TODO(johnniwinther): Change this to use a property on [cls] when such
178 // is added to kernel. 168 // is added to kernel.
179 : isUnnamedMixinApplication = 169 : isUnnamedMixinApplication =
180 cls.name.contains('+') || cls.name.contains('&'); 170 cls.name.contains('+') || cls.name.contains('&');
181 171
182 /// Copied from 'package:kernel/transformations/mixin_full_resolution.dart'. 172 /// Copied from 'package:kernel/transformations/mixin_full_resolution.dart'.
183 ir.Constructor _buildForwardingConstructor( 173 ir.Constructor _buildForwardingConstructor(
184 CloneVisitor cloner, ir.Constructor superclassConstructor) { 174 CloneVisitor cloner, ir.Constructor superclassConstructor) {
185 var superFunction = superclassConstructor.function; 175 var superFunction = superclassConstructor.function;
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 } else { 296 } else {
307 // Skip fields; these are also in _memberMap. 297 // Skip fields; these are also in _memberMap.
308 } 298 }
309 } 299 }
310 } 300 }
311 301
312 void forEachConstructor(void f(ir.Member member)) { 302 void forEachConstructor(void f(ir.Member member)) {
313 _ensureMaps(); 303 _ensureMaps();
314 _constructorMap.values.forEach(f); 304 _constructorMap.values.forEach(f);
315 } 305 }
306 }
307
308 class ClassData {
309 final ir.Class cls;
310 bool isMixinApplication;
311
312 InterfaceType thisType;
313 InterfaceType rawType;
314 InterfaceType supertype;
315 InterfaceType mixedInType;
316 List<InterfaceType> interfaces;
317 OrderedTypeSet orderedTypeSet;
318
319 Iterable<ConstantValue> _metadata;
320
321 ClassData(this.cls);
316 322
317 Iterable<ConstantValue> getMetadata(KernelToElementMapBase elementMap) { 323 Iterable<ConstantValue> getMetadata(KernelToElementMapBase elementMap) {
318 return _metadata ??= elementMap.getMetadata(cls.annotations); 324 return _metadata ??= elementMap.getMetadata(cls.annotations);
319 } 325 }
326
327 ClassData copy() {
328 return new ClassData(cls);
329 }
320 } 330 }
321 331
322 class MemberData { 332 class MemberData {
323 final ir.Member node; 333 final ir.Member node;
324 Iterable<ConstantValue> _metadata; 334 Iterable<ConstantValue> _metadata;
325 335
326 MemberData(this.node); 336 MemberData(this.node);
327 337
328 ResolutionImpact getWorldImpact(KernelToElementMapForImpact elementMap) { 338 ResolutionImpact getWorldImpact(KernelToElementMapForImpact elementMap) {
329 return buildKernelImpact(node, elementMap); 339 return buildKernelImpact(node, elementMap);
330 } 340 }
331 341
332 Iterable<ConstantValue> getMetadata(KernelToElementMapBase elementMap) { 342 Iterable<ConstantValue> getMetadata(KernelToElementMapBase elementMap) {
333 return _metadata ??= elementMap.getMetadata(node.annotations); 343 return _metadata ??= elementMap.getMetadata(node.annotations);
334 } 344 }
345
346 MemberData copy() {
347 return new MemberData(node);
348 }
335 } 349 }
336 350
337 class FunctionData extends MemberData { 351 class FunctionData extends MemberData {
338 final ir.FunctionNode functionNode; 352 final ir.FunctionNode functionNode;
339 FunctionType _type; 353 FunctionType _type;
340 354
341 FunctionData(ir.Member node, this.functionNode) : super(node); 355 FunctionData(ir.Member node, this.functionNode) : super(node);
342 356
343 FunctionType getFunctionType(KernelToElementMapBase elementMap) { 357 FunctionType getFunctionType(KernelToElementMapBase elementMap) {
344 return _type ??= elementMap.getFunctionType(functionNode); 358 return _type ??= elementMap.getFunctionType(functionNode);
(...skipping 16 matching lines...) Expand all
361 } 375 }
362 376
363 for (int i = 0; i < functionNode.positionalParameters.length; i++) { 377 for (int i = 0; i < functionNode.positionalParameters.length; i++) {
364 handleParameter(functionNode.positionalParameters[i], 378 handleParameter(functionNode.positionalParameters[i],
365 isOptional: i < functionNode.requiredParameterCount); 379 isOptional: i < functionNode.requiredParameterCount);
366 } 380 }
367 functionNode.namedParameters.toList() 381 functionNode.namedParameters.toList()
368 ..sort(namedOrdering) 382 ..sort(namedOrdering)
369 ..forEach(handleParameter); 383 ..forEach(handleParameter);
370 } 384 }
385
386 @override
387 FunctionData copy() {
388 return new FunctionData(node, functionNode);
389 }
371 } 390 }
372 391
373 class ConstructorData extends FunctionData { 392 class ConstructorData extends FunctionData {
374 ConstantConstructor _constantConstructor; 393 ConstantConstructor _constantConstructor;
375 394
376 ConstructorData(ir.Member node, ir.FunctionNode functionNode) 395 ConstructorData(ir.Member node, ir.FunctionNode functionNode)
377 : super(node, functionNode); 396 : super(node, functionNode);
378 397
379 ConstantConstructor getConstructorConstant( 398 ConstantConstructor getConstructorConstant(
380 KernelToElementMapBase elementMap, ConstructorEntity constructor) { 399 KernelToElementMapBase elementMap, ConstructorEntity constructor) {
381 if (_constantConstructor == null) { 400 if (_constantConstructor == null) {
382 if (node is ir.Constructor && constructor.isConst) { 401 if (node is ir.Constructor && constructor.isConst) {
383 _constantConstructor = 402 _constantConstructor =
384 new Constantifier(elementMap).computeConstantConstructor(node); 403 new Constantifier(elementMap).computeConstantConstructor(node);
385 } else { 404 } else {
386 throw new SpannableAssertionFailure( 405 throw new SpannableAssertionFailure(
387 constructor, 406 constructor,
388 "Unexpected constructor $constructor in " 407 "Unexpected constructor $constructor in "
389 "KernelWorldBuilder._getConstructorConstant"); 408 "KernelWorldBuilder._getConstructorConstant");
390 } 409 }
391 } 410 }
392 return _constantConstructor; 411 return _constantConstructor;
393 } 412 }
413
414 @override
415 ConstructorData copy() {
416 return new ConstructorData(node, functionNode);
417 }
394 } 418 }
395 419
396 class FieldData extends MemberData { 420 class FieldData extends MemberData {
397 ConstantExpression _constant; 421 ConstantExpression _constant;
398 422
399 FieldData(ir.Field node) : super(node); 423 FieldData(ir.Field node) : super(node);
400 424
401 ir.Field get node => super.node; 425 ir.Field get node => super.node;
402 426
403 ConstantExpression getFieldConstant( 427 ConstantExpression getFieldConstant(
404 KernelToElementMapBase elementMap, FieldEntity field) { 428 KernelToElementMapBase elementMap, FieldEntity field) {
405 if (_constant == null) { 429 if (_constant == null) {
406 if (node.isConst) { 430 if (node.isConst) {
407 _constant = new Constantifier(elementMap).visit(node.initializer); 431 _constant = new Constantifier(elementMap).visit(node.initializer);
408 } else { 432 } else {
409 throw new SpannableAssertionFailure( 433 throw new SpannableAssertionFailure(
410 field, 434 field,
411 "Unexpected field $field in " 435 "Unexpected field $field in "
412 "KernelWorldBuilder._getConstructorConstant"); 436 "KernelWorldBuilder._getConstructorConstant");
413 } 437 }
414 } 438 }
415 return _constant; 439 return _constant;
416 } 440 }
441
442 @override
443 FieldData copy() {
444 return new FieldData(node);
445 }
417 } 446 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/kernel/element_map_impl.dart ('k') | tests/compiler/dart2js/js_model/model_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698