Skip to content

Commit 79f3f12

Browse files
jakobkummerowV8 LUCI CQ
authored andcommitted
[wasm] Lower kMaxCanonicalTypes again
This reverts part of 2b43121, because there are still some ValueType uses of canonicalized type indices left. So for now we allow a maximum of 1'000'000 canonicalized types. Fixed: 360533914 Change-Id: I5041dc2190165781948b186f31cf02bdf894c1bb Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5797071 Reviewed-by: Matthias Liedtke <[email protected]> Auto-Submit: Jakob Kummerow <[email protected]> Commit-Queue: Matthias Liedtke <[email protected]> Commit-Queue: Jakob Kummerow <[email protected]> Cr-Commit-Position: refs/heads/main@{#95710}
1 parent 72c9d55 commit 79f3f12

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

src/wasm/canonical-types.cc

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,25 @@ TypeCanonicalizer* GetTypeCanonicalizer() {
1717

1818
TypeCanonicalizer::TypeCanonicalizer() { AddPredefinedArrayTypes(); }
1919

20-
// For convenience, limit canonicalized type indices to Smi range.
21-
// We could squeeze out a few more bits if necessary by passing them
22-
// from compiled wrappers to runtime functions as Smi-tagged unsigned ints.
23-
// That would give us "uint31" range on 32-bit platforms, and allow
24-
// uint32_t (or even more) on 64-bit platforms. But we probably don't want
25-
// to store that many types in the TypeCanonicalizer anyway.
26-
static constexpr size_t kMaxCanonicalTypes = kSmiMaxValue;
20+
// Inside the TypeCanonicalizer, we use ValueType instances constructed
21+
// from canonical type indices, so we can't let them get bigger than what
22+
// we have storage space for. Code outside the TypeCanonicalizer already
23+
// supports up to Smi range for canonical type indices.
24+
// TODO(jkummerow): Raise this limit. Possible options:
25+
// - increase the size of ValueType::HeapTypeField, using currently-unused bits.
26+
// - change the encoding of ValueType: one bit says whether it's a ref type,
27+
// the other bits then encode the index or the kind of non-ref type.
28+
// - refactor the TypeCanonicalizer's internals to no longer use ValueTypes
29+
// and related infrastructure, and use a wider encoding of canonicalized
30+
// type indices only here.
31+
// - wait for 32-bit platforms to no longer be relevant, and increase the
32+
// size of ValueType to 64 bits.
33+
// None of this seems urgent, as we have no evidence of the current limit
34+
// being an actual limitation in practice.
35+
static constexpr size_t kMaxCanonicalTypes = kV8MaxWasmTypes;
36+
// We don't want any valid modules to fail canonicalization.
2737
static_assert(kMaxCanonicalTypes >= kV8MaxWasmTypes);
38+
// We want the invalid index to fail any range checks.
2839
static_assert(kInvalidCanonicalIndex > kMaxCanonicalTypes);
2940

3041
void TypeCanonicalizer::CheckMaxCanonicalIndex() const {
@@ -215,6 +226,7 @@ ValueType TypeCanonicalizer::CanonicalizeValueType(
215226
const WasmModule* module, ValueType type,
216227
uint32_t recursive_group_start) const {
217228
if (!type.has_index()) return type;
229+
static_assert(kMaxCanonicalTypes <= (1u << ValueType::kHeapTypeBits));
218230
return type.ref_index() >= recursive_group_start
219231
? ValueType::CanonicalWithRelativeIndex(
220232
type.kind(), type.ref_index() - recursive_group_start)

src/wasm/value-type.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ class ValueType {
594594

595595
static constexpr ValueType FromIndex(ValueKind kind, uint32_t index) {
596596
DCHECK(kind == kRefNull || kind == kRef || kind == kRtt);
597+
CHECK_LT(index, kV8MaxWasmTypes);
597598
return ValueType(KindField::encode(kind) | HeapTypeField::encode(index));
598599
}
599600

0 commit comments

Comments
 (0)