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

Side by Side Diff: pkg/compiler/lib/src/ssa/locals_handler.dart

Issue 2918913003: Handle list and map literals (Closed)
Patch Set: Rebased 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 '../closure.dart'; 5 import '../closure.dart';
6 import '../common.dart'; 6 import '../common.dart';
7 import '../elements/resolution_types.dart';
8 import '../elements/elements.dart'; 7 import '../elements/elements.dart';
9 import '../elements/entities.dart'; 8 import '../elements/entities.dart';
9 import '../elements/types.dart';
10 import '../io/source_information.dart'; 10 import '../io/source_information.dart';
11 import '../js_backend/native_data.dart'; 11 import '../js_backend/native_data.dart';
12 import '../js_backend/interceptor_data.dart'; 12 import '../js_backend/interceptor_data.dart';
13 import '../tree/tree.dart' as ast; 13 import '../tree/tree.dart' as ast;
14 import '../types/types.dart'; 14 import '../types/types.dart';
15 import '../world.dart' show ClosedWorld; 15 import '../world.dart' show ClosedWorld;
16 16
17 import 'graph_builder.dart'; 17 import 'graph_builder.dart';
18 import 'nodes.dart'; 18 import 'nodes.dart';
19 import 'types.dart'; 19 import 'types.dart';
20 20
21 /// Keeps track of locals (including parameters and phis) when building. The 21 /// Keeps track of locals (including parameters and phis) when building. The
22 /// 'this' reference is treated as parameter and hence handled by this class, 22 /// 'this' reference is treated as parameter and hence handled by this class,
23 /// too. 23 /// too.
24 class LocalsHandler { 24 class LocalsHandler {
25 /// The values of locals that can be directly accessed (without redirections 25 /// The values of locals that can be directly accessed (without redirections
26 /// to boxes or closure-fields). 26 /// to boxes or closure-fields).
27 /// 27 ///
28 /// [directLocals] is iterated, so it is "insertion ordered" to make the 28 /// [directLocals] is iterated, so it is "insertion ordered" to make the
29 /// iteration order a function only of insertions and not a function of 29 /// iteration order a function only of insertions and not a function of
30 /// e.g. Element hash codes. I'd prefer to use a SortedMap but some elements 30 /// e.g. Element hash codes. I'd prefer to use a SortedMap but some elements
31 /// don't have source locations for [Elements.compareByPosition]. 31 /// don't have source locations for [Elements.compareByPosition].
32 Map<Local, HInstruction> directLocals = new Map<Local, HInstruction>(); 32 Map<Local, HInstruction> directLocals = new Map<Local, HInstruction>();
33 Map<Local, CapturedVariable> redirectionMapping = 33 Map<Local, CapturedVariable> redirectionMapping =
34 new Map<Local, CapturedVariable>(); 34 new Map<Local, CapturedVariable>();
35 final GraphBuilder builder; 35 final GraphBuilder builder;
36 ClosureClassMap closureData; 36 ClosureClassMap closureData;
37 Map<ResolutionTypeVariableType, TypeVariableLocal> typeVariableLocals = 37 Map<TypeVariableType, TypeVariableLocal> typeVariableLocals =
38 new Map<ResolutionTypeVariableType, TypeVariableLocal>(); 38 new Map<TypeVariableType, TypeVariableLocal>();
39 final Entity executableContext; 39 final Entity executableContext;
40 final MemberEntity memberContext; 40 final MemberEntity memberContext;
41 41
42 /// The class that defines the current type environment or null if no type 42 /// The class that defines the current type environment or null if no type
43 /// variables are in scope. 43 /// variables are in scope.
44 final ClassElement contextClass; 44 final ClassElement contextClass;
45 45
46 /// The type of the current instance, if concrete. 46 /// The type of the current instance, if concrete.
47 /// 47 ///
48 /// This allows for handling fixed type argument in case of inlining. For 48 /// This allows for handling fixed type argument in case of inlining. For
49 /// instance, checking `'foo'` against `String` instead of `T` in `main`: 49 /// instance, checking `'foo'` against `String` instead of `T` in `main`:
50 /// 50 ///
51 /// class Foo<T> { 51 /// class Foo<T> {
52 /// T field; 52 /// T field;
53 /// Foo(this.field); 53 /// Foo(this.field);
54 /// } 54 /// }
55 /// main() { 55 /// main() {
56 /// new Foo<String>('foo'); 56 /// new Foo<String>('foo');
57 /// } 57 /// }
58 /// 58 ///
59 /// [instanceType] is not used if it contains type variables, since these 59 /// [instanceType] is not used if it contains type variables, since these
60 /// might not be in scope or from the current instance. 60 /// might not be in scope or from the current instance.
61 /// 61 ///
62 final ResolutionInterfaceType instanceType; 62 final InterfaceType instanceType;
63 63
64 final NativeData _nativeData; 64 final NativeData _nativeData;
65 65
66 final InterceptorData _interceptorData; 66 final InterceptorData _interceptorData;
67 67
68 LocalsHandler( 68 LocalsHandler(
69 this.builder, 69 this.builder,
70 this.executableContext, 70 this.executableContext,
71 this.memberContext, 71 this.memberContext,
72 this.contextClass, 72 this.contextClass,
73 ResolutionInterfaceType instanceType, 73 InterfaceType instanceType,
74 this._nativeData, 74 this._nativeData,
75 this._interceptorData) 75 this._interceptorData)
76 : this.instanceType = 76 : this.instanceType =
77 instanceType == null || instanceType.containsTypeVariables 77 instanceType == null || instanceType.containsTypeVariables
78 ? null 78 ? null
79 : instanceType; 79 : instanceType;
80 80
81 ClosedWorld get closedWorld => builder.closedWorld; 81 ClosedWorld get closedWorld => builder.closedWorld;
82 82
83 CommonMasks get commonMasks => closedWorld.commonMasks; 83 CommonMasks get commonMasks => closedWorld.commonMasks;
84 84
85 GlobalTypeInferenceResults get _globalInferenceResults => 85 GlobalTypeInferenceResults get _globalInferenceResults =>
86 builder.globalInferenceResults; 86 builder.globalInferenceResults;
87 87
88 ClosureClassMaps get _closureToClassMapper => builder.closureToClassMapper; 88 ClosureClassMaps get _closureToClassMapper => builder.closureToClassMapper;
89 89
90 /// Substituted type variables occurring in [type] into the context of 90 /// Substituted type variables occurring in [type] into the context of
91 /// [contextClass]. 91 /// [contextClass].
92 ResolutionDartType substInContext(ResolutionDartType type) { 92 DartType substInContext(DartType type) {
93 if (contextClass != null) { 93 if (contextClass != null) {
94 ClassElement typeContext = Types.getClassContext(type); 94 ClassElement typeContext = DartTypes.getClassContext(type);
95 if (typeContext != null) { 95 if (typeContext != null) {
96 type = type.substByContext(contextClass.asInstanceOf(typeContext)); 96 type = builder.types.substByContext(
97 type,
98 builder.types.asInstanceOf(
99 builder.types.getThisType(contextClass), typeContext));
100 //type = type.substByContext(contextClass.asInstanceOf(typeContext));
Siggi Cherem (dart-lang) 2017/06/02 18:09:23 delete old code? also below?
Johnni Winther 2017/06/02 18:53:46 Done.
97 } 101 }
98 } 102 }
99 if (instanceType != null) { 103 if (instanceType != null) {
100 type = type.substByContext(instanceType); 104 type = builder.types.substByContext(type, instanceType);
105 //type = type.substByContext(instanceType);
101 } 106 }
102 return type; 107 return type;
103 } 108 }
104 109
105 /// Creates a new [LocalsHandler] based on [other]. We only need to 110 /// Creates a new [LocalsHandler] based on [other]. We only need to
106 /// copy the [directLocals], since the other fields can be shared 111 /// copy the [directLocals], since the other fields can be shared
107 /// throughout the AST visit. 112 /// throughout the AST visit.
108 LocalsHandler.from(LocalsHandler other) 113 LocalsHandler.from(LocalsHandler other)
109 : directLocals = new Map<Local, HInstruction>.from(other.directLocals), 114 : directLocals = new Map<Local, HInstruction>.from(other.directLocals),
110 redirectionMapping = other.redirectionMapping, 115 redirectionMapping = other.redirectionMapping,
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 } 396 }
392 397
393 return activationVariables.putIfAbsent(local, () { 398 return activationVariables.putIfAbsent(local, () {
394 HLocalValue localValue = new HLocalValue(local, commonMasks.nonNullType) 399 HLocalValue localValue = new HLocalValue(local, commonMasks.nonNullType)
395 ..sourceInformation = sourceInformation; 400 ..sourceInformation = sourceInformation;
396 builder.graph.entry.addAtExit(localValue); 401 builder.graph.entry.addAtExit(localValue);
397 return localValue; 402 return localValue;
398 }); 403 });
399 } 404 }
400 405
401 Local getTypeVariableAsLocal(ResolutionTypeVariableType type) { 406 Local getTypeVariableAsLocal(TypeVariableType type) {
402 return typeVariableLocals.putIfAbsent(type, () { 407 return typeVariableLocals.putIfAbsent(type, () {
403 return new TypeVariableLocal(type, executableContext); 408 return new TypeVariableLocal(type, executableContext);
404 }); 409 });
405 } 410 }
406 411
407 /// Sets the [element] to [value]. If the element is boxed or stored in a 412 /// Sets the [element] to [value]. If the element is boxed or stored in a
408 /// closure then the method generates code to set the value. 413 /// closure then the method generates code to set the value.
409 void updateLocal(Local local, HInstruction value, 414 void updateLocal(Local local, HInstruction value,
410 {SourceInformation sourceInformation}) { 415 {SourceInformation sourceInformation}) {
411 if (value is HRef) { 416 if (value is HRef) {
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 final MemberEntity memberContext; 684 final MemberEntity memberContext;
680 685
681 // Avoid slow Object.hashCode. 686 // Avoid slow Object.hashCode.
682 final int hashCode = _nextHashCode = (_nextHashCode + 1).toUnsigned(30); 687 final int hashCode = _nextHashCode = (_nextHashCode + 1).toUnsigned(30);
683 static int _nextHashCode = 0; 688 static int _nextHashCode = 0;
684 689
685 SyntheticLocal(this.name, this.executableContext, this.memberContext); 690 SyntheticLocal(this.name, this.executableContext, this.memberContext);
686 691
687 toString() => 'SyntheticLocal($name)'; 692 toString() => 'SyntheticLocal($name)';
688 } 693 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/ssa/kernel_ast_adapter.dart ('k') | pkg/compiler/lib/src/ssa/type_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698