remove FnId

This commit is contained in:
Aleksey Kladov 2018-12-27 23:51:44 +03:00
parent efb63a7666
commit dddbac6877
7 changed files with 26 additions and 45 deletions

10
Cargo.lock generated
View File

@ -688,7 +688,7 @@ dependencies = [
"rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"salsa 0.8.0 (git+https://github.com/matklad/salsa?branch=no-upgrade)",
"salsa 0.8.0 (git+https://github.com/matklad/salsa?branch=fix-cancelation-maybe)",
"test_utils 0.1.0",
]
@ -714,7 +714,7 @@ dependencies = [
"ra_syntax 0.1.0",
"relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"salsa 0.8.0 (git+https://github.com/matklad/salsa?branch=no-upgrade)",
"salsa 0.8.0 (git+https://github.com/matklad/salsa?branch=fix-cancelation-maybe)",
"test_utils 0.1.0",
]
@ -746,7 +746,7 @@ dependencies = [
"ra_syntax 0.1.0",
"relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"salsa 0.8.0 (git+https://github.com/matklad/salsa?branch=no-upgrade)",
"salsa 0.8.0 (git+https://github.com/matklad/salsa?branch=fix-cancelation-maybe)",
"test_utils 0.1.0",
]
@ -1050,7 +1050,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "salsa"
version = "0.8.0"
source = "git+https://github.com/matklad/salsa?branch=no-upgrade#1a7ae719af1601fda81186fb48bd100edd9cfb7f"
source = "git+https://github.com/matklad/salsa?branch=fix-cancelation-maybe#9f15af718f58c76a1280d457a113106baf7c20c5"
dependencies = [
"derive-new 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
"indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1621,7 +1621,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum rusty-fork 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9591f190d2852720b679c21f66ad929f9f1d7bb09d1193c26167586029d8489c"
"checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7"
"checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9"
"checksum salsa 0.8.0 (git+https://github.com/matklad/salsa?branch=no-upgrade)" = "<none>"
"checksum salsa 0.8.0 (git+https://github.com/matklad/salsa?branch=fix-cancelation-maybe)" = "<none>"
"checksum same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8f20c4be53a8a1ff4c1f1b2bd14570d2f634628709752f0702ecdd2b3f9a5267"
"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27"
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"

View File

@ -91,7 +91,6 @@ impl hir::db::HirDatabase {
fn file_item() for hir::db::FileItemQuery;
fn input_module_items() for hir::db::InputModuleItemsQuery;
fn item_map() for hir::db::ItemMapQuery;
fn fn_syntax() for hir::db::FnSyntaxQuery;
fn submodules() for hir::db::SubmodulesQuery;
fn infer() for hir::db::InferQuery;
fn type_for_def() for hir::db::TypeForDefQuery;

View File

@ -122,9 +122,6 @@ fn gc_syntax_trees(&mut self) {
self.db
.query(ra_db::SourceFileQuery)
.sweep(salsa::SweepStrategy::default().discard_values());
self.db
.query(hir::db::FnSyntaxQuery)
.sweep(salsa::SweepStrategy::default().discard_values());
self.db
.query(hir::db::SourceFileItemsQuery)
.sweep(salsa::SweepStrategy::default().discard_values());

View File

@ -3,7 +3,6 @@
use ra_syntax::{
SmolStr,
SyntaxNode,
ast::FnDefNode,
};
use ra_db::{SourceRootId, LocationIntener, SyntaxDatabase, FileId, Cancelable};
@ -12,7 +11,6 @@
SourceFileItems, SourceItemId,
query_definitions,
FnScopes,
function::FnId,
module::{ModuleId, ModuleTree, ModuleSource,
nameres::{ItemMap, InputModuleItems}},
ty::{InferenceResult, Ty},
@ -24,14 +22,10 @@
pub trait HirDatabase: SyntaxDatabase
+ AsRef<LocationIntener<DefLoc, DefId>>
{
fn fn_scopes(fn_id: FnId) -> Arc<FnScopes> {
fn fn_scopes(def_id: DefId) -> Arc<FnScopes> {
type FnScopesQuery;
use fn query_definitions::fn_scopes;
}
fn fn_syntax(fn_id: FnId) -> FnDefNode {
type FnSyntaxQuery;
use fn query_definitions::fn_syntax;
}
fn struct_data(def_id: DefId) -> Cancelable<Arc<StructData>> {
type StructDataQuery;
@ -43,7 +37,7 @@ fn enum_data(def_id: DefId) -> Cancelable<Arc<EnumData>> {
use fn query_definitions::enum_data;
}
fn infer(fn_id: FnId) -> Cancelable<Arc<InferenceResult>> {
fn infer(def_id: DefId) -> Cancelable<Arc<InferenceResult>> {
type InferQuery;
use fn query_definitions::infer;
}

View File

@ -11,43 +11,42 @@
ast::{self, AstNode, DocCommentsOwner, NameOwner},
};
use crate::{ DefId, HirDatabase, ty::InferenceResult, Module };
use crate::{DefId, DefKind, HirDatabase, ty::InferenceResult, Module};
pub use self::scope::FnScopes;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct FnId(pub(crate) DefId);
#[derive(Debug)]
pub struct Function {
pub(crate) fn_id: FnId,
def_id: DefId,
}
impl Function {
pub(crate) fn new(def_id: DefId) -> Function {
let fn_id = FnId(def_id);
Function { fn_id }
Function { def_id }
}
pub fn syntax(&self, db: &impl HirDatabase) -> ast::FnDefNode {
db.fn_syntax(self.fn_id)
let def_loc = self.def_id.loc(db);
assert!(def_loc.kind == DefKind::Function);
let syntax = db.file_item(def_loc.source_item_id);
ast::FnDef::cast(syntax.borrowed()).unwrap().owned()
}
pub fn scopes(&self, db: &impl HirDatabase) -> Arc<FnScopes> {
db.fn_scopes(self.fn_id)
db.fn_scopes(self.def_id)
}
pub fn signature_info(&self, db: &impl HirDatabase) -> Option<FnSignatureInfo> {
let syntax = db.fn_syntax(self.fn_id);
let syntax = self.syntax(db);
FnSignatureInfo::new(syntax.borrowed())
}
pub fn infer(&self, db: &impl HirDatabase) -> Cancelable<Arc<InferenceResult>> {
db.infer(self.fn_id)
db.infer(self.def_id)
}
pub fn module(&self, db: &impl HirDatabase) -> Cancelable<Module> {
self.fn_id.0.module(db)
self.def_id.module(db)
}
}

View File

@ -189,7 +189,6 @@ impl db::HirDatabase {
fn file_item() for db::FileItemQuery;
fn input_module_items() for db::InputModuleItemsQuery;
fn item_map() for db::ItemMapQuery;
fn fn_syntax() for db::FnSyntaxQuery;
fn submodules() for db::SubmodulesQuery;
fn infer() for db::InferQuery;
fn type_for_def() for db::TypeForDefQuery;

View File

@ -5,15 +5,15 @@
use rustc_hash::FxHashMap;
use ra_syntax::{
AstNode, SyntaxNode, SmolStr,
ast::{self, FnDef, FnDefNode, NameOwner, ModuleItemOwner}
AstNode, SyntaxNode, SmolStr,
ast::{self, NameOwner, ModuleItemOwner}
};
use ra_db::{SourceRootId, FileId, Cancelable,};
use crate::{
SourceFileItems, SourceItemId, DefKind, Function, DefId, Name, AsName,
db::HirDatabase,
function::{FnScopes, FnId},
function::FnScopes,
module::{
ModuleSource, ModuleSourceNode, ModuleId,
imp::Submodule,
@ -23,22 +23,15 @@
adt::{StructData, EnumData},
};
/// Resolve `FnId` to the corresponding `SyntaxNode`
pub(super) fn fn_syntax(db: &impl HirDatabase, fn_id: FnId) -> FnDefNode {
let def_loc = fn_id.0.loc(db);
assert!(def_loc.kind == DefKind::Function);
let syntax = db.file_item(def_loc.source_item_id);
FnDef::cast(syntax.borrowed()).unwrap().owned()
}
pub(super) fn fn_scopes(db: &impl HirDatabase, fn_id: FnId) -> Arc<FnScopes> {
let syntax = db.fn_syntax(fn_id);
pub(super) fn fn_scopes(db: &impl HirDatabase, def_id: DefId) -> Arc<FnScopes> {
let function = Function::new(def_id);
let syntax = function.syntax(db);
let res = FnScopes::new(syntax.borrowed());
Arc::new(res)
}
pub(super) fn infer(db: &impl HirDatabase, fn_id: FnId) -> Cancelable<Arc<InferenceResult>> {
let function = Function { fn_id };
pub(super) fn infer(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<InferenceResult>> {
let function = Function::new(def_id);
ty::infer(db, function).map(Arc::new)
}