Skip to content

Commit 731253c

Browse files
somdoronclaude
andcommitted
Share the struct MAX_FIELDS constant
Extract the duplicated 10_000 struct field limit into a shared StructType::MAX_FIELDS constant instead of mirroring it in rec_group.rs. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent b8e0fa2 commit 731253c

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

crates/wasmtime/src/runtime/rec_group.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ use wasmtime_environ::{
5151
WasmRefType, WasmStorageType, WasmStructType, WasmSubType, WasmValType,
5252
};
5353

54-
/// Maximum number of fields in a struct, mirroring `StructType::from_wasm_struct_type`.
55-
const MAX_FIELDS: usize = 10_000;
56-
5754
/// A process-global counter used to give each [`RecGroupBuilder`] a distinct id
5855
/// so that handles from one builder cannot be accidentally used with another.
5956
static NEXT_BUILDER_ID: AtomicUsize = AtomicUsize::new(0);
@@ -303,10 +300,11 @@ impl RecGroupBuilder {
303300
for (i, member) in members.iter().enumerate() {
304301
if let WasmCompositeInnerType::Struct(s) = &member.composite_type.inner {
305302
ensure!(
306-
s.fields.len() <= MAX_FIELDS,
303+
s.fields.len() <= StructType::MAX_FIELDS,
307304
"attempted to define struct type {i} with {} fields, but that is more than \
308-
the maximum supported number of fields ({MAX_FIELDS})",
305+
the maximum supported number of fields ({})",
309306
s.fields.len(),
307+
StructType::MAX_FIELDS,
310308
);
311309
}
312310
}

crates/wasmtime/src/runtime/types.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,6 +1853,9 @@ impl fmt::Display for StructType {
18531853
}
18541854

18551855
impl StructType {
1856+
/// Maximum number of fields supported in a struct type.
1857+
pub(crate) const MAX_FIELDS: usize = 10_000;
1858+
18561859
/// Construct a new `StructType` with the given field types.
18571860
///
18581861
/// This `StructType` will be final and without a supertype.
@@ -2058,13 +2061,13 @@ impl StructType {
20582061
supertype: Option<EngineOrModuleTypeIndex>,
20592062
ty: WasmStructType,
20602063
) -> Result<StructType> {
2061-
const MAX_FIELDS: usize = 10_000;
20622064
let fields_len = ty.fields.len();
20632065
ensure!(
2064-
fields_len <= MAX_FIELDS,
2066+
fields_len <= Self::MAX_FIELDS,
20652067
"attempted to define a struct type with {fields_len} fields, but \
20662068
that is more than the maximum supported number of fields \
2067-
({MAX_FIELDS})",
2069+
({})",
2070+
Self::MAX_FIELDS,
20682071
);
20692072

20702073
let ty = RegisteredType::new(

0 commit comments

Comments
 (0)