From c932ca5f1cf62d041c943e5cfdcc1767c0664692 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Thu, 27 Jan 2022 23:34:33 +0300 Subject: [PATCH] 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. --- crates/base_db/src/lib.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/crates/base_db/src/lib.rs b/crates/base_db/src/lib.rs index d80660f7c9a..a4c590cf6d9 100644 --- a/crates/base_db/src/lib.rs +++ b/crates/base_db/src/lib.rs @@ -69,6 +69,21 @@ pub trait SourceDatabase: FileLoader + std::fmt::Debug { /// The crate graph. #[salsa::input] fn crate_graph(&self) -> Arc; + + #[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 { -- 2.44.0