Files
rust/src/librustc/middle/recursion_limit.rs

34 lines
1.0 KiB
Rust
Raw Normal View History

// Recursion limit.
//
// There are various parts of the compiler that must impose arbitrary limits
// on how deeply they recurse to prevent stack overflow. Users can override
// this via an attribute on the crate like `#![recursion_limit="22"]`. This pass
// just peeks and looks for that attribute.
2019-02-05 11:20:45 -06:00
use crate::session::Session;
use syntax::ast;
2019-12-22 17:42:04 -05:00
use syntax::symbol::{sym, Symbol};
use rustc_data_structures::sync::Once;
pub fn update_limits(sess: &Session, krate: &ast::Crate) {
update_limit(krate, &sess.recursion_limit, sym::recursion_limit, 128);
update_limit(krate, &sess.type_length_limit, sym::type_length_limit, 1048576);
}
fn update_limit(krate: &ast::Crate, limit: &Once<usize>, name: Symbol, default: usize) {
2015-01-31 12:20:46 -05:00
for attr in &krate.attrs {
if !attr.check_name(name) {
continue;
}
if let Some(s) = attr.value_str() {
if let Some(n) = s.as_str().parse().ok() {
limit.set(n);
return;
}
}
}
limit.set(default);
}