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

Unified Diff: pkg/compiler/lib/src/types/constants.dart

Issue 2577423002: Further reduce use of Compiler.closedWorld. (Closed)
Patch Set: Created 4 years 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/ssa/nodes.dart ('k') | pkg/compiler/lib/src/types/masks.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/types/constants.dart
diff --git a/pkg/compiler/lib/src/types/constants.dart b/pkg/compiler/lib/src/types/constants.dart
index 60dbd90f21c019ec2437b31068305111689c9990..6e4407df989740aad94b0ff2737975df3b085c5a 100644
--- a/pkg/compiler/lib/src/types/constants.dart
+++ b/pkg/compiler/lib/src/types/constants.dart
@@ -5,61 +5,70 @@
library types.constants;
import '../common.dart';
+import '../constants/constant_system.dart' show ConstantSystem;
import '../compiler.dart' show Compiler;
import '../constants/values.dart';
-import '../js_backend/js_backend.dart' show SyntheticConstantKind;
+import '../js_backend/js_backend.dart'
+ show JavaScriptBackend, SyntheticConstantKind;
+import '../world.dart' show ClosedWorld;
import 'masks.dart';
/// Computes the [TypeMask] for the constant [value].
-TypeMask computeTypeMask(Compiler compiler, ConstantValue value) {
- return value.accept(const ConstantValueTypeMasks(), compiler);
+// TODO(johnniwinther): Avoid the need for [backend].
+TypeMask computeTypeMask(
+ ClosedWorld closedWorld, JavaScriptBackend backend, ConstantValue value) {
+ return value.accept(new ConstantValueTypeMasks(backend), closedWorld);
}
-class ConstantValueTypeMasks extends ConstantValueVisitor<TypeMask, Compiler> {
- const ConstantValueTypeMasks();
+class ConstantValueTypeMasks
+ extends ConstantValueVisitor<TypeMask, ClosedWorld> {
+ final JavaScriptBackend backend;
+
+ ConstantValueTypeMasks(this.backend);
@override
TypeMask visitConstructed(
- ConstructedConstantValue constant, Compiler compiler) {
- if (compiler.backend.isInterceptorClass(constant.type.element)) {
- return compiler.closedWorld.commonMasks.nonNullType;
+ ConstructedConstantValue constant, ClosedWorld closedWorld) {
+ if (backend.isInterceptorClass(constant.type.element)) {
+ return closedWorld.commonMasks.nonNullType;
}
- return new TypeMask.nonNullExact(
- constant.type.element, compiler.closedWorld);
+ return new TypeMask.nonNullExact(constant.type.element, closedWorld);
}
@override
- TypeMask visitDeferred(DeferredConstantValue constant, Compiler compiler) {
- return constant.referenced.accept(this, compiler);
+ TypeMask visitDeferred(
+ DeferredConstantValue constant, ClosedWorld closedWorld) {
+ return constant.referenced.accept(this, closedWorld);
}
@override
- TypeMask visitDouble(DoubleConstantValue constant, Compiler compiler) {
+ TypeMask visitDouble(DoubleConstantValue constant, ClosedWorld closedWorld) {
// We have to recognize double constants that are 'is int'.
- if (compiler.backend.constantSystem.isInt(constant)) {
+ if (backend.constantSystem.isInt(constant)) {
if (constant.isMinusZero) {
- return compiler.closedWorld.commonMasks.uint31Type;
+ return closedWorld.commonMasks.uint31Type;
} else {
assert(constant.isPositiveInfinity || constant.isNegativeInfinity);
- return compiler.closedWorld.commonMasks.intType;
+ return closedWorld.commonMasks.intType;
}
}
- return compiler.closedWorld.commonMasks.doubleType;
+ return closedWorld.commonMasks.doubleType;
}
@override
- TypeMask visitSynthetic(SyntheticConstantValue constant, Compiler compiler) {
+ TypeMask visitSynthetic(
+ SyntheticConstantValue constant, ClosedWorld closedWorld) {
switch (constant.valueKind) {
case SyntheticConstantKind.DUMMY_INTERCEPTOR:
return constant.payload;
case SyntheticConstantKind.EMPTY_VALUE:
return constant.payload;
case SyntheticConstantKind.TYPEVARIABLE_REFERENCE:
- return compiler.closedWorld.commonMasks.intType;
+ return closedWorld.commonMasks.intType;
case SyntheticConstantKind.NAME:
- return compiler.closedWorld.commonMasks.stringType;
+ return closedWorld.commonMasks.stringType;
default:
- DiagnosticReporter reporter = compiler.reporter;
+ DiagnosticReporter reporter = backend.reporter;
reporter.internalError(
CURRENT_ELEMENT_SPANNABLE, "Unexpected DummyConstantKind.");
return null;
@@ -67,57 +76,58 @@ class ConstantValueTypeMasks extends ConstantValueVisitor<TypeMask, Compiler> {
}
@override
- TypeMask visitBool(BoolConstantValue constant, Compiler compiler) {
- return compiler.closedWorld.commonMasks.boolType;
+ TypeMask visitBool(BoolConstantValue constant, ClosedWorld closedWorld) {
+ return closedWorld.commonMasks.boolType;
}
@override
- TypeMask visitFunction(FunctionConstantValue constant, Compiler compiler) {
- return compiler.closedWorld.commonMasks.functionType;
+ TypeMask visitFunction(
+ FunctionConstantValue constant, ClosedWorld closedWorld) {
+ return closedWorld.commonMasks.functionType;
}
@override
- TypeMask visitInt(IntConstantValue constant, Compiler compiler) {
- if (constant.isUInt31()) return compiler.closedWorld.commonMasks.uint31Type;
- if (constant.isUInt32()) return compiler.closedWorld.commonMasks.uint32Type;
- if (constant.isPositive())
- return compiler.closedWorld.commonMasks.positiveIntType;
- return compiler.closedWorld.commonMasks.intType;
+ TypeMask visitInt(IntConstantValue constant, ClosedWorld closedWorld) {
+ if (constant.isUInt31()) return closedWorld.commonMasks.uint31Type;
+ if (constant.isUInt32()) return closedWorld.commonMasks.uint32Type;
+ if (constant.isPositive()) return closedWorld.commonMasks.positiveIntType;
+ return closedWorld.commonMasks.intType;
}
@override
TypeMask visitInterceptor(
- InterceptorConstantValue constant, Compiler compiler) {
- return compiler.closedWorld.commonMasks.nonNullType;
+ InterceptorConstantValue constant, ClosedWorld closedWorld) {
+ return closedWorld.commonMasks.nonNullType;
}
@override
- TypeMask visitList(ListConstantValue constant, Compiler compiler) {
- return compiler.closedWorld.commonMasks.constListType;
+ TypeMask visitList(ListConstantValue constant, ClosedWorld closedWorld) {
+ return closedWorld.commonMasks.constListType;
}
@override
- TypeMask visitMap(MapConstantValue constant, Compiler compiler) {
- return compiler.closedWorld.commonMasks.constMapType;
+ TypeMask visitMap(MapConstantValue constant, ClosedWorld closedWorld) {
+ return closedWorld.commonMasks.constMapType;
}
@override
- TypeMask visitNull(NullConstantValue constant, Compiler compiler) {
- return compiler.closedWorld.commonMasks.nullType;
+ TypeMask visitNull(NullConstantValue constant, ClosedWorld closedWorld) {
+ return closedWorld.commonMasks.nullType;
}
@override
- TypeMask visitNonConstant(NonConstantValue constant, Compiler compiler) {
- return compiler.closedWorld.commonMasks.nullType;
+ TypeMask visitNonConstant(
+ NonConstantValue constant, ClosedWorld closedWorld) {
+ return closedWorld.commonMasks.nullType;
}
@override
- TypeMask visitString(StringConstantValue constant, Compiler compiler) {
- return compiler.closedWorld.commonMasks.stringType;
+ TypeMask visitString(StringConstantValue constant, ClosedWorld closedWorld) {
+ return closedWorld.commonMasks.stringType;
}
@override
- TypeMask visitType(TypeConstantValue constant, Compiler compiler) {
- return compiler.closedWorld.commonMasks.typeType;
+ TypeMask visitType(TypeConstantValue constant, ClosedWorld closedWorld) {
+ return closedWorld.commonMasks.typeType;
}
}
« no previous file with comments | « pkg/compiler/lib/src/ssa/nodes.dart ('k') | pkg/compiler/lib/src/types/masks.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698