From b9d806a2dd7d6b137cd9f0099ec0f8ed0abea4d6 Mon Sep 17 00:00:00 2001 From: StefanStojanovic Date: Wed, 31 Jan 2024 11:05:20 +0100 Subject: [PATCH] deps: patch V8 to support compilation with MSVC This patches V8 v12.2 for Windows, by fixing multiple compilation errors caused by V8 being a Clang-oriented project. There are various types of errors fixed by this going from changing `using` directives and renaming to overcoming the differences in which Clang and MSVC see templates and metaprogramming. The changes introduced here are strictly meant as a patch only, so they shouldn't be pushed upstream. Refs: https://github.com/targos/node/pull/13 Refs: https://github.com/targos/node/pull/14 PR-URL: https://github.com/nodejs/node/pull/51362 Reviewed-By: Matteo Collina Reviewed-By: Antoine du Hamel Reviewed-By: Rafael Gonzaga --- common.gypi | 2 +- .../src/builtins/builtins-collections-gen.cc | 7 ++- deps/v8/src/codegen/code-stub-assembler.cc | 2 +- deps/v8/src/compiler/turboshaft/assembler.h | 6 +++ ...de-elimination-and-simplification-phase.cc | 3 +- .../src/compiler/turboshaft/copying-phase.h | 35 +++++++++---- .../compiler/turboshaft/csa-optimize-phase.cc | 10 ++-- .../debug-feature-lowering-phase.cc | 2 +- .../turboshaft/int64-lowering-phase.cc | 2 +- .../compiler/turboshaft/loop-peeling-phase.cc | 2 +- .../turboshaft/loop-unrolling-phase.cc | 2 +- .../turboshaft/machine-lowering-phase.cc | 4 +- .../turboshaft/machine-optimization-reducer.h | 50 ++++--------------- .../src/compiler/turboshaft/optimize-phase.cc | 2 +- .../turboshaft/simplified-lowering-phase.cc | 2 +- .../turboshaft/simplified-lowering-reducer.h | 14 +++--- .../store-store-elimination-phase.cc | 2 +- .../turboshaft/type-assertions-phase.cc | 5 +- .../turboshaft/typed-optimizations-phase.cc | 3 +- .../wasm-dead-code-elimination-phase.cc | 3 +- .../turboshaft/wasm-gc-optimize-phase.cc | 2 +- .../turboshaft/wasm-lowering-phase.cc | 2 +- .../turboshaft/wasm-optimize-phase.cc | 2 +- .../compiler/turboshaft/wasm-revec-phase.cc | 2 +- deps/v8/src/heap/heap.cc | 2 +- deps/v8/src/objects/dictionary.h | 5 +- deps/v8/src/objects/fixed-array.h | 20 +++++--- deps/v8/src/objects/hash-table-inl.h | 12 ++--- deps/v8/src/objects/hash-table.h | 11 ++-- deps/v8/src/objects/objects.cc | 42 ++++++++-------- deps/v8/src/objects/template-objects.cc | 2 +- 31 files changed, 129 insertions(+), 131 deletions(-) diff --git a/common.gypi b/common.gypi index a5e5df78732e38..18f60c1435c6ef 100644 --- a/common.gypi +++ b/common.gypi @@ -37,7 +37,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.6', + 'v8_embedder_string': '-node.7', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/src/builtins/builtins-collections-gen.cc b/deps/v8/src/builtins/builtins-collections-gen.cc index e5e6026ce61632..6fea5c37e8c2f2 100644 --- a/deps/v8/src/builtins/builtins-collections-gen.cc +++ b/deps/v8/src/builtins/builtins-collections-gen.cc @@ -2782,10 +2782,9 @@ TNode WeakCollectionsBuiltinsAssembler::ShouldShrink( TNode WeakCollectionsBuiltinsAssembler::ValueIndexFromKeyIndex( TNode key_index) { - return IntPtrAdd( - key_index, - IntPtrConstant(EphemeronHashTable::TodoShape::kEntryValueIndex - - EphemeronHashTable::kEntryKeyIndex)); + return IntPtrAdd(key_index, + IntPtrConstant(EphemeronHashTable::ShapeT::kEntryValueIndex - + EphemeronHashTable::kEntryKeyIndex)); } TF_BUILTIN(WeakMapConstructor, WeakCollectionsBuiltinsAssembler) { diff --git a/deps/v8/src/codegen/code-stub-assembler.cc b/deps/v8/src/codegen/code-stub-assembler.cc index 170cf773d71c39..ec9f176f342d64 100644 --- a/deps/v8/src/codegen/code-stub-assembler.cc +++ b/deps/v8/src/codegen/code-stub-assembler.cc @@ -9455,7 +9455,7 @@ void CodeStubAssembler::NameDictionaryLookup( CAST(UnsafeLoadFixedArrayElement(dictionary, index)); GotoIf(TaggedEqual(current, undefined), if_not_found); if (mode == kFindExisting) { - if (Dictionary::TodoShape::kMatchNeedsHoleCheck) { + if (Dictionary::ShapeT::kMatchNeedsHoleCheck) { GotoIf(TaggedEqual(current, TheHoleConstant()), &next_probe); } current = LoadName(current); diff --git a/deps/v8/src/compiler/turboshaft/assembler.h b/deps/v8/src/compiler/turboshaft/assembler.h index 81a952bf580145..7a8149b4c92922 100644 --- a/deps/v8/src/compiler/turboshaft/assembler.h +++ b/deps/v8/src/compiler/turboshaft/assembler.h @@ -3934,8 +3934,14 @@ class TSAssembler : public Assembler> { public: +#ifdef _WIN32 + explicit TSAssembler(Graph& input_graph, Graph& output_graph, + Zone* phase_zone) + : Assembler(input_graph, output_graph, phase_zone) {} +#else using Assembler>::Assembler; +#endif }; #include "src/compiler/turboshaft/undef-assembler-macros.inc" diff --git a/deps/v8/src/compiler/turboshaft/code-elimination-and-simplification-phase.cc b/deps/v8/src/compiler/turboshaft/code-elimination-and-simplification-phase.cc index 416d0da2ad3846..fcb579f6f62d7a 100644 --- a/deps/v8/src/compiler/turboshaft/code-elimination-and-simplification-phase.cc +++ b/deps/v8/src/compiler/turboshaft/code-elimination-and-simplification-phase.cc @@ -32,7 +32,8 @@ void CodeEliminationAndSimplificationPhase::Run(Zone* temp_zone) { // (which, for simplificy, doesn't use the Assembler helper // methods, but only calls Next::ReduceLoad/Store). DuplicationOptimizationReducer, - ValueNumberingReducer>::Run(temp_zone); + VariableReducerHotfix, + ValueNumberingReducer>::Run(temp_zone); } } // namespace v8::internal::compiler::turboshaft diff --git a/deps/v8/src/compiler/turboshaft/copying-phase.h b/deps/v8/src/compiler/turboshaft/copying-phase.h index 64893f7173cbf6..fa2acafd12d6f2 100644 --- a/deps/v8/src/compiler/turboshaft/copying-phase.h +++ b/deps/v8/src/compiler/turboshaft/copying-phase.h @@ -36,6 +36,18 @@ struct PaddingSpace { V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os, PaddingSpace padding); +template +class VariableReducerHotfix : public Next { +public: + TURBOSHAFT_REDUCER_BOILERPLATE() + + void SetVariable(Variable var, OpIndex new_index) {} + Variable NewLoopInvariantVariable(MaybeRegisterRepresentation rep) { return Variable(); } + + OpIndex GetVariable(Variable var) { return OpIndex(); } + OpIndex GetPredecessorValue(Variable var, int predecessor_index) { return OpIndex(); } +}; + template class ReducerBaseForwarder; template @@ -46,6 +58,9 @@ class GraphVisitor : public Next { template friend class ReducerBaseForwarder; + private: + bool contains_variable_reducer_; + public: TURBOSHAFT_REDUCER_BOILERPLATE() @@ -66,7 +81,8 @@ class GraphVisitor : public Next { // `trace_reduction` is a template parameter to avoid paying for tracing at // runtime. template - void VisitGraph() { + void VisitGraph(bool contains_variable_reducer) { + contains_variable_reducer_ = contains_variable_reducer; Asm().Analyze(); // Creating initial old-to-new Block mapping. @@ -177,8 +193,7 @@ class GraphVisitor : public Next { DCHECK(old_index.valid()); OpIndex result = op_mapping_[old_index]; - if constexpr (reducer_list_contains::value) { + if (contains_variable_reducer_) { if (!result.valid()) { // {op_mapping} doesn't have a mapping for {old_index}. The assembler // should provide the mapping. @@ -1294,8 +1309,7 @@ class GraphVisitor : public Next { DCHECK(Asm().input_graph().BelongsToThisGraph(old_index)); DCHECK_IMPLIES(new_index.valid(), Asm().output_graph().BelongsToThisGraph(new_index)); - if constexpr (reducer_list_contains::value) { + if (contains_variable_reducer_) { if (current_block_needs_variables_) { MaybeVariable var = GetVariableFor(old_index); if (!var.has_value()) { @@ -1393,17 +1407,17 @@ template