Skip to content

Commit 48a927a

Browse files
Revert "[kernel] Introduce assert initializers."
Reverting due to several test failures. This reverts commit 67adfe7. Bug: Change-Id: Idd1aa15d47df68f2938285468dfa3d5043d8dae2 Reviewed-on: https://dart-review.googlesource.com/25520 Reviewed-by: Brian Wilkerson <[email protected]>
1 parent ede2367 commit 48a927a

18 files changed

+68
-82
lines changed

pkg/analyzer/lib/src/kernel/resynthesize.dart

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -354,11 +354,21 @@ class _ExprBuilder {
354354
return initializer;
355355
}
356356

357-
if (k is kernel.AssertInitializer) {
358-
var body = k.statement;
359-
var condition = build(body.condition);
360-
var message = body.message != null ? build(body.message) : null;
361-
return AstTestFactory.assertInitializer(condition, message);
357+
if (k is kernel.LocalInitializer) {
358+
var invocation = k.variable.initializer;
359+
if (invocation is kernel.MethodInvocation) {
360+
var receiver = invocation.receiver;
361+
if (receiver is kernel.FunctionExpression &&
362+
invocation.name.name == 'call') {
363+
var body = receiver.function.body;
364+
if (body is kernel.AssertStatement) {
365+
var condition = build(body.condition);
366+
var message = body.message != null ? build(body.message) : null;
367+
return AstTestFactory.assertInitializer(condition, message);
368+
}
369+
}
370+
}
371+
throw new StateError('Expected assert initializer $k');
362372
}
363373

364374
if (k is kernel.RedirectingInitializer) {

pkg/front_end/lib/src/fasta/kernel/body_builder.dart

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2941,11 +2941,33 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
29412941
break;
29422942

29432943
case Assert.Initializer:
2944-
push(new ShadowAssertInitializer(statement));
2944+
push(buildAssertInitializer(statement));
29452945
break;
29462946
}
29472947
}
29482948

2949+
Initializer buildAssertInitializer(AssertStatement statement) {
2950+
// Since kernel only has asserts in statment form, we convert it to an
2951+
// expression by wrapping it in an anonymous function which we call
2952+
// immediately.
2953+
//
2954+
// Additionally, kernel has no initializer that evaluates an expression,
2955+
// but it does have `LocalInitializer` which requires a variable declartion.
2956+
//
2957+
// So we produce an initializer like this:
2958+
//
2959+
// var #t0 = (() { statement; }) ()
2960+
return new ShadowAssertInitializer(
2961+
new VariableDeclaration.forValue(buildMethodInvocation(
2962+
new FunctionExpression(new FunctionNode(statement)),
2963+
callName,
2964+
new Arguments.empty(),
2965+
statement.fileOffset,
2966+
isConstantExpression: true,
2967+
isImplicitCall: true)),
2968+
statement);
2969+
}
2970+
29492971
@override
29502972
void endYieldStatement(Token yieldToken, Token starToken, Token endToken) {
29512973
debugEvent("YieldStatement");

pkg/front_end/lib/src/fasta/kernel/kernel_shadow_ast.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,18 @@ class ShadowAsExpression extends AsExpression implements ShadowExpression {
119119
}
120120

121121
/// Concrete shadow object representing an assert initializer in kernel form.
122-
class ShadowAssertInitializer extends AssertInitializer
122+
class ShadowAssertInitializer extends LocalInitializer
123123
implements ShadowInitializer {
124-
ShadowAssertInitializer(AssertStatement statement) : super(statement);
124+
/// The assert statement performing the check
125+
AssertStatement _statement;
126+
127+
ShadowAssertInitializer(VariableDeclaration variable, this._statement)
128+
: super(variable);
125129

126130
@override
127131
void _inferInitializer(ShadowTypeInferrer inferrer) {
128132
inferrer.listener.assertInitializerEnter(this);
129-
inferrer.inferStatement(statement);
133+
inferrer.inferStatement(_statement);
130134
inferrer.listener.assertInitializerExit(this);
131135
}
132136
}

pkg/front_end/lib/src/fasta/type_inference/type_inference_listener.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ class TypeInferenceListener
107107
void asExpressionExit(AsExpression expression, DartType inferredType) =>
108108
genericExpressionExit("asExpression", expression, inferredType);
109109

110-
void assertInitializerEnter(AssertInitializer initializer) =>
110+
void assertInitializerEnter(LocalInitializer initializer) =>
111111
genericInitializerEnter("assertInitializer", initializer);
112112

113-
void assertInitializerExit(AssertInitializer initializer) =>
113+
void assertInitializerExit(LocalInitializer initializer) =>
114114
genericInitializerExit("assertInitializer", initializer);
115115

116116
void assertStatementEnter(AssertStatement statement) =>

pkg/front_end/testcases/inference/assert_initializer.dart.direct.expect

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ import "dart:core" as core;
44

55
class C extends core::Object {
66
constructor expressionOnly() → void
7-
: assert(self::f<dynamic>()), super core::Object::•()
7+
: final dynamic #t1 = (() → dynamic
8+
assert(self::f<dynamic>());
9+
).call(), super core::Object::•()
810
;
911
constructor expressionAndMessage() → void
10-
: assert(self::f<dynamic>(), self::f<dynamic>()), super core::Object::•()
12+
: final dynamic #t2 = (() → dynamic
13+
assert(self::f<dynamic>(), self::f<dynamic>());
14+
).call(), super core::Object::•()
1115
;
1216
}
1317
static method f<T extends core::Object>() → self::f::T

pkg/front_end/testcases/inference/assert_initializer.dart.strong.expect

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ import "dart:core" as core;
44

55
class C extends core::Object {
66
constructor expressionOnly() → void
7-
: assert(self::f<core::bool>()), super core::Object::•()
7+
: final dynamic #t1 = (() → dynamic
8+
assert(self::f<core::bool>());
9+
).call(), super core::Object::•()
810
;
911
constructor expressionAndMessage() → void
10-
: assert(self::f<core::bool>(), self::f<dynamic>()), super core::Object::•()
12+
: final dynamic #t2 = (() → dynamic
13+
assert(self::f<core::bool>(), self::f<dynamic>());
14+
).call(), super core::Object::•()
1115
;
1216
}
1317
static method f<T extends core::Object>() → self::f::T

pkg/front_end/testcases/runtime_checks/implicit_downcast_assert_initializer.dart.direct.expect

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import "dart:core" as core;
44

55
class C extends core::Object {
66
constructor •(core::Object o) → void
7-
: assert(o), super core::Object::•()
7+
: final dynamic #t1 = (() → dynamic
8+
assert(o);
9+
).call(), super core::Object::•()
810
;
911
}
1012
static method main() → dynamic {

pkg/front_end/testcases/runtime_checks/implicit_downcast_assert_initializer.dart.strong.expect

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import "dart:core" as core;
44

55
class C extends core::Object {
66
constructor •(core::Object o) → void
7-
: assert(o as{TypeError} core::bool), super core::Object::•()
7+
: final dynamic #t1 = (() → dynamic
8+
assert(o as{TypeError} core::bool);
9+
).call(), super core::Object::•()
810
;
911
}
1012
static method main() → dynamic {

pkg/kernel/binary.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -408,12 +408,6 @@ type LocalInitializer extends Initializer {
408408
VariableDeclaration variable;
409409
}
410410

411-
type AssertInitializer extends Initializer {
412-
Byte tag = 12;
413-
Byte isSynthetic;
414-
AssertStatement statement;
415-
}
416-
417411
/*
418412
enum AsyncMarker {
419413
Sync,

pkg/kernel/lib/ast.dart

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,25 +1759,6 @@ class LocalInitializer extends Initializer {
17591759
}
17601760
}
17611761

1762-
class AssertInitializer extends Initializer {
1763-
AssertStatement statement;
1764-
1765-
AssertInitializer(this.statement) {
1766-
statement.parent = this;
1767-
}
1768-
1769-
accept(InitializerVisitor v) => v.visitAssertInitializer(this);
1770-
1771-
visitChildren(Visitor v) {
1772-
statement.accept(v);
1773-
}
1774-
1775-
transformChildren(Transformer v) {
1776-
statement = statement.accept(v);
1777-
statement.parent = this;
1778-
}
1779-
}
1780-
17811762
// ------------------------------------------------------------------------
17821763
// FUNCTIONS
17831764
// ------------------------------------------------------------------------

pkg/kernel/lib/binary/ast_from_binary.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,8 +1010,6 @@ class BinaryBuilder {
10101010
readMemberReference(), readArguments());
10111011
case Tag.LocalInitializer:
10121012
return new LocalInitializer(readAndPushVariableDeclaration());
1013-
case Tag.AssertInitializer:
1014-
return new AssertInitializer(readStatement());
10151013
default:
10161014
throw fail('Invalid initializer tag: $tag');
10171015
}

pkg/kernel/lib/binary/ast_to_binary.dart

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -833,12 +833,6 @@ class BinaryPrinter extends Visitor implements BinarySink {
833833
writeVariableDeclaration(node.variable);
834834
}
835835

836-
visitAssertInitializer(AssertInitializer node) {
837-
writeByte(Tag.AssertInitializer);
838-
writeByte(node.isSynthetic ? 1 : 0);
839-
writeNode(node.statement);
840-
}
841-
842836
visitFunctionNode(FunctionNode node) {
843837
writeByte(Tag.FunctionNode);
844838
assert(_variableIndexer != null);

pkg/kernel/lib/binary/tag.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class Tag {
2121
static const int SuperInitializer = 9;
2222
static const int RedirectingInitializer = 10;
2323
static const int LocalInitializer = 11;
24-
static const int AssertInitializer = 12;
2524

2625
static const int CheckLibraryIsLoaded = 13;
2726
static const int LoadLibrary = 14;

pkg/kernel/lib/text/ast_to_text.dart

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,22 +1425,16 @@ class Printer extends Visitor<Null> {
14251425
endLine(';');
14261426
}
14271427

1428-
visitAssertStatement(AssertStatement node, {bool asExpr = false}) {
1429-
if (asExpr != true) {
1430-
writeIndentation();
1431-
}
1428+
visitAssertStatement(AssertStatement node) {
1429+
writeIndentation();
14321430
writeWord('assert');
14331431
writeSymbol('(');
14341432
writeExpression(node.condition);
14351433
if (node.message != null) {
14361434
writeComma();
14371435
writeExpression(node.message);
14381436
}
1439-
if (asExpr != true) {
1440-
endLine(');');
1441-
} else {
1442-
writeSymbol(')');
1443-
}
1437+
endLine(');');
14441438
}
14451439

14461440
visitLabeledStatement(LabeledStatement node) {
@@ -1712,10 +1706,6 @@ class Printer extends Visitor<Null> {
17121706
writeVariableDeclaration(node.variable);
17131707
}
17141708

1715-
visitAssertInitializer(AssertInitializer node) {
1716-
visitAssertStatement(node.statement, asExpr: true);
1717-
}
1718-
17191709
defaultInitializer(Initializer node) {
17201710
writeIndentation();
17211711
endLine(': ${node.runtimeType}');

pkg/kernel/lib/type_checker.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -998,11 +998,6 @@ class TypeCheckingVisitor
998998
visitVariableDeclaration(node.variable);
999999
}
10001000

1001-
@override
1002-
visitAssertInitializer(AssertInitializer node) {
1003-
visitAssertStatement(node.statement);
1004-
}
1005-
10061001
@override
10071002
visitInvalidInitializer(InvalidInitializer node) {}
10081003

pkg/kernel/lib/visitor.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ abstract class InitializerVisitor<R> {
120120
R visitRedirectingInitializer(RedirectingInitializer node) =>
121121
defaultInitializer(node);
122122
R visitLocalInitializer(LocalInitializer node) => defaultInitializer(node);
123-
R visitAssertInitializer(AssertInitializer node) => defaultInitializer(node);
124123
}
125124

126125
class TreeVisitor<R>
@@ -236,7 +235,6 @@ class TreeVisitor<R>
236235
R visitRedirectingInitializer(RedirectingInitializer node) =>
237236
defaultInitializer(node);
238237
R visitLocalInitializer(LocalInitializer node) => defaultInitializer(node);
239-
R visitAssertInitializer(AssertInitializer node) => defaultInitializer(node);
240238

241239
// Other tree nodes
242240
R visitLibrary(Library node) => defaultTreeNode(node);

runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,9 +1126,6 @@ void StreamingScopeBuilder::VisitInitializer() {
11261126
case kLocalInitializer:
11271127
VisitVariableDeclaration(); // read variable.
11281128
return;
1129-
case kAssertInitializer:
1130-
VisitStatement();
1131-
return;
11321129
default:
11331130
H.ReportError("Unsupported tag at this point: %d.", tag);
11341131
UNREACHABLE();
@@ -3726,10 +3723,6 @@ Fragment StreamingFlowGraphBuilder::BuildInitializers(
37263723
instructions += BuildFieldInitializer(canonical_name); // read value.
37273724
break;
37283725
}
3729-
case kAssertInitializer: {
3730-
instructions += BuildStatement();
3731-
break;
3732-
}
37333726
case kSuperInitializer: {
37343727
NameIndex canonical_target =
37353728
ReadCanonicalNameReference(); // read target_reference.
@@ -4783,9 +4776,6 @@ void StreamingFlowGraphBuilder::SkipInitializer() {
47834776
case kLocalInitializer:
47844777
SkipVariableDeclaration(); // read variable.
47854778
return;
4786-
case kAssertInitializer:
4787-
SkipStatement();
4788-
return;
47894779
default:
47904780
H.ReportError("Unsupported tag at this point: %d.", tag);
47914781
UNREACHABLE();

runtime/vm/kernel_binary.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ enum Tag {
3838
kSuperInitializer = 9,
3939
kRedirectingInitializer = 10,
4040
kLocalInitializer = 11,
41-
kAssertInitializer = 12,
4241

4342
kDirectPropertyGet = 15,
4443
kDirectPropertySet = 16,

0 commit comments

Comments
 (0)