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

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

Issue 2349163003: Move towards using WorldImpact for codegen (Closed)
Patch Set: Reinsert missing features uses. Created 4 years, 3 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
« no previous file with comments | « pkg/compiler/lib/src/types/masks.dart ('k') | pkg/compiler/lib/src/world.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 99c1c3c129c339086edae64724c094a5e55c4095..723a87af8bddcdc817f0589bd60adc1db38f080e 100644
--- a/pkg/compiler/lib/src/universe/world_impact.dart
+++ b/pkg/compiler/lib/src/universe/world_impact.dart
@@ -61,12 +61,18 @@ class WorldImpact {
}
}
-class WorldImpactBuilder {
+abstract class WorldImpactBuilder {
+ void registerDynamicUse(DynamicUse dynamicUse);
+ void registerTypeUse(TypeUse typeUse);
+ void registerStaticUse(StaticUse staticUse);
+}
+
+class WorldImpactBuilderImpl extends WorldImpact implements WorldImpactBuilder {
// TODO(johnniwinther): Do we benefit from lazy initialization of the
// [Setlet]s?
- Setlet<DynamicUse> _dynamicUses;
- Setlet<StaticUse> _staticUses;
- Setlet<TypeUse> _typeUses;
+ Set<DynamicUse> _dynamicUses;
+ Set<StaticUse> _staticUses;
+ Set<TypeUse> _typeUses;
void registerDynamicUse(DynamicUse dynamicUse) {
assert(dynamicUse != null);
@@ -105,9 +111,60 @@ class WorldImpactBuilder {
}
}
+/// [WorldImpactBuilder] that can create and collect a sequence of
+/// [WorldImpact]s.
+class StagedWorldImpactBuilder implements WorldImpactBuilder {
+ final bool collectImpacts;
+ WorldImpactBuilderImpl _currentBuilder;
+ List<WorldImpactBuilderImpl> _builders = <WorldImpactBuilderImpl>[];
+
+ StagedWorldImpactBuilder({this.collectImpacts: false});
+
+ void _ensureBuilder() {
+ if (_currentBuilder == null) {
+ _currentBuilder = new WorldImpactBuilderImpl();
+ if (collectImpacts) {
+ _builders.add(_currentBuilder);
+ }
+ }
+ }
+
+ @override
+ void registerTypeUse(TypeUse typeUse) {
+ _ensureBuilder();
+ _currentBuilder.registerTypeUse(typeUse);
+ }
+
+ @override
+ void registerDynamicUse(DynamicUse dynamicUse) {
+ _ensureBuilder();
+ _currentBuilder.registerDynamicUse(dynamicUse);
+ }
+
+ @override
+ void registerStaticUse(StaticUse staticUse) {
+ _ensureBuilder();
+ _currentBuilder.registerStaticUse(staticUse);
+ }
+
+ /// Returns the [WorldImpact] built so far with this builder. The builder
+ /// is reset, and if [collectImpacts] is `true` the impact is cached for
+ /// [worldImpacts].
+ WorldImpact flush() {
+ if (_currentBuilder == null) return const WorldImpact();
+ WorldImpact worldImpact = _currentBuilder;
+ _currentBuilder = null;
+ return worldImpact;
+ }
+
+ /// If [collectImpacts] is `true` this returns all [WorldImpact]s built with
+ /// this builder.
+ Iterable<WorldImpact> get worldImpacts => _builders;
+}
+
/// Mutable implementation of [WorldImpact] used to transform
/// [ResolutionImpact] or [CodegenImpact] to [WorldImpact].
-class TransformedWorldImpact implements WorldImpact {
+class TransformedWorldImpact implements WorldImpact, WorldImpactBuilder {
final WorldImpact worldImpact;
Setlet<StaticUse> _staticUses;
« no previous file with comments | « pkg/compiler/lib/src/types/masks.dart ('k') | pkg/compiler/lib/src/world.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698