Add crate_limits query to SourceDatabase

This allows fetching crate limits like `recursion_limit`. The
implementation is currently dummy and just returns the defaults.

Future work: Use this query instead of the hardcoded constant.

Future work: Actually implement this query by parsing
`#![recursion_limit = N]` attribute.
This commit is contained in:
Maybe Waffle 2022-01-27 23:34:33 +03:00
parent 93036aa0e2
commit c932ca5f1c

View File

@ -69,6 +69,21 @@ pub trait SourceDatabase: FileLoader + std::fmt::Debug {
/// The crate graph.
#[salsa::input]
fn crate_graph(&self) -> Arc<CrateGraph>;
#[salsa::transparent]
fn crate_limits(&self, crate_id: CrateId) -> CrateLimits;
}
pub struct CrateLimits {
/// The maximum depth for potentially infinitely-recursive compile-time operations like macro expansion or auto-dereference.
pub recursion_limit: u32,
}
fn crate_limits(_db: &dyn SourceDatabase, _crate_id: CrateId) -> CrateLimits {
CrateLimits {
// 128 is the default in rustc.
recursion_limit: 128,
}
}
fn parse_query(db: &dyn SourceDatabase, file_id: FileId) -> Parse<ast::SourceFile> {