Skip to content

Commit

Permalink
Merge pull request rust-lang#19191 from Veykril/push-yzzlosskwrxs
Browse files Browse the repository at this point in the history
Remove `limit` crate in favor `usize`
  • Loading branch information
Veykril authored Feb 23, 2025
2 parents 8a493b1 + a941de4 commit 286595e
Show file tree
Hide file tree
Showing 17 changed files with 23 additions and 131 deletions.
9 changes: 0 additions & 9 deletions src/tools/rust-analyzer/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,6 @@ dependencies = [
"intern",
"itertools",
"la-arena 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"limit",
"mbe",
"ra-ap-rustc_abi",
"ra-ap-rustc_parse_format",
Expand Down Expand Up @@ -591,7 +590,6 @@ dependencies = [
"intern",
"itertools",
"la-arena 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"limit",
"mbe",
"parser",
"rustc-hash 2.0.0",
Expand Down Expand Up @@ -626,7 +624,6 @@ dependencies = [
"intern",
"itertools",
"la-arena 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"limit",
"nohash-hasher",
"oorandom",
"project-model",
Expand Down Expand Up @@ -744,7 +741,6 @@ dependencies = [
"hir",
"indexmap",
"itertools",
"limit",
"line-index 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"memchr",
"nohash-hasher",
Expand Down Expand Up @@ -943,10 +939,6 @@ dependencies = [
"redox_syscall",
]

[[package]]
name = "limit"
version = "0.0.0"

[[package]]
name = "line-index"
version = "0.1.2"
Expand Down Expand Up @@ -1279,7 +1271,6 @@ dependencies = [
"drop_bomb",
"edition",
"expect-test",
"limit",
"ra-ap-rustc_lexer",
"stdx",
"tracing",
Expand Down
1 change: 0 additions & 1 deletion src/tools/rust-analyzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ ide-db = { path = "./crates/ide-db", version = "0.0.0" }
ide-diagnostics = { path = "./crates/ide-diagnostics", version = "0.0.0" }
ide-ssr = { path = "./crates/ide-ssr", version = "0.0.0" }
intern = { path = "./crates/intern", version = "0.0.0" }
limit = { path = "./crates/limit", version = "0.0.0" }
load-cargo = { path = "./crates/load-cargo", version = "0.0.0" }
mbe = { path = "./crates/mbe", version = "0.0.0" }
parser = { path = "./crates/parser", version = "0.0.0" }
Expand Down
1 change: 0 additions & 1 deletion src/tools/rust-analyzer/crates/hir-def/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ hir-expand.workspace = true
mbe.workspace = true
cfg.workspace = true
tt.workspace = true
limit.workspace = true
span.workspace = true


Expand Down
9 changes: 4 additions & 5 deletions src/tools/rust-analyzer/crates/hir-def/src/expander.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use hir_expand::{
attrs::RawAttrs, mod_path::ModPath, span_map::SpanMap, ExpandError, ExpandErrorKind,
ExpandResult, HirFileId, InFile, Lookup, MacroCallId,
};
use limit::Limit;
use span::{Edition, SyntaxContextId};
use syntax::{ast, Parse};
use triomphe::Arc;
Expand All @@ -28,18 +27,18 @@ pub struct Expander {
pub(crate) module: ModuleId,
/// `recursion_depth == usize::MAX` indicates that the recursion limit has been reached.
recursion_depth: u32,
recursion_limit: Limit,
recursion_limit: usize,
}

impl Expander {
pub fn new(db: &dyn DefDatabase, current_file_id: HirFileId, module: ModuleId) -> Expander {
let recursion_limit = module.def_map(db).recursion_limit() as usize;
let recursion_limit = Limit::new(if cfg!(test) {
let recursion_limit = if cfg!(test) {
// Without this, `body::tests::your_stack_belongs_to_me` stack-overflows in debug
std::cmp::min(32, recursion_limit)
} else {
recursion_limit
});
};
Expander {
current_file_id,
module,
Expand Down Expand Up @@ -194,7 +193,7 @@ impl Expander {
let Some(call_id) = value else {
return ExpandResult { value: None, err };
};
if self.recursion_limit.check(self.recursion_depth as usize + 1).is_err() {
if self.recursion_depth as usize > self.recursion_limit {
self.recursion_depth = u32::MAX;
cov_mark::hit!(your_stack_belongs_to_me);
return ExpandResult::only_err(ExpandError::new(
Expand Down
13 changes: 5 additions & 8 deletions src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use hir_expand::{
use intern::{sym, Interned};
use itertools::{izip, Itertools};
use la_arena::Idx;
use limit::Limit;
use rustc_hash::{FxHashMap, FxHashSet};
use span::{Edition, EditionedFileId, FileAstId, SyntaxContextId};
use syntax::ast;
Expand Down Expand Up @@ -55,8 +54,8 @@ use crate::{
UnresolvedMacro, UseId, UseLoc,
};

static GLOB_RECURSION_LIMIT: Limit = Limit::new(100);
static FIXED_POINT_LIMIT: Limit = Limit::new(8192);
const GLOB_RECURSION_LIMIT: usize = 100;
const FIXED_POINT_LIMIT: usize = 8192;

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

i += 1;
if FIXED_POINT_LIMIT.check(i).is_err() {
if i > FIXED_POINT_LIMIT {
tracing::error!("name resolution is stuck");
break 'resolve_attr;
}
Expand Down Expand Up @@ -993,7 +992,7 @@ impl DefCollector<'_> {
import: Option<ImportOrExternCrate>,
depth: usize,
) {
if GLOB_RECURSION_LIMIT.check(depth).is_err() {
if depth > GLOB_RECURSION_LIMIT {
// prevent stack overflows (but this shouldn't be possible)
panic!("infinite recursion in glob imports!");
}
Expand Down Expand Up @@ -1470,8 +1469,7 @@ impl DefCollector<'_> {
depth: usize,
container: ItemContainerId,
) {
let recursion_limit = Limit::new(self.def_map.recursion_limit() as usize);
if recursion_limit.check(depth).is_err() {
if depth > self.def_map.recursion_limit() as usize {
cov_mark::hit!(macro_expansion_overflow);
tracing::warn!("macro expansion is too deep");
return;
Expand Down Expand Up @@ -1499,7 +1497,6 @@ impl DefCollector<'_> {

fn finish(mut self) -> DefMap {
// Emit diagnostics for all remaining unexpanded macros.

let _p = tracing::info_span!("DefCollector::finish").entered();

for directive in &self.unresolved_macros {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
use arrayvec::ArrayVec;
use base_db::AnchoredPath;
use hir_expand::{name::Name, HirFileIdExt};
use limit::Limit;
use span::EditionedFileId;

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

static MOD_DEPTH_LIMIT: Limit = Limit::new(32);
const MOD_DEPTH_LIMIT: usize = 32;

#[derive(Clone, Debug)]
pub(super) struct ModDir {
Expand Down Expand Up @@ -50,7 +49,7 @@ impl ModDir {

fn child(&self, dir_path: DirPath, root_non_dir_owner: bool) -> Option<ModDir> {
let depth = self.depth + 1;
if MOD_DEPTH_LIMIT.check(depth as usize).is_err() {
if depth as usize > MOD_DEPTH_LIMIT {
tracing::error!("MOD_DEPTH_LIMIT exceeded");
cov_mark::hit!(circular_mods);
return None;
Expand Down
1 change: 0 additions & 1 deletion src/tools/rust-analyzer/crates/hir-expand/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ cfg.workspace = true
syntax.workspace = true
tt.workspace = true
mbe.workspace = true
limit.workspace = true
span.workspace = true
parser.workspace = true
syntax-bridge.workspace = true
Expand Down
12 changes: 5 additions & 7 deletions src/tools/rust-analyzer/crates/hir-expand/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
use base_db::{ra_salsa, CrateId, SourceDatabase};
use either::Either;
use limit::Limit;
use mbe::MatchedArmIndex;
use rustc_hash::FxHashSet;
use span::{AstIdMap, Edition, EditionedFileId, Span, SyntaxContextData, SyntaxContextId};
Expand Down Expand Up @@ -35,7 +34,7 @@ type MacroArgResult = (Arc<tt::TopSubtree>, SyntaxFixupUndoInfo, Span);
/// an error will be emitted.
///
/// Actual max for `analysis-stats .` at some point: 30672.
static TOKEN_LIMIT: Limit = Limit::new(2_097_152);
const TOKEN_LIMIT: usize = 2_097_152;

#[derive(Debug, Clone, Eq, PartialEq)]
pub enum TokenExpander {
Expand Down Expand Up @@ -740,20 +739,19 @@ pub(crate) fn token_tree_to_syntax_node(
fn check_tt_count(tt: &tt::TopSubtree) -> Result<(), ExpandResult<()>> {
let tt = tt.top_subtree();
let count = tt.count();
if TOKEN_LIMIT.check(count).is_err() {
if count <= TOKEN_LIMIT {
Ok(())
} else {
Err(ExpandResult {
value: (),
err: Some(ExpandError::other(
tt.delimiter.open,
format!(
"macro invocation exceeds token limit: produced {} tokens, limit is {}",
count,
TOKEN_LIMIT.inner(),
count, TOKEN_LIMIT,
),
)),
})
} else {
Ok(())
}
}

Expand Down
1 change: 0 additions & 1 deletion src/tools/rust-analyzer/crates/hir-ty/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ hir-def.workspace = true
hir-expand.workspace = true
base-db.workspace = true
syntax.workspace = true
limit.workspace = true
span.workspace = true

[dev-dependencies]
Expand Down
5 changes: 2 additions & 3 deletions src/tools/rust-analyzer/crates/hir-ty/src/autoderef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ use chalk_ir::cast::Cast;
use hir_def::lang_item::LangItem;
use hir_expand::name::Name;
use intern::sym;
use limit::Limit;
use triomphe::Arc;

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

static AUTODEREF_RECURSION_LIMIT: Limit = Limit::new(20);
const AUTODEREF_RECURSION_LIMIT: usize = 20;

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

if AUTODEREF_RECURSION_LIMIT.check(self.steps.len() + 1).is_err() {
if self.steps.len() > AUTODEREF_RECURSION_LIMIT {
return None;
}

Expand Down
1 change: 0 additions & 1 deletion src/tools/rust-analyzer/crates/ide-db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ bitflags.workspace = true

# local deps
base-db.workspace = true
limit.workspace = true
parser.workspace = true
profile.workspace = true
stdx.workspace = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ fn path_applicable_imports(
let mod_path = mod_path(item)?;
Some(LocatedImport::new(mod_path, item, item))
})
.take(DEFAULT_QUERY_SEARCH_LIMIT.inner())
.take(DEFAULT_QUERY_SEARCH_LIMIT)
.collect()
}
// we have some unresolved qualifier that we search an import for
Expand All @@ -383,7 +383,7 @@ fn path_applicable_imports(
qualifier_rest,
)
})
.take(DEFAULT_QUERY_SEARCH_LIMIT.inner())
.take(DEFAULT_QUERY_SEARCH_LIMIT)
.collect(),
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/tools/rust-analyzer/crates/ide-db/src/items_locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use std::ops::ControlFlow;

use either::Either;
use hir::{import_map, Crate, ItemInNs, Module, Semantics};
use limit::Limit;

use crate::{
imports::import_assets::NameToImport,
Expand All @@ -15,7 +14,7 @@ use crate::{
};

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

pub use import_map::AssocSearchMode;

Expand Down
16 changes: 0 additions & 16 deletions src/tools/rust-analyzer/crates/limit/Cargo.toml

This file was deleted.

67 changes: 0 additions & 67 deletions src/tools/rust-analyzer/crates/limit/src/lib.rs

This file was deleted.

Loading

0 comments on commit 286595e

Please sign in to comment.