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

Unified Diff: pkg/compiler/lib/src/universe/world_impact.dart

Issue 2742283002: Add ConstantUse to WorldImpact (Closed)
Patch Set: Cleanup. Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: pkg/compiler/lib/src/universe/world_impact.dart
diff --git a/pkg/compiler/lib/src/universe/world_impact.dart b/pkg/compiler/lib/src/universe/world_impact.dart
index 0c708a23455fd5a9c7d253249eedca92a46df5c3..3620b853ca0bd9c78abb9c95530140225be6e083 100644
--- a/pkg/compiler/lib/src/universe/world_impact.dart
+++ b/pkg/compiler/lib/src/universe/world_impact.dart
@@ -5,7 +5,7 @@
library dart2js.universe.world_impact;
import '../util/util.dart' show Setlet;
-import 'use.dart' show DynamicUse, StaticUse, TypeUse;
+import 'use.dart';
/// Describes how an element (e.g. a method) impacts the closed-world
/// semantics of a program.
@@ -32,12 +32,15 @@ class WorldImpact {
Iterable<TypeUse> get typeUses => const <TypeUse>[];
+ Iterable<ConstantUse> get constantUses => const <ConstantUse>[];
+
bool get isEmpty => true;
void apply(WorldImpactVisitor visitor) {
staticUses.forEach(visitor.visitStaticUse);
dynamicUses.forEach(visitor.visitDynamicUse);
typeUses.forEach(visitor.visitTypeUse);
+ constantUses.forEach(visitor.visitConstantUse);
}
String toString() => dump(this);
@@ -59,6 +62,7 @@ class WorldImpact {
add('dynamic uses', worldImpact.dynamicUses);
add('static uses', worldImpact.staticUses);
add('type uses', worldImpact.typeUses);
+ add('constant uses', worldImpact.constantUses);
}
}
@@ -66,6 +70,7 @@ abstract class WorldImpactBuilder {
void registerDynamicUse(DynamicUse dynamicUse);
void registerTypeUse(TypeUse typeUse);
void registerStaticUse(StaticUse staticUse);
+ void registerConstantUse(ConstantUse constantUse);
}
class WorldImpactBuilderImpl extends WorldImpact implements WorldImpactBuilder {
@@ -74,10 +79,14 @@ class WorldImpactBuilderImpl extends WorldImpact implements WorldImpactBuilder {
Set<DynamicUse> _dynamicUses;
Set<StaticUse> _staticUses;
Set<TypeUse> _typeUses;
+ Set<ConstantUse> _constantUses;
@override
bool get isEmpty =>
- _dynamicUses == null && _staticUses == null && _typeUses == null;
+ _dynamicUses == null &&
+ _staticUses == null &&
+ _typeUses == null &&
+ _constantUses == null;
/// Copy uses in [impact] to this impact builder.
void addImpact(WorldImpact impact) {
@@ -85,6 +94,7 @@ class WorldImpactBuilderImpl extends WorldImpact implements WorldImpactBuilder {
impact.dynamicUses.forEach(registerDynamicUse);
impact.staticUses.forEach(registerStaticUse);
impact.typeUses.forEach(registerTypeUse);
+ impact.constantUses.forEach(registerConstantUse);
}
void registerDynamicUse(DynamicUse dynamicUse) {
@@ -122,6 +132,18 @@ class WorldImpactBuilderImpl extends WorldImpact implements WorldImpactBuilder {
Iterable<StaticUse> get staticUses {
return _staticUses != null ? _staticUses : const <StaticUse>[];
}
+
+ void registerConstantUse(ConstantUse constantUse) {
+ assert(constantUse != null);
+ if (_constantUses == null) {
+ _constantUses = new Setlet<ConstantUse>();
+ }
+ _constantUses.add(constantUse);
+ }
+
+ Iterable<ConstantUse> get constantUses {
+ return _constantUses != null ? _constantUses : const <ConstantUse>[];
+ }
}
/// [WorldImpactBuilder] that can create and collect a sequence of
@@ -160,6 +182,12 @@ class StagedWorldImpactBuilder implements WorldImpactBuilder {
_currentBuilder.registerStaticUse(staticUse);
}
+ @override
+ void registerConstantUse(ConstantUse constantUse) {
+ _ensureBuilder();
+ _currentBuilder.registerConstantUse(constantUse);
+ }
+
/// Returns the [WorldImpact] built so far with this builder. The builder
/// is reset, and if [collectImpacts] is `true` the impact is cached for
/// [worldImpacts].
@@ -183,6 +211,7 @@ class TransformedWorldImpact implements WorldImpact, WorldImpactBuilder {
Setlet<StaticUse> _staticUses;
Setlet<TypeUse> _typeUses;
Setlet<DynamicUse> _dynamicUses;
+ Setlet<ConstantUse> _constantUses;
TransformedWorldImpact(this.worldImpact);
@@ -191,7 +220,8 @@ class TransformedWorldImpact implements WorldImpact, WorldImpactBuilder {
return worldImpact.isEmpty &&
_staticUses == null &&
_typeUses == null &&
- _dynamicUses == null;
+ _dynamicUses == null &&
+ _constantUses == null;
}
@override
@@ -233,10 +263,24 @@ class TransformedWorldImpact implements WorldImpact, WorldImpactBuilder {
return _staticUses != null ? _staticUses : worldImpact.staticUses;
}
+ @override
+ Iterable<ConstantUse> get constantUses {
+ return _constantUses != null ? _constantUses : worldImpact.constantUses;
+ }
+
+ void registerConstantUse(ConstantUse constantUse) {
+ if (_constantUses == null) {
+ _constantUses = new Setlet<ConstantUse>();
+ _constantUses.addAll(worldImpact.constantUses);
+ }
+ _constantUses.add(constantUse);
+ }
+
void apply(WorldImpactVisitor visitor) {
staticUses.forEach(visitor.visitStaticUse);
dynamicUses.forEach(visitor.visitDynamicUse);
typeUses.forEach(visitor.visitTypeUse);
+ constantUses.forEach(visitor.visitConstantUse);
}
String toString() {
@@ -279,6 +323,7 @@ abstract class WorldImpactVisitor {
void visitStaticUse(StaticUse staticUse);
void visitDynamicUse(DynamicUse dynamicUse);
void visitTypeUse(TypeUse typeUse);
+ void visitConstantUse(ConstantUse typeUse);
}
// TODO(johnniwinther): Remove these when we get anonymous local classes.
@@ -288,14 +333,17 @@ class WorldImpactVisitorImpl implements WorldImpactVisitor {
final VisitUse<StaticUse> _visitStaticUse;
final VisitUse<DynamicUse> _visitDynamicUse;
final VisitUse<TypeUse> _visitTypeUse;
+ final VisitUse<ConstantUse> _visitConstantUse;
WorldImpactVisitorImpl(
{VisitUse<StaticUse> visitStaticUse,
VisitUse<DynamicUse> visitDynamicUse,
- VisitUse<TypeUse> visitTypeUse})
+ VisitUse<TypeUse> visitTypeUse,
+ VisitUse<ConstantUse> visitConstantUse})
: _visitStaticUse = visitStaticUse,
_visitDynamicUse = visitDynamicUse,
- _visitTypeUse = visitTypeUse;
+ _visitTypeUse = visitTypeUse,
+ _visitConstantUse = visitConstantUse;
@override
void visitStaticUse(StaticUse use) {
@@ -317,4 +365,11 @@ class WorldImpactVisitorImpl implements WorldImpactVisitor {
_visitTypeUse(use);
}
}
+
+ @override
+ void visitConstantUse(ConstantUse use) {
+ if (_visitConstantUse != null) {
+ _visitConstantUse(use);
+ }
+ }
}

Powered by Google App Engine
This is Rietveld 408576698