Skip to content

Commit

Permalink
[kernel] Remove obsolete AsyncMarker.SyncYielding and YieldStatement.…
Browse files Browse the repository at this point in the history
…isNative

AsyncMarker.SyncYielding and YieldStatement.isNative became
obsolete after async/async*/sync* kernel transformation was removed in
https://dart-review.googlesource.com/c/sdk/+/249944.

TEST=ci

Issue: #48378
Change-Id: I69ac994af77f7e403686750bf8df437868bf33fa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/249947
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
  • Loading branch information
alexmarkov authored and Commit Bot committed Jul 11, 2022
1 parent 3a45cf1 commit 3a1229e
Show file tree
Hide file tree
Showing 16 changed files with 98 additions and 365 deletions.
4 changes: 0 additions & 4 deletions pkg/compiler/lib/src/inferrer/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,6 @@ class KernelTypeGraphBuilder extends ir.Visitor<TypeInformation>
case ir.AsyncMarker.AsyncStar:
recordReturnType(_types.asyncStarStreamType);
break;
case ir.AsyncMarker.SyncYielding:
failedAt(
_analyzedMember, "Unexpected async marker: ${node.asyncMarker}");
break;
}
assert(_breaksFor.isEmpty);
assert(_continuesFor.isEmpty);
Expand Down
4 changes: 0 additions & 4 deletions pkg/compiler/lib/src/ir/impact_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,6 @@ class ImpactBuilder extends StaticTypeVisitor implements ImpactRegistry {
}
registerAsyncStar(elementType);
break;

case ir.AsyncMarker.SyncYielding:
failedAt(CURRENT_ELEMENT_SPANNABLE,
"Unexpected async marker: ${asyncMarker}");
}
}

Expand Down
1 change: 0 additions & 1 deletion pkg/compiler/lib/src/ir/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ AsyncMarker getAsyncMarker(ir.FunctionNode node) {
return AsyncMarker.SYNC;
case ir.AsyncMarker.SyncStar:
return AsyncMarker.SYNC_STAR;
case ir.AsyncMarker.SyncYielding:
default:
throw UnsupportedError(
"Async marker ${node.asyncMarker} is not supported.");
Expand Down
6 changes: 1 addition & 5 deletions pkg/front_end/lib/src/fasta/kernel/body_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ import '../messages.dart' as messages show getLocationFromUri;
import '../modifier.dart'
show Modifier, constMask, covariantMask, finalMask, lateMask, requiredMask;
import '../names.dart' show emptyName, minusName, plusName;
import '../problems.dart'
show internalProblem, unexpected, unhandled, unsupported;
import '../problems.dart' show internalProblem, unhandled, unsupported;
import '../scope.dart';
import '../source/diet_parser.dart';
import '../source/source_class_builder.dart';
Expand Down Expand Up @@ -1415,9 +1414,6 @@ class BodyBuilder extends StackListenerImpl

case AsyncMarker.Sync:
break; // skip
case AsyncMarker.SyncYielding:
unexpected("async, async*, sync, or sync*", "$asyncModifier",
member.charOffset, uri);
}

if (problem != null) {
Expand Down
7 changes: 3 additions & 4 deletions pkg/kernel/binary.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ type CanonicalName {

type ComponentFile {
UInt32 magic = 0x90ABCDEF;
UInt32 formatVersion = 82;
UInt32 formatVersion = 83;
Byte[10] shortSdkHash;
List<String> problemsAsJson; // Described in problems.md.
Library[] libraries;
Expand Down Expand Up @@ -510,8 +510,7 @@ enum AsyncMarker {
Sync,
SyncStar,
Async,
AsyncStar,
SyncYielding
AsyncStar
}
*/

Expand Down Expand Up @@ -1398,7 +1397,7 @@ type TryFinally extends Statement {
type YieldStatement extends Statement {
Byte tag = 77;
FileOffset fileOffset;
Byte flags (isYieldStar, isNative);
Byte flags (isYieldStar);
Expression expression;
}

Expand Down
49 changes: 1 addition & 48 deletions pkg/kernel/lib/ast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3956,43 +3956,6 @@ enum AsyncMarker {
SyncStar,
Async,
AsyncStar,

// `SyncYielding` is a marker that tells Dart VM that this function is an
// artificial closure introduced by an async transformer which desugared all
// async syntax into a combination of native yields and helper method calls.
//
// Native yields (formatted as `[yield]`) are semantically close to
// `yield x` statement: they denote a yield/resume point within a function
// but are completely decoupled from the notion of iterators. When
// execution of the closure reaches `[yield] x` it stops and return the
// value of `x` to the caller. If closure is called again it continues
// to the next statement after this yield as if it was suspended and resumed.
//
// Consider this example:
//
// g() {
// var :await_jump_var = 0;
// var :await_ctx_var;
//
// f(x) yielding {
// [yield] '${x}:0';
// [yield] '${x}:1';
// [yield] '${x}:2';
// }
//
// return f;
// }
//
// print(f('a')); /* prints 'a:0', :await_jump_var = 1 */
// print(f('b')); /* prints 'b:1', :await_jump_var = 2 */
// print(f('c')); /* prints 'c:2', :await_jump_var = 3 */
//
// Note: currently Dart VM implicitly relies on async transformer to
// inject certain artificial variables into g (like `:await_jump_var`).
// As such SyncYielding and native yield are not intended to be used on their
// own, but are rather an implementation artifact of the async transformer
// itself.
SyncYielding,
}

// ------------------------------------------------------------------------
Expand Down Expand Up @@ -10523,33 +10486,23 @@ class TryFinally extends Statement {
}

/// Statement of form `yield x` or `yield* x`.
///
/// For native yield semantics see `AsyncMarker.SyncYielding`.
class YieldStatement extends Statement {
Expression expression;
int flags = 0;

YieldStatement(this.expression,
{bool isYieldStar: false, bool isNative: false}) {
YieldStatement(this.expression, {bool isYieldStar: false}) {
expression.parent = this;
this.isYieldStar = isYieldStar;
this.isNative = isNative;
}

static const int FlagYieldStar = 1 << 0;
static const int FlagNative = 1 << 1;

bool get isYieldStar => flags & FlagYieldStar != 0;
bool get isNative => flags & FlagNative != 0;

void set isYieldStar(bool value) {
flags = value ? (flags | FlagYieldStar) : (flags & ~FlagYieldStar);
}

void set isNative(bool value) {
flags = value ? (flags | FlagNative) : (flags & ~FlagNative);
}

@override
R accept<R>(StatementVisitor<R> v) => v.visitYieldStatement(this);

Expand Down
3 changes: 1 addition & 2 deletions pkg/kernel/lib/binary/ast_from_binary.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2895,8 +2895,7 @@ class BinaryBuilder {
int offset = readOffset();
int flags = readByte();
return new YieldStatement(readExpression(),
isYieldStar: flags & YieldStatement.FlagYieldStar != 0,
isNative: flags & YieldStatement.FlagNative != 0)
isYieldStar: flags & YieldStatement.FlagYieldStar != 0)
..fileOffset = offset;
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/kernel/lib/binary/tag.dart
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class Tag {
/// 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 = 82;
static const int BinaryFormatVersion = 83;
}

abstract class ConstantTag {
Expand Down
4 changes: 0 additions & 4 deletions pkg/kernel/lib/text/ast_to_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -818,8 +818,6 @@ class Printer extends Visitor<void> with VisitorVoidMixin {
return 'async';
case AsyncMarker.AsyncStar:
return 'async*';
case AsyncMarker.SyncYielding:
return 'yielding';
default:
return '<Invalid async marker: $marker>';
}
Expand Down Expand Up @@ -2414,8 +2412,6 @@ class Printer extends Visitor<void> with VisitorVoidMixin {
writeIndentation();
if (node.isYieldStar) {
writeWord('yield*');
} else if (node.isNative) {
writeWord('[yield]');
} else {
writeWord('yield');
}
Expand Down
23 changes: 0 additions & 23 deletions pkg/kernel/lib/type_checker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -363,26 +363,6 @@ class TypeCheckingVisitor
case AsyncMarker.AsyncStar:
return null;

case AsyncMarker.SyncYielding:
// The SyncStar transform wraps the original function body twice,
// where the inner most function returns bool.
TreeNode? parent = function.parent;
while (parent is! FunctionNode) {
parent = parent!.parent;
}
FunctionNode enclosingFunction = parent;
if (enclosingFunction.dartAsyncMarker == AsyncMarker.Sync) {
parent = enclosingFunction.parent;
while (parent is! FunctionNode) {
parent = parent!.parent;
}
enclosingFunction = parent;
if (enclosingFunction.dartAsyncMarker == AsyncMarker.SyncStar) {
return coreTypes.boolLegacyRawType;
}
}
return null;

default:
throw 'Unexpected async marker: ${function.asyncMarker}';
}
Expand All @@ -405,9 +385,6 @@ class TypeCheckingVisitor
}
return const DynamicType();

case AsyncMarker.SyncYielding:
return function.returnType;

default:
throw 'Unexpected async marker: ${function.asyncMarker}';
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/kernel/lib/verifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,6 @@ class VerifyingVisitor extends RecursiveResultVisitor<void> {
switch (currentAsyncMarker) {
case AsyncMarker.Sync:
case AsyncMarker.Async:
case AsyncMarker.SyncYielding:
// ok
break;
case AsyncMarker.SyncStar:
Expand Down Expand Up @@ -556,7 +555,6 @@ class VerifyingVisitor extends RecursiveResultVisitor<void> {
break;
case AsyncMarker.SyncStar:
case AsyncMarker.AsyncStar:
case AsyncMarker.SyncYielding:
// ok
break;
}
Expand Down
11 changes: 0 additions & 11 deletions pkg/vm/lib/transformations/type_flow/summary_collector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -363,17 +363,6 @@ class _VariablesInfoCollector extends RecursiveVisitor {
final function = node.function;
function.accept(this);

if (function.asyncMarker == AsyncMarker.SyncYielding) {
// Mark parameters of synthetic async_op closures as captured
// to make sure their updates at yield points are taken into account.
for (var v in function.positionalParameters) {
_captureVariable(v);
}
for (var v in function.namedParameters) {
_captureVariable(v);
}
}

activeStatements = savedActiveStatements;
numVariablesAtActiveStatements = savedNumVariablesAtActiveStatements;
numVariablesAtFunctionEntry = savedNumVariablesAtFunctionEntry;
Expand Down
Loading

0 comments on commit 3a1229e

Please sign in to comment.