Skip to content

Commit

Permalink
Try to ease the Rust compiler's pain
Browse files Browse the repository at this point in the history
We apparently blew the stack on Emscripten during emulation so let's try to cut
down on the pain by running at most 1000 tests in one function, hopefully
reducing stack size
  • Loading branch information
alexcrichton committed Aug 27, 2017
1 parent f4e0e2f commit 4447cfb
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,7 @@ impl<'a> Generator<'a> {

self.tests.push(format!("field_offset_size_{}", ty));
t!(writeln!(self.rust, r#"
#[inline(never)]
fn field_offset_size_{ty}() {{
"#, ty = ty));
for field in s.fields() {
Expand Down Expand Up @@ -973,6 +974,7 @@ impl<'a> Generator<'a> {
uint64_t __test_align_{ty}(void) {{ return {align_of}({cty}); }}
"#, ty = rust, cty = c, align_of = align_of));
t!(writeln!(self.rust, r#"
#[inline(never)]
fn size_align_{ty}() {{
extern {{
fn __test_size_{ty}() -> u64;
Expand Down Expand Up @@ -1003,6 +1005,7 @@ impl<'a> Generator<'a> {
}}
"#, ty = rust, cty = c));
t!(writeln!(self.rust, r#"
#[inline(never)]
fn sign_{ty}() {{
extern {{
fn __test_signed_{ty}() -> u32;
Expand Down Expand Up @@ -1049,6 +1052,7 @@ impl<'a> Generator<'a> {

if rust_ty == "&str" {
t!(writeln!(self.rust, r#"
#[inline(never)]
fn const_{name}() {{
extern {{
fn __test_const_{name}() -> *const *const u8;
Expand Down Expand Up @@ -1105,6 +1109,7 @@ impl<'a> Generator<'a> {
}}
"#, name = name, cname = cname, args = args, ret = cret, abi = abi));
t!(writeln!(self.rust, r#"
#[inline(never)]
fn fn_{name}() {{
extern {{
fn __test_fn_{name}() -> *mut u32;
Expand Down Expand Up @@ -1331,10 +1336,27 @@ impl<'a> Generator<'a> {
}

fn emit_run_all(&mut self) {
const N: usize = 1000;
let mut n = 0;
let mut tests = self.tests.clone();
while tests.len() > N {
let name = format!("run_group{}", n);
n += 1;
t!(writeln!(self.rust, "
#[inline(never)]
fn {}() {{
", name));
for test in tests.drain(..1000) {
t!(writeln!(self.rust, "{}();", test));
}
t!(writeln!(self.rust, "}}"));
tests.push(name);
}
t!(writeln!(self.rust, "
#[inline(never)]
fn run_all() {{
"));
for test in self.tests.iter() {
for test in tests.iter() {
t!(writeln!(self.rust, "{}();", test));
}
t!(writeln!(self.rust, "
Expand Down

0 comments on commit 4447cfb

Please sign in to comment.