Revert "[vm] Remove --causal-async-stacks flag"

This reverts commit b1f1aee94d8730d7d3b6def8a1fffec2181fcfb1.

Reason for revert: Some left-over uses in g3 need to removed first
(some were removed in b/380758599 but apparently there's some 
usages left).

Original change's description:
> [vm] Remove --causal-async-stacks flag
>
> The flag isn't used anywhere in our tests or in embedder code. Turning
> it on will result in a VM startup error.
>
> We should therefore remove all uses of the flag and the flag itself.
>
> TEST=Existing test suite.
>
> Change-Id: I19dfba052df7948dfdb379c0610dab67ebbcd12d
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/204500
> Reviewed-by: Clement Skau <cskau@google.com>
> Commit-Queue: Martin Kustermann <kustermann@google.com>

TBR=kustermann@google.com,cskau@google.com

Change-Id: I03aad46f46153d5ea4ac2fcdd5685d0ef2a0d9af
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/204723
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
diff --git a/runtime/lib/stacktrace.cc b/runtime/lib/stacktrace.cc
index da73ef8..545a3d3 100644
--- a/runtime/lib/stacktrace.cc
+++ b/runtime/lib/stacktrace.cc
@@ -74,6 +74,11 @@
 }
 
 // Gets current stack trace for `thread`.
+// This functions itself handles the --causel-async-stacks case.
+// For --lazy-async-stacks see `CurrentSyncStackTraceLazy`.
+// For fallback see `CurrentSyncStackTrace`.
+// Extracts the causal async stack from the thread if any set, then prepends
+// the current sync. stack up until the current async function (if any).
 static StackTracePtr CurrentStackTrace(Thread* thread,
                                        bool for_async_function,
                                        intptr_t skip_frames = 1) {
diff --git a/runtime/tests/concurrency/stress_test_list.json b/runtime/tests/concurrency/stress_test_list.json
index 17a8b0a..502555d 100644
--- a/runtime/tests/concurrency/stress_test_list.json
+++ b/runtime/tests/concurrency/stress_test_list.json
@@ -2800,8 +2800,8 @@
     "../../../tests/language/vm/bitnot_int_test.dart",
     "../../../tests/language/vm/bool_check_stack_traces_test.dart",
     "../../../tests/language/vm/canonicalization_preserves_deopt_test.dart",
-    "../../../tests/language/vm/lazy_async_exception_stack2_test.dart",
-    "../../../tests/language/vm/lazy_async_exception_stack_test.dart",
+    "../../../tests/language/vm/causal_async_exception_stack2_test.dart",
+    "../../../tests/language/vm/causal_async_exception_stack_test.dart",
     "../../../tests/language/vm/checked_smi_comparison_test.dart",
     "../../../tests/language/vm/checked_smi_op_test.dart",
     "../../../tests/language/vm/clamp_37868_test.dart",
@@ -3224,7 +3224,7 @@
     "../../../tests/standalone/assert_assignable_canon_test.dart",
     "../../../tests/standalone/byte_array_view_optimized_test.dart",
     "../../../tests/standalone/bytedata_test.dart",
-    "../../../tests/standalone/lazy_async_stack_test.dart",
+    "../../../tests/standalone/causal_async_stack_test.dart",
     "../../../tests/standalone/check_class_cha_test.dart",
     "../../../tests/standalone/check_null_cha_test.dart",
     "../../../tests/standalone/constant_left_shift_test.dart",
@@ -6160,8 +6160,8 @@
     "../../../tests/language_2/vm/await_synchronous_future_test.dart",
     "../../../tests/language_2/vm/bitnot_int_test.dart",
     "../../../tests/language_2/vm/canonicalization_preserves_deopt_test.dart",
-    "../../../tests/language_2/vm/lazy_async_exception_stack2_test.dart",
-    "../../../tests/language_2/vm/lazy_async_exception_stack_test.dart",
+    "../../../tests/language_2/vm/causal_async_exception_stack2_test.dart",
+    "../../../tests/language_2/vm/causal_async_exception_stack_test.dart",
     "../../../tests/language_2/vm/checked_smi_comparison_test.dart",
     "../../../tests/language_2/vm/checked_smi_op_test.dart",
     "../../../tests/language_2/vm/clamp_37868_test.dart",
@@ -6570,7 +6570,7 @@
     "../../../tests/standalone_2/assert_assignable_canon_test.dart",
     "../../../tests/standalone_2/byte_array_view_optimized_test.dart",
     "../../../tests/standalone_2/bytedata_test.dart",
-    "../../../tests/standalone_2/lazy_async_stack_test.dart",
+    "../../../tests/standalone_2/causal_async_stack_test.dart",
     "../../../tests/standalone_2/check_class_cha_test.dart",
     "../../../tests/standalone_2/check_null_cha_test.dart",
     "../../../tests/standalone_2/constant_left_shift_test.dart",
diff --git a/runtime/tests/vm/dart/causal_stacks/sync_async_start_pkg_test_test.dart b/runtime/tests/vm/dart/causal_stacks/sync_async_start_pkg_test_test.dart
index 7015fe0..e2bcd2f 100644
--- a/runtime/tests/vm/dart/causal_stacks/sync_async_start_pkg_test_test.dart
+++ b/runtime/tests/vm/dart/causal_stacks/sync_async_start_pkg_test_test.dart
@@ -3,7 +3,7 @@
 // BSD-style license that can be found in the LICENSE file.
 //
 // This test ensures that "pkg:stack_trace" (used by "pkg:test") doesn't break
-// when lazy async stacks are enabled by dropping frames below a synchronous
+// when causal async stacks are enabled by dropping frames below a synchronous
 // start to an async function.
 
 import "package:test/test.dart";
diff --git a/runtime/tests/vm/dart_2/causal_stacks/sync_async_start_pkg_test_test.dart b/runtime/tests/vm/dart_2/causal_stacks/sync_async_start_pkg_test_test.dart
index 7015fe0..e2bcd2f 100644
--- a/runtime/tests/vm/dart_2/causal_stacks/sync_async_start_pkg_test_test.dart
+++ b/runtime/tests/vm/dart_2/causal_stacks/sync_async_start_pkg_test_test.dart
@@ -3,7 +3,7 @@
 // BSD-style license that can be found in the LICENSE file.
 //
 // This test ensures that "pkg:stack_trace" (used by "pkg:test") doesn't break
-// when lazy async stacks are enabled by dropping frames below a synchronous
+// when causal async stacks are enabled by dropping frames below a synchronous
 // start to an async function.
 
 import "package:test/test.dart";
diff --git a/runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc b/runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc
index 3798c3d..226faff 100644
--- a/runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc
+++ b/runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc
@@ -5523,9 +5523,11 @@
             break;
           case FunctionNodeHelper::kAsync:
             function.set_modifier(UntaggedFunction::kAsync);
+            function.set_is_inlinable(!FLAG_causal_async_stacks);
             break;
           case FunctionNodeHelper::kAsyncStar:
             function.set_modifier(UntaggedFunction::kAsyncGen);
+            function.set_is_inlinable(!FLAG_causal_async_stacks);
             break;
           default:
             // no special modifier
@@ -5544,7 +5546,8 @@
         }
         // Note: Is..() methods use the modifiers set above, so order matters.
         if (function.IsAsyncClosure() || function.IsAsyncGenClosure()) {
-          function.set_is_inlinable(!FLAG_lazy_async_stacks);
+          function.set_is_inlinable(!FLAG_causal_async_stacks &&
+                                    !FLAG_lazy_async_stacks);
         }
 
         function.set_end_token_pos(function_node_helper.end_position_);
diff --git a/runtime/vm/dart.cc b/runtime/vm/dart.cc
index b2601a5..4a634d4 100644
--- a/runtime/vm/dart.cc
+++ b/runtime/vm/dart.cc
@@ -221,6 +221,14 @@
       return error;
     }
   }
+  if (FLAG_causal_async_stacks && FLAG_lazy_async_stacks) {
+    return Utils::StrDup(
+        "To use --lazy-async-stacks, please disable --causal-async-stacks!");
+  }
+  // TODO(cskau): Remove once flag deprecation has been completed.
+  if (FLAG_causal_async_stacks) {
+    return Utils::StrDup("--causal-async-stacks is deprecated!");
+  }
 
   UntaggedFrame::Init();
 
diff --git a/runtime/vm/debugger.cc b/runtime/vm/debugger.cc
index 71d09e7..8f0ed32 100644
--- a/runtime/vm/debugger.cc
+++ b/runtime/vm/debugger.cc
@@ -1903,7 +1903,10 @@
   if (FLAG_lazy_async_stacks) {
     return CollectAsyncLazy();
   }
-  return nullptr;
+  if (!FLAG_causal_async_stacks) {
+    return nullptr;
+  }
+  UNREACHABLE();  //  FLAG_causal_async_stacks is deprecated.
 }
 
 DebuggerStackTrace* DebuggerStackTrace::CollectAsyncLazy() {
@@ -1976,7 +1979,7 @@
 
 DebuggerStackTrace* DebuggerStackTrace::CollectAwaiterReturn() {
 #if defined(DART_PRECOMPILED_RUNTIME)
-  // AOT does not support debugging.
+  // Causal async stacks are not supported in the AOT runtime.
   ASSERT(!FLAG_async_debugger);
   return nullptr;
 #else
diff --git a/runtime/vm/flag_list.h b/runtime/vm/flag_list.h
index 7e7a773..86ede97 100644
--- a/runtime/vm/flag_list.h
+++ b/runtime/vm/flag_list.h
@@ -58,10 +58,12 @@
 //
 // The syntax used is the same as that for FLAG_LIST below, as these flags are
 // automatically included in FLAG_LIST.
+// TODO(cskau): Remove causal_async_stacks when deprecated.
 #define VM_GLOBAL_FLAG_LIST(P, R, C, D)                                        \
   P(code_comments, bool, false, "Include comments into code and disassembly.") \
   P(dwarf_stack_traces_mode, bool, false,                                      \
     "Use --[no-]dwarf-stack-traces instead.")                                  \
+  P(causal_async_stacks, bool, false, "DEPRECATED: Improved async stacks")     \
   P(lazy_async_stacks, bool, true, "Reconstruct async stacks from listeners")  \
   P(lazy_dispatchers, bool, true, "Generate dispatchers lazily")               \
   P(use_bare_instructions, bool, true, "Enable bare instructions mode.")       \
diff --git a/runtime/vm/kernel_loader.cc b/runtime/vm/kernel_loader.cc
index eceb625..7e59984 100644
--- a/runtime/vm/kernel_loader.cc
+++ b/runtime/vm/kernel_loader.cc
@@ -2014,17 +2014,22 @@
   switch (function_node_helper.dart_async_marker_) {
     case FunctionNodeHelper::kSyncStar:
       function.set_modifier(UntaggedFunction::kSyncGen);
-      function.set_is_visible(!FLAG_lazy_async_stacks);
+      function.set_is_visible(!FLAG_causal_async_stacks &&
+                              !FLAG_lazy_async_stacks);
       break;
     case FunctionNodeHelper::kAsync:
       function.set_modifier(UntaggedFunction::kAsync);
-      function.set_is_inlinable(!FLAG_lazy_async_stacks);
-      function.set_is_visible(!FLAG_lazy_async_stacks);
+      function.set_is_inlinable(!FLAG_causal_async_stacks &&
+                                !FLAG_lazy_async_stacks);
+      function.set_is_visible(!FLAG_causal_async_stacks &&
+                              !FLAG_lazy_async_stacks);
       break;
     case FunctionNodeHelper::kAsyncStar:
       function.set_modifier(UntaggedFunction::kAsyncGen);
-      function.set_is_inlinable(!FLAG_lazy_async_stacks);
-      function.set_is_visible(!FLAG_lazy_async_stacks);
+      function.set_is_inlinable(!FLAG_causal_async_stacks &&
+                                !FLAG_lazy_async_stacks);
+      function.set_is_visible(!FLAG_causal_async_stacks &&
+                              !FLAG_lazy_async_stacks);
       break;
     default:
       // no special modifier
diff --git a/tests/language/language_kernel.status b/tests/language/language_kernel.status
index acd118f..a0fb2d7 100644
--- a/tests/language/language_kernel.status
+++ b/tests/language/language_kernel.status
@@ -228,8 +228,8 @@
 unsorted/inference_enum_list_test: Skip # Issue 35885
 
 [ $compiler == dartk && $mode == product && $runtime == vm ]
-vm/lazy_async_exception_stack2_test: SkipByDesign
-vm/lazy_async_exception_stack_test: SkipByDesign
+vm/causal_async_exception_stack2_test: SkipByDesign
+vm/causal_async_exception_stack_test: SkipByDesign
 
 # ===== dartk + vm status lines =====
 [ $compiler == dartk && $runtime == vm ]
@@ -277,9 +277,9 @@
 optimize/deopt_inlined_function_lazy_test: Skip # Incompatible flag: --deoptimize-alot
 unsorted/hello_dart_test: Skip # Incompatible flag: --compile_all
 unsorted/invocation_mirror2_test: SkipByDesign
+vm/causal_async_exception_stack2_test: SkipByDesign
+vm/causal_async_exception_stack_test: SkipByDesign
 vm/closure_memory_retention_test: Skip # KernelVM bug: Hits OOM
-vm/lazy_async_exception_stack2_test: SkipByDesign
-vm/lazy_async_exception_stack_test: SkipByDesign
 vm/reflect_core_vm_test: SkipByDesign
 vm/regress_27671_test: Skip # Unsupported
 vm/regress_29145_test: Skip # Issue 29145
diff --git a/tests/language/vm/lazy_async_exception_stack2_test.dart b/tests/language/vm/causal_async_exception_stack2_test.dart
similarity index 95%
rename from tests/language/vm/lazy_async_exception_stack2_test.dart
rename to tests/language/vm/causal_async_exception_stack2_test.dart
index bd9b8d5..e3ddda0 100644
--- a/tests/language/vm/lazy_async_exception_stack2_test.dart
+++ b/tests/language/vm/causal_async_exception_stack2_test.dart
@@ -6,7 +6,7 @@
 
 import 'package:async_helper/async_minitest.dart';
 
-import 'lazy_async_exception_stack_helper.dart' as h;
+import 'causal_async_exception_stack_helper.dart' as h;
 
 foo3() async => throw "foo";
 bar3() async => throw "bar";
@@ -93,7 +93,7 @@
 }
 
 main() async {
-  test('lazy async exception stack', () async {
+  test('causal async exception stack', () async {
     await test1();
     await test2();
   });
diff --git a/tests/language/vm/lazy_async_exception_stack_helper.dart b/tests/language/vm/causal_async_exception_stack_helper.dart
similarity index 100%
rename from tests/language/vm/lazy_async_exception_stack_helper.dart
rename to tests/language/vm/causal_async_exception_stack_helper.dart
diff --git a/tests/language/vm/lazy_async_exception_stack_test.dart b/tests/language/vm/causal_async_exception_stack_test.dart
similarity index 94%
rename from tests/language/vm/lazy_async_exception_stack_test.dart
rename to tests/language/vm/causal_async_exception_stack_test.dart
index 9b9705e..e9df0a7 100644
--- a/tests/language/vm/lazy_async_exception_stack_test.dart
+++ b/tests/language/vm/causal_async_exception_stack_test.dart
@@ -6,7 +6,7 @@
 
 import 'package:async_helper/async_minitest.dart';
 
-import 'lazy_async_exception_stack_helper.dart' as h;
+import 'causal_async_exception_stack_helper.dart' as h;
 
 thrower() async {
   throw 'oops';
@@ -29,7 +29,7 @@
 
 main() async {
   // Test async and async*.
-  test('lazy async exception stack', () async {
+  test('causal async exception stack', () async {
     try {
       await foo();
       fail("Did not throw");
diff --git a/tests/language_2/language_2_kernel.status b/tests/language_2/language_2_kernel.status
index 1db04b4..9b5f403 100644
--- a/tests/language_2/language_2_kernel.status
+++ b/tests/language_2/language_2_kernel.status
@@ -48,8 +48,8 @@
 unsorted/inference_enum_list_test: Skip # Issue 35885
 
 [ $compiler == dartk && $mode == product && $runtime == vm ]
-vm/lazy_async_exception_stack2_test: SkipByDesign
-vm/lazy_async_exception_stack_test: SkipByDesign
+vm/causal_async_exception_stack2_test: SkipByDesign
+vm/causal_async_exception_stack_test: SkipByDesign
 
 # ===== dartk + vm status lines =====
 [ $compiler == dartk && $runtime == vm ]
@@ -91,9 +91,9 @@
 optimize/deopt_inlined_function_lazy_test: Skip # Incompatible flag: --deoptimize-alot
 unsorted/hello_dart_test: Skip # Incompatible flag: --compile_all
 unsorted/invocation_mirror2_test: SkipByDesign
+vm/causal_async_exception_stack2_test: SkipByDesign
+vm/causal_async_exception_stack_test: SkipByDesign
 vm/closure_memory_retention_test: Skip # KernelVM bug: Hits OOM
-vm/lazy_async_exception_stack2_test: SkipByDesign
-vm/lazy_async_exception_stack_test: SkipByDesign
 vm/reflect_core_vm_test: SkipByDesign
 vm/regress_27671_test: Skip # Unsupported
 vm/regress_29145_test: Skip # Issue 29145
@@ -118,4 +118,4 @@
 optimize/deopt_inlined_function_lazy_test: Skip
 
 [ $mode == debug && ($hot_reload || $hot_reload_rollback) ]
-regress/regress41983_test: Pass, Slow
+regress/regress41983_test: Pass, Slow
\ No newline at end of file
diff --git a/tests/language_2/vm/lazy_async_exception_stack2_test.dart b/tests/language_2/vm/causal_async_exception_stack2_test.dart
similarity index 95%
rename from tests/language_2/vm/lazy_async_exception_stack2_test.dart
rename to tests/language_2/vm/causal_async_exception_stack2_test.dart
index 81df6ce..6e21580 100644
--- a/tests/language_2/vm/lazy_async_exception_stack2_test.dart
+++ b/tests/language_2/vm/causal_async_exception_stack2_test.dart
@@ -8,7 +8,7 @@
 
 import 'package:async_helper/async_minitest.dart';
 
-import 'lazy_async_exception_stack_helper.dart' as h;
+import 'causal_async_exception_stack_helper.dart' as h;
 
 foo3() async => throw "foo";
 bar3() async => throw "bar";
@@ -95,7 +95,7 @@
 }
 
 main() async {
-  test('lazy async exception stack', () async {
+  test('causal async exception stack', () async {
     await test1();
     await test2();
   });
diff --git a/tests/language_2/vm/lazy_async_exception_stack_helper.dart b/tests/language_2/vm/causal_async_exception_stack_helper.dart
similarity index 100%
rename from tests/language_2/vm/lazy_async_exception_stack_helper.dart
rename to tests/language_2/vm/causal_async_exception_stack_helper.dart
diff --git a/tests/language_2/vm/lazy_async_exception_stack_test.dart b/tests/language_2/vm/causal_async_exception_stack_test.dart
similarity index 94%
rename from tests/language_2/vm/lazy_async_exception_stack_test.dart
rename to tests/language_2/vm/causal_async_exception_stack_test.dart
index 46ee9ff..8afe38f 100644
--- a/tests/language_2/vm/lazy_async_exception_stack_test.dart
+++ b/tests/language_2/vm/causal_async_exception_stack_test.dart
@@ -8,7 +8,7 @@
 
 import 'package:async_helper/async_minitest.dart';
 
-import 'lazy_async_exception_stack_helper.dart' as h;
+import 'causal_async_exception_stack_helper.dart' as h;
 
 thrower() async {
   throw 'oops';
@@ -31,7 +31,7 @@
 
 main() async {
   // Test async and async*.
-  test('lazy async exception stack', () async {
+  test('causal async exception stack', () async {
     try {
       await foo();
       fail("Did not throw");
diff --git a/tests/standalone/lazy_async_stack_test.dart b/tests/standalone/causal_async_stack_test.dart
similarity index 100%
rename from tests/standalone/lazy_async_stack_test.dart
rename to tests/standalone/causal_async_stack_test.dart
diff --git a/tests/standalone/standalone.status b/tests/standalone/standalone.status
index 38d3989..fc091da 100644
--- a/tests/standalone/standalone.status
+++ b/tests/standalone/standalone.status
@@ -41,7 +41,7 @@
 deferred_transitive_import_error_test: Skip
 
 [ $compiler == dartkp ]
-lazy_async_stack_test: Skip # Flaky.
+causal_async_stack_test: Skip # Flaky.
 
 [ $mode == product ]
 io/stdio_implicit_close_test: Skip # SkipByDesign
diff --git a/tests/standalone_2/lazy_async_stack_test.dart b/tests/standalone_2/causal_async_stack_test.dart
similarity index 100%
rename from tests/standalone_2/lazy_async_stack_test.dart
rename to tests/standalone_2/causal_async_stack_test.dart
diff --git a/tests/standalone_2/standalone_2.status b/tests/standalone_2/standalone_2.status
index 18323d3..d875452 100644
--- a/tests/standalone_2/standalone_2.status
+++ b/tests/standalone_2/standalone_2.status
@@ -41,7 +41,7 @@
 deferred_transitive_import_error_test: Skip
 
 [ $compiler == dartkp ]
-lazy_async_stack_test: Skip # Flaky.
+causal_async_stack_test: Skip # Flaky.
 
 [ $mode == product ]
 io/stdio_implicit_close_test: Skip # SkipByDesign