mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 00:58:29 +00:00
Revert "[kernel] Introduce assert initializers."
Reverting due to several test failures.
This reverts commit 67adfe741b
.
Bug:
Change-Id: Idd1aa15d47df68f2938285468dfa3d5043d8dae2
Reviewed-on: https://dart-review.googlesource.com/25520
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
ede2367ef6
commit
48a927acb2
|
@ -354,12 +354,22 @@ class _ExprBuilder {
|
|||
return initializer;
|
||||
}
|
||||
|
||||
if (k is kernel.AssertInitializer) {
|
||||
var body = k.statement;
|
||||
if (k is kernel.LocalInitializer) {
|
||||
var invocation = k.variable.initializer;
|
||||
if (invocation is kernel.MethodInvocation) {
|
||||
var receiver = invocation.receiver;
|
||||
if (receiver is kernel.FunctionExpression &&
|
||||
invocation.name.name == 'call') {
|
||||
var body = receiver.function.body;
|
||||
if (body is kernel.AssertStatement) {
|
||||
var condition = build(body.condition);
|
||||
var message = body.message != null ? build(body.message) : null;
|
||||
return AstTestFactory.assertInitializer(condition, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new StateError('Expected assert initializer $k');
|
||||
}
|
||||
|
||||
if (k is kernel.RedirectingInitializer) {
|
||||
ConstructorElementImpl redirect = _getElement(k.targetReference);
|
||||
|
|
|
@ -2941,11 +2941,33 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
|
|||
break;
|
||||
|
||||
case Assert.Initializer:
|
||||
push(new ShadowAssertInitializer(statement));
|
||||
push(buildAssertInitializer(statement));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Initializer buildAssertInitializer(AssertStatement statement) {
|
||||
// Since kernel only has asserts in statment form, we convert it to an
|
||||
// expression by wrapping it in an anonymous function which we call
|
||||
// immediately.
|
||||
//
|
||||
// Additionally, kernel has no initializer that evaluates an expression,
|
||||
// but it does have `LocalInitializer` which requires a variable declartion.
|
||||
//
|
||||
// So we produce an initializer like this:
|
||||
//
|
||||
// var #t0 = (() { statement; }) ()
|
||||
return new ShadowAssertInitializer(
|
||||
new VariableDeclaration.forValue(buildMethodInvocation(
|
||||
new FunctionExpression(new FunctionNode(statement)),
|
||||
callName,
|
||||
new Arguments.empty(),
|
||||
statement.fileOffset,
|
||||
isConstantExpression: true,
|
||||
isImplicitCall: true)),
|
||||
statement);
|
||||
}
|
||||
|
||||
@override
|
||||
void endYieldStatement(Token yieldToken, Token starToken, Token endToken) {
|
||||
debugEvent("YieldStatement");
|
||||
|
|
|
@ -119,14 +119,18 @@ class ShadowAsExpression extends AsExpression implements ShadowExpression {
|
|||
}
|
||||
|
||||
/// Concrete shadow object representing an assert initializer in kernel form.
|
||||
class ShadowAssertInitializer extends AssertInitializer
|
||||
class ShadowAssertInitializer extends LocalInitializer
|
||||
implements ShadowInitializer {
|
||||
ShadowAssertInitializer(AssertStatement statement) : super(statement);
|
||||
/// The assert statement performing the check
|
||||
AssertStatement _statement;
|
||||
|
||||
ShadowAssertInitializer(VariableDeclaration variable, this._statement)
|
||||
: super(variable);
|
||||
|
||||
@override
|
||||
void _inferInitializer(ShadowTypeInferrer inferrer) {
|
||||
inferrer.listener.assertInitializerEnter(this);
|
||||
inferrer.inferStatement(statement);
|
||||
inferrer.inferStatement(_statement);
|
||||
inferrer.listener.assertInitializerExit(this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,10 +107,10 @@ class TypeInferenceListener
|
|||
void asExpressionExit(AsExpression expression, DartType inferredType) =>
|
||||
genericExpressionExit("asExpression", expression, inferredType);
|
||||
|
||||
void assertInitializerEnter(AssertInitializer initializer) =>
|
||||
void assertInitializerEnter(LocalInitializer initializer) =>
|
||||
genericInitializerEnter("assertInitializer", initializer);
|
||||
|
||||
void assertInitializerExit(AssertInitializer initializer) =>
|
||||
void assertInitializerExit(LocalInitializer initializer) =>
|
||||
genericInitializerExit("assertInitializer", initializer);
|
||||
|
||||
void assertStatementEnter(AssertStatement statement) =>
|
||||
|
|
|
@ -4,10 +4,14 @@ import "dart:core" as core;
|
|||
|
||||
class C extends core::Object {
|
||||
constructor expressionOnly() → void
|
||||
: assert(self::f<dynamic>()), super core::Object::•()
|
||||
: final dynamic #t1 = (() → dynamic
|
||||
assert(self::f<dynamic>());
|
||||
).call(), super core::Object::•()
|
||||
;
|
||||
constructor expressionAndMessage() → void
|
||||
: assert(self::f<dynamic>(), self::f<dynamic>()), super core::Object::•()
|
||||
: final dynamic #t2 = (() → dynamic
|
||||
assert(self::f<dynamic>(), self::f<dynamic>());
|
||||
).call(), super core::Object::•()
|
||||
;
|
||||
}
|
||||
static method f<T extends core::Object>() → self::f::T
|
||||
|
|
|
@ -4,10 +4,14 @@ import "dart:core" as core;
|
|||
|
||||
class C extends core::Object {
|
||||
constructor expressionOnly() → void
|
||||
: assert(self::f<core::bool>()), super core::Object::•()
|
||||
: final dynamic #t1 = (() → dynamic
|
||||
assert(self::f<core::bool>());
|
||||
).call(), super core::Object::•()
|
||||
;
|
||||
constructor expressionAndMessage() → void
|
||||
: assert(self::f<core::bool>(), self::f<dynamic>()), super core::Object::•()
|
||||
: final dynamic #t2 = (() → dynamic
|
||||
assert(self::f<core::bool>(), self::f<dynamic>());
|
||||
).call(), super core::Object::•()
|
||||
;
|
||||
}
|
||||
static method f<T extends core::Object>() → self::f::T
|
||||
|
|
|
@ -4,7 +4,9 @@ import "dart:core" as core;
|
|||
|
||||
class C extends core::Object {
|
||||
constructor •(core::Object o) → void
|
||||
: assert(o), super core::Object::•()
|
||||
: final dynamic #t1 = (() → dynamic
|
||||
assert(o);
|
||||
).call(), super core::Object::•()
|
||||
;
|
||||
}
|
||||
static method main() → dynamic {
|
||||
|
|
|
@ -4,7 +4,9 @@ import "dart:core" as core;
|
|||
|
||||
class C extends core::Object {
|
||||
constructor •(core::Object o) → void
|
||||
: assert(o as{TypeError} core::bool), super core::Object::•()
|
||||
: final dynamic #t1 = (() → dynamic
|
||||
assert(o as{TypeError} core::bool);
|
||||
).call(), super core::Object::•()
|
||||
;
|
||||
}
|
||||
static method main() → dynamic {
|
||||
|
|
|
@ -408,12 +408,6 @@ type LocalInitializer extends Initializer {
|
|||
VariableDeclaration variable;
|
||||
}
|
||||
|
||||
type AssertInitializer extends Initializer {
|
||||
Byte tag = 12;
|
||||
Byte isSynthetic;
|
||||
AssertStatement statement;
|
||||
}
|
||||
|
||||
/*
|
||||
enum AsyncMarker {
|
||||
Sync,
|
||||
|
|
|
@ -1759,25 +1759,6 @@ class LocalInitializer extends Initializer {
|
|||
}
|
||||
}
|
||||
|
||||
class AssertInitializer extends Initializer {
|
||||
AssertStatement statement;
|
||||
|
||||
AssertInitializer(this.statement) {
|
||||
statement.parent = this;
|
||||
}
|
||||
|
||||
accept(InitializerVisitor v) => v.visitAssertInitializer(this);
|
||||
|
||||
visitChildren(Visitor v) {
|
||||
statement.accept(v);
|
||||
}
|
||||
|
||||
transformChildren(Transformer v) {
|
||||
statement = statement.accept(v);
|
||||
statement.parent = this;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// FUNCTIONS
|
||||
// ------------------------------------------------------------------------
|
||||
|
|
|
@ -1010,8 +1010,6 @@ class BinaryBuilder {
|
|||
readMemberReference(), readArguments());
|
||||
case Tag.LocalInitializer:
|
||||
return new LocalInitializer(readAndPushVariableDeclaration());
|
||||
case Tag.AssertInitializer:
|
||||
return new AssertInitializer(readStatement());
|
||||
default:
|
||||
throw fail('Invalid initializer tag: $tag');
|
||||
}
|
||||
|
|
|
@ -833,12 +833,6 @@ class BinaryPrinter extends Visitor implements BinarySink {
|
|||
writeVariableDeclaration(node.variable);
|
||||
}
|
||||
|
||||
visitAssertInitializer(AssertInitializer node) {
|
||||
writeByte(Tag.AssertInitializer);
|
||||
writeByte(node.isSynthetic ? 1 : 0);
|
||||
writeNode(node.statement);
|
||||
}
|
||||
|
||||
visitFunctionNode(FunctionNode node) {
|
||||
writeByte(Tag.FunctionNode);
|
||||
assert(_variableIndexer != null);
|
||||
|
|
|
@ -21,7 +21,6 @@ class Tag {
|
|||
static const int SuperInitializer = 9;
|
||||
static const int RedirectingInitializer = 10;
|
||||
static const int LocalInitializer = 11;
|
||||
static const int AssertInitializer = 12;
|
||||
|
||||
static const int CheckLibraryIsLoaded = 13;
|
||||
static const int LoadLibrary = 14;
|
||||
|
|
|
@ -1425,10 +1425,8 @@ class Printer extends Visitor<Null> {
|
|||
endLine(';');
|
||||
}
|
||||
|
||||
visitAssertStatement(AssertStatement node, {bool asExpr = false}) {
|
||||
if (asExpr != true) {
|
||||
visitAssertStatement(AssertStatement node) {
|
||||
writeIndentation();
|
||||
}
|
||||
writeWord('assert');
|
||||
writeSymbol('(');
|
||||
writeExpression(node.condition);
|
||||
|
@ -1436,11 +1434,7 @@ class Printer extends Visitor<Null> {
|
|||
writeComma();
|
||||
writeExpression(node.message);
|
||||
}
|
||||
if (asExpr != true) {
|
||||
endLine(');');
|
||||
} else {
|
||||
writeSymbol(')');
|
||||
}
|
||||
}
|
||||
|
||||
visitLabeledStatement(LabeledStatement node) {
|
||||
|
@ -1712,10 +1706,6 @@ class Printer extends Visitor<Null> {
|
|||
writeVariableDeclaration(node.variable);
|
||||
}
|
||||
|
||||
visitAssertInitializer(AssertInitializer node) {
|
||||
visitAssertStatement(node.statement, asExpr: true);
|
||||
}
|
||||
|
||||
defaultInitializer(Initializer node) {
|
||||
writeIndentation();
|
||||
endLine(': ${node.runtimeType}');
|
||||
|
|
|
@ -998,11 +998,6 @@ class TypeCheckingVisitor
|
|||
visitVariableDeclaration(node.variable);
|
||||
}
|
||||
|
||||
@override
|
||||
visitAssertInitializer(AssertInitializer node) {
|
||||
visitAssertStatement(node.statement);
|
||||
}
|
||||
|
||||
@override
|
||||
visitInvalidInitializer(InvalidInitializer node) {}
|
||||
|
||||
|
|
|
@ -120,7 +120,6 @@ abstract class InitializerVisitor<R> {
|
|||
R visitRedirectingInitializer(RedirectingInitializer node) =>
|
||||
defaultInitializer(node);
|
||||
R visitLocalInitializer(LocalInitializer node) => defaultInitializer(node);
|
||||
R visitAssertInitializer(AssertInitializer node) => defaultInitializer(node);
|
||||
}
|
||||
|
||||
class TreeVisitor<R>
|
||||
|
@ -236,7 +235,6 @@ class TreeVisitor<R>
|
|||
R visitRedirectingInitializer(RedirectingInitializer node) =>
|
||||
defaultInitializer(node);
|
||||
R visitLocalInitializer(LocalInitializer node) => defaultInitializer(node);
|
||||
R visitAssertInitializer(AssertInitializer node) => defaultInitializer(node);
|
||||
|
||||
// Other tree nodes
|
||||
R visitLibrary(Library node) => defaultTreeNode(node);
|
||||
|
|
|
@ -1126,9 +1126,6 @@ void StreamingScopeBuilder::VisitInitializer() {
|
|||
case kLocalInitializer:
|
||||
VisitVariableDeclaration(); // read variable.
|
||||
return;
|
||||
case kAssertInitializer:
|
||||
VisitStatement();
|
||||
return;
|
||||
default:
|
||||
H.ReportError("Unsupported tag at this point: %d.", tag);
|
||||
UNREACHABLE();
|
||||
|
@ -3726,10 +3723,6 @@ Fragment StreamingFlowGraphBuilder::BuildInitializers(
|
|||
instructions += BuildFieldInitializer(canonical_name); // read value.
|
||||
break;
|
||||
}
|
||||
case kAssertInitializer: {
|
||||
instructions += BuildStatement();
|
||||
break;
|
||||
}
|
||||
case kSuperInitializer: {
|
||||
NameIndex canonical_target =
|
||||
ReadCanonicalNameReference(); // read target_reference.
|
||||
|
@ -4783,9 +4776,6 @@ void StreamingFlowGraphBuilder::SkipInitializer() {
|
|||
case kLocalInitializer:
|
||||
SkipVariableDeclaration(); // read variable.
|
||||
return;
|
||||
case kAssertInitializer:
|
||||
SkipStatement();
|
||||
return;
|
||||
default:
|
||||
H.ReportError("Unsupported tag at this point: %d.", tag);
|
||||
UNREACHABLE();
|
||||
|
|
|
@ -38,7 +38,6 @@ enum Tag {
|
|||
kSuperInitializer = 9,
|
||||
kRedirectingInitializer = 10,
|
||||
kLocalInitializer = 11,
|
||||
kAssertInitializer = 12,
|
||||
|
||||
kDirectPropertyGet = 15,
|
||||
kDirectPropertySet = 16,
|
||||
|
|
Loading…
Reference in a new issue