Skip to content

Commit

Permalink
[vm] Disable dart:cli waitFor by default
Browse files Browse the repository at this point in the history
Per breaking change request we are now disabling
waitFor by default.

Users can still enable it by passing the flag:

     --enabled-deprecated-wait-for

Issue #52121

TEST=standalone/io/wait_for_deprecation_test

CoreLibraryReviewExempt: standalone VM only change
Change-Id: Ied78f91344d15cb77e932514e2b752bb6ac5dc5d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/326021
Commit-Queue: Slava Egorov <[email protected]>
Reviewed-by: Martin Kustermann <[email protected]>
Reviewed-by: Michael Thomsen <[email protected]>
  • Loading branch information
mraleph authored and Commit Queue committed Sep 14, 2023
1 parent 8d71986 commit 61b03b4
Show file tree
Hide file tree
Showing 31 changed files with 105 additions and 25 deletions.
17 changes: 17 additions & 0 deletions runtime/vm/dart_api_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ DEFINE_FLAG(bool,
dump_tables,
false,
"Dump common hash tables before snapshotting.");
DEFINE_FLAG(bool,
enable_deprecated_wait_for,
false,
"Enable deprecated dart:cli waitFor. "
"This feature will be fully removed in Dart 3.4 release. "
"See https://dartbug.com/52121.");

#define CHECK_ERROR_HANDLE(error) \
{ \
Expand Down Expand Up @@ -2110,6 +2116,17 @@ DART_EXPORT Dart_Handle Dart_HandleMessage() {
}

DART_EXPORT Dart_Handle Dart_WaitForEvent(int64_t timeout_millis) {
if (!FLAG_enable_deprecated_wait_for) {
return Dart_NewUnhandledExceptionError(Dart_NewStringFromCString(
"Synchronous waiting using dart:cli waitFor "
"and C API Dart_WaitForEvent is deprecated and disabled by default. "
"This feature will be fully removed in Dart 3.4 release. "
"You can currently still enable it by passing "
"--enable_deprecated_wait_for "
"to the Dart VM. "
"See https://dartbug.com/52121."));
}

Thread* T = Thread::Current();
Isolate* I = T->isolate();
CHECK_API_SCOPE(T);
Expand Down
34 changes: 9 additions & 25 deletions sdk/lib/cli/wait_for.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,29 +71,14 @@ class _WaitForUtils {
*
* ## Deprecation notice
*
* The `waitFor` feature is deprecated.
* The feature was intended to solve a particular problem for existing code,
* a problem introduced by a breaking change to the platform libraries.
* The `waitFor` function is not suitable for general use.
* The feature has shortcomings that can affect other code
* running in the same isolate, including:
* * A function call that looks synchronous may cause other asynchronous
* events to run before it returns.
* This is something synchronous code can usually assume not to happen,
* and some code may have been written to take advantage of that
* assumed behavior. Such code can fail in unexpected ways.
* * Multiple nested calls to `waitFor` may block each other
* since the most recent call always needs to complete
* before any other call can complete.
* Judicious use of `waitFor` is necessary to avoid unexpected deadlocks
* which wouldn't happen if using `await` instead.
* If more than one library in the same program is using `waitFor`,
* then it's hard to avoid or control whether such blocking will happen.
*
* The feature is not actively maintained.
* It will remain as-is to support the original problem it was added to solve,
* at least until that problem can be solved in some other way.
*
* The `waitFor` feature is deprecated, disabled by default and slated for
* removal in Dart 3.4 release.
*
* See https://dartbug.com/52121
*
* During transitionary period you can still force enable this feature
* by passing --enable-deprecated-wait-for to Dart VM.
*
* ## Call semantics
*
* This call does the following:
Expand Down Expand Up @@ -137,8 +122,7 @@ class _WaitForUtils {
* subsequent calls block waiting for a condition that is only satisfied when
* an earlier call returns.
*/
@Deprecated(
"This functionality is incomplete and may be removed in a later version")
@Deprecated("This functionality is deprecated and will be removed in Dart 3.4")
T waitFor<T>(Future<T> future, {Duration? timeout}) {
late T result;
bool futureCompleted = false;
Expand Down
2 changes: 2 additions & 0 deletions tests/standalone/io/issue_32052_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// VMOptions=--enable-deprecated-wait-for

import 'dart:async';
import 'dart:cli';

Expand Down
23 changes: 23 additions & 0 deletions tests/standalone/io/wait_for_deprecation_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// This test verifies that attempting to use `waitFor` without enabling it
// causes an exception.

import 'dart:async';
import 'dart:cli';

import 'package:async_helper/async_helper.dart';
import 'package:expect/expect.dart';

main() {
asyncStart();
Expect.throws<String>(() {
waitFor(Future.delayed(Duration(milliseconds: 10)).whenComplete(asyncEnd));
}, (v) {
return v.contains('deprecated and disabled') &&
v.contains('dartbug.com/52121') &&
v.contains('enable_deprecated_wait_for');
});
}
2 changes: 2 additions & 0 deletions tests/standalone/io/wait_for_error_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// VMOptions=--enable-deprecated-wait-for

import 'dart:async';
import 'dart:cli';

Expand Down
2 changes: 2 additions & 0 deletions tests/standalone/io/wait_for_event_isolate_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// VMOptions=--enable-deprecated-wait-for

import 'dart:async';
import 'dart:isolate';

Expand Down
2 changes: 2 additions & 0 deletions tests/standalone/io/wait_for_event_microtask_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// VMOptions=--enable-deprecated-wait-for

import 'dart:async';
import 'dart:cli';

Expand Down
2 changes: 2 additions & 0 deletions tests/standalone/io/wait_for_event_nested_microtask_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// VMOptions=--enable-deprecated-wait-for

import 'dart:async';
import 'dart:cli';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// VMOptions=--enable-deprecated-wait-for

import 'dart:async';
import 'dart:cli';

Expand Down
2 changes: 2 additions & 0 deletions tests/standalone/io/wait_for_event_nested_timer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// VMOptions=--enable-deprecated-wait-for

import 'dart:async';
import 'dart:cli';

Expand Down
2 changes: 2 additions & 0 deletions tests/standalone/io/wait_for_event_nested_waits_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// VMOptions=--enable-deprecated-wait-for

import 'dart:async';
import 'dart:cli';

Expand Down
2 changes: 2 additions & 0 deletions tests/standalone/io/wait_for_event_timer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// VMOptions=--enable-deprecated-wait-for

import 'dart:async';
import 'dart:cli';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// VMOptions=--enable-deprecated-wait-for

import 'dart:async';
import 'dart:cli';

Expand Down
2 changes: 2 additions & 0 deletions tests/standalone/io/wait_for_event_zone_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// VMOptions=--enable-deprecated-wait-for

import 'dart:async';
import 'dart:cli';

Expand Down
2 changes: 2 additions & 0 deletions tests/standalone/io/wait_for_exception_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// VMOptions=--enable-deprecated-wait-for

import 'dart:async';
import 'dart:cli';

Expand Down
2 changes: 2 additions & 0 deletions tests/standalone/io/wait_for_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// VMOptions=--enable-deprecated-wait-for

import 'dart:async';
import 'dart:mirrors';
import 'dart:cli';
Expand Down
2 changes: 2 additions & 0 deletions tests/standalone/io/wait_for_timeout_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// VMOptions=--enable-deprecated-wait-for

import 'dart:async';
import 'dart:cli';

Expand Down
2 changes: 2 additions & 0 deletions tests/standalone_2/io/issue_32052_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// VMOptions=--enable-deprecated-wait-for

// @dart = 2.9

import 'dart:async';
Expand Down
2 changes: 2 additions & 0 deletions tests/standalone_2/io/wait_for_error_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// VMOptions=--enable-deprecated-wait-for

// @dart = 2.9

import 'dart:async';
Expand Down
2 changes: 2 additions & 0 deletions tests/standalone_2/io/wait_for_event_isolate_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// VMOptions=--enable-deprecated-wait-for

// @dart = 2.9

import 'dart:async';
Expand Down
2 changes: 2 additions & 0 deletions tests/standalone_2/io/wait_for_event_microtask_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// VMOptions=--enable-deprecated-wait-for

// @dart = 2.9

import 'dart:async';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// VMOptions=--enable-deprecated-wait-for

// @dart = 2.9

import 'dart:async';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// VMOptions=--enable-deprecated-wait-for

// @dart = 2.9

import 'dart:async';
Expand Down
2 changes: 2 additions & 0 deletions tests/standalone_2/io/wait_for_event_nested_timer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// VMOptions=--enable-deprecated-wait-for

// @dart = 2.9

import 'dart:async';
Expand Down
2 changes: 2 additions & 0 deletions tests/standalone_2/io/wait_for_event_nested_waits_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// VMOptions=--enable-deprecated-wait-for

// @dart = 2.9

import 'dart:async';
Expand Down
2 changes: 2 additions & 0 deletions tests/standalone_2/io/wait_for_event_timer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// VMOptions=--enable-deprecated-wait-for

// @dart = 2.9

import 'dart:async';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// VMOptions=--enable-deprecated-wait-for

// @dart = 2.9

import 'dart:async';
Expand Down
2 changes: 2 additions & 0 deletions tests/standalone_2/io/wait_for_event_zone_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// VMOptions=--enable-deprecated-wait-for

// @dart = 2.9

import 'dart:async';
Expand Down
2 changes: 2 additions & 0 deletions tests/standalone_2/io/wait_for_exception_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// VMOptions=--enable-deprecated-wait-for

// @dart = 2.9

import 'dart:async';
Expand Down
2 changes: 2 additions & 0 deletions tests/standalone_2/io/wait_for_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// VMOptions=--enable-deprecated-wait-for

// @dart = 2.9

import 'dart:async';
Expand Down
2 changes: 2 additions & 0 deletions tests/standalone_2/io/wait_for_timeout_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// VMOptions=--enable-deprecated-wait-for

// @dart = 2.9

import 'dart:async';
Expand Down

0 comments on commit 61b03b4

Please sign in to comment.