Skip to content

Commit 12d52a7

Browse files
committed
Demonstrate excessive stack usage
Use this to run the test: cargo test --package ra_hir_ty --lib --release -- \ tests::regression::your_stack_belongs_to_me --exact --nocapture You can uncomment more branches to see the effect on stack usage. It seems that we use Sum(branches) in debug, and Max(branches) in release (as measured by the final depth before SO).
1 parent c884ceb commit 12d52a7

File tree

3 files changed

+410
-369
lines changed

3 files changed

+410
-369
lines changed

crates/ra_hir_def/src/body.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
11
//! Defines `Body`: a lowered representation of bodies of functions, statics and
22
//! consts.
3+
4+
pub(crate) static STACK: AtomicUsize = AtomicUsize::new(0);
5+
6+
macro_rules! stack {
7+
($name:literal) => {
8+
let anchor = 92;
9+
let addr = &anchor as *const _ as usize;
10+
let prev = crate::body::STACK.swap(addr, std::sync::atomic::Ordering::Relaxed);
11+
let diff = prev.saturating_sub(addr);
12+
eprintln!("{:10} {}", $name, diff / std::mem::size_of::<usize>());
13+
};
14+
}
15+
316
mod lower;
417
pub mod scope;
518

6-
use std::{mem, ops::Index, sync::Arc};
19+
use std::{
20+
mem,
21+
ops::Index,
22+
sync::{atomic::AtomicUsize, Arc},
23+
};
724

825
use drop_bomb::DropBomb;
926
use either::Either;
@@ -91,6 +108,7 @@ impl Expander {
91108
local_scope: Option<&ItemScope>,
92109
macro_call: ast::MacroCall,
93110
) -> Option<(Mark, T)> {
111+
eprintln!("{:?}", self.recursive_limit);
94112
if self.recursive_limit > 1024 {
95113
return None;
96114
}

0 commit comments

Comments
 (0)