Skip to content

Commit 6d68c47

Browse files
authoredFeb 23, 2025··
Merge pull request #19191 from Veykril/push-yzzlosskwrxs
Remove `limit` crate in favor `usize`
2 parents 83ff2c9 + 0b2e816 commit 6d68c47

File tree

17 files changed

+23
-131
lines changed

17 files changed

+23
-131
lines changed
 

‎Cargo.lock

-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ ide-db = { path = "./crates/ide-db", version = "0.0.0" }
6464
ide-diagnostics = { path = "./crates/ide-diagnostics", version = "0.0.0" }
6565
ide-ssr = { path = "./crates/ide-ssr", version = "0.0.0" }
6666
intern = { path = "./crates/intern", version = "0.0.0" }
67-
limit = { path = "./crates/limit", version = "0.0.0" }
6867
load-cargo = { path = "./crates/load-cargo", version = "0.0.0" }
6968
mbe = { path = "./crates/mbe", version = "0.0.0" }
7069
parser = { path = "./crates/parser", version = "0.0.0" }

‎crates/hir-def/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ hir-expand.workspace = true
4343
mbe.workspace = true
4444
cfg.workspace = true
4545
tt.workspace = true
46-
limit.workspace = true
4746
span.workspace = true
4847

4948

‎crates/hir-def/src/expander.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use hir_expand::{
99
attrs::RawAttrs, mod_path::ModPath, span_map::SpanMap, ExpandError, ExpandErrorKind,
1010
ExpandResult, HirFileId, InFile, Lookup, MacroCallId,
1111
};
12-
use limit::Limit;
1312
use span::{Edition, SyntaxContextId};
1413
use syntax::{ast, Parse};
1514
use triomphe::Arc;
@@ -28,18 +27,18 @@ pub struct Expander {
2827
pub(crate) module: ModuleId,
2928
/// `recursion_depth == usize::MAX` indicates that the recursion limit has been reached.
3029
recursion_depth: u32,
31-
recursion_limit: Limit,
30+
recursion_limit: usize,
3231
}
3332

3433
impl Expander {
3534
pub fn new(db: &dyn DefDatabase, current_file_id: HirFileId, module: ModuleId) -> Expander {
3635
let recursion_limit = module.def_map(db).recursion_limit() as usize;
37-
let recursion_limit = Limit::new(if cfg!(test) {
36+
let recursion_limit = if cfg!(test) {
3837
// Without this, `body::tests::your_stack_belongs_to_me` stack-overflows in debug
3938
std::cmp::min(32, recursion_limit)
4039
} else {
4140
recursion_limit
42-
});
41+
};
4342
Expander {
4443
current_file_id,
4544
module,
@@ -194,7 +193,7 @@ impl Expander {
194193
let Some(call_id) = value else {
195194
return ExpandResult { value: None, err };
196195
};
197-
if self.recursion_limit.check(self.recursion_depth as usize + 1).is_err() {
196+
if self.recursion_depth as usize > self.recursion_limit {
198197
self.recursion_depth = u32::MAX;
199198
cov_mark::hit!(your_stack_belongs_to_me);
200199
return ExpandResult::only_err(ExpandError::new(

‎crates/hir-def/src/nameres/collector.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use hir_expand::{
1919
use intern::{sym, Interned};
2020
use itertools::{izip, Itertools};
2121
use la_arena::Idx;
22-
use limit::Limit;
2322
use rustc_hash::{FxHashMap, FxHashSet};
2423
use span::{Edition, EditionedFileId, FileAstId, SyntaxContextId};
2524
use syntax::ast;
@@ -55,8 +54,8 @@ use crate::{
5554
UnresolvedMacro, UseId, UseLoc,
5655
};
5756

58-
static GLOB_RECURSION_LIMIT: Limit = Limit::new(100);
59-
static FIXED_POINT_LIMIT: Limit = Limit::new(8192);
57+
const GLOB_RECURSION_LIMIT: usize = 100;
58+
const FIXED_POINT_LIMIT: usize = 8192;
6059

6160
pub(super) fn collect_defs(db: &dyn DefDatabase, def_map: DefMap, tree_id: TreeId) -> DefMap {
6261
let crate_graph = db.crate_graph();
@@ -393,7 +392,7 @@ impl DefCollector<'_> {
393392
}
394393

395394
i += 1;
396-
if FIXED_POINT_LIMIT.check(i).is_err() {
395+
if i > FIXED_POINT_LIMIT {
397396
tracing::error!("name resolution is stuck");
398397
break 'resolve_attr;
399398
}
@@ -993,7 +992,7 @@ impl DefCollector<'_> {
993992
import: Option<ImportOrExternCrate>,
994993
depth: usize,
995994
) {
996-
if GLOB_RECURSION_LIMIT.check(depth).is_err() {
995+
if depth > GLOB_RECURSION_LIMIT {
997996
// prevent stack overflows (but this shouldn't be possible)
998997
panic!("infinite recursion in glob imports!");
999998
}
@@ -1470,8 +1469,7 @@ impl DefCollector<'_> {
14701469
depth: usize,
14711470
container: ItemContainerId,
14721471
) {
1473-
let recursion_limit = Limit::new(self.def_map.recursion_limit() as usize);
1474-
if recursion_limit.check(depth).is_err() {
1472+
if depth > self.def_map.recursion_limit() as usize {
14751473
cov_mark::hit!(macro_expansion_overflow);
14761474
tracing::warn!("macro expansion is too deep");
14771475
return;
@@ -1499,7 +1497,6 @@ impl DefCollector<'_> {
14991497

15001498
fn finish(mut self) -> DefMap {
15011499
// Emit diagnostics for all remaining unexpanded macros.
1502-
15031500
let _p = tracing::info_span!("DefCollector::finish").entered();
15041501

15051502
for directive in &self.unresolved_macros {

‎crates/hir-def/src/nameres/mod_resolution.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
use arrayvec::ArrayVec;
33
use base_db::AnchoredPath;
44
use hir_expand::{name::Name, HirFileIdExt};
5-
use limit::Limit;
65
use span::EditionedFileId;
76

87
use crate::{db::DefDatabase, HirFileId};
98

10-
static MOD_DEPTH_LIMIT: Limit = Limit::new(32);
9+
const MOD_DEPTH_LIMIT: usize = 32;
1110

1211
#[derive(Clone, Debug)]
1312
pub(super) struct ModDir {
@@ -50,7 +49,7 @@ impl ModDir {
5049

5150
fn child(&self, dir_path: DirPath, root_non_dir_owner: bool) -> Option<ModDir> {
5251
let depth = self.depth + 1;
53-
if MOD_DEPTH_LIMIT.check(depth as usize).is_err() {
52+
if depth as usize > MOD_DEPTH_LIMIT {
5453
tracing::error!("MOD_DEPTH_LIMIT exceeded");
5554
cov_mark::hit!(circular_mods);
5655
return None;

‎crates/hir-expand/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ cfg.workspace = true
3131
syntax.workspace = true
3232
tt.workspace = true
3333
mbe.workspace = true
34-
limit.workspace = true
3534
span.workspace = true
3635
parser.workspace = true
3736
syntax-bridge.workspace = true

‎crates/hir-expand/src/db.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
33
use base_db::{ra_salsa, CrateId, SourceDatabase};
44
use either::Either;
5-
use limit::Limit;
65
use mbe::MatchedArmIndex;
76
use rustc_hash::FxHashSet;
87
use span::{AstIdMap, Edition, EditionedFileId, Span, SyntaxContextData, SyntaxContextId};
@@ -35,7 +34,7 @@ type MacroArgResult = (Arc<tt::TopSubtree>, SyntaxFixupUndoInfo, Span);
3534
/// an error will be emitted.
3635
///
3736
/// Actual max for `analysis-stats .` at some point: 30672.
38-
static TOKEN_LIMIT: Limit = Limit::new(2_097_152);
37+
const TOKEN_LIMIT: usize = 2_097_152;
3938

4039
#[derive(Debug, Clone, Eq, PartialEq)]
4140
pub enum TokenExpander {
@@ -740,20 +739,19 @@ pub(crate) fn token_tree_to_syntax_node(
740739
fn check_tt_count(tt: &tt::TopSubtree) -> Result<(), ExpandResult<()>> {
741740
let tt = tt.top_subtree();
742741
let count = tt.count();
743-
if TOKEN_LIMIT.check(count).is_err() {
742+
if count <= TOKEN_LIMIT {
743+
Ok(())
744+
} else {
744745
Err(ExpandResult {
745746
value: (),
746747
err: Some(ExpandError::other(
747748
tt.delimiter.open,
748749
format!(
749750
"macro invocation exceeds token limit: produced {} tokens, limit is {}",
750-
count,
751-
TOKEN_LIMIT.inner(),
751+
count, TOKEN_LIMIT,
752752
),
753753
)),
754754
})
755-
} else {
756-
Ok(())
757755
}
758756
}
759757

‎crates/hir-ty/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ hir-def.workspace = true
4747
hir-expand.workspace = true
4848
base-db.workspace = true
4949
syntax.workspace = true
50-
limit.workspace = true
5150
span.workspace = true
5251

5352
[dev-dependencies]

‎crates/hir-ty/src/autoderef.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@ use chalk_ir::cast::Cast;
99
use hir_def::lang_item::LangItem;
1010
use hir_expand::name::Name;
1111
use intern::sym;
12-
use limit::Limit;
1312
use triomphe::Arc;
1413

1514
use crate::{
1615
db::HirDatabase, infer::unify::InferenceTable, Canonical, Goal, Interner, ProjectionTyExt,
1716
TraitEnvironment, Ty, TyBuilder, TyKind,
1817
};
1918

20-
static AUTODEREF_RECURSION_LIMIT: Limit = Limit::new(20);
19+
const AUTODEREF_RECURSION_LIMIT: usize = 20;
2120

2221
#[derive(Debug)]
2322
pub(crate) enum AutoderefKind {
@@ -140,7 +139,7 @@ impl<T: TrackAutoderefSteps> Iterator for Autoderef<'_, '_, T> {
140139
return Some((self.ty.clone(), 0));
141140
}
142141

143-
if AUTODEREF_RECURSION_LIMIT.check(self.steps.len() + 1).is_err() {
142+
if self.steps.len() > AUTODEREF_RECURSION_LIMIT {
144143
return None;
145144
}
146145

‎crates/ide-db/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ bitflags.workspace = true
3030

3131
# local deps
3232
base-db.workspace = true
33-
limit.workspace = true
3433
parser.workspace = true
3534
profile.workspace = true
3635
stdx.workspace = true

‎crates/ide-db/src/imports/import_assets.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ fn path_applicable_imports(
357357
let mod_path = mod_path(item)?;
358358
Some(LocatedImport::new(mod_path, item, item))
359359
})
360-
.take(DEFAULT_QUERY_SEARCH_LIMIT.inner())
360+
.take(DEFAULT_QUERY_SEARCH_LIMIT)
361361
.collect()
362362
}
363363
// we have some unresolved qualifier that we search an import for
@@ -383,7 +383,7 @@ fn path_applicable_imports(
383383
qualifier_rest,
384384
)
385385
})
386-
.take(DEFAULT_QUERY_SEARCH_LIMIT.inner())
386+
.take(DEFAULT_QUERY_SEARCH_LIMIT)
387387
.collect(),
388388
}
389389
}

‎crates/ide-db/src/items_locator.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use std::ops::ControlFlow;
66

77
use either::Either;
88
use hir::{import_map, Crate, ItemInNs, Module, Semantics};
9-
use limit::Limit;
109

1110
use crate::{
1211
imports::import_assets::NameToImport,
@@ -15,7 +14,7 @@ use crate::{
1514
};
1615

1716
/// A value to use, when uncertain which limit to pick.
18-
pub static DEFAULT_QUERY_SEARCH_LIMIT: Limit = Limit::new(100);
17+
pub const DEFAULT_QUERY_SEARCH_LIMIT: usize = 100;
1918

2019
pub use import_map::AssocSearchMode;
2120

‎crates/limit/Cargo.toml

-16
This file was deleted.

‎crates/limit/src/lib.rs

-67
This file was deleted.

‎crates/parser/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ doctest = false
1515
[dependencies]
1616
drop_bomb = "0.1.5"
1717
ra-ap-rustc_lexer.workspace = true
18-
limit.workspace = true
1918
tracing = { workspace = true, optional = true }
2019

2120
edition.workspace = true

‎crates/parser/src/parser.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
use std::cell::Cell;
44

55
use drop_bomb::DropBomb;
6-
use limit::Limit;
76

87
use crate::{
98
event::Event,
@@ -30,7 +29,7 @@ pub(crate) struct Parser<'t> {
3029
edition: Edition,
3130
}
3231

33-
static PARSER_STEP_LIMIT: Limit = Limit::new(15_000_000);
32+
const PARSER_STEP_LIMIT: usize = 15_000_000;
3433

3534
impl<'t> Parser<'t> {
3635
pub(super) fn new(inp: &'t Input, edition: Edition) -> Parser<'t> {
@@ -54,7 +53,7 @@ impl<'t> Parser<'t> {
5453
assert!(n <= 3);
5554

5655
let steps = self.steps.get();
57-
assert!(PARSER_STEP_LIMIT.check(steps as usize).is_ok(), "the parser seems stuck");
56+
assert!((steps as usize) < PARSER_STEP_LIMIT, "the parser seems stuck");
5857
self.steps.set(steps + 1);
5958

6059
self.inp.kind(self.pos + n)

0 commit comments

Comments
 (0)
Please sign in to comment.