Auto merge of #13678 - Veykril:hir-file-encode, r=Veykril
Encode the variants of `HirFileId` in a u32 with MSB as the tag This saves 10mb on `self` analysis, while this does limit us to 2billion real files and 2 billion macro expansions, I doubt we will ever hit that limit :) `HirFileId` is used a lot, so going from 8 bytes to 4 is a decent win.
This commit is contained in:
commit
d2281f0367
@ -240,7 +240,7 @@ fn ast_id_map(db: &dyn AstDatabase, file_id: HirFileId) -> Arc<AstIdMap> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn parse_or_expand(db: &dyn AstDatabase, file_id: HirFileId) -> Option<SyntaxNode> {
|
fn parse_or_expand(db: &dyn AstDatabase, file_id: HirFileId) -> Option<SyntaxNode> {
|
||||||
match file_id.0 {
|
match file_id.repr() {
|
||||||
HirFileIdRepr::FileId(file_id) => Some(db.parse(file_id).tree().syntax().clone()),
|
HirFileIdRepr::FileId(file_id) => Some(db.parse(file_id).tree().syntax().clone()),
|
||||||
HirFileIdRepr::MacroFile(macro_file) => {
|
HirFileIdRepr::MacroFile(macro_file) => {
|
||||||
// FIXME: Note how we convert from `Parse` to `SyntaxNode` here,
|
// FIXME: Note how we convert from `Parse` to `SyntaxNode` here,
|
||||||
|
@ -17,7 +17,7 @@ use crate::{
|
|||||||
db::{self, AstDatabase},
|
db::{self, AstDatabase},
|
||||||
fixup,
|
fixup,
|
||||||
name::{AsName, Name},
|
name::{AsName, Name},
|
||||||
HirFileId, HirFileIdRepr, InFile, MacroCallKind, MacroCallLoc, MacroDefKind, MacroFile,
|
HirFileId, InFile, MacroCallKind, MacroCallLoc, MacroDefKind, MacroFile,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
@ -216,9 +216,9 @@ fn make_hygiene_info(
|
|||||||
|
|
||||||
impl HygieneFrame {
|
impl HygieneFrame {
|
||||||
pub(crate) fn new(db: &dyn AstDatabase, file_id: HirFileId) -> HygieneFrame {
|
pub(crate) fn new(db: &dyn AstDatabase, file_id: HirFileId) -> HygieneFrame {
|
||||||
let (info, krate, local_inner) = match file_id.0 {
|
let (info, krate, local_inner) = match file_id.macro_file() {
|
||||||
HirFileIdRepr::FileId(_) => (None, None, false),
|
None => (None, None, false),
|
||||||
HirFileIdRepr::MacroFile(macro_file) => {
|
Some(macro_file) => {
|
||||||
let loc = db.lookup_intern_macro_call(macro_file.macro_call_id);
|
let loc = db.lookup_intern_macro_call(macro_file.macro_call_id);
|
||||||
let info =
|
let info =
|
||||||
make_hygiene_info(db, macro_file, &loc).map(|info| (loc.kind.file_id(), info));
|
make_hygiene_info(db, macro_file, &loc).map(|info| (loc.kind.file_id(), info));
|
||||||
|
@ -23,7 +23,11 @@ pub use mbe::{Origin, ValueResult};
|
|||||||
|
|
||||||
use std::{fmt, hash::Hash, iter, sync::Arc};
|
use std::{fmt, hash::Hash, iter, sync::Arc};
|
||||||
|
|
||||||
use base_db::{impl_intern_key, salsa, CrateId, FileId, FileRange, ProcMacroKind};
|
use base_db::{
|
||||||
|
impl_intern_key,
|
||||||
|
salsa::{self, InternId},
|
||||||
|
CrateId, FileId, FileRange, ProcMacroKind,
|
||||||
|
};
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
algo::{self, skip_trivia_token},
|
algo::{self, skip_trivia_token},
|
||||||
@ -79,26 +83,12 @@ impl fmt::Display for ExpandError {
|
|||||||
/// finite (because everything bottoms out at the real `FileId`) and small
|
/// finite (because everything bottoms out at the real `FileId`) and small
|
||||||
/// (`MacroCallId` uses the location interning. You can check details here:
|
/// (`MacroCallId` uses the location interning. You can check details here:
|
||||||
/// <https://en.wikipedia.org/wiki/String_interning>).
|
/// <https://en.wikipedia.org/wiki/String_interning>).
|
||||||
|
///
|
||||||
|
/// The two variants are encoded in a single u32 which are differentiated by the MSB.
|
||||||
|
/// If the MSB is 0, the value represents a `FileId`, otherwise the remaining 31 bits represent a
|
||||||
|
/// `MacroCallId`.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct HirFileId(HirFileIdRepr);
|
pub struct HirFileId(u32);
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
|
||||||
enum HirFileIdRepr {
|
|
||||||
FileId(FileId),
|
|
||||||
MacroFile(MacroFile),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<FileId> for HirFileId {
|
|
||||||
fn from(id: FileId) -> Self {
|
|
||||||
HirFileId(HirFileIdRepr::FileId(id))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<MacroFile> for HirFileId {
|
|
||||||
fn from(id: MacroFile) -> Self {
|
|
||||||
HirFileId(HirFileIdRepr::MacroFile(id))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct MacroFile {
|
pub struct MacroFile {
|
||||||
@ -172,13 +162,37 @@ pub enum MacroCallKind {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
|
enum HirFileIdRepr {
|
||||||
|
FileId(FileId),
|
||||||
|
MacroFile(MacroFile),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<FileId> for HirFileId {
|
||||||
|
fn from(FileId(id): FileId) -> Self {
|
||||||
|
assert!(id < Self::MAX_FILE_ID);
|
||||||
|
HirFileId(id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<MacroFile> for HirFileId {
|
||||||
|
fn from(MacroFile { macro_call_id: MacroCallId(id) }: MacroFile) -> Self {
|
||||||
|
let id = id.as_u32();
|
||||||
|
assert!(id < Self::MAX_FILE_ID);
|
||||||
|
HirFileId(id | Self::MACRO_FILE_TAG_MASK)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl HirFileId {
|
impl HirFileId {
|
||||||
|
const MAX_FILE_ID: u32 = u32::MAX ^ Self::MACRO_FILE_TAG_MASK;
|
||||||
|
const MACRO_FILE_TAG_MASK: u32 = 1 << 31;
|
||||||
|
|
||||||
/// For macro-expansion files, returns the file original source file the
|
/// For macro-expansion files, returns the file original source file the
|
||||||
/// expansion originated from.
|
/// expansion originated from.
|
||||||
pub fn original_file(self, db: &dyn db::AstDatabase) -> FileId {
|
pub fn original_file(self, db: &dyn db::AstDatabase) -> FileId {
|
||||||
let mut file_id = self;
|
let mut file_id = self;
|
||||||
loop {
|
loop {
|
||||||
match file_id.0 {
|
match file_id.repr() {
|
||||||
HirFileIdRepr::FileId(id) => break id,
|
HirFileIdRepr::FileId(id) => break id,
|
||||||
HirFileIdRepr::MacroFile(MacroFile { macro_call_id }) => {
|
HirFileIdRepr::MacroFile(MacroFile { macro_call_id }) => {
|
||||||
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_call_id);
|
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_call_id);
|
||||||
@ -194,7 +208,7 @@ impl HirFileId {
|
|||||||
pub fn expansion_level(self, db: &dyn db::AstDatabase) -> u32 {
|
pub fn expansion_level(self, db: &dyn db::AstDatabase) -> u32 {
|
||||||
let mut level = 0;
|
let mut level = 0;
|
||||||
let mut curr = self;
|
let mut curr = self;
|
||||||
while let HirFileIdRepr::MacroFile(macro_file) = curr.0 {
|
while let Some(macro_file) = curr.macro_file() {
|
||||||
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
|
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
|
||||||
|
|
||||||
level += 1;
|
level += 1;
|
||||||
@ -205,25 +219,17 @@ impl HirFileId {
|
|||||||
|
|
||||||
/// If this is a macro call, returns the syntax node of the call.
|
/// If this is a macro call, returns the syntax node of the call.
|
||||||
pub fn call_node(self, db: &dyn db::AstDatabase) -> Option<InFile<SyntaxNode>> {
|
pub fn call_node(self, db: &dyn db::AstDatabase) -> Option<InFile<SyntaxNode>> {
|
||||||
match self.0 {
|
let macro_file = self.macro_file()?;
|
||||||
HirFileIdRepr::FileId(_) => None,
|
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
|
||||||
HirFileIdRepr::MacroFile(macro_file) => {
|
Some(loc.kind.to_node(db))
|
||||||
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
|
|
||||||
Some(loc.kind.to_node(db))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// If this is a macro call, returns the syntax node of the very first macro call this file resides in.
|
/// If this is a macro call, returns the syntax node of the very first macro call this file resides in.
|
||||||
pub fn original_call_node(self, db: &dyn db::AstDatabase) -> Option<(FileId, SyntaxNode)> {
|
pub fn original_call_node(self, db: &dyn db::AstDatabase) -> Option<(FileId, SyntaxNode)> {
|
||||||
let mut call = match self.0 {
|
let mut call =
|
||||||
HirFileIdRepr::FileId(_) => return None,
|
db.lookup_intern_macro_call(self.macro_file()?.macro_call_id).kind.to_node(db);
|
||||||
HirFileIdRepr::MacroFile(MacroFile { macro_call_id }) => {
|
|
||||||
db.lookup_intern_macro_call(macro_call_id).kind.to_node(db)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
loop {
|
loop {
|
||||||
match call.file_id.0 {
|
match call.file_id.repr() {
|
||||||
HirFileIdRepr::FileId(file_id) => break Some((file_id, call.value)),
|
HirFileIdRepr::FileId(file_id) => break Some((file_id, call.value)),
|
||||||
HirFileIdRepr::MacroFile(MacroFile { macro_call_id }) => {
|
HirFileIdRepr::MacroFile(MacroFile { macro_call_id }) => {
|
||||||
call = db.lookup_intern_macro_call(macro_call_id).kind.to_node(db);
|
call = db.lookup_intern_macro_call(macro_call_id).kind.to_node(db);
|
||||||
@ -234,84 +240,74 @@ impl HirFileId {
|
|||||||
|
|
||||||
/// Return expansion information if it is a macro-expansion file
|
/// Return expansion information if it is a macro-expansion file
|
||||||
pub fn expansion_info(self, db: &dyn db::AstDatabase) -> Option<ExpansionInfo> {
|
pub fn expansion_info(self, db: &dyn db::AstDatabase) -> Option<ExpansionInfo> {
|
||||||
match self.0 {
|
let macro_file = self.macro_file()?;
|
||||||
HirFileIdRepr::FileId(_) => None,
|
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
|
||||||
HirFileIdRepr::MacroFile(macro_file) => {
|
|
||||||
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
|
|
||||||
|
|
||||||
let arg_tt = loc.kind.arg(db)?;
|
let arg_tt = loc.kind.arg(db)?;
|
||||||
|
|
||||||
let macro_def = db.macro_def(loc.def).ok()?;
|
let macro_def = db.macro_def(loc.def).ok()?;
|
||||||
let (parse, exp_map) = db.parse_macro_expansion(macro_file).value?;
|
let (parse, exp_map) = db.parse_macro_expansion(macro_file).value?;
|
||||||
let macro_arg = db.macro_arg(macro_file.macro_call_id)?;
|
let macro_arg = db.macro_arg(macro_file.macro_call_id)?;
|
||||||
|
|
||||||
let def = loc.def.ast_id().left().and_then(|id| {
|
let def = loc.def.ast_id().left().and_then(|id| {
|
||||||
let def_tt = match id.to_node(db) {
|
let def_tt = match id.to_node(db) {
|
||||||
ast::Macro::MacroRules(mac) => mac.token_tree()?,
|
ast::Macro::MacroRules(mac) => mac.token_tree()?,
|
||||||
ast::Macro::MacroDef(_)
|
ast::Macro::MacroDef(_) if matches!(*macro_def, TokenExpander::BuiltinAttr(_)) => {
|
||||||
if matches!(*macro_def, TokenExpander::BuiltinAttr(_)) =>
|
return None
|
||||||
{
|
}
|
||||||
return None
|
ast::Macro::MacroDef(mac) => mac.body()?,
|
||||||
}
|
};
|
||||||
ast::Macro::MacroDef(mac) => mac.body()?,
|
Some(InFile::new(id.file_id, def_tt))
|
||||||
};
|
});
|
||||||
Some(InFile::new(id.file_id, def_tt))
|
let attr_input_or_mac_def = def.or_else(|| match loc.kind {
|
||||||
});
|
MacroCallKind::Attr { ast_id, invoc_attr_index, .. } => {
|
||||||
let attr_input_or_mac_def = def.or_else(|| match loc.kind {
|
let tt = ast_id
|
||||||
MacroCallKind::Attr { ast_id, invoc_attr_index, .. } => {
|
.to_node(db)
|
||||||
let tt = ast_id
|
.doc_comments_and_attrs()
|
||||||
.to_node(db)
|
.nth(invoc_attr_index as usize)
|
||||||
.doc_comments_and_attrs()
|
.and_then(Either::left)?
|
||||||
.nth(invoc_attr_index as usize)
|
.token_tree()?;
|
||||||
.and_then(Either::left)?
|
Some(InFile::new(ast_id.file_id, tt))
|
||||||
.token_tree()?;
|
|
||||||
Some(InFile::new(ast_id.file_id, tt))
|
|
||||||
}
|
|
||||||
_ => None,
|
|
||||||
});
|
|
||||||
|
|
||||||
Some(ExpansionInfo {
|
|
||||||
expanded: InFile::new(self, parse.syntax_node()),
|
|
||||||
arg: InFile::new(loc.kind.file_id(), arg_tt),
|
|
||||||
attr_input_or_mac_def,
|
|
||||||
macro_arg_shift: mbe::Shift::new(¯o_arg.0),
|
|
||||||
macro_arg,
|
|
||||||
macro_def,
|
|
||||||
exp_map,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
_ => None,
|
||||||
|
});
|
||||||
|
|
||||||
|
Some(ExpansionInfo {
|
||||||
|
expanded: InFile::new(self, parse.syntax_node()),
|
||||||
|
arg: InFile::new(loc.kind.file_id(), arg_tt),
|
||||||
|
attr_input_or_mac_def,
|
||||||
|
macro_arg_shift: mbe::Shift::new(¯o_arg.0),
|
||||||
|
macro_arg,
|
||||||
|
macro_def,
|
||||||
|
exp_map,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Indicate it is macro file generated for builtin derive
|
/// Indicate it is macro file generated for builtin derive
|
||||||
pub fn is_builtin_derive(&self, db: &dyn db::AstDatabase) -> Option<InFile<ast::Attr>> {
|
pub fn is_builtin_derive(&self, db: &dyn db::AstDatabase) -> Option<InFile<ast::Attr>> {
|
||||||
match self.0 {
|
let macro_file = self.macro_file()?;
|
||||||
HirFileIdRepr::FileId(_) => None,
|
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
|
||||||
HirFileIdRepr::MacroFile(macro_file) => {
|
let attr = match loc.def.kind {
|
||||||
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
|
MacroDefKind::BuiltInDerive(..) => loc.kind.to_node(db),
|
||||||
let attr = match loc.def.kind {
|
_ => return None,
|
||||||
MacroDefKind::BuiltInDerive(..) => loc.kind.to_node(db),
|
};
|
||||||
_ => return None,
|
Some(attr.with_value(ast::Attr::cast(attr.value.clone())?))
|
||||||
};
|
|
||||||
Some(attr.with_value(ast::Attr::cast(attr.value.clone())?))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_custom_derive(&self, db: &dyn db::AstDatabase) -> bool {
|
pub fn is_custom_derive(&self, db: &dyn db::AstDatabase) -> bool {
|
||||||
match self.0 {
|
match self.macro_file() {
|
||||||
HirFileIdRepr::FileId(_) => false,
|
Some(macro_file) => {
|
||||||
HirFileIdRepr::MacroFile(macro_file) => {
|
|
||||||
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
|
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
|
||||||
matches!(loc.def.kind, MacroDefKind::ProcMacro(_, ProcMacroKind::CustomDerive, _))
|
matches!(loc.def.kind, MacroDefKind::ProcMacro(_, ProcMacroKind::CustomDerive, _))
|
||||||
}
|
}
|
||||||
|
None => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return whether this file is an include macro
|
/// Return whether this file is an include macro
|
||||||
pub fn is_include_macro(&self, db: &dyn db::AstDatabase) -> bool {
|
pub fn is_include_macro(&self, db: &dyn db::AstDatabase) -> bool {
|
||||||
match self.0 {
|
match self.macro_file() {
|
||||||
HirFileIdRepr::MacroFile(macro_file) => {
|
Some(macro_file) => {
|
||||||
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
|
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
|
||||||
matches!(loc.eager, Some(EagerCallInfo { included_file: Some(_), .. }))
|
matches!(loc.eager, Some(EagerCallInfo { included_file: Some(_), .. }))
|
||||||
}
|
}
|
||||||
@ -321,8 +317,8 @@ impl HirFileId {
|
|||||||
|
|
||||||
/// Return whether this file is an attr macro
|
/// Return whether this file is an attr macro
|
||||||
pub fn is_attr_macro(&self, db: &dyn db::AstDatabase) -> bool {
|
pub fn is_attr_macro(&self, db: &dyn db::AstDatabase) -> bool {
|
||||||
match self.0 {
|
match self.macro_file() {
|
||||||
HirFileIdRepr::MacroFile(macro_file) => {
|
Some(macro_file) => {
|
||||||
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
|
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
|
||||||
matches!(loc.kind, MacroCallKind::Attr { .. })
|
matches!(loc.kind, MacroCallKind::Attr { .. })
|
||||||
}
|
}
|
||||||
@ -333,23 +329,36 @@ impl HirFileId {
|
|||||||
/// Return whether this file is the pseudo expansion of the derive attribute.
|
/// Return whether this file is the pseudo expansion of the derive attribute.
|
||||||
/// See [`crate::builtin_attr_macro::derive_attr_expand`].
|
/// See [`crate::builtin_attr_macro::derive_attr_expand`].
|
||||||
pub fn is_derive_attr_pseudo_expansion(&self, db: &dyn db::AstDatabase) -> bool {
|
pub fn is_derive_attr_pseudo_expansion(&self, db: &dyn db::AstDatabase) -> bool {
|
||||||
match self.0 {
|
match self.macro_file() {
|
||||||
HirFileIdRepr::MacroFile(macro_file) => {
|
Some(macro_file) => {
|
||||||
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
|
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
|
||||||
matches!(loc.kind, MacroCallKind::Attr { is_derive: true, .. })
|
matches!(loc.kind, MacroCallKind::Attr { is_derive: true, .. })
|
||||||
}
|
}
|
||||||
_ => false,
|
None => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn is_macro(self) -> bool {
|
pub fn is_macro(self) -> bool {
|
||||||
matches!(self.0, HirFileIdRepr::MacroFile(_))
|
self.0 & Self::MACRO_FILE_TAG_MASK != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn macro_file(self) -> Option<MacroFile> {
|
pub fn macro_file(self) -> Option<MacroFile> {
|
||||||
match self.0 {
|
match self.0 & Self::MACRO_FILE_TAG_MASK {
|
||||||
HirFileIdRepr::FileId(_) => None,
|
0 => None,
|
||||||
HirFileIdRepr::MacroFile(m) => Some(m),
|
_ => Some(MacroFile {
|
||||||
|
macro_call_id: MacroCallId(InternId::from(self.0 ^ Self::MACRO_FILE_TAG_MASK)),
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn repr(self) -> HirFileIdRepr {
|
||||||
|
match self.0 & Self::MACRO_FILE_TAG_MASK {
|
||||||
|
0 => HirFileIdRepr::FileId(FileId(self.0)),
|
||||||
|
_ => HirFileIdRepr::MacroFile(MacroFile {
|
||||||
|
macro_call_id: MacroCallId(InternId::from(self.0 ^ Self::MACRO_FILE_TAG_MASK)),
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -442,7 +451,7 @@ impl MacroCallKind {
|
|||||||
pub fn original_call_range_with_body(self, db: &dyn db::AstDatabase) -> FileRange {
|
pub fn original_call_range_with_body(self, db: &dyn db::AstDatabase) -> FileRange {
|
||||||
let mut kind = self;
|
let mut kind = self;
|
||||||
let file_id = loop {
|
let file_id = loop {
|
||||||
match kind.file_id().0 {
|
match kind.file_id().repr() {
|
||||||
HirFileIdRepr::MacroFile(file) => {
|
HirFileIdRepr::MacroFile(file) => {
|
||||||
kind = db.lookup_intern_macro_call(file.macro_call_id).kind;
|
kind = db.lookup_intern_macro_call(file.macro_call_id).kind;
|
||||||
}
|
}
|
||||||
@ -467,7 +476,7 @@ impl MacroCallKind {
|
|||||||
pub fn original_call_range(self, db: &dyn db::AstDatabase) -> FileRange {
|
pub fn original_call_range(self, db: &dyn db::AstDatabase) -> FileRange {
|
||||||
let mut kind = self;
|
let mut kind = self;
|
||||||
let file_id = loop {
|
let file_id = loop {
|
||||||
match kind.file_id().0 {
|
match kind.file_id().repr() {
|
||||||
HirFileIdRepr::MacroFile(file) => {
|
HirFileIdRepr::MacroFile(file) => {
|
||||||
kind = db.lookup_intern_macro_call(file.macro_call_id).kind;
|
kind = db.lookup_intern_macro_call(file.macro_call_id).kind;
|
||||||
}
|
}
|
||||||
@ -779,7 +788,7 @@ impl<'a> InFile<&'a SyntaxNode> {
|
|||||||
/// For attributes and derives, this will point back to the attribute only.
|
/// For attributes and derives, this will point back to the attribute only.
|
||||||
/// For the entire item `InFile::use original_file_range_full`.
|
/// For the entire item `InFile::use original_file_range_full`.
|
||||||
pub fn original_file_range(self, db: &dyn db::AstDatabase) -> FileRange {
|
pub fn original_file_range(self, db: &dyn db::AstDatabase) -> FileRange {
|
||||||
match self.file_id.0 {
|
match self.file_id.repr() {
|
||||||
HirFileIdRepr::FileId(file_id) => FileRange { file_id, range: self.value.text_range() },
|
HirFileIdRepr::FileId(file_id) => FileRange { file_id, range: self.value.text_range() },
|
||||||
HirFileIdRepr::MacroFile(mac_file) => {
|
HirFileIdRepr::MacroFile(mac_file) => {
|
||||||
if let Some(res) = self.original_file_range_opt(db) {
|
if let Some(res) = self.original_file_range_opt(db) {
|
||||||
@ -846,7 +855,7 @@ impl InFile<SyntaxToken> {
|
|||||||
|
|
||||||
/// Falls back to the macro call range if the node cannot be mapped up fully.
|
/// Falls back to the macro call range if the node cannot be mapped up fully.
|
||||||
pub fn original_file_range(self, db: &dyn db::AstDatabase) -> FileRange {
|
pub fn original_file_range(self, db: &dyn db::AstDatabase) -> FileRange {
|
||||||
match self.file_id.0 {
|
match self.file_id.repr() {
|
||||||
HirFileIdRepr::FileId(file_id) => FileRange { file_id, range: self.value.text_range() },
|
HirFileIdRepr::FileId(file_id) => FileRange { file_id, range: self.value.text_range() },
|
||||||
HirFileIdRepr::MacroFile(mac_file) => {
|
HirFileIdRepr::MacroFile(mac_file) => {
|
||||||
if let Some(res) = self.original_file_range_opt(db) {
|
if let Some(res) = self.original_file_range_opt(db) {
|
||||||
@ -861,7 +870,7 @@ impl InFile<SyntaxToken> {
|
|||||||
|
|
||||||
/// Attempts to map the syntax node back up its macro calls.
|
/// Attempts to map the syntax node back up its macro calls.
|
||||||
pub fn original_file_range_opt(self, db: &dyn db::AstDatabase) -> Option<FileRange> {
|
pub fn original_file_range_opt(self, db: &dyn db::AstDatabase) -> Option<FileRange> {
|
||||||
match self.file_id.0 {
|
match self.file_id.repr() {
|
||||||
HirFileIdRepr::FileId(file_id) => {
|
HirFileIdRepr::FileId(file_id) => {
|
||||||
Some(FileRange { file_id, range: self.value.text_range() })
|
Some(FileRange { file_id, range: self.value.text_range() })
|
||||||
}
|
}
|
||||||
|
@ -14,11 +14,7 @@
|
|||||||
name: "Alias",
|
name: "Alias",
|
||||||
loc: DeclarationLocation {
|
loc: DeclarationLocation {
|
||||||
hir_file_id: HirFileId(
|
hir_file_id: HirFileId(
|
||||||
FileId(
|
0,
|
||||||
FileId(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
ptr: SyntaxNodePtr {
|
ptr: SyntaxNodePtr {
|
||||||
kind: TYPE_ALIAS,
|
kind: TYPE_ALIAS,
|
||||||
@ -36,11 +32,7 @@
|
|||||||
name: "CONST",
|
name: "CONST",
|
||||||
loc: DeclarationLocation {
|
loc: DeclarationLocation {
|
||||||
hir_file_id: HirFileId(
|
hir_file_id: HirFileId(
|
||||||
FileId(
|
0,
|
||||||
FileId(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
ptr: SyntaxNodePtr {
|
ptr: SyntaxNodePtr {
|
||||||
kind: CONST,
|
kind: CONST,
|
||||||
@ -58,11 +50,7 @@
|
|||||||
name: "CONST_WITH_INNER",
|
name: "CONST_WITH_INNER",
|
||||||
loc: DeclarationLocation {
|
loc: DeclarationLocation {
|
||||||
hir_file_id: HirFileId(
|
hir_file_id: HirFileId(
|
||||||
FileId(
|
0,
|
||||||
FileId(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
ptr: SyntaxNodePtr {
|
ptr: SyntaxNodePtr {
|
||||||
kind: CONST,
|
kind: CONST,
|
||||||
@ -80,11 +68,7 @@
|
|||||||
name: "Enum",
|
name: "Enum",
|
||||||
loc: DeclarationLocation {
|
loc: DeclarationLocation {
|
||||||
hir_file_id: HirFileId(
|
hir_file_id: HirFileId(
|
||||||
FileId(
|
0,
|
||||||
FileId(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
ptr: SyntaxNodePtr {
|
ptr: SyntaxNodePtr {
|
||||||
kind: ENUM,
|
kind: ENUM,
|
||||||
@ -102,11 +86,7 @@
|
|||||||
name: "Macro",
|
name: "Macro",
|
||||||
loc: DeclarationLocation {
|
loc: DeclarationLocation {
|
||||||
hir_file_id: HirFileId(
|
hir_file_id: HirFileId(
|
||||||
FileId(
|
0,
|
||||||
FileId(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
ptr: SyntaxNodePtr {
|
ptr: SyntaxNodePtr {
|
||||||
kind: MACRO_DEF,
|
kind: MACRO_DEF,
|
||||||
@ -124,11 +104,7 @@
|
|||||||
name: "STATIC",
|
name: "STATIC",
|
||||||
loc: DeclarationLocation {
|
loc: DeclarationLocation {
|
||||||
hir_file_id: HirFileId(
|
hir_file_id: HirFileId(
|
||||||
FileId(
|
0,
|
||||||
FileId(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
ptr: SyntaxNodePtr {
|
ptr: SyntaxNodePtr {
|
||||||
kind: STATIC,
|
kind: STATIC,
|
||||||
@ -146,11 +122,7 @@
|
|||||||
name: "Struct",
|
name: "Struct",
|
||||||
loc: DeclarationLocation {
|
loc: DeclarationLocation {
|
||||||
hir_file_id: HirFileId(
|
hir_file_id: HirFileId(
|
||||||
FileId(
|
0,
|
||||||
FileId(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
ptr: SyntaxNodePtr {
|
ptr: SyntaxNodePtr {
|
||||||
kind: STRUCT,
|
kind: STRUCT,
|
||||||
@ -168,13 +140,7 @@
|
|||||||
name: "StructFromMacro",
|
name: "StructFromMacro",
|
||||||
loc: DeclarationLocation {
|
loc: DeclarationLocation {
|
||||||
hir_file_id: HirFileId(
|
hir_file_id: HirFileId(
|
||||||
MacroFile(
|
2147483648,
|
||||||
MacroFile {
|
|
||||||
macro_call_id: MacroCallId(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
ptr: SyntaxNodePtr {
|
ptr: SyntaxNodePtr {
|
||||||
kind: STRUCT,
|
kind: STRUCT,
|
||||||
@ -192,11 +158,7 @@
|
|||||||
name: "StructInFn",
|
name: "StructInFn",
|
||||||
loc: DeclarationLocation {
|
loc: DeclarationLocation {
|
||||||
hir_file_id: HirFileId(
|
hir_file_id: HirFileId(
|
||||||
FileId(
|
0,
|
||||||
FileId(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
ptr: SyntaxNodePtr {
|
ptr: SyntaxNodePtr {
|
||||||
kind: STRUCT,
|
kind: STRUCT,
|
||||||
@ -216,11 +178,7 @@
|
|||||||
name: "StructInNamedConst",
|
name: "StructInNamedConst",
|
||||||
loc: DeclarationLocation {
|
loc: DeclarationLocation {
|
||||||
hir_file_id: HirFileId(
|
hir_file_id: HirFileId(
|
||||||
FileId(
|
0,
|
||||||
FileId(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
ptr: SyntaxNodePtr {
|
ptr: SyntaxNodePtr {
|
||||||
kind: STRUCT,
|
kind: STRUCT,
|
||||||
@ -240,11 +198,7 @@
|
|||||||
name: "StructInUnnamedConst",
|
name: "StructInUnnamedConst",
|
||||||
loc: DeclarationLocation {
|
loc: DeclarationLocation {
|
||||||
hir_file_id: HirFileId(
|
hir_file_id: HirFileId(
|
||||||
FileId(
|
0,
|
||||||
FileId(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
ptr: SyntaxNodePtr {
|
ptr: SyntaxNodePtr {
|
||||||
kind: STRUCT,
|
kind: STRUCT,
|
||||||
@ -262,11 +216,7 @@
|
|||||||
name: "Trait",
|
name: "Trait",
|
||||||
loc: DeclarationLocation {
|
loc: DeclarationLocation {
|
||||||
hir_file_id: HirFileId(
|
hir_file_id: HirFileId(
|
||||||
FileId(
|
0,
|
||||||
FileId(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
ptr: SyntaxNodePtr {
|
ptr: SyntaxNodePtr {
|
||||||
kind: TRAIT,
|
kind: TRAIT,
|
||||||
@ -284,11 +234,7 @@
|
|||||||
name: "Union",
|
name: "Union",
|
||||||
loc: DeclarationLocation {
|
loc: DeclarationLocation {
|
||||||
hir_file_id: HirFileId(
|
hir_file_id: HirFileId(
|
||||||
FileId(
|
0,
|
||||||
FileId(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
ptr: SyntaxNodePtr {
|
ptr: SyntaxNodePtr {
|
||||||
kind: UNION,
|
kind: UNION,
|
||||||
@ -306,11 +252,7 @@
|
|||||||
name: "a_mod",
|
name: "a_mod",
|
||||||
loc: DeclarationLocation {
|
loc: DeclarationLocation {
|
||||||
hir_file_id: HirFileId(
|
hir_file_id: HirFileId(
|
||||||
FileId(
|
0,
|
||||||
FileId(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
ptr: SyntaxNodePtr {
|
ptr: SyntaxNodePtr {
|
||||||
kind: MODULE,
|
kind: MODULE,
|
||||||
@ -328,11 +270,7 @@
|
|||||||
name: "b_mod",
|
name: "b_mod",
|
||||||
loc: DeclarationLocation {
|
loc: DeclarationLocation {
|
||||||
hir_file_id: HirFileId(
|
hir_file_id: HirFileId(
|
||||||
FileId(
|
0,
|
||||||
FileId(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
ptr: SyntaxNodePtr {
|
ptr: SyntaxNodePtr {
|
||||||
kind: MODULE,
|
kind: MODULE,
|
||||||
@ -350,11 +288,7 @@
|
|||||||
name: "define_struct",
|
name: "define_struct",
|
||||||
loc: DeclarationLocation {
|
loc: DeclarationLocation {
|
||||||
hir_file_id: HirFileId(
|
hir_file_id: HirFileId(
|
||||||
FileId(
|
0,
|
||||||
FileId(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
ptr: SyntaxNodePtr {
|
ptr: SyntaxNodePtr {
|
||||||
kind: MACRO_RULES,
|
kind: MACRO_RULES,
|
||||||
@ -372,11 +306,7 @@
|
|||||||
name: "impl_fn",
|
name: "impl_fn",
|
||||||
loc: DeclarationLocation {
|
loc: DeclarationLocation {
|
||||||
hir_file_id: HirFileId(
|
hir_file_id: HirFileId(
|
||||||
FileId(
|
0,
|
||||||
FileId(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
ptr: SyntaxNodePtr {
|
ptr: SyntaxNodePtr {
|
||||||
kind: FN,
|
kind: FN,
|
||||||
@ -394,11 +324,7 @@
|
|||||||
name: "macro_rules_macro",
|
name: "macro_rules_macro",
|
||||||
loc: DeclarationLocation {
|
loc: DeclarationLocation {
|
||||||
hir_file_id: HirFileId(
|
hir_file_id: HirFileId(
|
||||||
FileId(
|
0,
|
||||||
FileId(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
ptr: SyntaxNodePtr {
|
ptr: SyntaxNodePtr {
|
||||||
kind: MACRO_RULES,
|
kind: MACRO_RULES,
|
||||||
@ -416,11 +342,7 @@
|
|||||||
name: "main",
|
name: "main",
|
||||||
loc: DeclarationLocation {
|
loc: DeclarationLocation {
|
||||||
hir_file_id: HirFileId(
|
hir_file_id: HirFileId(
|
||||||
FileId(
|
0,
|
||||||
FileId(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
ptr: SyntaxNodePtr {
|
ptr: SyntaxNodePtr {
|
||||||
kind: FN,
|
kind: FN,
|
||||||
@ -438,11 +360,7 @@
|
|||||||
name: "trait_fn",
|
name: "trait_fn",
|
||||||
loc: DeclarationLocation {
|
loc: DeclarationLocation {
|
||||||
hir_file_id: HirFileId(
|
hir_file_id: HirFileId(
|
||||||
FileId(
|
0,
|
||||||
FileId(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
ptr: SyntaxNodePtr {
|
ptr: SyntaxNodePtr {
|
||||||
kind: FN,
|
kind: FN,
|
||||||
@ -475,11 +393,7 @@
|
|||||||
name: "StructInModA",
|
name: "StructInModA",
|
||||||
loc: DeclarationLocation {
|
loc: DeclarationLocation {
|
||||||
hir_file_id: HirFileId(
|
hir_file_id: HirFileId(
|
||||||
FileId(
|
0,
|
||||||
FileId(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
ptr: SyntaxNodePtr {
|
ptr: SyntaxNodePtr {
|
||||||
kind: STRUCT,
|
kind: STRUCT,
|
||||||
@ -510,11 +424,7 @@
|
|||||||
name: "StructInModB",
|
name: "StructInModB",
|
||||||
loc: DeclarationLocation {
|
loc: DeclarationLocation {
|
||||||
hir_file_id: HirFileId(
|
hir_file_id: HirFileId(
|
||||||
FileId(
|
1,
|
||||||
FileId(
|
|
||||||
1,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
ptr: SyntaxNodePtr {
|
ptr: SyntaxNodePtr {
|
||||||
kind: STRUCT,
|
kind: STRUCT,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user