Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 2bc015b

Browse files
johnniwinthercommit-bot@chromium.org
authored andcommitted
Remove dependency on TypeEnvironment.hierarchy
Change-Id: Ibc675aa37bf1d5f90640b41471d094025ae3da86 Reviewed-on: https://dart-review.googlesource.com/c/88805 Commit-Queue: Johnni Winther <[email protected]> Auto-Submit: Johnni Winther <[email protected]> Reviewed-by: Peter von der Ahé <[email protected]>
1 parent 7ba1997 commit 2bc015b

File tree

7 files changed

+41
-18
lines changed

7 files changed

+41
-18
lines changed

pkg/compiler/lib/src/ir/static_type.dart

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ abstract class StaticTypeVisitor extends StaticTypeBase {
3636
Map<ir.Expression, ir.DartType> _cache = {};
3737
Map<ir.Expression, TypeMap> typeMapsForTesting;
3838

39-
StaticTypeVisitor(ir.TypeEnvironment typeEnvironment)
39+
final ir.ClassHierarchy hierarchy;
40+
41+
StaticTypeVisitor(ir.TypeEnvironment typeEnvironment, this.hierarchy)
4042
: super(typeEnvironment);
4143

4244
Map<ir.Expression, ir.DartType> get cachedStaticTypes => _cache;
@@ -165,8 +167,8 @@ abstract class StaticTypeVisitor extends StaticTypeBase {
165167
ir.PropertyGet node, ir.DartType receiverType) {
166168
ir.Member interfaceTarget = node.interfaceTarget;
167169
if (interfaceTarget == null && receiverType is ir.InterfaceType) {
168-
interfaceTarget = node.interfaceTarget = typeEnvironment.hierarchy
169-
.getInterfaceMember(receiverType.classNode, node.name);
170+
interfaceTarget = node.interfaceTarget =
171+
hierarchy.getInterfaceMember(receiverType.classNode, node.name);
170172
}
171173
if (interfaceTarget != null) {
172174
ir.Class superclass = interfaceTarget.enclosingClass;
@@ -205,7 +207,7 @@ abstract class StaticTypeVisitor extends StaticTypeBase {
205207
ir.DartType receiverType = visitNode(node.receiver);
206208
ir.DartType valueType = super.visitPropertySet(node);
207209
if (node.interfaceTarget == null && receiverType is ir.InterfaceType) {
208-
node.interfaceTarget = typeEnvironment.hierarchy
210+
node.interfaceTarget = hierarchy
209211
.getInterfaceMember(receiverType.classNode, node.name, setter: true);
210212
}
211213
receiverType = _narrowInstanceReceiver(node.interfaceTarget, receiverType);
@@ -388,8 +390,8 @@ abstract class StaticTypeVisitor extends StaticTypeBase {
388390
interfaceTarget = node.interfaceTarget = objectEquals;
389391
}
390392
if (interfaceTarget == null && receiverType is ir.InterfaceType) {
391-
ir.Member member = typeEnvironment.hierarchy
392-
.getInterfaceMember(receiverType.classNode, node.name);
393+
ir.Member member =
394+
hierarchy.getInterfaceMember(receiverType.classNode, node.name);
393395
if (_isApplicable(node.arguments, member)) {
394396
interfaceTarget = node.interfaceTarget = member;
395397
}

pkg/compiler/lib/src/js_model/element_map_impl.dart

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ class JsKernelToElementMap
9999
JsConstantEnvironment _constantEnvironment;
100100
KernelDartTypes _types;
101101
ir.TypeEnvironment _typeEnvironment;
102+
ir.ClassHierarchy _classHierarchy;
102103

103104
/// Library environment. Used for fast lookup.
104105
JProgramEnv programEnv;
@@ -1057,12 +1058,18 @@ class JsKernelToElementMap
10571058
ir.TypeEnvironment get typeEnvironment {
10581059
if (_typeEnvironment == null) {
10591060
_typeEnvironment ??= new ir.TypeEnvironment(
1060-
new ir.CoreTypes(programEnv.mainComponent),
1061-
new ir.ClassHierarchy(programEnv.mainComponent));
1061+
new ir.CoreTypes(programEnv.mainComponent), classHierarchy);
10621062
}
10631063
return _typeEnvironment;
10641064
}
10651065

1066+
ir.ClassHierarchy get classHierarchy {
1067+
if (_classHierarchy == null) {
1068+
_classHierarchy ??= new ir.ClassHierarchy(programEnv.mainComponent);
1069+
}
1070+
return _classHierarchy;
1071+
}
1072+
10661073
StaticTypeProvider getStaticTypeProvider(MemberEntity member) {
10671074
MemberDefinition memberDefinition = members.getData(member).definition;
10681075
Map<ir.Expression, ir.DartType> cachedStaticTypes;
@@ -1098,8 +1105,7 @@ class JsKernelToElementMap
10981105
return new CachedStaticType(
10991106
// We need a copy of the type environment since the `thisType` field
11001107
// is holds state, making the environment contextually bound.
1101-
new ir.TypeEnvironment(
1102-
typeEnvironment.coreTypes, typeEnvironment.hierarchy)
1108+
new ir.TypeEnvironment(typeEnvironment.coreTypes, classHierarchy)
11031109
..thisType = thisType,
11041110
cachedStaticTypes);
11051111
}

pkg/compiler/lib/src/kernel/element_map.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:kernel/ast.dart' as ir;
6+
import 'package:kernel/class_hierarchy.dart' as ir;
67
import 'package:kernel/type_environment.dart' as ir;
78

89
import '../constants/values.dart';
@@ -29,8 +30,12 @@ abstract class KernelToElementMap {
2930
/// Access to the [DartTypes] object.
3031
DartTypes get types;
3132

33+
/// Returns the type environment for the underlying kernel model.
3234
ir.TypeEnvironment get typeEnvironment;
3335

36+
/// Returns the class hierarchy for the underlying kernel model.
37+
ir.ClassHierarchy get classHierarchy;
38+
3439
/// Returns the [DartType] corresponding to [type].
3540
DartType getDartType(ir.DartType type);
3641

pkg/compiler/lib/src/kernel/element_map_impl.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class KernelToElementMapImpl implements KernelToElementMap, IrToElementMap {
7171
KernelConstantEnvironment _constantEnvironment;
7272
KernelDartTypes _types;
7373
ir.TypeEnvironment _typeEnvironment;
74+
ir.ClassHierarchy _classHierarchy;
7475

7576
/// Library environment. Used for fast lookup.
7677
KProgramEnv env = new KProgramEnv();
@@ -718,12 +719,18 @@ class KernelToElementMapImpl implements KernelToElementMap, IrToElementMap {
718719
ir.TypeEnvironment get typeEnvironment {
719720
if (_typeEnvironment == null) {
720721
_typeEnvironment ??= new ir.TypeEnvironment(
721-
new ir.CoreTypes(env.mainComponent),
722-
new ir.ClassHierarchy(env.mainComponent));
722+
new ir.CoreTypes(env.mainComponent), classHierarchy);
723723
}
724724
return _typeEnvironment;
725725
}
726726

727+
ir.ClassHierarchy get classHierarchy {
728+
if (_classHierarchy == null) {
729+
_classHierarchy ??= new ir.ClassHierarchy(env.mainComponent);
730+
}
731+
return _classHierarchy;
732+
}
733+
727734
DartType getStaticType(ir.Expression node) {
728735
ir.TreeNode enclosingClass = node;
729736
while (enclosingClass != null && enclosingClass is! ir.Class) {

pkg/compiler/lib/src/kernel/kernel_impact.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class KernelImpactBuilder extends StaticTypeVisitor {
4242
this._options, this.variableScopeModel, this._annotations)
4343
: this.impactBuilder =
4444
new ResolutionWorldImpactBuilder('${currentMember}'),
45-
super(elementMap.typeEnvironment);
45+
super(elementMap.typeEnvironment, elementMap.classHierarchy);
4646

4747
CommonElements get commonElements => elementMap.commonElements;
4848

tests/compiler/dart2js/analyses/analysis_helper.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@ run(Uri entryPoint, String allowedListPath,
7171
class StaticTypeVisitorBase extends StaticTypeVisitor {
7272
VariableScopeModel variableScopeModel;
7373

74-
StaticTypeVisitorBase(ir.Component component)
75-
: super(new ir.TypeEnvironment(
76-
new ir.CoreTypes(component), new ir.ClassHierarchy(component)));
74+
StaticTypeVisitorBase(
75+
ir.Component component, ir.ClassHierarchy classHierarchy)
76+
: super(
77+
new ir.TypeEnvironment(new ir.CoreTypes(component), classHierarchy),
78+
classHierarchy);
7779

7880
@override
7981
bool get useAsserts => false;
@@ -132,7 +134,7 @@ class DynamicVisitor extends StaticTypeVisitorBase {
132134

133135
DynamicVisitor(this.reporter, this.component, this._allowedListPath,
134136
this.analyzedUrisFilter)
135-
: super(component);
137+
: super(component, new ir.ClassHierarchy(component));
136138

137139
void run({bool verbose = false, bool generate = false}) {
138140
if (!generate && _allowedListPath != null) {

tests/compiler/dart2js/analyses/static_type_visitor_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ main() {
3131
}
3232

3333
class Visitor extends StaticTypeVisitorBase {
34-
Visitor(ir.Component component) : super(component);
34+
Visitor(ir.Component component)
35+
: super(component, new ir.ClassHierarchy(component));
3536

3637
ir.DartType getStaticType(ir.Expression node) {
3738
if (typeEnvironment == null) {

0 commit comments

Comments
 (0)