Remove ids module

This commit is contained in:
Aleksey Kladov 2019-11-24 14:25:48 +03:00
parent 53506a7552
commit 9c766db5ff
6 changed files with 33 additions and 41 deletions

View file

@ -5,7 +5,6 @@ use std::sync::Arc;
use ra_db::salsa;
use crate::{
ids,
ty::{
method_resolution::CrateImplBlocks,
traits::{AssocTyValue, Impl},
@ -71,11 +70,14 @@ pub trait HirDatabase: DefDatabase {
// Interned IDs for Chalk integration
#[salsa::interned]
fn intern_type_ctor(&self, type_ctor: TypeCtor) -> ids::TypeCtorId;
fn intern_type_ctor(&self, type_ctor: TypeCtor) -> crate::ty::TypeCtorId;
#[salsa::interned]
fn intern_chalk_impl(&self, impl_: Impl) -> ids::GlobalImplId;
fn intern_chalk_impl(&self, impl_: Impl) -> crate::ty::traits::GlobalImplId;
#[salsa::interned]
fn intern_assoc_ty_value(&self, assoc_ty_value: AssocTyValue) -> ids::AssocTyValueId;
fn intern_assoc_ty_value(
&self,
assoc_ty_value: AssocTyValue,
) -> crate::ty::traits::AssocTyValueId;
#[salsa::invoke(crate::ty::traits::chalk::associated_ty_data_query)]
fn associated_ty_data(

View file

@ -1,26 +0,0 @@
//! hir makes heavy use of ids: integer (u32) handlers to various things. You
//! can think of id as a pointer (but without a lifetime) or a file descriptor
//! (but for hir objects).
//!
//! This module defines a bunch of ids we are using. The most important ones are
//! probably `HirFileId` and `DefId`.
use ra_db::{impl_intern_key, salsa};
/// This exists just for Chalk, because Chalk just has a single `StructId` where
/// we have different kinds of ADTs, primitive types and special type
/// constructors like tuples and function pointers.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct TypeCtorId(salsa::InternId);
impl_intern_key!(TypeCtorId);
/// This exists just for Chalk, because our ImplIds are only unique per module.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct GlobalImplId(salsa::InternId);
impl_intern_key!(GlobalImplId);
/// This exists just for Chalk, because it needs a unique ID for each associated
/// type value in an impl (even synthetic ones).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct AssocTyValueId(salsa::InternId);
impl_intern_key!(AssocTyValueId);

View file

@ -31,7 +31,6 @@ pub mod debug;
pub mod db;
pub mod source_binder;
mod ids;
mod ty;
mod impl_block;
mod expr;

View file

@ -18,6 +18,7 @@ use std::sync::Arc;
use std::{fmt, iter, mem};
use hir_def::{generics::GenericParams, AdtId};
use ra_db::{impl_intern_key, salsa};
use crate::{
db::HirDatabase, expr::ExprId, util::make_mut_slice, Adt, Crate, DefWithBody, FloatTy,
@ -114,6 +115,13 @@ pub enum TypeCtor {
Closure { def: DefWithBody, expr: ExprId },
}
/// This exists just for Chalk, because Chalk just has a single `StructId` where
/// we have different kinds of ADTs, primitive types and special type
/// constructors like tuples and function pointers.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct TypeCtorId(salsa::InternId);
impl_intern_key!(TypeCtorId);
impl TypeCtor {
pub fn num_ty_params(self, db: &impl HirDatabase) -> usize {
match self {

View file

@ -3,7 +3,7 @@ use std::sync::{Arc, Mutex};
use chalk_ir::{cast::Cast, family::ChalkIr};
use log::debug;
use ra_db::salsa;
use ra_db::{impl_intern_key, salsa};
use ra_prof::profile;
use rustc_hash::FxHashSet;
@ -304,6 +304,10 @@ pub enum Impl {
/// Closure types implement the Fn traits synthetically.
ClosureFnTraitImpl(ClosureFnTraitImplData),
}
/// This exists just for Chalk, because our ImplIds are only unique per module.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct GlobalImplId(salsa::InternId);
impl_intern_key!(GlobalImplId);
/// An associated type value. Usually this comes from a `type` declaration
/// inside an impl block, but for built-in impls we have to synthesize it.
@ -315,3 +319,8 @@ pub enum AssocTyValue {
/// The output type of the Fn trait implementation.
ClosureFnTraitImplOutput(ClosureFnTraitImplData),
}
/// This exists just for Chalk, because it needs a unique ID for each associated
/// type value in an impl (even synthetic ones).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct AssocTyValueId(salsa::InternId);
impl_intern_key!(AssocTyValueId);

View file

@ -847,38 +847,38 @@ fn id_to_chalk<T: InternKey>(salsa_id: T) -> chalk_ir::RawId {
chalk_ir::RawId { index: salsa_id.as_intern_id().as_u32() }
}
impl From<chalk_ir::StructId> for crate::ids::TypeCtorId {
impl From<chalk_ir::StructId> for crate::ty::TypeCtorId {
fn from(struct_id: chalk_ir::StructId) -> Self {
id_from_chalk(struct_id.0)
}
}
impl From<crate::ids::TypeCtorId> for chalk_ir::StructId {
fn from(type_ctor_id: crate::ids::TypeCtorId) -> Self {
impl From<crate::ty::TypeCtorId> for chalk_ir::StructId {
fn from(type_ctor_id: crate::ty::TypeCtorId) -> Self {
chalk_ir::StructId(id_to_chalk(type_ctor_id))
}
}
impl From<chalk_ir::ImplId> for crate::ids::GlobalImplId {
impl From<chalk_ir::ImplId> for crate::ty::traits::GlobalImplId {
fn from(impl_id: chalk_ir::ImplId) -> Self {
id_from_chalk(impl_id.0)
}
}
impl From<crate::ids::GlobalImplId> for chalk_ir::ImplId {
fn from(impl_id: crate::ids::GlobalImplId) -> Self {
impl From<crate::ty::traits::GlobalImplId> for chalk_ir::ImplId {
fn from(impl_id: crate::ty::traits::GlobalImplId) -> Self {
chalk_ir::ImplId(id_to_chalk(impl_id))
}
}
impl From<chalk_rust_ir::AssociatedTyValueId> for crate::ids::AssocTyValueId {
impl From<chalk_rust_ir::AssociatedTyValueId> for crate::ty::traits::AssocTyValueId {
fn from(id: chalk_rust_ir::AssociatedTyValueId) -> Self {
id_from_chalk(id.0)
}
}
impl From<crate::ids::AssocTyValueId> for chalk_rust_ir::AssociatedTyValueId {
fn from(assoc_ty_value_id: crate::ids::AssocTyValueId) -> Self {
impl From<crate::ty::traits::AssocTyValueId> for chalk_rust_ir::AssociatedTyValueId {
fn from(assoc_ty_value_id: crate::ty::traits::AssocTyValueId) -> Self {
chalk_rust_ir::AssociatedTyValueId(id_to_chalk(assoc_ty_value_id))
}
}