Skip to content

Commit 4722ed1

Browse files
deps: patch V8 to support compilation with MSVC
This patches V8 v12.4 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: targos#13 Refs: targos#14 Refs: targos#15
1 parent afb9fbf commit 4722ed1

15 files changed

+93
-115
lines changed

deps/v8/src/builtins/builtins-collections-gen.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2784,7 +2784,7 @@ TNode<IntPtrT> WeakCollectionsBuiltinsAssembler::ValueIndexFromKeyIndex(
27842784
TNode<IntPtrT> key_index) {
27852785
return IntPtrAdd(
27862786
key_index,
2787-
IntPtrConstant(EphemeronHashTable::TodoShape::kEntryValueIndex -
2787+
IntPtrConstant(EphemeronHashTable::ShapeT::kEntryValueIndex -
27882788
EphemeronHashTable::kEntryKeyIndex));
27892789
}
27902790

deps/v8/src/codegen/code-stub-assembler.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9719,7 +9719,7 @@ void CodeStubAssembler::NameDictionaryLookup(
97199719
break;
97209720
case kFindExisting:
97219721
case kFindExistingOrInsertionIndex:
9722-
if (Dictionary::TodoShape::kMatchNeedsHoleCheck) {
9722+
if (Dictionary::ShapeT::kMatchNeedsHoleCheck) {
97239723
GotoIf(TaggedEqual(current, TheHoleConstant()), &next_probe);
97249724
}
97259725
current = LoadName<Dictionary>(current);

deps/v8/src/codegen/code-stub-assembler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1577,7 +1577,7 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
15771577
TNode<Smi> LoadFixedArrayBaseLength(TNode<FixedArrayBase> array);
15781578
template <typename Array>
15791579
TNode<Smi> LoadArrayCapacity(TNode<Array> array) {
1580-
return LoadObjectField<Smi>(array, Array::Shape::kCapacityOffset);
1580+
return LoadObjectField<Smi>(array, Array::ShapeT::kCapacityOffset);
15811581
}
15821582
// Load the length of a fixed array base instance.
15831583
TNode<IntPtrT> LoadAndUntagFixedArrayBaseLength(TNode<FixedArrayBase> array);

deps/v8/src/compiler/turboshaft/assembler.h

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,8 +1161,7 @@ class TurboshaftAssemblerOpInterface
11611161

11621162
template <typename... Args>
11631163
explicit TurboshaftAssemblerOpInterface(Args... args)
1164-
: GenericAssemblerOpInterface<Next>(args...),
1165-
matcher_(Asm().output_graph()) {}
1164+
: matcher_(Asm().output_graph()) {}
11661165

11671166
const OperationMatcher& matcher() const { return matcher_; }
11681167

@@ -2420,11 +2419,11 @@ class TurboshaftAssemblerOpInterface
24202419

24212420
// Helpers to read the most common fields.
24222421
// TODO(nicohartmann@): Strengthen this to `V<HeapObject>`.
2423-
V<Map> LoadMapField(V<Object> object) {
2424-
return LoadField<Map>(object, AccessBuilder::ForMap());
2422+
V<v8::internal::Map> LoadMapField(V<Object> object) {
2423+
return LoadField<v8::internal::Map>(object, AccessBuilder::ForMap());
24252424
}
24262425

2427-
V<Word32> LoadInstanceTypeField(V<Map> map) {
2426+
V<Word32> LoadInstanceTypeField(V<v8::internal::Map> map) {
24282427
return LoadField<Word32>(map, AccessBuilder::ForMapInstanceType());
24292428
}
24302429

@@ -3114,7 +3113,7 @@ class TurboshaftAssemblerOpInterface
31143113
V<Object> CallRuntime_TransitionElementsKind(Isolate* isolate,
31153114
V<Context> context,
31163115
V<HeapObject> object,
3117-
V<Map> target_map) {
3116+
V<v8::internal::Map> target_map) {
31183117
return CallRuntime<typename RuntimeCallDescriptor::TransitionElementsKind>(
31193118
isolate, context, {object, target_map});
31203119
}
@@ -3532,8 +3531,8 @@ class TurboshaftAssemblerOpInterface
35323531

35333532
void TransitionAndStoreArrayElement(
35343533
V<Object> array, V<WordPtr> index, OpIndex value,
3535-
TransitionAndStoreArrayElementOp::Kind kind, MaybeHandle<Map> fast_map,
3536-
MaybeHandle<Map> double_map) {
3534+
TransitionAndStoreArrayElementOp::Kind kind, MaybeHandle<v8::internal::Map> fast_map,
3535+
MaybeHandle<v8::internal::Map> double_map) {
35373536
ReduceIfReachableTransitionAndStoreArrayElement(array, index, value, kind,
35383537
fast_map, double_map);
35393538
}
@@ -3546,17 +3545,17 @@ class TurboshaftAssemblerOpInterface
35463545
}
35473546

35483547
V<Word32> CompareMaps(V<HeapObject> heap_object,
3549-
const ZoneRefSet<Map>& maps) {
3548+
const ZoneRefSet<v8::internal::Map>& maps) {
35503549
return ReduceIfReachableCompareMaps(heap_object, maps);
35513550
}
35523551

35533552
void CheckMaps(V<HeapObject> heap_object, OpIndex frame_state,
3554-
const ZoneRefSet<Map>& maps, CheckMapsFlags flags,
3553+
const ZoneRefSet<v8::internal::Map>& maps, CheckMapsFlags flags,
35553554
const FeedbackSource& feedback) {
35563555
ReduceIfReachableCheckMaps(heap_object, frame_state, maps, flags, feedback);
35573556
}
35583557

3559-
void AssumeMap(V<HeapObject> heap_object, const ZoneRefSet<Map>& maps) {
3558+
void AssumeMap(V<HeapObject> heap_object, const ZoneRefSet<v8::internal::Map>& maps) {
35603559
ReduceIfReachableAssumeMap(heap_object, maps);
35613560
}
35623561

@@ -3665,16 +3664,16 @@ class TurboshaftAssemblerOpInterface
36653664
return ReduceIfReachableAssertNotNull(object, type, trap_id);
36663665
}
36673666

3668-
V<Map> RttCanon(V<FixedArray> rtts, uint32_t type_index) {
3667+
V<v8::internal::Map> RttCanon(V<FixedArray> rtts, uint32_t type_index) {
36693668
return ReduceIfReachableRttCanon(rtts, type_index);
36703669
}
36713670

3672-
V<Word32> WasmTypeCheck(V<Object> object, OptionalV<Map> rtt,
3671+
V<Word32> WasmTypeCheck(V<Object> object, OptionalV<v8::internal::Map> rtt,
36733672
WasmTypeCheckConfig config) {
36743673
return ReduceIfReachableWasmTypeCheck(object, rtt, config);
36753674
}
36763675

3677-
V<Object> WasmTypeCast(V<Object> object, OptionalV<Map> rtt,
3676+
V<Object> WasmTypeCast(V<Object> object, OptionalV<v8::internal::Map> rtt,
36783677
WasmTypeCheckConfig config) {
36793678
return ReduceIfReachableWasmTypeCast(object, rtt, config);
36803679
}
@@ -3719,12 +3718,12 @@ class TurboshaftAssemblerOpInterface
37193718
return ReduceIfReachableArrayLength(array, null_check);
37203719
}
37213720

3722-
V<HeapObject> WasmAllocateArray(V<Map> rtt, ConstOrV<Word32> length,
3721+
V<HeapObject> WasmAllocateArray(V<v8::internal::Map> rtt, ConstOrV<Word32> length,
37233722
const wasm::ArrayType* array_type) {
37243723
return ReduceIfReachableWasmAllocateArray(rtt, resolve(length), array_type);
37253724
}
37263725

3727-
V<HeapObject> WasmAllocateStruct(V<Map> rtt,
3726+
V<HeapObject> WasmAllocateStruct(V<v8::internal::Map> rtt,
37283727
const wasm::StructType* struct_type) {
37293728
return ReduceIfReachableWasmAllocateStruct(rtt, struct_type);
37303729
}

deps/v8/src/compiler/turboshaft/machine-optimization-reducer.h

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,53 +1467,23 @@ class MachineOptimizationReducer : public Next {
14671467
if (matcher.MatchConstantShiftRightArithmeticShiftOutZeros(
14681468
left, &x, rep_w, &k1) &&
14691469
matcher.MatchIntegralWordConstant(right, rep_w, &k2) &&
1470-
CountLeadingSignBits(k2, rep_w) > k1) {
1471-
if (matcher.Get(left).saturated_use_count.IsZero()) {
1472-
return __ Comparison(
1473-
x, __ WordConstant(base::bits::Unsigned(k2) << k1, rep_w), kind,
1474-
rep_w);
1475-
} else if constexpr (reducer_list_contains<
1476-
ReducerList, ValueNumberingReducer>::value) {
1477-
// If the shift has uses, we only apply the transformation if the
1478-
// result would be GVNed away.
1479-
OpIndex rhs =
1480-
__ WordConstant(base::bits::Unsigned(k2) << k1, rep_w);
1481-
static_assert(ComparisonOp::input_count == 2);
1482-
static_assert(sizeof(ComparisonOp) == 8);
1483-
base::SmallVector<OperationStorageSlot, 32> storage;
1484-
ComparisonOp* cmp =
1485-
CreateOperation<ComparisonOp>(storage, x, rhs, kind, rep_w);
1486-
if (__ WillGVNOp(*cmp)) {
1487-
return __ Comparison(x, rhs, kind, rep_w);
1488-
}
1489-
}
1470+
CountLeadingSignBits(k2, rep_w) > k1 &&
1471+
matcher.Get(left).saturated_use_count.IsZero()) {
1472+
return __ Comparison(
1473+
x, __ WordConstant(base::bits::Unsigned(k2) << k1, rep_w), kind,
1474+
rep_w);
14901475
}
14911476
// k2 </<= (x >> k1) => (k2 << k1) </<= x if shifts reversible
14921477
// Only perform the transformation if the shift is not used yet, to
14931478
// avoid keeping both the shift and x alive.
14941479
if (matcher.MatchConstantShiftRightArithmeticShiftOutZeros(
14951480
right, &x, rep_w, &k1) &&
14961481
matcher.MatchIntegralWordConstant(left, rep_w, &k2) &&
1497-
CountLeadingSignBits(k2, rep_w) > k1) {
1498-
if (matcher.Get(right).saturated_use_count.IsZero()) {
1499-
return __ Comparison(
1500-
__ WordConstant(base::bits::Unsigned(k2) << k1, rep_w), x, kind,
1501-
rep_w);
1502-
} else if constexpr (reducer_list_contains<
1503-
ReducerList, ValueNumberingReducer>::value) {
1504-
// If the shift has uses, we only apply the transformation if the
1505-
// result would be GVNed away.
1506-
OpIndex lhs =
1507-
__ WordConstant(base::bits::Unsigned(k2) << k1, rep_w);
1508-
static_assert(ComparisonOp::input_count == 2);
1509-
static_assert(sizeof(ComparisonOp) == 8);
1510-
base::SmallVector<OperationStorageSlot, 32> storage;
1511-
ComparisonOp* cmp =
1512-
CreateOperation<ComparisonOp>(storage, lhs, x, kind, rep_w);
1513-
if (__ WillGVNOp(*cmp)) {
1514-
return __ Comparison(lhs, x, kind, rep_w);
1515-
}
1516-
}
1482+
CountLeadingSignBits(k2, rep_w) > k1 &&
1483+
matcher.Get(right).saturated_use_count.IsZero()) {
1484+
return __ Comparison(
1485+
__ WordConstant(base::bits::Unsigned(k2) << k1, rep_w), x, kind,
1486+
rep_w);
15171487
}
15181488
}
15191489
// Map 64bit to 32bit comparisons.

deps/v8/src/compiler/turboshaft/simplified-lowering-reducer.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@ class SimplifiedLoweringReducer : public Next {
3232
OpIndex ig_index, const SpeculativeNumberBinopOp& op) {
3333
DCHECK_EQ(op.kind, SpeculativeNumberBinopOp::Kind::kSafeIntegerAdd);
3434

35-
OpIndex frame_state = Map(op.frame_state());
36-
V<Word32> left = ProcessInput(Map(op.left()), Rep::Word32(),
35+
OpIndex frame_state = MapImpl(op.frame_state());
36+
V<Word32> left = ProcessInput(MapImpl(op.left()), Rep::Word32(),
3737
CheckKind::kSigned32, frame_state);
38-
V<Word32> right = ProcessInput(Map(op.right()), Rep::Word32(),
38+
V<Word32> right = ProcessInput(MapImpl(op.right()), Rep::Word32(),
3939
CheckKind::kSigned32, frame_state);
4040

4141
V<Word32> result = __ OverflowCheckedBinop(
4242
left, right, OverflowCheckedBinopOp::Kind::kSignedAdd,
4343
WordRepresentation::Word32());
4444

4545
V<Word32> overflow = __ Projection(result, 1, Rep::Word32());
46-
__ DeoptimizeIf(overflow, Map(op.frame_state()),
46+
__ DeoptimizeIf(overflow, MapImpl(op.frame_state()),
4747
DeoptimizeReason::kOverflow, FeedbackSource{});
4848
return __ Projection(result, 0, Rep::Word32());
4949
}
@@ -52,10 +52,10 @@ class SimplifiedLoweringReducer : public Next {
5252
base::SmallVector<OpIndex, 8> return_values;
5353
for (OpIndex input : ret.return_values()) {
5454
return_values.push_back(
55-
ProcessInput(Map(input), Rep::Tagged(), CheckKind::kNone, {}));
55+
ProcessInput(MapImpl(input), Rep::Tagged(), CheckKind::kNone, {}));
5656
}
5757

58-
__ Return(Map(ret.pop_count()), base::VectorOf(return_values));
58+
__ Return(MapImpl(ret.pop_count()), base::VectorOf(return_values));
5959
return OpIndex::Invalid();
6060
}
6161

@@ -94,7 +94,7 @@ class SimplifiedLoweringReducer : public Next {
9494
}
9595
}
9696

97-
inline OpIndex Map(OpIndex ig_index) { return __ MapToNewGraph(ig_index); }
97+
inline OpIndex MapImpl(OpIndex ig_index) { return __ MapToNewGraph(ig_index); }
9898
};
9999

100100
#include "src/compiler/turboshaft/undef-assembler-macros.inc"

deps/v8/src/compiler/turboshaft/variable-reducer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@ namespace v8::internal::compiler::turboshaft {
5555
// with constant inputs introduced by `VariableReducer` need to be eliminated.
5656
template <class AfterNext>
5757
class VariableReducer : public RequiredOptimizationReducer<AfterNext> {
58+
protected:
5859
using Next = RequiredOptimizationReducer<AfterNext>;
5960
using Snapshot = SnapshotTable<OpIndex, VariableData>::Snapshot;
6061

62+
private:
6163
struct GetActiveLoopVariablesIndex {
6264
IntrusiveSetIndex& operator()(Variable var) const {
6365
return var.data().active_loop_variables_index;

deps/v8/src/heap/heap.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3580,7 +3580,7 @@ void Heap::RightTrimArray(Tagged<Array> object, int new_capacity,
35803580
}
35813581

35823582
const int bytes_to_trim =
3583-
(old_capacity - new_capacity) * Array::Shape::kElementSize;
3583+
(old_capacity - new_capacity) * Array::HotfixShape::kElementSize;
35843584

35853585
// Calculate location of new array end.
35863586
const int old_size = Array::SizeFor(old_capacity);

deps/v8/src/objects/dictionary.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) Dictionary
3232
using DerivedHashTable = HashTable<Derived, Shape>;
3333

3434
public:
35-
using TodoShape = Shape;
36-
using Key = typename TodoShape::Key;
35+
using Key = typename Shape::Key;
3736
inline Tagged<Object> ValueAt(InternalIndex entry);
3837
inline Tagged<Object> ValueAt(PtrComprCageBase cage_base,
3938
InternalIndex entry);
@@ -126,7 +125,7 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) Dictionary
126125
Key key, Handle<Object> value,
127126
PropertyDetails details);
128127

129-
OBJECT_CONSTRUCTORS(Dictionary, HashTable<Derived, TodoShape>);
128+
OBJECT_CONSTRUCTORS(Dictionary, HashTable<Derived, Shape>);
130129
};
131130

132131
#define EXTERN_DECLARE_DICTIONARY(DERIVED, SHAPE) \

deps/v8/src/objects/fixed-array.h

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ namespace internal {
2525
#include "torque-generated/src/objects/fixed-array-tq.inc"
2626

2727
// Derived: must have a Smi slot at kCapacityOffset.
28-
template <class Derived, class ShapeT, class Super = HeapObject>
28+
template <class Derived, class Shape, class Super = HeapObject>
2929
class TaggedArrayBase : public Super {
3030
static_assert(std::is_base_of<HeapObject, Super>::value);
3131
OBJECT_CONSTRUCTORS(TaggedArrayBase, Super);
3232

33-
using ElementT = typename ShapeT::ElementT;
34-
static_assert(ShapeT::kElementSize == kTaggedSize);
33+
using ElementT = typename Shape::ElementT;
34+
static_assert(Shape::kElementSize == kTaggedSize);
3535
static_assert(is_subtype_v<ElementT, MaybeObject>);
3636

3737
using ElementFieldT =
38-
TaggedField<ElementT, 0, typename ShapeT::CompressionScheme>;
38+
TaggedField<ElementT, 0, typename Shape::CompressionScheme>;
3939

4040
template <typename ElementT>
4141
static constexpr bool kSupportsSmiElements =
@@ -52,13 +52,18 @@ class TaggedArrayBase : public Super {
5252
std::conditional_t<kElementsAreMaybeObject, MaybeObjectSlot, ObjectSlot>;
5353

5454
public:
55-
using Shape = ShapeT;
55+
using ShapeT = Shape;
5656

5757
inline int capacity() const;
5858
inline int capacity(AcquireLoadTag) const;
5959
inline void set_capacity(int value);
6060
inline void set_capacity(int value, ReleaseStoreTag);
6161

62+
inline int length() const { return capacity(); }
63+
inline int length(AcquireLoadTag tag) const { return capacity(tag); }
64+
inline void set_length(int value) { set_capacity(value); }
65+
inline void set_length(int value, AcquireLoadTag tag) { set_capacity(value, tag); }
66+
6267
// For most arraylike objects, length equals capacity. Provide these
6368
// convenience accessors:
6469
template <typename T = Shape,
@@ -193,6 +198,7 @@ class FixedArray : public TaggedArrayBase<FixedArray, TaggedArrayShape> {
193198
OBJECT_CONSTRUCTORS(FixedArray, Super);
194199

195200
public:
201+
using HotfixShape = TaggedArrayShape;
196202
template <class IsolateT>
197203
static inline Handle<FixedArray> New(
198204
IsolateT* isolate, int capacity,
@@ -238,7 +244,7 @@ class FixedArray : public TaggedArrayBase<FixedArray, TaggedArrayShape> {
238244

239245
class BodyDescriptor;
240246

241-
static constexpr int kLengthOffset = Shape::kCapacityOffset;
247+
static constexpr int kLengthOffset = ShapeT::kCapacityOffset;
242248
static constexpr int kMaxLength = FixedArray::kMaxCapacity;
243249
static constexpr int kMaxRegularLength = FixedArray::kMaxRegularCapacity;
244250

@@ -289,7 +295,7 @@ class TrustedFixedArray
289295
class BodyDescriptor;
290296

291297
static constexpr int kLengthOffset =
292-
TrustedFixedArray::Shape::kCapacityOffset;
298+
TrustedFixedArray::ShapeT::kCapacityOffset;
293299
static constexpr int kMaxLength = TrustedFixedArray::kMaxCapacity;
294300
static constexpr int kMaxRegularLength =
295301
TrustedFixedArray::kMaxRegularCapacity;
@@ -337,7 +343,7 @@ class ProtectedFixedArray
337343
class BodyDescriptor;
338344

339345
static constexpr int kLengthOffset =
340-
ProtectedFixedArray::Shape::kCapacityOffset;
346+
ProtectedFixedArray::ShapeT::kCapacityOffset;
341347
static constexpr int kMaxLength = ProtectedFixedArray::kMaxCapacity;
342348
static constexpr int kMaxRegularLength =
343349
ProtectedFixedArray::kMaxRegularCapacity;
@@ -394,6 +400,7 @@ class PrimitiveArrayBase : public Super {
394400

395401
public:
396402
using Shape = ShapeT;
403+
using HotfixShape = ShapeT;
397404
static constexpr bool kElementsAreMaybeObject = false;
398405

399406
inline int length() const;
@@ -534,6 +541,8 @@ class WeakFixedArray
534541
OBJECT_CONSTRUCTORS(WeakFixedArray, Super);
535542

536543
public:
544+
using Shape = WeakFixedArrayShape;
545+
using HotfixShape = WeakFixedArrayShape;
537546
template <class IsolateT>
538547
static inline Handle<WeakFixedArray> New(
539548
IsolateT* isolate, int capacity,
@@ -545,7 +554,7 @@ class WeakFixedArray
545554

546555
class BodyDescriptor;
547556

548-
static constexpr int kLengthOffset = Shape::kCapacityOffset;
557+
static constexpr int kLengthOffset = ShapeT::kCapacityOffset;
549558
};
550559

551560
// WeakArrayList is like a WeakFixedArray with static convenience methods for
@@ -682,6 +691,7 @@ class ArrayList : public TaggedArrayBase<ArrayList, ArrayListShape> {
682691

683692
public:
684693
using Shape = ArrayListShape;
694+
using HotfixShape = ArrayListShape;
685695

686696
template <class IsolateT>
687697
static inline Handle<ArrayList> New(
@@ -754,6 +764,7 @@ class ByteArray : public PrimitiveArrayBase<ByteArray, ByteArrayShape> {
754764

755765
public:
756766
using Shape = ByteArrayShape;
767+
using HotfixShape = ByteArrayShape;
757768

758769
template <class IsolateT>
759770
static inline Handle<ByteArray> New(

0 commit comments

Comments
 (0)