From dc5a5da4f82eba4b2e5e09a1ac827e75eddc6b04 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Mon, 22 Mar 2021 18:36:48 +0200 Subject: [PATCH] deps: backport v8 f19142e6 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [top-level-await] Implement the new post-order requirement for async subgraphs Refs: https://github.com/v8/v8/commit/f19142e6139979da3a177cb0b9f382e459f5ccec PR-URL: https://github.com/nodejs/node/pull/37864 Reviewed-By: Michaël Zasso Reviewed-By: Colin Ihrig --- common.gypi | 2 +- deps/v8/src/common/globals.h | 3 + deps/v8/src/diagnostics/objects-debug.cc | 2 +- deps/v8/src/diagnostics/objects-printer.cc | 1 + deps/v8/src/execution/isolate-inl.h | 31 +++ deps/v8/src/execution/isolate.cc | 3 + deps/v8/src/execution/isolate.h | 18 ++ deps/v8/src/heap/factory.cc | 2 +- deps/v8/src/objects/module-inl.h | 8 +- deps/v8/src/objects/source-text-module.cc | 243 ++++++++++++------ deps/v8/src/objects/source-text-module.h | 36 ++- deps/v8/src/objects/source-text-module.tq | 2 +- ...ules-import-rqstd-order-async-subgraph.mjs | 11 + .../harmony/modules-skip-async-subgraph-1.mjs | 12 + .../harmony/modules-skip-async-subgraph-2.mjs | 12 + .../modules-skip-async-subgraph-async.mjs | 12 + .../modules-skip-async-subgraph-start.mjs | 14 + .../harmony/modules-skip-async-subgraph-x.mjs | 12 + 18 files changed, 336 insertions(+), 88 deletions(-) create mode 100644 deps/v8/test/mjsunit/harmony/modules-import-rqstd-order-async-subgraph.mjs create mode 100644 deps/v8/test/mjsunit/harmony/modules-skip-async-subgraph-1.mjs create mode 100644 deps/v8/test/mjsunit/harmony/modules-skip-async-subgraph-2.mjs create mode 100644 deps/v8/test/mjsunit/harmony/modules-skip-async-subgraph-async.mjs create mode 100644 deps/v8/test/mjsunit/harmony/modules-skip-async-subgraph-start.mjs create mode 100644 deps/v8/test/mjsunit/harmony/modules-skip-async-subgraph-x.mjs diff --git a/common.gypi b/common.gypi index 79a22ac0faca37..5e6383ab3cc44d 100644 --- a/common.gypi +++ b/common.gypi @@ -36,7 +36,7 @@ # Reset this number to 0 on major V8 upgrades. # Increment by one for each non-official patch applied to deps/v8. - 'v8_embedder_string': '-node.7', + 'v8_embedder_string': '-node.8', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/src/common/globals.h b/deps/v8/src/common/globals.h index d9d502aa519a26..5b9dd0923f96c5 100644 --- a/deps/v8/src/common/globals.h +++ b/deps/v8/src/common/globals.h @@ -356,6 +356,9 @@ constexpr int kUC16Size = sizeof(uc16); // NOLINT // 128 bit SIMD value size. constexpr int kSimd128Size = 16; +// Maximum ordinal used for tracking asynchronous module evaluation order. +constexpr unsigned kMaxModuleAsyncEvaluatingOrdinal = (1 << 30) - 1; + // FUNCTION_ADDR(f) gets the address of a C function f. #define FUNCTION_ADDR(f) (reinterpret_cast(f)) diff --git a/deps/v8/src/diagnostics/objects-debug.cc b/deps/v8/src/diagnostics/objects-debug.cc index 203548eb4456ef..bf841db010a025 100644 --- a/deps/v8/src/diagnostics/objects-debug.cc +++ b/deps/v8/src/diagnostics/objects-debug.cc @@ -1523,7 +1523,7 @@ void SourceTextModule::SourceTextModuleVerify(Isolate* isolate) { } CHECK(!AsyncParentModuleCount()); CHECK(!pending_async_dependencies()); - CHECK(!async_evaluating()); + CHECK(!IsAsyncEvaluating()); } CHECK_EQ(requested_modules().length(), info().module_requests().length()); diff --git a/deps/v8/src/diagnostics/objects-printer.cc b/deps/v8/src/diagnostics/objects-printer.cc index bd03a837a817f2..df848422c76429 100644 --- a/deps/v8/src/diagnostics/objects-printer.cc +++ b/deps/v8/src/diagnostics/objects-printer.cc @@ -1731,6 +1731,7 @@ void SourceTextModule::SourceTextModulePrint(std::ostream& os) { // NOLINT os << "\n - requested_modules: " << Brief(requested_modules()); os << "\n - import_meta: " << Brief(import_meta()); os << "\n - cycle_root: " << Brief(cycle_root()); + os << "\n - async_evaluating_ordinal: " << async_evaluating_ordinal(); os << "\n"; } diff --git a/deps/v8/src/execution/isolate-inl.h b/deps/v8/src/execution/isolate-inl.h index 7a81bf7d24d9ba..28beea58ee687d 100644 --- a/deps/v8/src/execution/isolate-inl.h +++ b/deps/v8/src/execution/isolate-inl.h @@ -13,6 +13,7 @@ #include "src/objects/property-cell.h" #include "src/objects/regexp-match-info.h" #include "src/objects/shared-function-info.h" +#include "src/objects/source-text-module-inl.h" namespace v8 { namespace internal { @@ -119,6 +120,36 @@ bool Isolate::IsAnyInitialArrayPrototype(JSArray array) { return IsInAnyContext(array, Context::INITIAL_ARRAY_PROTOTYPE_INDEX); } +void Isolate::DidFinishModuleAsyncEvaluation(unsigned ordinal) { + // To address overflow, the ordinal is reset when the async module with the + // largest vended ordinal finishes evaluating. Modules are evaluated in + // ascending order of their async_evaluating_ordinal. + // + // While the specification imposes a global total ordering, the intention is + // that for each async module, all its parents are totally ordered by when + // they first had their [[AsyncEvaluating]] bit set. + // + // The module with largest vended ordinal finishes evaluating implies that the + // async dependency as well as all other modules in that module's graph + // depending on async dependencies are finished evaluating. + // + // If the async dependency participates in other module graphs (e.g. via + // dynamic import, or other