Skip to content

Commit 4fea3e0

Browse files
committed
add goto implementation and rename via SemanticQuery
1 parent 6672a03 commit 4fea3e0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1438
-1442
lines changed

crates/hir-analysis/src/analysis_pass.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,22 @@ impl AnalysisPassManager {
4141
diags
4242
}
4343

44+
/// Stable alternative to run_on_module that uses File as the key.
45+
/// This prevents issues with stale TopLevelMod references during incremental recompilation.
46+
pub fn run_on_file<'db, DB>(
47+
&mut self,
48+
db: &'db DB,
49+
file: common::file::File,
50+
) -> Vec<Box<dyn DiagnosticVoucher + 'db>>
51+
where
52+
DB: HirAnalysisDb + hir::LowerHirDb,
53+
{
54+
// Convert File to fresh TopLevelMod using the stable API
55+
let top_mod = hir::lower::map_file_to_mod(db, file);
56+
// Use the existing analysis logic
57+
self.run_on_module(db, top_mod)
58+
}
59+
4460
pub fn run_on_module_tree<'db>(
4561
&mut self,
4662
db: &'db dyn HirAnalysisDb,

crates/hir-analysis/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ pub trait HirAnalysisDb: HirDb {}
88
#[salsa::db]
99
impl<T> HirAnalysisDb for T where T: HirDb {}
1010

11+
pub mod lookup;
1112
pub mod name_resolution;
1213
pub mod ty;
13-
pub mod lookup;
1414

1515
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1616
pub struct Spanned<'db, T> {

crates/hir-analysis/src/lookup.rs

Lines changed: 190 additions & 95 deletions
Large diffs are not rendered by default.

crates/hir-analysis/src/name_resolution/method_api.rs

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,8 @@
1-
use hir::hir_def::{scope_graph::ScopeId, IdentId};
2-
31
use crate::{
4-
name_resolution::{
5-
method_selection::{select_method_candidate, MethodCandidate},
6-
PathRes,
7-
},
8-
ty::{func_def::FuncDef, trait_resolution::PredicateListId},
9-
HirAnalysisDb,
2+
name_resolution::{method_selection::MethodCandidate, PathRes},
3+
ty::func_def::FuncDef,
104
};
115

12-
/// High-level façade for method lookup. Wraps the low-level selector and
13-
/// provides a stable API for consumers.
14-
/// Returns the function definition of the selected method if resolution succeeds.
15-
pub fn find_method_id<'db>(
16-
db: &'db dyn HirAnalysisDb,
17-
receiver_ty: crate::ty::canonical::Canonical<crate::ty::ty_def::TyId<'db>>,
18-
method_name: IdentId<'db>,
19-
scope: ScopeId<'db>,
20-
assumptions: PredicateListId<'db>,
21-
) -> Option<FuncDef<'db>> {
22-
match select_method_candidate(db, receiver_ty, method_name, scope, assumptions) {
23-
Ok(MethodCandidate::InherentMethod(fd)) => Some(fd),
24-
Ok(MethodCandidate::TraitMethod(tm)) | Ok(MethodCandidate::NeedsConfirmation(tm)) => {
25-
Some(tm.method.0)
26-
}
27-
Err(_) => None,
28-
}
29-
}
30-
316
/// Extract the underlying function definition for a resolved method PathRes.
327
/// Returns None if the PathRes is not a method.
338
pub fn method_func_def_from_res<'db>(

crates/hir-analysis/src/name_resolution/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub use name_resolver::{
2020
// NOTE: `resolve_path` is the low-level resolver that still requires callers to
2121
// pass a boolean domain hint. Prefer `resolve_with_policy` for new call-sites
2222
// to avoid boolean flags at API boundaries.
23-
pub use method_api::{find_method_id, method_func_def_from_res};
23+
pub use method_api::method_func_def_from_res;
2424
pub use path_resolver::{
2525
find_associated_type, resolve_ident_to_bucket, resolve_name_res, resolve_path,
2626
resolve_path_with_observer, PathRes, PathResError, PathResErrorKind, ResolvedVariant,

crates/hir-analysis/src/name_resolution/path_resolver.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use common::indexmap::IndexMap;
22
use either::Either;
33
use hir::{
44
hir_def::{
5-
scope_graph::ScopeId, Body, Enum, EnumVariant, ExprId, GenericParamOwner, IdentId, ImplTrait, ItemKind,
6-
Partial, PathId, PathKind, Trait, TypeBound, TypeId, VariantKind,
5+
scope_graph::ScopeId, Body, Enum, EnumVariant, ExprId, GenericParamOwner, IdentId,
6+
ImplTrait, ItemKind, Partial, PathId, PathKind, Trait, TypeBound, TypeId, VariantKind,
77
},
88
span::DynLazySpan,
99
};

crates/hir-analysis/src/name_resolution/policy.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,3 @@ pub fn resolve_with_policy<'db>(
3535
}
3636
}
3737
}
38-
39-
// Legacy convenience wrapper removed; prefer `resolve_with_policy` directly

crates/hir-analysis/src/ty/def_analysis.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,8 +1525,7 @@ fn find_const_ty_param<'db>(
15251525
scope,
15261526
PredicateListId::empty_list(db),
15271527
DomainPreference::Value,
1528-
)
1529-
else {
1528+
) else {
15301529
return None;
15311530
};
15321531
match ty.data(db) {

crates/hir-analysis/src/ty/trait_resolution/mod.rs

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ use crate::{
1616
};
1717
use common::indexmap::IndexSet;
1818
use constraint::collect_constraints;
19-
use hir::{hir_def::{HirIngot, Func}, Ingot};
19+
use hir::{
20+
hir_def::HirIngot,
21+
Ingot,
22+
};
2023
use salsa::Update;
2124

2225
pub(crate) mod constraint;
2326
mod proof_forest;
2427

25-
2628
#[salsa::tracked(return_ref)]
2729
pub fn is_goal_satisfiable<'db>(
2830
db: &'db dyn HirAnalysisDb,
@@ -38,30 +40,6 @@ pub fn is_goal_satisfiable<'db>(
3840
ProofForest::new(db, ingot, goal, assumptions).solve()
3941
}
4042

41-
/// A minimal, user-facing explanation of trait goal satisfiability.
42-
#[derive(Debug, Clone, PartialEq, Eq)]
43-
pub enum GoalExplanation<'db> {
44-
Success,
45-
ContainsInvalid,
46-
NeedsConfirmation,
47-
Failure { subgoal: Option<super::trait_def::TraitInstId<'db>> },
48-
}
49-
50-
/// Facade: Explain why a goal is (not) satisfiable, reusing existing solver.
51-
pub fn explain_goal<'db>(
52-
db: &'db dyn HirAnalysisDb,
53-
ingot: Ingot<'db>,
54-
goal: Canonical<TraitInstId<'db>>,
55-
assumptions: PredicateListId<'db>,
56-
) -> GoalExplanation<'db> {
57-
match is_goal_satisfiable(db, ingot, goal, assumptions) {
58-
GoalSatisfiability::Satisfied(_) => GoalExplanation::Success,
59-
GoalSatisfiability::ContainsInvalid => GoalExplanation::ContainsInvalid,
60-
GoalSatisfiability::NeedsConfirmation(_) => GoalExplanation::NeedsConfirmation,
61-
GoalSatisfiability::UnSat(sub) => GoalExplanation::Failure { subgoal: sub.map(|s| s.value) },
62-
}
63-
}
64-
6543
/// Checks if the given type is well-formed, i.e., the arguments of the given
6644
/// type applications satisfies the constraints under the given assumptions.
6745
#[salsa::tracked]
@@ -318,13 +296,3 @@ impl<'db> PredicateListId<'db> {
318296
Self::new(db, all_predicates.into_iter().collect::<Vec<_>>())
319297
}
320298
}
321-
322-
/// Public helper: collect full assumptions (constraints) applicable to a function definition,
323-
/// including parent trait/impl bounds when relevant.
324-
pub fn func_assumptions_for_func<'db>(
325-
db: &'db dyn HirAnalysisDb,
326-
func: Func<'db>,
327-
) -> PredicateListId<'db> {
328-
constraint::collect_func_def_constraints(db, super::func_def::HirFuncDefKind::Func(func), true)
329-
.instantiate_identity()
330-
}

crates/hir-analysis/src/ty/ty_check/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ impl<'db> TyChecker<'db> {
446446
ExpectedPathKind::Value
447447
};
448448

449-
if let Some(diag) = err.into_diag(self.db, *path, span.into(), expected_kind) {
449+
if let Some(diag) = err.into_diag(self.db, *path, span, expected_kind) {
450450
self.push_diag(diag)
451451
}
452452
ResolvedPathInBody::Invalid

0 commit comments

Comments
 (0)