[Kernel] Remove the dedicated fromEnvironment constants
These can be represented as an unevaluated static invocation.
Change-Id: Ib827345f1f65a09f1a856eae33366722a2e613d2
Reviewed-on: https://dart-review.googlesource.com/c/90008
Commit-Queue: Kevin Millikin <kmillikin@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
diff --git a/pkg/dev_compiler/lib/src/kernel/compiler.dart b/pkg/dev_compiler/lib/src/kernel/compiler.dart
index 035611f..cd0af30e 100644
--- a/pkg/dev_compiler/lib/src/kernel/compiler.dart
+++ b/pkg/dev_compiler/lib/src/kernel/compiler.dart
@@ -5120,12 +5120,6 @@
@override
visitPartialInstantiationConstant(node) => defaultConstant(node);
@override
- visitEnvironmentBoolConstant(node) => defaultConstant(node);
- @override
- visitEnvironmentIntConstant(node) => defaultConstant(node);
- @override
- visitEnvironmentStringConstant(node) => defaultConstant(node);
- @override
visitUnevaluatedConstant(node) => defaultConstant(node);
}
diff --git a/pkg/front_end/lib/src/fasta/kernel/kernel_constants.dart b/pkg/front_end/lib/src/fasta/kernel/kernel_constants.dart
index 10d1650..ffc4c2f 100644
--- a/pkg/front_end/lib/src/fasta/kernel/kernel_constants.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/kernel_constants.dart
@@ -6,21 +6,18 @@
import 'package:kernel/ast.dart'
show
+ Arguments,
Constant,
DartType,
- EnvironmentBoolConstant,
- EnvironmentIntConstant,
- EnvironmentStringConstant,
IntConstant,
Library,
ListConstant,
MapConstant,
Member,
- NullConstant,
Procedure,
StaticInvocation,
- StringConstant,
- TreeNode;
+ TreeNode,
+ UnevaluatedConstant;
import 'package:kernel/type_environment.dart' show TypeEnvironment;
@@ -50,8 +47,6 @@
import '../loader.dart' show Loader;
-import '../problems.dart' show unexpected;
-
class KernelConstantErrorReporter extends ErrorReporter {
final Loader<Library> loader;
final TypeEnvironment typeEnvironment;
@@ -218,24 +213,17 @@
if (nativeName == 'Bool_fromEnvironment' ||
nativeName == 'Integer_fromEnvironment' ||
nativeName == 'String_fromEnvironment') {
- if (positionalArguments.length == 1 &&
- positionalArguments.first is StringConstant &&
- (namedArguments.length == 0 ||
- (namedArguments.length == 1 &&
- namedArguments.containsKey('defaultValue')))) {
- StringConstant name = positionalArguments.first;
- Constant defaultValue =
- namedArguments['defaultValue'] ?? new NullConstant();
- if (nativeName == 'Bool_fromEnvironment') {
- return new EnvironmentBoolConstant(name.value, defaultValue);
- }
- if (nativeName == 'Integer_fromEnvironment') {
- return new EnvironmentIntConstant(name.value, defaultValue);
- }
- return new EnvironmentStringConstant(name.value, defaultValue);
+ // Replace the evaluated arguments.
+ Arguments arguments = node.arguments;
+ for (int i = 0; i < arguments.positional.length; ++i) {
+ Constant constant = positionalArguments[i];
+ arguments.positional[i] = constant.asExpression()..parent = arguments;
}
- return unexpected('valid constructor invocation', node.toString(),
- node.fileOffset, node.location.file);
+ for (int i = 0; i < arguments.named.length; ++i) {
+ Constant constant = namedArguments[arguments.named[i].name];
+ arguments.named[i].value = constant.asExpression()..parent = arguments;
+ }
+ return new UnevaluatedConstant(node);
}
return abortEvaluation(
errorReporter.invalidStaticInvocation(context, node, node.target));
diff --git a/pkg/front_end/lib/src/fasta/kernel/type_labeler.dart b/pkg/front_end/lib/src/fasta/kernel/type_labeler.dart
index fe026e6..d24c6fc 100644
--- a/pkg/front_end/lib/src/fasta/kernel/type_labeler.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/type_labeler.dart
@@ -14,9 +14,6 @@
DartType,
DoubleConstant,
DynamicType,
- EnvironmentBoolConstant,
- EnvironmentIntConstant,
- EnvironmentStringConstant,
Field,
FunctionType,
InvalidType,
@@ -314,18 +311,6 @@
node.type.accept(this);
}
- void visitEnvironmentBoolConstant(EnvironmentBoolConstant node) {
- unsupported('printing unevaluated constants', -1, null);
- }
-
- void visitEnvironmentIntConstant(EnvironmentIntConstant node) {
- unsupported('printing unevaluated constants', -1, null);
- }
-
- void visitEnvironmentStringConstant(EnvironmentStringConstant node) {
- unsupported('printing unevaluated constants', -1, null);
- }
-
void visitUnevaluatedConstant(UnevaluatedConstant node) {
unsupported('printing unevaluated constants', -1, null);
}
diff --git a/pkg/kernel/binary.md b/pkg/kernel/binary.md
index 94e1c0f..9456ebe 100644
--- a/pkg/kernel/binary.md
+++ b/pkg/kernel/binary.md
@@ -137,7 +137,7 @@
type ComponentFile {
UInt32 magic = 0x90ABCDEF;
- UInt32 formatVersion = 17;
+ UInt32 formatVersion = 18;
List<String> problemsAsJson; // Described in problems.md.
Library[] libraries;
UriSource sourceMap;
@@ -934,26 +934,8 @@
DartType type;
}
-type EnvironmentBoolConstant extends Constant {
- Byte tag = 12;
- StringReference name;
- ConstantReference defaultValue;
-}
-
-type EnvironmentIntConstant extends Constant {
- Byte tag = 13;
- StringReference name;
- ConstantReference defaultValue;
-}
-
-type EnvironmentStringConstant extends Constant {
- Byte tag = 14;
- StringReference name;
- ConstantReference defaultValue;
-}
-
type UnevaluatedConstant extends Constant {
- Byte tag = 15;
+ Byte tag = 12;
Expression expression;
}
diff --git a/pkg/kernel/lib/ast.dart b/pkg/kernel/lib/ast.dart
index e01258f..6d7102b 100644
--- a/pkg/kernel/lib/ast.dart
+++ b/pkg/kernel/lib/ast.dart
@@ -5110,6 +5110,10 @@
/// Gets the type of this constant.
DartType getType(TypeEnvironment types);
+
+ Expression asExpression() {
+ return new ConstantExpression(this);
+ }
}
abstract class PrimitiveConstant<T> extends Constant {
@@ -5446,56 +5450,12 @@
DartType getType(TypeEnvironment types) => types.typeType;
}
-abstract class EnvironmentConstant extends Constant {
- final String name;
- final Constant defaultValue;
-
- EnvironmentConstant(this.name, this.defaultValue);
- visitChildren(Visitor v) {
- defaultValue.acceptReference(v);
- }
-}
-
-class EnvironmentBoolConstant extends EnvironmentConstant {
- EnvironmentBoolConstant(String name, Constant defaultValue)
- : super(name, defaultValue);
-
- accept(ConstantVisitor v) => v.visitEnvironmentBoolConstant(this);
- acceptReference(Visitor v) {
- return v.visitEnvironmentBoolConstantReference(this);
- }
-
- DartType getType(TypeEnvironment types) => types.boolType;
-}
-
-class EnvironmentIntConstant extends EnvironmentConstant {
- EnvironmentIntConstant(String name, Constant defaultValue)
- : super(name, defaultValue);
-
- accept(ConstantVisitor v) => v.visitEnvironmentIntConstant(this);
- acceptReference(Visitor v) {
- return v.visitEnvironmentIntConstantReference(this);
- }
-
- DartType getType(TypeEnvironment types) => types.intType;
-}
-
-class EnvironmentStringConstant extends EnvironmentConstant {
- EnvironmentStringConstant(String name, Constant defaultValue)
- : super(name, defaultValue);
-
- accept(ConstantVisitor v) => v.visitEnvironmentStringConstant(this);
- acceptReference(Visitor v) {
- return v.visitEnvironmentStringConstantReference(this);
- }
-
- DartType getType(TypeEnvironment types) => types.stringType;
-}
-
class UnevaluatedConstant extends Constant {
final Expression expression;
- UnevaluatedConstant(this.expression);
+ UnevaluatedConstant(this.expression) {
+ expression?.parent = null;
+ }
visitChildren(Visitor v) {
expression.accept(v);
@@ -5505,6 +5465,9 @@
acceptReference(Visitor v) => v.visitUnevaluatedConstantReference(this);
DartType getType(TypeEnvironment types) => expression.getStaticType(types);
+
+ @override
+ Expression asExpression() => expression;
}
// ------------------------------------------------------------------------
diff --git a/pkg/kernel/lib/binary/ast_from_binary.dart b/pkg/kernel/lib/binary/ast_from_binary.dart
index 39e2b50..89e2183 100644
--- a/pkg/kernel/lib/binary/ast_from_binary.dart
+++ b/pkg/kernel/lib/binary/ast_from_binary.dart
@@ -270,18 +270,6 @@
case ConstantTag.TypeLiteralConstant:
final DartType type = readDartType();
return new TypeLiteralConstant(type);
- case ConstantTag.EnvironmentBoolConstant:
- final String name = readStringReference();
- final Constant defaultValue = readConstantReference();
- return new EnvironmentBoolConstant(name, defaultValue);
- case ConstantTag.EnvironmentIntConstant:
- final String name = readStringReference();
- final Constant defaultValue = readConstantReference();
- return new EnvironmentIntConstant(name, defaultValue);
- case ConstantTag.EnvironmentStringConstant:
- final String name = readStringReference();
- final Constant defaultValue = readConstantReference();
- return new EnvironmentStringConstant(name, defaultValue);
case ConstantTag.UnevaluatedConstant:
final Expression expression = readExpression();
return new UnevaluatedConstant(expression);
diff --git a/pkg/kernel/lib/binary/ast_to_binary.dart b/pkg/kernel/lib/binary/ast_to_binary.dart
index 49be362..cea20d1 100644
--- a/pkg/kernel/lib/binary/ast_to_binary.dart
+++ b/pkg/kernel/lib/binary/ast_to_binary.dart
@@ -243,18 +243,6 @@
} else if (constant is TypeLiteralConstant) {
writeByte(ConstantTag.TypeLiteralConstant);
writeDartType(constant.type);
- } else if (constant is EnvironmentBoolConstant) {
- writeByte(ConstantTag.EnvironmentBoolConstant);
- writeStringReference(constant.name);
- writeConstantReference(constant.defaultValue);
- } else if (constant is EnvironmentIntConstant) {
- writeByte(ConstantTag.EnvironmentIntConstant);
- writeStringReference(constant.name);
- writeConstantReference(constant.defaultValue);
- } else if (constant is EnvironmentStringConstant) {
- writeByte(ConstantTag.EnvironmentStringConstant);
- writeStringReference(constant.name);
- writeConstantReference(constant.defaultValue);
} else if (constant is UnevaluatedConstant) {
writeByte(ConstantTag.UnevaluatedConstant);
writeNode(constant.expression);
@@ -2077,39 +2065,6 @@
}
@override
- void visitEnvironmentBoolConstant(EnvironmentBoolConstant node) {
- throw new UnsupportedError('serialization of EnvironmentBoolConstants');
- }
-
- @override
- void visitEnvironmentBoolConstantReference(EnvironmentBoolConstant node) {
- throw new UnsupportedError(
- 'serialization of EnvironmentBoolConstant references');
- }
-
- @override
- void visitEnvironmentIntConstant(EnvironmentIntConstant node) {
- throw new UnsupportedError('serialization of EnvironmentIntConstants');
- }
-
- @override
- void visitEnvironmentIntConstantReference(EnvironmentIntConstant node) {
- throw new UnsupportedError(
- 'serialization of EnvironmentIntConstant references');
- }
-
- @override
- void visitEnvironmentStringConstant(EnvironmentStringConstant node) {
- throw new UnsupportedError('serialization of EnvironmentStringConstants');
- }
-
- @override
- void visitEnvironmentStringConstantReference(EnvironmentStringConstant node) {
- throw new UnsupportedError(
- 'serialization of EnvironmentStringConstant references');
- }
-
- @override
void visitFieldReference(Field node) {
throw new UnsupportedError('serialization of Field references');
}
diff --git a/pkg/kernel/lib/binary/tag.dart b/pkg/kernel/lib/binary/tag.dart
index 6c3db78..280454f 100644
--- a/pkg/kernel/lib/binary/tag.dart
+++ b/pkg/kernel/lib/binary/tag.dart
@@ -137,7 +137,7 @@
/// Internal version of kernel binary format.
/// Bump it when making incompatible changes in kernel binaries.
/// Keep in sync with runtime/vm/kernel_binary.h, pkg/kernel/binary.md.
- static const int BinaryFormatVersion = 17;
+ static const int BinaryFormatVersion = 18;
}
abstract class ConstantTag {
@@ -153,8 +153,5 @@
static const int PartialInstantiationConstant = 9;
static const int TearOffConstant = 10;
static const int TypeLiteralConstant = 11;
- static const int EnvironmentBoolConstant = 12;
- static const int EnvironmentIntConstant = 13;
- static const int EnvironmentStringConstant = 14;
- static const int UnevaluatedConstant = 15;
+ static const int UnevaluatedConstant = 12;
}
diff --git a/pkg/kernel/lib/text/ast_to_text.dart b/pkg/kernel/lib/text/ast_to_text.dart
index eab69e2..33ce1dd 100644
--- a/pkg/kernel/lib/text/ast_to_text.dart
+++ b/pkg/kernel/lib/text/ast_to_text.dart
@@ -1955,24 +1955,6 @@
endLine(sb.toString());
}
- visitEnvironmentBoolConstant(EnvironmentBoolConstant node) {
- final String name = syntheticNames.nameConstant(node);
- final String defaultValue = syntheticNames.nameConstant(node.defaultValue);
- endLine(' $name = bool.fromEnvironment(${node.name}, ${defaultValue})');
- }
-
- visitEnvironmentIntConstant(EnvironmentIntConstant node) {
- final String name = syntheticNames.nameConstant(node);
- final String defaultValue = syntheticNames.nameConstant(node.defaultValue);
- endLine(' $name = int.fromEnvironment(${node.name}, ${defaultValue})');
- }
-
- visitEnvironmentStringConstant(EnvironmentStringConstant node) {
- final String name = syntheticNames.nameConstant(node);
- final String defaultValue = syntheticNames.nameConstant(node.defaultValue);
- endLine(' $name = String.fromEnvironment(${node.name}, ${defaultValue})');
- }
-
visitUnevaluatedConstant(UnevaluatedConstant node) {
final String name = syntheticNames.nameConstant(node);
write(' $name = ');
diff --git a/pkg/kernel/lib/text/text_serialization_verifier.dart b/pkg/kernel/lib/text/text_serialization_verifier.dart
index 644f15a..6d20366 100644
--- a/pkg/kernel/lib/text/text_serialization_verifier.dart
+++ b/pkg/kernel/lib/text/text_serialization_verifier.dart
@@ -302,24 +302,6 @@
}
@override
- void visitEnvironmentBoolConstantReference(EnvironmentBoolConstant node) {
- storeLastSeenUriAndOffset(node);
- node.visitChildren(this);
- }
-
- @override
- void visitEnvironmentIntConstantReference(EnvironmentIntConstant node) {
- storeLastSeenUriAndOffset(node);
- node.visitChildren(this);
- }
-
- @override
- void visitEnvironmentStringConstantReference(EnvironmentStringConstant node) {
- storeLastSeenUriAndOffset(node);
- node.visitChildren(this);
- }
-
- @override
void visitUnevaluatedConstantReference(UnevaluatedConstant node) {
storeLastSeenUriAndOffset(node);
node.visitChildren(this);
@@ -404,24 +386,6 @@
}
@override
- void visitEnvironmentBoolConstant(EnvironmentBoolConstant node) {
- storeLastSeenUriAndOffset(node);
- node.visitChildren(this);
- }
-
- @override
- void visitEnvironmentIntConstant(EnvironmentIntConstant node) {
- storeLastSeenUriAndOffset(node);
- node.visitChildren(this);
- }
-
- @override
- void visitEnvironmentStringConstant(EnvironmentStringConstant node) {
- storeLastSeenUriAndOffset(node);
- node.visitChildren(this);
- }
-
- @override
void visitUnevaluatedConstant(UnevaluatedConstant node) {
storeLastSeenUriAndOffset(node);
node.visitChildren(this);
diff --git a/pkg/kernel/lib/visitor.dart b/pkg/kernel/lib/visitor.dart
index 79a3be8..a83374b 100644
--- a/pkg/kernel/lib/visitor.dart
+++ b/pkg/kernel/lib/visitor.dart
@@ -295,12 +295,6 @@
defaultConstant(node);
R visitTearOffConstant(TearOffConstant node) => defaultConstant(node);
R visitTypeLiteralConstant(TypeLiteralConstant node) => defaultConstant(node);
- R visitEnvironmentBoolConstant(EnvironmentBoolConstant node) =>
- defaultConstant(node);
- R visitEnvironmentIntConstant(EnvironmentIntConstant node) =>
- defaultConstant(node);
- R visitEnvironmentStringConstant(EnvironmentStringConstant node) =>
- defaultConstant(node);
R visitUnevaluatedConstant(UnevaluatedConstant node) => defaultConstant(node);
}
@@ -355,12 +349,6 @@
defaultConstant(node);
R visitTearOffConstant(TearOffConstant node) => defaultConstant(node);
R visitTypeLiteralConstant(TypeLiteralConstant node) => defaultConstant(node);
- R visitEnvironmentBoolConstant(EnvironmentBoolConstant node) =>
- defaultConstant(node);
- R visitEnvironmentIntConstant(EnvironmentIntConstant node) =>
- defaultConstant(node);
- R visitEnvironmentStringConstant(EnvironmentStringConstant node) =>
- defaultConstant(node);
R visitUnevaluatedConstant(UnevaluatedConstant node) => defaultConstant(node);
// Class references
@@ -394,12 +382,6 @@
defaultConstantReference(node);
R visitTypeLiteralConstantReference(TypeLiteralConstant node) =>
defaultConstantReference(node);
- R visitEnvironmentBoolConstantReference(EnvironmentBoolConstant node) =>
- defaultConstantReference(node);
- R visitEnvironmentIntConstantReference(EnvironmentIntConstant node) =>
- defaultConstantReference(node);
- R visitEnvironmentStringConstantReference(EnvironmentStringConstant node) =>
- defaultConstantReference(node);
R visitUnevaluatedConstantReference(UnevaluatedConstant node) =>
defaultConstantReference(node);
diff --git a/runtime/vm/compiler/frontend/constant_evaluator.cc b/runtime/vm/compiler/frontend/constant_evaluator.cc
index 3ac3ecc..9c9b8ec 100644
--- a/runtime/vm/compiler/frontend/constant_evaluator.cc
+++ b/runtime/vm/compiler/frontend/constant_evaluator.cc
@@ -1293,9 +1293,6 @@
// Note: This is already lowered to InstanceConstant/ListConstant.
UNREACHABLE();
break;
- case kEnvironmentBoolConstant:
- case kEnvironmentIntConstant:
- case kEnvironmentStringConstant:
case kUnevaluatedConstant:
// We should not see unevaluated constants in the constant table, they
// should have been fully evaluated before we get them.
diff --git a/runtime/vm/kernel_binary.h b/runtime/vm/kernel_binary.h
index 2e50142..8473fec 100644
--- a/runtime/vm/kernel_binary.h
+++ b/runtime/vm/kernel_binary.h
@@ -17,7 +17,7 @@
// package:kernel/binary.md.
static const uint32_t kMagicProgramFile = 0x90ABCDEFu;
-static const uint32_t kBinaryFormatVersion = 17;
+static const uint32_t kBinaryFormatVersion = 18;
// Keep in sync with package:kernel/lib/binary/tag.dart
#define KERNEL_TAG_LIST(V) \
@@ -149,10 +149,7 @@
kTypeLiteralConstant = 11,
// These constants are not expected to be seen by the VM, because all
// constants are fully evaluated.
- kEnvironmentBoolConstant = 12,
- kEnvironmentIntConstant = 13,
- kEnvironmentStringConstant = 14,
- kUnevaluatedConstant = 15,
+ kUnevaluatedConstant = 12,
};
static const int SpecializedIntLiteralBias = 3;