Skip to content

Fix CI, again. #316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,5 @@ mod codegen {
}

fn main() {
if std::mem::size_of::<Option<bool>>() == 1 {
// https://github.com/rust-lang/rust/pull/45225
println!("cargo:rustc-cfg=rustc_has_pr45225")
}

if std::mem::size_of::<std::borrow::Cow<'static, str>>() == 24 {
println!("cargo:rustc-cfg=rustc_has_better_cow_layout")
}

codegen::main();
}
37 changes: 12 additions & 25 deletions src/size_of_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,49 @@

use crate::cow_rc_str::CowRcStr;
use crate::tokenizer::Token;
use std::borrow::Cow;

macro_rules! size_of_test {
($testname: ident, $t: ty, $expected_size: expr) => {
($testname: ident, $t: ty, $expected_min_size: expr, $expected_max_size: expr) => {
#[test]
fn $testname() {
let new = ::std::mem::size_of::<$t>();
let old = $expected_size;
if new < old {
if new < $expected_min_size {
panic!(
"Your changes have decreased the stack size of {} from {} to {}. \
Good work! Please update the expected size in {}.",
stringify!($t),
old,
$expected_min_size,
new,
file!()
)
} else if new > old {
} else if new > $expected_max_size {
panic!(
"Your changes have increased the stack size of {} from {} to {}. \
Please consider choosing a design which avoids this increase. \
If you feel that the increase is necessary, update the size in {}.",
stringify!($t),
old,
$expected_max_size,
new,
file!()
)
}
}
};
($testname: ident, $t: ty, $expected_size: expr) => {
size_of_test!($testname, $t, $expected_size, $expected_size);
};
}

// Some of these assume 64-bit
size_of_test!(token, Token, 32);
size_of_test!(std_cow_str, Cow<'static, str>, if cfg!(rustc_has_better_cow_layout) { 24 } else { 32 });
size_of_test!(std_cow_str, std::borrow::Cow<'static, str>, 24, 32);
size_of_test!(cow_rc_str, CowRcStr, 16);

size_of_test!(tokenizer, crate::tokenizer::Tokenizer, 72);
size_of_test!(
parser_input,
crate::parser::ParserInput,
if cfg!(rustc_has_pr45225) { 136 } else { 144 }
);
size_of_test!(parser_input, crate::parser::ParserInput, 136);
size_of_test!(parser, crate::parser::Parser, 16);
size_of_test!(source_position, crate::SourcePosition, 8);
size_of_test!(parser_state, crate::ParserState, 24);

size_of_test!(basic_parse_error, crate::BasicParseError, if cfg!(rustc_has_better_cow_layout) { 40 } else { 48 });
size_of_test!(
parse_error_lower_bound,
crate::ParseError<()>,
if cfg!(rustc_has_better_cow_layout) {
40
} else if cfg!(rustc_has_pr45225) {
48
} else {
56
}
);
size_of_test!(basic_parse_error, crate::BasicParseError, 40, 48);
size_of_test!(parse_error_lower_bound, crate::ParseError<()>, 40, 48);