Skip to content

Commit 196a6be

Browse files
authored
Move some const asserts to runtime asserts (bytecodealliance#1894)
Helps to address [builds with `-Zrandomize-layout`][comment] [comment]: bytecodealliance#1750 (comment)
1 parent fce817c commit 196a6be

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

crates/wasmparser/src/validator/component_types.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,9 +476,10 @@ pub struct ComponentDefinedTypeId {
476476
alias_id: u32,
477477
}
478478

479-
const _: () = {
479+
#[test]
480+
fn assert_defined_type_small() {
480481
assert!(core::mem::size_of::<ComponentDefinedTypeId>() <= 8);
481-
};
482+
}
482483

483484
impl TypeIdentifier for ComponentDefinedTypeId {
484485
type Data = ComponentDefinedType;

crates/wasmparser/src/validator/operators.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,10 @@ enum MaybeType<T = ValType> {
252252
// The validator is pretty performance-sensitive and `MaybeType` is the main
253253
// unit of storage, so assert that it doesn't exceed 4 bytes which is the
254254
// current expected size.
255-
const _: () = {
255+
#[test]
256+
fn assert_maybe_type_small() {
256257
assert!(core::mem::size_of::<MaybeType>() == 4);
257-
};
258+
}
258259

259260
impl core::fmt::Display for MaybeType {
260261
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {

crates/wasmparser/src/validator/types.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ macro_rules! define_type_id {
8989
}
9090
}
9191

92+
9293
// The size of type IDs was seen to have a large-ish impact in #844, so
9394
// this assert ensures that it stays relatively small.
9495
const _: () = {
@@ -106,9 +107,10 @@ pub struct CoreTypeId {
106107
index: u32,
107108
}
108109

109-
const _: () = {
110+
#[test]
111+
fn assert_core_type_id_small() {
110112
assert!(core::mem::size_of::<CoreTypeId>() <= 4);
111-
};
113+
}
112114

113115
impl TypeIdentifier for CoreTypeId {
114116
type Data = SubType;

crates/wast/src/core/expr.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,11 +1208,12 @@ instructions! {
12081208
// since big `*.wat` files will have a lot of these. This is a small ratchet to
12091209
// make sure that this enum doesn't become larger than it already is, although
12101210
// ideally it also wouldn't be as large as it is now.
1211-
const _: () = {
1211+
#[test]
1212+
fn assert_instruction_not_too_large() {
12121213
let size = std::mem::size_of::<Instruction<'_>>();
12131214
let pointer = std::mem::size_of::<u64>();
12141215
assert!(size <= pointer * 11);
1215-
};
1216+
}
12161217

12171218
impl<'a> Instruction<'a> {
12181219
pub(crate) fn needs_data_count(&self) -> bool {

0 commit comments

Comments
 (0)