chore: Remove legacy SyntaxContextId re-export

This commit is contained in:
Lukas Wirth 2025-03-15 16:07:52 +01:00
parent 60cd01864a
commit 02a793bd59
38 changed files with 164 additions and 228 deletions

View file

@ -9,7 +9,7 @@ use hir_expand::{
attrs::RawAttrs, mod_path::ModPath, span_map::SpanMap, ExpandError, ExpandErrorKind, attrs::RawAttrs, mod_path::ModPath, span_map::SpanMap, ExpandError, ExpandErrorKind,
ExpandResult, HirFileId, InFile, Lookup, MacroCallId, ExpandResult, HirFileId, InFile, Lookup, MacroCallId,
}; };
use span::{Edition, SyntaxContextId}; use span::{Edition, SyntaxContext};
use syntax::{ast, Parse}; use syntax::{ast, Parse};
use triomphe::Arc; use triomphe::Arc;
@ -57,9 +57,9 @@ impl Expander {
self.module.krate self.module.krate
} }
pub fn syntax_context(&self) -> SyntaxContextId { pub fn syntax_context(&self) -> SyntaxContext {
// FIXME: // FIXME:
SyntaxContextId::root(Edition::CURRENT) SyntaxContext::root(Edition::CURRENT)
} }
pub fn enter_expand<T: ast::AstNode>( pub fn enter_expand<T: ast::AstNode>(

View file

@ -37,13 +37,13 @@ pub use self::body::{Body, BodySourceMap};
/// A wrapper around [`span::SyntaxContextId`] that is intended only for comparisons. /// A wrapper around [`span::SyntaxContextId`] that is intended only for comparisons.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct HygieneId(span::SyntaxContextId); pub struct HygieneId(span::SyntaxContext);
impl HygieneId { impl HygieneId {
// The edition doesn't matter here, we only use this for comparisons and to lookup the macro. // The edition doesn't matter here, we only use this for comparisons and to lookup the macro.
pub const ROOT: Self = Self(span::SyntaxContextId::root(Edition::Edition2015)); pub const ROOT: Self = Self(span::SyntaxContext::root(Edition::Edition2015));
pub fn new(mut ctx: span::SyntaxContextId) -> Self { pub fn new(mut ctx: span::SyntaxContext) -> Self {
// See `Name` for why we're doing that. // See `Name` for why we're doing that.
ctx.remove_root_edition(); ctx.remove_root_edition();
Self(ctx) Self(ctx)

View file

@ -4,7 +4,7 @@ use either::Either;
use hir_expand::name::Name; use hir_expand::name::Name;
use intern::Symbol; use intern::Symbol;
use rustc_parse_format as parse; use rustc_parse_format as parse;
use span::SyntaxContextId; use span::SyntaxContext;
use stdx::TupleExt; use stdx::TupleExt;
use syntax::{ use syntax::{
ast::{self, IsString}, ast::{self, IsString},
@ -176,7 +176,7 @@ pub(crate) fn parse(
is_direct_literal: bool, is_direct_literal: bool,
mut synth: impl FnMut(Name, Option<TextRange>) -> ExprId, mut synth: impl FnMut(Name, Option<TextRange>) -> ExprId,
mut record_usage: impl FnMut(Name, Option<TextRange>), mut record_usage: impl FnMut(Name, Option<TextRange>),
call_ctx: SyntaxContextId, call_ctx: SyntaxContext,
) -> FormatArgs { ) -> FormatArgs {
let Ok(text) = s.value() else { let Ok(text) = s.value() else {
return FormatArgs { return FormatArgs {

View file

@ -51,7 +51,7 @@ use intern::{Interned, Symbol};
use la_arena::{Arena, Idx, RawIdx}; use la_arena::{Arena, Idx, RawIdx};
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use smallvec::SmallVec; use smallvec::SmallVec;
use span::{AstIdNode, Edition, FileAstId, SyntaxContextId}; use span::{AstIdNode, Edition, FileAstId, SyntaxContext};
use stdx::never; use stdx::never;
use syntax::{ast, match_ast, SyntaxKind}; use syntax::{ast, match_ast, SyntaxKind};
use triomphe::Arc; use triomphe::Arc;
@ -1098,7 +1098,7 @@ pub struct MacroCall {
pub path: Interned<ModPath>, pub path: Interned<ModPath>,
pub ast_id: FileAstId<ast::MacroCall>, pub ast_id: FileAstId<ast::MacroCall>,
pub expand_to: ExpandTo, pub expand_to: ExpandTo,
pub ctxt: SyntaxContextId, pub ctxt: SyntaxContext,
} }
#[derive(Debug, Clone, Eq, PartialEq)] #[derive(Debug, Clone, Eq, PartialEq)]

View file

@ -11,7 +11,7 @@ use hir_expand::{
use intern::{sym, Symbol}; use intern::{sym, Symbol};
use la_arena::Arena; use la_arena::Arena;
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use span::{AstIdMap, SyntaxContextId}; use span::{AstIdMap, SyntaxContext};
use stdx::thin_vec::ThinVec; use stdx::thin_vec::ThinVec;
use syntax::{ use syntax::{
ast::{self, HasModuleItem, HasName, HasTypeBounds, IsString}, ast::{self, HasModuleItem, HasName, HasTypeBounds, IsString},
@ -968,7 +968,7 @@ impl UseTreeLowering<'_> {
fn lower_use_tree( fn lower_use_tree(
&mut self, &mut self,
tree: ast::UseTree, tree: ast::UseTree,
span_for_range: &mut dyn FnMut(::tt::TextRange) -> SyntaxContextId, span_for_range: &mut dyn FnMut(::tt::TextRange) -> SyntaxContext,
) -> Option<UseTree> { ) -> Option<UseTree> {
if let Some(use_tree_list) = tree.use_tree_list() { if let Some(use_tree_list) = tree.use_tree_list() {
let prefix = match tree.path() { let prefix = match tree.path() {
@ -1035,7 +1035,7 @@ impl UseTreeLowering<'_> {
pub(crate) fn lower_use_tree( pub(crate) fn lower_use_tree(
db: &dyn DefDatabase, db: &dyn DefDatabase,
tree: ast::UseTree, tree: ast::UseTree,
span_for_range: &mut dyn FnMut(::tt::TextRange) -> SyntaxContextId, span_for_range: &mut dyn FnMut(::tt::TextRange) -> SyntaxContext,
) -> Option<(UseTree, Arena<ast::UseTree>)> { ) -> Option<(UseTree, Arena<ast::UseTree>)> {
let mut lowering = UseTreeLowering { db, mapping: Arena::new() }; let mut lowering = UseTreeLowering { db, mapping: Arena::new() };
let tree = lowering.lower_use_tree(tree, span_for_range)?; let tree = lowering.lower_use_tree(tree, span_for_range)?;

View file

@ -85,7 +85,7 @@ use hir_expand::{
use item_tree::ExternBlock; use item_tree::ExternBlock;
use la_arena::Idx; use la_arena::Idx;
use nameres::DefMap; use nameres::DefMap;
use span::{AstIdNode, Edition, FileAstId, SyntaxContextId}; use span::{AstIdNode, Edition, FileAstId, SyntaxContext};
use stdx::impl_from; use stdx::impl_from;
use syntax::{ast, AstNode}; use syntax::{ast, AstNode};
@ -1451,7 +1451,7 @@ impl<T: AstIdNode> AstIdWithPath<T> {
fn macro_call_as_call_id( fn macro_call_as_call_id(
db: &dyn ExpandDatabase, db: &dyn ExpandDatabase,
call: &AstIdWithPath<ast::MacroCall>, call: &AstIdWithPath<ast::MacroCall>,
call_site: SyntaxContextId, call_site: SyntaxContext,
expand_to: ExpandTo, expand_to: ExpandTo,
krate: Crate, krate: Crate,
resolver: impl Fn(&path::ModPath) -> Option<MacroDefId> + Copy, resolver: impl Fn(&path::ModPath) -> Option<MacroDefId> + Copy,
@ -1473,7 +1473,7 @@ fn macro_call_as_call_id_with_eager(
db: &dyn ExpandDatabase, db: &dyn ExpandDatabase,
ast_id: AstId<ast::MacroCall>, ast_id: AstId<ast::MacroCall>,
path: &path::ModPath, path: &path::ModPath,
call_site: SyntaxContextId, call_site: SyntaxContext,
expand_to: ExpandTo, expand_to: ExpandTo,
krate: Crate, krate: Crate,
resolver: impl FnOnce(&path::ModPath) -> Option<MacroDefId>, resolver: impl FnOnce(&path::ModPath) -> Option<MacroDefId>,

View file

@ -6,7 +6,7 @@ use hir_expand::{
inert_attr_macro::find_builtin_attr_idx, inert_attr_macro::find_builtin_attr_idx,
MacroCallId, MacroCallKind, MacroDefId, MacroCallId, MacroCallKind, MacroDefId,
}; };
use span::SyntaxContextId; use span::SyntaxContext;
use syntax::ast; use syntax::ast;
use triomphe::Arc; use triomphe::Arc;
@ -137,7 +137,7 @@ pub(super) fn derive_macro_as_call_id(
item_attr: &AstIdWithPath<ast::Adt>, item_attr: &AstIdWithPath<ast::Adt>,
derive_attr_index: AttrId, derive_attr_index: AttrId,
derive_pos: u32, derive_pos: u32,
call_site: SyntaxContextId, call_site: SyntaxContext,
krate: Crate, krate: Crate,
resolver: impl Fn(&path::ModPath) -> Option<(MacroId, MacroDefId)>, resolver: impl Fn(&path::ModPath) -> Option<(MacroId, MacroDefId)>,
derive_macro_id: MacroCallId, derive_macro_id: MacroCallId,

View file

@ -20,7 +20,7 @@ use intern::{sym, Interned};
use itertools::{izip, Itertools}; use itertools::{izip, Itertools};
use la_arena::Idx; use la_arena::Idx;
use rustc_hash::{FxHashMap, FxHashSet}; use rustc_hash::{FxHashMap, FxHashSet};
use span::{Edition, EditionedFileId, FileAstId, SyntaxContextId}; use span::{Edition, EditionedFileId, FileAstId, SyntaxContext};
use syntax::ast; use syntax::ast;
use triomphe::Arc; use triomphe::Arc;
@ -192,13 +192,13 @@ enum MacroDirectiveKind {
FnLike { FnLike {
ast_id: AstIdWithPath<ast::MacroCall>, ast_id: AstIdWithPath<ast::MacroCall>,
expand_to: ExpandTo, expand_to: ExpandTo,
ctxt: SyntaxContextId, ctxt: SyntaxContext,
}, },
Derive { Derive {
ast_id: AstIdWithPath<ast::Adt>, ast_id: AstIdWithPath<ast::Adt>,
derive_attr: AttrId, derive_attr: AttrId,
derive_pos: usize, derive_pos: usize,
ctxt: SyntaxContextId, ctxt: SyntaxContext,
/// The "parent" macro it is resolved to. /// The "parent" macro it is resolved to.
derive_macro_id: MacroCallId, derive_macro_id: MacroCallId,
}, },

View file

@ -7,7 +7,7 @@ use intern::{sym, Symbol};
use itertools::Itertools as _; use itertools::Itertools as _;
use rustc_hash::FxHashSet; use rustc_hash::FxHashSet;
use smallvec::{smallvec, SmallVec}; use smallvec::{smallvec, SmallVec};
use span::SyntaxContextId; use span::SyntaxContext;
use triomphe::Arc; use triomphe::Arc;
use crate::{ use crate::{
@ -903,7 +903,7 @@ impl Resolver {
fn handle_macro_def_scope( fn handle_macro_def_scope(
db: &dyn DefDatabase, db: &dyn DefDatabase,
hygiene_id: &mut HygieneId, hygiene_id: &mut HygieneId,
hygiene_info: &mut Option<(SyntaxContextId, MacroDefId)>, hygiene_info: &mut Option<(SyntaxContext, MacroDefId)>,
macro_id: &MacroDefId, macro_id: &MacroDefId,
) { ) {
if let Some((parent_ctx, label_macro_id)) = hygiene_info { if let Some((parent_ctx, label_macro_id)) = hygiene_info {
@ -924,7 +924,7 @@ fn handle_macro_def_scope(
fn hygiene_info( fn hygiene_info(
db: &dyn DefDatabase, db: &dyn DefDatabase,
hygiene_id: HygieneId, hygiene_id: HygieneId,
) -> Option<(SyntaxContextId, MacroDefId)> { ) -> Option<(SyntaxContext, MacroDefId)> {
if !hygiene_id.is_root() { if !hygiene_id.is_root() {
let ctx = hygiene_id.lookup(); let ctx = hygiene_id.lookup();
ctx.outer_expn(db).map(|expansion| { ctx.outer_expn(db).map(|expansion| {

View file

@ -4,7 +4,7 @@ use std::iter;
use intern::Interned; use intern::Interned;
use la_arena::ArenaMap; use la_arena::ArenaMap;
use span::SyntaxContextId; use span::SyntaxContext;
use syntax::ast; use syntax::ast;
use triomphe::Arc; use triomphe::Arc;
@ -37,7 +37,7 @@ impl RawVisibility {
pub(crate) fn from_ast( pub(crate) fn from_ast(
db: &dyn DefDatabase, db: &dyn DefDatabase,
node: Option<ast::Visibility>, node: Option<ast::Visibility>,
span_for_range: &mut dyn FnMut(::tt::TextRange) -> SyntaxContextId, span_for_range: &mut dyn FnMut(::tt::TextRange) -> SyntaxContext,
) -> RawVisibility { ) -> RawVisibility {
let node = match node { let node = match node {
None => return RawVisibility::private(), None => return RawVisibility::private(),
@ -49,7 +49,7 @@ impl RawVisibility {
fn from_ast_with_span_map( fn from_ast_with_span_map(
db: &dyn DefDatabase, db: &dyn DefDatabase,
node: ast::Visibility, node: ast::Visibility,
span_for_range: &mut dyn FnMut(::tt::TextRange) -> SyntaxContextId, span_for_range: &mut dyn FnMut(::tt::TextRange) -> SyntaxContext,
) -> RawVisibility { ) -> RawVisibility {
let path = match node.kind() { let path = match node.kind() {
ast::VisibilityKind::In(path) => { ast::VisibilityKind::In(path) => {

View file

@ -8,7 +8,7 @@ use intern::{sym, Interned, Symbol};
use mbe::{DelimiterKind, Punct}; use mbe::{DelimiterKind, Punct};
use smallvec::{smallvec, SmallVec}; use smallvec::{smallvec, SmallVec};
use span::{Span, SyntaxContextId}; use span::{Span, SyntaxContext};
use syntax::unescape; use syntax::unescape;
use syntax::{ast, match_ast, AstNode, AstToken, SyntaxNode}; use syntax::{ast, match_ast, AstNode, AstToken, SyntaxNode};
use syntax_bridge::{desugar_doc_comment_text, syntax_node_to_token_tree, DocCommentDesugarMode}; use syntax_bridge::{desugar_doc_comment_text, syntax_node_to_token_tree, DocCommentDesugarMode};
@ -210,7 +210,7 @@ pub struct Attr {
pub id: AttrId, pub id: AttrId,
pub path: Interned<ModPath>, pub path: Interned<ModPath>,
pub input: Option<Box<AttrInput>>, pub input: Option<Box<AttrInput>>,
pub ctxt: SyntaxContextId, pub ctxt: SyntaxContext,
} }
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]

View file

@ -4,7 +4,7 @@ use intern::sym;
use itertools::{izip, Itertools}; use itertools::{izip, Itertools};
use parser::SyntaxKind; use parser::SyntaxKind;
use rustc_hash::FxHashSet; use rustc_hash::FxHashSet;
use span::{Edition, MacroCallId, Span, SyntaxContextId}; use span::{Edition, MacroCallId, Span, SyntaxContext};
use stdx::never; use stdx::never;
use syntax_bridge::DocCommentDesugarMode; use syntax_bridge::DocCommentDesugarMode;
use tracing::debug; use tracing::debug;
@ -237,7 +237,7 @@ fn parse_adt(
fn parse_adt_from_syntax( fn parse_adt_from_syntax(
adt: &ast::Adt, adt: &ast::Adt,
tm: &span::SpanMap<SyntaxContextId>, tm: &span::SpanMap<SyntaxContext>,
call_site: Span, call_site: Span,
) -> Result<BasicAdtInfo, ExpandError> { ) -> Result<BasicAdtInfo, ExpandError> {
let (name, generic_param_list, where_clause, shape) = match &adt { let (name, generic_param_list, where_clause, shape) = match &adt {
@ -389,7 +389,7 @@ fn to_adt_syntax(
db: &dyn ExpandDatabase, db: &dyn ExpandDatabase,
tt: &tt::TopSubtree, tt: &tt::TopSubtree,
call_site: Span, call_site: Span,
) -> Result<(ast::Adt, span::SpanMap<SyntaxContextId>), ExpandError> { ) -> Result<(ast::Adt, span::SpanMap<SyntaxContext>), ExpandError> {
let (parsed, tm) = crate::db::token_tree_to_syntax_node( let (parsed, tm) = crate::db::token_tree_to_syntax_node(
db, db,
tt, tt,

View file

@ -226,7 +226,7 @@ mod tests {
use ::tt::IdentIsRaw; use ::tt::IdentIsRaw;
use expect_test::expect; use expect_test::expect;
use intern::Symbol; use intern::Symbol;
use span::{Edition, SpanAnchor, SyntaxContextId, ROOT_ERASED_FILE_AST_ID}; use span::{Edition, SpanAnchor, SyntaxContext, ROOT_ERASED_FILE_AST_ID};
use syntax::{TextRange, TextSize}; use syntax::{TextRange, TextSize};
use super::quote; use super::quote;
@ -240,7 +240,7 @@ mod tests {
), ),
ast_id: ROOT_ERASED_FILE_AST_ID, ast_id: ROOT_ERASED_FILE_AST_ID,
}, },
ctx: SyntaxContextId::root(Edition::CURRENT), ctx: SyntaxContext::root(Edition::CURRENT),
}; };
#[test] #[test]

View file

@ -7,7 +7,7 @@ use rustc_hash::FxHashSet;
use salsa::plumbing::AsId; use salsa::plumbing::AsId;
use span::{ use span::{
AstIdMap, Edition, EditionedFileId, HirFileId, HirFileIdRepr, MacroCallId, MacroFileId, Span, AstIdMap, Edition, EditionedFileId, HirFileId, HirFileIdRepr, MacroCallId, MacroFileId, Span,
SyntaxContextId, SyntaxContext,
}; };
use syntax::{ast, AstNode, Parse, SyntaxElement, SyntaxError, SyntaxNode, SyntaxToken, T}; use syntax::{ast, AstNode, Parse, SyntaxElement, SyntaxError, SyntaxNode, SyntaxToken, T};
use syntax_bridge::{syntax_node_to_token_tree, DocCommentDesugarMode}; use syntax_bridge::{syntax_node_to_token_tree, DocCommentDesugarMode};
@ -96,10 +96,6 @@ pub trait ExpandDatabase: RootQueryDb {
#[salsa::transparent] #[salsa::transparent]
fn lookup_intern_macro_call(&self, macro_call: MacroCallId) -> MacroCallLoc; fn lookup_intern_macro_call(&self, macro_call: MacroCallId) -> MacroCallLoc;
#[salsa::transparent]
#[salsa::invoke(crate::hygiene::dump_syntax_contexts)]
fn dump_syntax_contexts(&self) -> String;
/// Lowers syntactic macro call to a token tree representation. That's a firewall /// Lowers syntactic macro call to a token tree representation. That's a firewall
/// query, only typing in the macro call itself changes the returned /// query, only typing in the macro call itself changes the returned
/// subtree. /// subtree.
@ -148,7 +144,7 @@ pub trait ExpandDatabase: RootQueryDb {
) -> Option<Arc<ExpandResult<Arc<[SyntaxError]>>>>; ) -> Option<Arc<ExpandResult<Arc<[SyntaxError]>>>>;
#[salsa::transparent] #[salsa::transparent]
fn syntax_context(&self, file: HirFileId, edition: Edition) -> SyntaxContextId; fn syntax_context(&self, file: HirFileId, edition: Edition) -> SyntaxContext;
} }
#[salsa::interned(no_lifetime, id = span::MacroCallId)] #[salsa::interned(no_lifetime, id = span::MacroCallId)]
@ -164,14 +160,14 @@ fn lookup_intern_macro_call(db: &dyn ExpandDatabase, macro_call: MacroCallId) ->
MacroCallWrapper::ingredient(db).data(db.as_dyn_database(), macro_call.as_id()).0.clone() MacroCallWrapper::ingredient(db).data(db.as_dyn_database(), macro_call.as_id()).0.clone()
} }
#[salsa::interned(no_lifetime, id = span::SyntaxContextId)] #[salsa::interned(no_lifetime, id = span::SyntaxContext)]
pub struct SyntaxContextWrapper { pub struct SyntaxContextWrapper {
pub data: SyntaxContextId, pub data: SyntaxContext,
} }
fn syntax_context(db: &dyn ExpandDatabase, file: HirFileId, edition: Edition) -> SyntaxContextId { fn syntax_context(db: &dyn ExpandDatabase, file: HirFileId, edition: Edition) -> SyntaxContext {
match file.repr() { match file.repr() {
HirFileIdRepr::FileId(_) => SyntaxContextId::root(edition), HirFileIdRepr::FileId(_) => SyntaxContext::root(edition),
HirFileIdRepr::MacroFile(m) => { HirFileIdRepr::MacroFile(m) => {
let kind = db.lookup_intern_macro_call(m.macro_call_id).kind; let kind = db.lookup_intern_macro_call(m.macro_call_id).kind;
db.macro_arg_considering_derives(m.macro_call_id, &kind).2.ctx db.macro_arg_considering_derives(m.macro_call_id, &kind).2.ctx

View file

@ -2,7 +2,7 @@
use base_db::Crate; use base_db::Crate;
use intern::sym; use intern::sym;
use span::{Edition, HirFileIdRepr, MacroCallId, Span, SyntaxContextId}; use span::{Edition, HirFileIdRepr, MacroCallId, Span, SyntaxContext};
use stdx::TupleExt; use stdx::TupleExt;
use syntax::{ast, AstNode}; use syntax::{ast, AstNode};
use syntax_bridge::DocCommentDesugarMode; use syntax_bridge::DocCommentDesugarMode;
@ -100,7 +100,7 @@ impl DeclarativeMacroExpander {
_ => None, _ => None,
} }
}; };
let ctx_edition = |ctx: SyntaxContextId| { let ctx_edition = |ctx: SyntaxContext| {
if ctx.is_root() { if ctx.is_root() {
def_crate.data(db).edition def_crate.data(db).edition
} else { } else {
@ -161,7 +161,7 @@ impl DeclarativeMacroExpander {
}; };
let edition = ctx_edition(match id.file_id.repr() { let edition = ctx_edition(match id.file_id.repr() {
HirFileIdRepr::MacroFile(macro_file) => macro_file.macro_call_id.lookup(db).ctxt, HirFileIdRepr::MacroFile(macro_file) => macro_file.macro_call_id.lookup(db).ctxt,
HirFileIdRepr::FileId(file) => SyntaxContextId::root(file.edition()), HirFileIdRepr::FileId(file) => SyntaxContext::root(file.edition()),
}); });
Arc::new(DeclarativeMacroExpander { mac, transparency, edition }) Arc::new(DeclarativeMacroExpander { mac, transparency, edition })
} }

View file

@ -19,7 +19,7 @@
//! //!
//! See the full discussion : <https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Eager.20expansion.20of.20built-in.20macros> //! See the full discussion : <https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Eager.20expansion.20of.20built-in.20macros>
use base_db::Crate; use base_db::Crate;
use span::SyntaxContextId; use span::SyntaxContext;
use syntax::{ted, Parse, SyntaxElement, SyntaxNode, TextSize, WalkEvent}; use syntax::{ted, Parse, SyntaxElement, SyntaxNode, TextSize, WalkEvent};
use syntax_bridge::DocCommentDesugarMode; use syntax_bridge::DocCommentDesugarMode;
use triomphe::Arc; use triomphe::Arc;
@ -38,7 +38,7 @@ pub fn expand_eager_macro_input(
macro_call: &ast::MacroCall, macro_call: &ast::MacroCall,
ast_id: AstId<ast::MacroCall>, ast_id: AstId<ast::MacroCall>,
def: MacroDefId, def: MacroDefId,
call_site: SyntaxContextId, call_site: SyntaxContext,
resolver: &dyn Fn(&ModPath) -> Option<MacroDefId>, resolver: &dyn Fn(&ModPath) -> Option<MacroDefId>,
) -> ExpandResult<Option<MacroCallId>> { ) -> ExpandResult<Option<MacroCallId>> {
let expand_to = ExpandTo::from_call_site(macro_call); let expand_to = ExpandTo::from_call_site(macro_call);
@ -116,7 +116,7 @@ fn lazy_expand(
macro_call: &ast::MacroCall, macro_call: &ast::MacroCall,
ast_id: AstId<ast::MacroCall>, ast_id: AstId<ast::MacroCall>,
krate: Crate, krate: Crate,
call_site: SyntaxContextId, call_site: SyntaxContext,
) -> ExpandResult<(InFile<Parse<SyntaxNode>>, Arc<ExpansionSpanMap>)> { ) -> ExpandResult<(InFile<Parse<SyntaxNode>>, Arc<ExpansionSpanMap>)> {
let expand_to = ExpandTo::from_call_site(macro_call); let expand_to = ExpandTo::from_call_site(macro_call);
let id = def.make_call( let id = def.make_call(
@ -138,7 +138,7 @@ fn eager_macro_recur(
mut offset: TextSize, mut offset: TextSize,
curr: InFile<SyntaxNode>, curr: InFile<SyntaxNode>,
krate: Crate, krate: Crate,
call_site: SyntaxContextId, call_site: SyntaxContext,
macro_resolver: &dyn Fn(&ModPath) -> Option<MacroDefId>, macro_resolver: &dyn Fn(&ModPath) -> Option<MacroDefId>,
) -> ExpandResult<Option<(SyntaxNode, TextSize)>> { ) -> ExpandResult<Option<(SyntaxNode, TextSize)>> {
let original = curr.value.clone_for_update(); let original = curr.value.clone_for_update();

View file

@ -4,7 +4,7 @@ use std::borrow::Borrow;
use either::Either; use either::Either;
use span::{ use span::{
AstIdNode, EditionedFileId, ErasedFileAstId, FileAstId, HirFileId, HirFileIdRepr, MacroFileId, AstIdNode, EditionedFileId, ErasedFileAstId, FileAstId, HirFileId, HirFileIdRepr, MacroFileId,
SyntaxContextId, SyntaxContext,
}; };
use syntax::{AstNode, AstPtr, SyntaxNode, SyntaxNodePtr, SyntaxToken, TextRange, TextSize}; use syntax::{AstNode, AstPtr, SyntaxNode, SyntaxNodePtr, SyntaxToken, TextRange, TextSize};
@ -311,7 +311,7 @@ impl InFile<&SyntaxNode> {
pub fn original_file_range_opt( pub fn original_file_range_opt(
self, self,
db: &dyn db::ExpandDatabase, db: &dyn db::ExpandDatabase,
) -> Option<(FileRange, SyntaxContextId)> { ) -> Option<(FileRange, SyntaxContext)> {
self.borrow().map(SyntaxNode::text_range).original_node_file_range_opt(db) self.borrow().map(SyntaxNode::text_range).original_node_file_range_opt(db)
} }
} }
@ -376,7 +376,7 @@ impl InFile<SyntaxToken> {
} }
impl InMacroFile<TextSize> { impl InMacroFile<TextSize> {
pub fn original_file_range(self, db: &dyn db::ExpandDatabase) -> (FileRange, SyntaxContextId) { pub fn original_file_range(self, db: &dyn db::ExpandDatabase) -> (FileRange, SyntaxContext) {
span_for_offset(db, &db.expansion_span_map(self.file_id), self.value) span_for_offset(db, &db.expansion_span_map(self.file_id), self.value)
} }
} }
@ -385,17 +385,17 @@ impl InFile<TextRange> {
pub fn original_node_file_range( pub fn original_node_file_range(
self, self,
db: &dyn db::ExpandDatabase, db: &dyn db::ExpandDatabase,
) -> (FileRange, SyntaxContextId) { ) -> (FileRange, SyntaxContext) {
match self.file_id.repr() { match self.file_id.repr() {
HirFileIdRepr::FileId(file_id) => { HirFileIdRepr::FileId(file_id) => {
(FileRange { file_id, range: self.value }, SyntaxContextId::root(file_id.edition())) (FileRange { file_id, range: self.value }, SyntaxContext::root(file_id.edition()))
} }
HirFileIdRepr::MacroFile(mac_file) => { HirFileIdRepr::MacroFile(mac_file) => {
match map_node_range_up(db, &db.expansion_span_map(mac_file), self.value) { match map_node_range_up(db, &db.expansion_span_map(mac_file), self.value) {
Some(it) => it, Some(it) => it,
None => { None => {
let loc = db.lookup_intern_macro_call(mac_file.macro_call_id); let loc = db.lookup_intern_macro_call(mac_file.macro_call_id);
(loc.kind.original_call_range(db), SyntaxContextId::root(loc.def.edition)) (loc.kind.original_call_range(db), SyntaxContext::root(loc.def.edition))
} }
} }
} }
@ -438,11 +438,11 @@ impl InFile<TextRange> {
pub fn original_node_file_range_opt( pub fn original_node_file_range_opt(
self, self,
db: &dyn db::ExpandDatabase, db: &dyn db::ExpandDatabase,
) -> Option<(FileRange, SyntaxContextId)> { ) -> Option<(FileRange, SyntaxContext)> {
match self.file_id.repr() { match self.file_id.repr() {
HirFileIdRepr::FileId(file_id) => Some(( HirFileIdRepr::FileId(file_id) => Some((
FileRange { file_id, range: self.value }, FileRange { file_id, range: self.value },
SyntaxContextId::root(file_id.edition()), SyntaxContext::root(file_id.edition()),
)), )),
HirFileIdRepr::MacroFile(mac_file) => { HirFileIdRepr::MacroFile(mac_file) => {
map_node_range_up(db, &db.expansion_span_map(mac_file), self.value) map_node_range_up(db, &db.expansion_span_map(mac_file), self.value)

View file

@ -4,7 +4,7 @@
use intern::sym; use intern::sym;
use rustc_hash::{FxHashMap, FxHashSet}; use rustc_hash::{FxHashMap, FxHashSet};
use span::{ use span::{
ErasedFileAstId, Span, SpanAnchor, SyntaxContextId, FIXUP_ERASED_FILE_AST_ID_MARKER, ErasedFileAstId, Span, SpanAnchor, SyntaxContext, FIXUP_ERASED_FILE_AST_ID_MARKER,
ROOT_ERASED_FILE_AST_ID, ROOT_ERASED_FILE_AST_ID,
}; };
use stdx::never; use stdx::never;
@ -353,7 +353,7 @@ pub(crate) fn reverse_fixups(tt: &mut TopSubtree, undo_info: &SyntaxFixupUndoInf
let span = |file_id| Span { let span = |file_id| Span {
range: TextRange::empty(TextSize::new(0)), range: TextRange::empty(TextSize::new(0)),
anchor: SpanAnchor { file_id, ast_id: ROOT_ERASED_FILE_AST_ID }, anchor: SpanAnchor { file_id, ast_id: ROOT_ERASED_FILE_AST_ID },
ctx: SyntaxContextId::root(span::Edition::Edition2015), ctx: SyntaxContext::root(span::Edition::Edition2015),
}; };
delimiter.open = span(delimiter.open.anchor.file_id); delimiter.open = span(delimiter.open.anchor.file_id);
delimiter.close = span(delimiter.close.anchor.file_id); delimiter.close = span(delimiter.close.anchor.file_id);

View file

@ -24,9 +24,9 @@
use std::{convert::identity, iter}; use std::{convert::identity, iter};
use span::{Edition, MacroCallId, Span, SyntaxContextId}; use span::{Edition, MacroCallId, Span, SyntaxContext};
use crate::db::{ExpandDatabase, MacroCallWrapper}; use crate::db::ExpandDatabase;
pub use span::Transparency; pub use span::Transparency;
@ -65,18 +65,18 @@ fn span_with_ctxt_from_mark(
edition: Edition, edition: Edition,
) -> Span { ) -> Span {
Span { Span {
ctx: apply_mark(db, SyntaxContextId::root(edition), expn_id, transparency, edition), ctx: apply_mark(db, SyntaxContext::root(edition), expn_id, transparency, edition),
..span ..span
} }
} }
pub(super) fn apply_mark( pub(super) fn apply_mark(
db: &dyn ExpandDatabase, db: &dyn ExpandDatabase,
ctxt: span::SyntaxContextId, ctxt: span::SyntaxContext,
call_id: span::MacroCallId, call_id: span::MacroCallId,
transparency: Transparency, transparency: Transparency,
edition: Edition, edition: Edition,
) -> SyntaxContextId { ) -> SyntaxContext {
if transparency == Transparency::Opaque { if transparency == Transparency::Opaque {
return apply_mark_internal(db, ctxt, call_id, transparency, edition); return apply_mark_internal(db, ctxt, call_id, transparency, edition);
} }
@ -109,11 +109,11 @@ pub(super) fn apply_mark(
fn apply_mark_internal( fn apply_mark_internal(
db: &dyn ExpandDatabase, db: &dyn ExpandDatabase,
ctxt: SyntaxContextId, ctxt: SyntaxContext,
call_id: MacroCallId, call_id: MacroCallId,
transparency: Transparency, transparency: Transparency,
edition: Edition, edition: Edition,
) -> SyntaxContextId { ) -> SyntaxContext {
let call_id = Some(call_id); let call_id = Some(call_id);
let mut opaque = ctxt.opaque(db); let mut opaque = ctxt.opaque(db);
@ -121,18 +121,17 @@ fn apply_mark_internal(
if transparency >= Transparency::Opaque { if transparency >= Transparency::Opaque {
let parent = opaque; let parent = opaque;
opaque = opaque = SyntaxContext::new(db, call_id, transparency, edition, parent, identity, identity);
SyntaxContextId::new(db, call_id, transparency, edition, parent, identity, identity);
} }
if transparency >= Transparency::SemiTransparent { if transparency >= Transparency::SemiTransparent {
let parent = opaque_and_semitransparent; let parent = opaque_and_semitransparent;
opaque_and_semitransparent = opaque_and_semitransparent =
SyntaxContextId::new(db, call_id, transparency, edition, parent, |_| opaque, identity); SyntaxContext::new(db, call_id, transparency, edition, parent, |_| opaque, identity);
} }
let parent = ctxt; let parent = ctxt;
SyntaxContextId::new( SyntaxContext::new(
db, db,
call_id, call_id,
transparency, transparency,
@ -144,9 +143,9 @@ fn apply_mark_internal(
} }
pub trait SyntaxContextExt { pub trait SyntaxContextExt {
fn normalize_to_macro_rules(self, db: &dyn ExpandDatabase) -> span::SyntaxContextId; fn normalize_to_macro_rules(self, db: &dyn ExpandDatabase) -> span::SyntaxContext;
fn normalize_to_macros_2_0(self, db: &dyn ExpandDatabase) -> span::SyntaxContextId; fn normalize_to_macros_2_0(self, db: &dyn ExpandDatabase) -> span::SyntaxContext;
fn parent_ctxt(self, db: &dyn ExpandDatabase) -> span::SyntaxContextId; fn parent_ctxt(self, db: &dyn ExpandDatabase) -> span::SyntaxContext;
fn remove_mark(&mut self, db: &dyn ExpandDatabase) fn remove_mark(&mut self, db: &dyn ExpandDatabase)
-> (Option<span::MacroCallId>, Transparency); -> (Option<span::MacroCallId>, Transparency);
fn outer_mark(self, db: &dyn ExpandDatabase) -> (Option<span::MacroCallId>, Transparency); fn outer_mark(self, db: &dyn ExpandDatabase) -> (Option<span::MacroCallId>, Transparency);
@ -154,14 +153,14 @@ pub trait SyntaxContextExt {
fn is_opaque(self, db: &dyn ExpandDatabase) -> bool; fn is_opaque(self, db: &dyn ExpandDatabase) -> bool;
} }
impl SyntaxContextExt for SyntaxContextId { impl SyntaxContextExt for SyntaxContext {
fn normalize_to_macro_rules(self, db: &dyn ExpandDatabase) -> span::SyntaxContextId { fn normalize_to_macro_rules(self, db: &dyn ExpandDatabase) -> span::SyntaxContext {
self.opaque_and_semitransparent(db) self.opaque_and_semitransparent(db)
} }
fn normalize_to_macros_2_0(self, db: &dyn ExpandDatabase) -> span::SyntaxContextId { fn normalize_to_macros_2_0(self, db: &dyn ExpandDatabase) -> span::SyntaxContext {
self.opaque(db) self.opaque(db)
} }
fn parent_ctxt(self, db: &dyn ExpandDatabase) -> span::SyntaxContextId { fn parent_ctxt(self, db: &dyn ExpandDatabase) -> span::SyntaxContext {
self.parent(db) self.parent(db)
} }
fn outer_mark(self, db: &dyn ExpandDatabase) -> (Option<span::MacroCallId>, Transparency) { fn outer_mark(self, db: &dyn ExpandDatabase) -> (Option<span::MacroCallId>, Transparency) {
@ -188,7 +187,7 @@ impl SyntaxContextExt for SyntaxContextId {
// FIXME: Make this a SyntaxContextExt method once we have RPIT // FIXME: Make this a SyntaxContextExt method once we have RPIT
pub fn marks_rev( pub fn marks_rev(
ctxt: SyntaxContextId, ctxt: SyntaxContext,
db: &dyn ExpandDatabase, db: &dyn ExpandDatabase,
) -> impl Iterator<Item = (span::MacroCallId, Transparency)> + '_ { ) -> impl Iterator<Item = (span::MacroCallId, Transparency)> + '_ {
iter::successors(Some(ctxt), move |&mark| Some(mark.parent_ctxt(db))) iter::successors(Some(ctxt), move |&mark| Some(mark.parent_ctxt(db)))
@ -200,53 +199,3 @@ pub fn marks_rev(
(mark.0.unwrap(), mark.1) (mark.0.unwrap(), mark.1)
}) })
} }
pub(crate) fn dump_syntax_contexts(db: &dyn ExpandDatabase) -> String {
let mut s = String::from("Expansions:");
let entries =
MacroCallWrapper::ingredient(db).entries(db.as_dyn_database()).collect::<Vec<_>>();
for loc in entries {
let expn_data = &loc.fields().0;
s.push_str(&format!(
"parent: {:?}, call_site_ctxt: {:?}, kind: {:?}",
expn_data.kind.file_id(),
expn_data.ctxt,
expn_data.kind.descr(),
));
}
s.push_str("\n\nSyntaxContexts:\n");
let entries = SyntaxContextId::ingredient(db).entries(db.as_dyn_database()).collect::<Vec<_>>();
for e in entries {
struct SyntaxContextDebug<'a>(
&'a dyn ExpandDatabase,
&'a span::SyntaxContextUnderlyingData,
);
impl std::fmt::Debug for SyntaxContextDebug<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
fancy_debug(self.1, self.0, f)
}
}
fn fancy_debug(
this: &span::SyntaxContextUnderlyingData,
db: &dyn ExpandDatabase,
f: &mut std::fmt::Formatter<'_>,
) -> std::fmt::Result {
write!(f, "parent: #{}, outer_mark: (", this.parent)?;
match this.outer_expn {
Some(id) => {
write!(f, "{:?}::{{{{expn{:?}}}}}", db.lookup_intern_macro_call(id).krate, id)?
}
None => write!(f, "root")?,
}
write!(f, ", {:?})", this.outer_transparency)
}
let dbg = SyntaxContextDebug(db, e.fields());
stdx::format_to!(s, "{:?}\n", dbg);
}
s
}

View file

@ -37,7 +37,7 @@ use base_db::Crate;
use either::Either; use either::Either;
use span::{ use span::{
Edition, EditionedFileId, ErasedFileAstId, FileAstId, HirFileIdRepr, Span, SpanAnchor, Edition, EditionedFileId, ErasedFileAstId, FileAstId, HirFileIdRepr, Span, SpanAnchor,
SyntaxContextId, SyntaxContext,
}; };
use syntax::{ use syntax::{
ast::{self, AstNode}, ast::{self, AstNode},
@ -252,7 +252,7 @@ pub struct MacroCallLoc {
pub def: MacroDefId, pub def: MacroDefId,
pub krate: Crate, pub krate: Crate,
pub kind: MacroCallKind, pub kind: MacroCallKind,
pub ctxt: SyntaxContextId, pub ctxt: SyntaxContext,
} }
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@ -527,7 +527,7 @@ impl MacroDefId {
db: &dyn ExpandDatabase, db: &dyn ExpandDatabase,
krate: Crate, krate: Crate,
kind: MacroCallKind, kind: MacroCallKind,
ctxt: SyntaxContextId, ctxt: SyntaxContext,
) -> MacroCallId { ) -> MacroCallId {
db.intern_macro_call(MacroCallLoc { def: self, krate, kind, ctxt }) db.intern_macro_call(MacroCallLoc { def: self, krate, kind, ctxt })
} }
@ -683,7 +683,7 @@ impl MacroCallLoc {
} }
impl MacroCallKind { impl MacroCallKind {
fn descr(&self) -> &'static str { pub fn descr(&self) -> &'static str {
match self { match self {
MacroCallKind::FnLike { .. } => "macro call", MacroCallKind::FnLike { .. } => "macro call",
MacroCallKind::Derive { .. } => "derive macro", MacroCallKind::Derive { .. } => "derive macro",
@ -831,7 +831,7 @@ impl ExpansionInfo {
pub fn map_range_down_exact( pub fn map_range_down_exact(
&self, &self,
span: Span, span: Span,
) -> Option<InMacroFile<impl Iterator<Item = (SyntaxToken, SyntaxContextId)> + '_>> { ) -> Option<InMacroFile<impl Iterator<Item = (SyntaxToken, SyntaxContext)> + '_>> {
let tokens = self.exp_map.ranges_with_span_exact(span).flat_map(move |(range, ctx)| { let tokens = self.exp_map.ranges_with_span_exact(span).flat_map(move |(range, ctx)| {
self.expanded.value.covering_element(range).into_token().zip(Some(ctx)) self.expanded.value.covering_element(range).into_token().zip(Some(ctx))
}); });
@ -846,7 +846,7 @@ impl ExpansionInfo {
pub fn map_range_down( pub fn map_range_down(
&self, &self,
span: Span, span: Span,
) -> Option<InMacroFile<impl Iterator<Item = (SyntaxToken, SyntaxContextId)> + '_>> { ) -> Option<InMacroFile<impl Iterator<Item = (SyntaxToken, SyntaxContext)> + '_>> {
let tokens = self.exp_map.ranges_with_span(span).flat_map(move |(range, ctx)| { let tokens = self.exp_map.ranges_with_span(span).flat_map(move |(range, ctx)| {
self.expanded.value.covering_element(range).into_token().zip(Some(ctx)) self.expanded.value.covering_element(range).into_token().zip(Some(ctx))
}); });
@ -859,7 +859,7 @@ impl ExpansionInfo {
&self, &self,
db: &dyn ExpandDatabase, db: &dyn ExpandDatabase,
offset: TextSize, offset: TextSize,
) -> (FileRange, SyntaxContextId) { ) -> (FileRange, SyntaxContext) {
debug_assert!(self.expanded.value.text_range().contains(offset)); debug_assert!(self.expanded.value.text_range().contains(offset));
span_for_offset(db, &self.exp_map, offset) span_for_offset(db, &self.exp_map, offset)
} }
@ -869,7 +869,7 @@ impl ExpansionInfo {
&self, &self,
db: &dyn ExpandDatabase, db: &dyn ExpandDatabase,
range: TextRange, range: TextRange,
) -> Option<(FileRange, SyntaxContextId)> { ) -> Option<(FileRange, SyntaxContext)> {
debug_assert!(self.expanded.value.text_range().contains_range(range)); debug_assert!(self.expanded.value.text_range().contains_range(range));
map_node_range_up(db, &self.exp_map, range) map_node_range_up(db, &self.exp_map, range)
} }
@ -953,7 +953,7 @@ pub fn map_node_range_up(
db: &dyn ExpandDatabase, db: &dyn ExpandDatabase,
exp_map: &ExpansionSpanMap, exp_map: &ExpansionSpanMap,
range: TextRange, range: TextRange,
) -> Option<(FileRange, SyntaxContextId)> { ) -> Option<(FileRange, SyntaxContext)> {
let mut spans = exp_map.spans_for_range(range); let mut spans = exp_map.spans_for_range(range);
let Span { range, anchor, ctx } = spans.next()?; let Span { range, anchor, ctx } = spans.next()?;
let mut start = range.start(); let mut start = range.start();
@ -980,7 +980,7 @@ pub fn map_node_range_up_aggregated(
db: &dyn ExpandDatabase, db: &dyn ExpandDatabase,
exp_map: &ExpansionSpanMap, exp_map: &ExpansionSpanMap,
range: TextRange, range: TextRange,
) -> FxHashMap<(SpanAnchor, SyntaxContextId), TextRange> { ) -> FxHashMap<(SpanAnchor, SyntaxContext), TextRange> {
let mut map = FxHashMap::default(); let mut map = FxHashMap::default();
for span in exp_map.spans_for_range(range) { for span in exp_map.spans_for_range(range) {
let range = map.entry((span.anchor, span.ctx)).or_insert_with(|| span.range); let range = map.entry((span.anchor, span.ctx)).or_insert_with(|| span.range);
@ -1002,7 +1002,7 @@ pub fn span_for_offset(
db: &dyn ExpandDatabase, db: &dyn ExpandDatabase,
exp_map: &ExpansionSpanMap, exp_map: &ExpansionSpanMap,
offset: TextSize, offset: TextSize,
) -> (FileRange, SyntaxContextId) { ) -> (FileRange, SyntaxContext) {
let span = exp_map.span_at(offset); let span = exp_map.span_at(offset);
let anchor_offset = db let anchor_offset = db
.ast_id_map(span.anchor.file_id.into()) .ast_id_map(span.anchor.file_id.into())

View file

@ -14,7 +14,7 @@ use crate::{
use base_db::Crate; use base_db::Crate;
use intern::sym; use intern::sym;
use smallvec::SmallVec; use smallvec::SmallVec;
use span::{Edition, SyntaxContextId}; use span::{Edition, SyntaxContext};
use syntax::{ast, AstNode}; use syntax::{ast, AstNode};
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
@ -44,7 +44,7 @@ impl ModPath {
pub fn from_src( pub fn from_src(
db: &dyn ExpandDatabase, db: &dyn ExpandDatabase,
path: ast::Path, path: ast::Path,
span_for_range: &mut dyn FnMut(::tt::TextRange) -> SyntaxContextId, span_for_range: &mut dyn FnMut(::tt::TextRange) -> SyntaxContext,
) -> Option<ModPath> { ) -> Option<ModPath> {
convert_path(db, path, span_for_range) convert_path(db, path, span_for_range)
} }
@ -209,7 +209,7 @@ fn display_fmt_path(
fn convert_path( fn convert_path(
db: &dyn ExpandDatabase, db: &dyn ExpandDatabase,
path: ast::Path, path: ast::Path,
span_for_range: &mut dyn FnMut(::tt::TextRange) -> SyntaxContextId, span_for_range: &mut dyn FnMut(::tt::TextRange) -> SyntaxContext,
) -> Option<ModPath> { ) -> Option<ModPath> {
let mut segments = path.segments(); let mut segments = path.segments();
@ -333,7 +333,7 @@ fn convert_path_tt(db: &dyn ExpandDatabase, tt: tt::TokenTreesView<'_>) -> Optio
Some(ModPath { kind, segments }) Some(ModPath { kind, segments })
} }
pub fn resolve_crate_root(db: &dyn ExpandDatabase, mut ctxt: SyntaxContextId) -> Option<Crate> { pub fn resolve_crate_root(db: &dyn ExpandDatabase, mut ctxt: SyntaxContext) -> Option<Crate> {
// When resolving `$crate` from a `macro_rules!` invoked in a `macro`, // When resolving `$crate` from a `macro_rules!` invoked in a `macro`,
// we don't want to pretend that the `macro_rules!` definition is in the `macro` // we don't want to pretend that the `macro_rules!` definition is in the `macro`
// as described in `SyntaxContextId::apply_mark`, so we ignore prepended opaque marks. // as described in `SyntaxContextId::apply_mark`, so we ignore prepended opaque marks.

View file

@ -3,7 +3,7 @@
use std::fmt; use std::fmt;
use intern::{sym, Symbol}; use intern::{sym, Symbol};
use span::{Edition, SyntaxContextId}; use span::{Edition, SyntaxContext};
use syntax::utils::is_raw_identifier; use syntax::utils::is_raw_identifier;
use syntax::{ast, format_smolstr}; use syntax::{ast, format_smolstr};
@ -74,7 +74,7 @@ impl Name {
Name { symbol: Symbol::intern(text), ctx: () } Name { symbol: Symbol::intern(text), ctx: () }
} }
pub fn new(text: &str, mut ctx: SyntaxContextId) -> Name { pub fn new(text: &str, mut ctx: SyntaxContext) -> Name {
// For comparisons etc. we remove the edition, because sometimes we search for some `Name` // For comparisons etc. we remove the edition, because sometimes we search for some `Name`
// and we don't know which edition it came from. // and we don't know which edition it came from.
// Can't do that for all `SyntaxContextId`s because it breaks Salsa. // Can't do that for all `SyntaxContextId`s because it breaks Salsa.
@ -88,7 +88,7 @@ impl Name {
pub fn new_root(text: &str) -> Name { pub fn new_root(text: &str) -> Name {
// The edition doesn't matter for hygiene. // The edition doesn't matter for hygiene.
Self::new(text, SyntaxContextId::root(Edition::Edition2015)) Self::new(text, SyntaxContext::root(Edition::Edition2015))
} }
pub fn new_tuple_field(idx: usize) -> Name { pub fn new_tuple_field(idx: usize) -> Name {
@ -122,7 +122,7 @@ impl Name {
} }
} }
pub fn new_symbol(symbol: Symbol, ctx: SyntaxContextId) -> Self { pub fn new_symbol(symbol: Symbol, ctx: SyntaxContext) -> Self {
debug_assert!(!symbol.as_str().starts_with("r#")); debug_assert!(!symbol.as_str().starts_with("r#"));
_ = ctx; _ = ctx;
Self { symbol, ctx: () } Self { symbol, ctx: () }
@ -130,7 +130,7 @@ impl Name {
// FIXME: This needs to go once we have hygiene // FIXME: This needs to go once we have hygiene
pub fn new_symbol_root(sym: Symbol) -> Self { pub fn new_symbol_root(sym: Symbol) -> Self {
Self::new_symbol(sym, SyntaxContextId::root(Edition::Edition2015)) Self::new_symbol(sym, SyntaxContext::root(Edition::Edition2015))
} }
/// A fake name for things missing in the source code. /// A fake name for things missing in the source code.

View file

@ -154,7 +154,7 @@ impl CrateProcMacros {
/// Fetch the [`CustomProcMacroExpander`]s and their corresponding names for the given crate. /// Fetch the [`CustomProcMacroExpander`]s and their corresponding names for the given crate.
pub fn list( pub fn list(
&self, &self,
def_site_ctx: span::SyntaxContextId, def_site_ctx: span::SyntaxContext,
) -> Option<Box<[(crate::name::Name, CustomProcMacroExpander, bool)]>> { ) -> Option<Box<[(crate::name::Name, CustomProcMacroExpander, bool)]>> {
match &self.0 { match &self.0 {
Ok(proc_macros) => Some( Ok(proc_macros) => Some(

View file

@ -1,6 +1,6 @@
//! Span maps for real files and macro expansions. //! Span maps for real files and macro expansions.
use span::{EditionedFileId, HirFileId, HirFileIdRepr, MacroFileId, Span, SyntaxContextId}; use span::{EditionedFileId, HirFileId, HirFileIdRepr, MacroFileId, Span, SyntaxContext};
use stdx::TupleExt; use stdx::TupleExt;
use syntax::{ast, AstNode, TextRange}; use syntax::{ast, AstNode, TextRange};
use triomphe::Arc; use triomphe::Arc;
@ -9,7 +9,7 @@ pub use span::RealSpanMap;
use crate::{attrs::collect_attrs, db::ExpandDatabase}; use crate::{attrs::collect_attrs, db::ExpandDatabase};
pub type ExpansionSpanMap = span::SpanMap<SyntaxContextId>; pub type ExpansionSpanMap = span::SpanMap<SyntaxContext>;
/// Spanmap for a macro file or a real file /// Spanmap for a macro file or a real file
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]

View file

@ -36,7 +36,7 @@ use intern::{sym, Symbol};
use itertools::Itertools; use itertools::Itertools;
use rustc_hash::{FxHashMap, FxHashSet}; use rustc_hash::{FxHashMap, FxHashSet};
use smallvec::{smallvec, SmallVec}; use smallvec::{smallvec, SmallVec};
use span::{AstIdMap, EditionedFileId, FileId, HirFileIdRepr, SyntaxContextId}; use span::{AstIdMap, EditionedFileId, FileId, HirFileIdRepr, SyntaxContext};
use stdx::TupleExt; use stdx::TupleExt;
use syntax::{ use syntax::{
algo::skip_trivia_token, algo::skip_trivia_token,
@ -877,7 +877,7 @@ impl<'db> SemanticsImpl<'db> {
pub fn descend_into_macros_cb( pub fn descend_into_macros_cb(
&self, &self,
token: SyntaxToken, token: SyntaxToken,
mut cb: impl FnMut(InFile<SyntaxToken>, SyntaxContextId), mut cb: impl FnMut(InFile<SyntaxToken>, SyntaxContext),
) { ) {
if let Ok(token) = self.wrap_token_infile(token).into_real_file() { if let Ok(token) = self.wrap_token_infile(token).into_real_file() {
self.descend_into_macros_impl(token, &mut |t, ctx| { self.descend_into_macros_impl(token, &mut |t, ctx| {
@ -921,7 +921,7 @@ impl<'db> SemanticsImpl<'db> {
pub fn descend_into_macros_breakable<T>( pub fn descend_into_macros_breakable<T>(
&self, &self,
token: InRealFile<SyntaxToken>, token: InRealFile<SyntaxToken>,
mut cb: impl FnMut(InFile<SyntaxToken>, SyntaxContextId) -> ControlFlow<T>, mut cb: impl FnMut(InFile<SyntaxToken>, SyntaxContext) -> ControlFlow<T>,
) -> Option<T> { ) -> Option<T> {
self.descend_into_macros_impl(token.clone(), &mut cb) self.descend_into_macros_impl(token.clone(), &mut cb)
} }
@ -979,7 +979,7 @@ impl<'db> SemanticsImpl<'db> {
fn descend_into_macros_impl<T>( fn descend_into_macros_impl<T>(
&self, &self,
InRealFile { value: token, file_id }: InRealFile<SyntaxToken>, InRealFile { value: token, file_id }: InRealFile<SyntaxToken>,
f: &mut dyn FnMut(InFile<SyntaxToken>, SyntaxContextId) -> ControlFlow<T>, f: &mut dyn FnMut(InFile<SyntaxToken>, SyntaxContext) -> ControlFlow<T>,
) -> Option<T> { ) -> Option<T> {
let _p = tracing::info_span!("descend_into_macros_impl").entered(); let _p = tracing::info_span!("descend_into_macros_impl").entered();
@ -1016,7 +1016,7 @@ impl<'db> SemanticsImpl<'db> {
None => { None => {
stack.push(( stack.push((
file_id.into(), file_id.into(),
smallvec![(token, SyntaxContextId::root(file_id.edition()))], smallvec![(token, SyntaxContext::root(file_id.edition()))],
)); ));
} }
} }

View file

@ -29,7 +29,7 @@ use crate::{
use base_db::AnchoredPathBuf; use base_db::AnchoredPathBuf;
use either::Either; use either::Either;
use hir::{FieldSource, FileRange, HirFileIdExt, InFile, ModuleSource, Semantics}; use hir::{FieldSource, FileRange, HirFileIdExt, InFile, ModuleSource, Semantics};
use span::{Edition, EditionedFileId, FileId, SyntaxContextId}; use span::{Edition, EditionedFileId, FileId, SyntaxContext};
use stdx::{never, TupleExt}; use stdx::{never, TupleExt};
use syntax::{ use syntax::{
ast::{self, HasName}, ast::{self, HasName},
@ -113,7 +113,7 @@ impl Definition {
/// renamed and extern crate names will report its range, though a rename will introduce /// renamed and extern crate names will report its range, though a rename will introduce
/// an alias instead. /// an alias instead.
pub fn range_for_rename(self, sema: &Semantics<'_, RootDatabase>) -> Option<FileRange> { pub fn range_for_rename(self, sema: &Semantics<'_, RootDatabase>) -> Option<FileRange> {
let syn_ctx_is_root = |(range, ctx): (_, SyntaxContextId)| ctx.is_root().then_some(range); let syn_ctx_is_root = |(range, ctx): (_, SyntaxContext)| ctx.is_root().then_some(range);
let res = match self { let res = match self {
Definition::Macro(mac) => { Definition::Macro(mac) => {
let src = sema.source(mac)?; let src = sema.source(mac)?;
@ -220,7 +220,7 @@ impl Definition {
fn name_range<D>( fn name_range<D>(
def: D, def: D,
sema: &Semantics<'_, RootDatabase>, sema: &Semantics<'_, RootDatabase>,
) -> Option<(FileRange, SyntaxContextId)> ) -> Option<(FileRange, SyntaxContext)>
where where
D: hir::HasSource, D: hir::HasSource,
D::Ast: ast::HasName, D::Ast: ast::HasName,

View file

@ -4,7 +4,7 @@ use ide_db::{
base_db::Crate, helpers::pick_best_token, syntax_helpers::prettify_macro_expansion, FileId, base_db::Crate, helpers::pick_best_token, syntax_helpers::prettify_macro_expansion, FileId,
RootDatabase, RootDatabase,
}; };
use span::{Edition, SpanMap, SyntaxContextId, TextRange, TextSize}; use span::{Edition, SpanMap, SyntaxContext, TextRange, TextSize};
use stdx::format_to; use stdx::format_to;
use syntax::{ast, ted, AstNode, NodeOrToken, SyntaxKind, SyntaxNode, T}; use syntax::{ast, ted, AstNode, NodeOrToken, SyntaxKind, SyntaxNode, T};
@ -142,7 +142,7 @@ fn expand_macro_recur(
sema: &Semantics<'_, RootDatabase>, sema: &Semantics<'_, RootDatabase>,
macro_call: &ast::Item, macro_call: &ast::Item,
error: &mut String, error: &mut String,
result_span_map: &mut SpanMap<SyntaxContextId>, result_span_map: &mut SpanMap<SyntaxContext>,
offset_in_original_node: TextSize, offset_in_original_node: TextSize,
) -> Option<SyntaxNode> { ) -> Option<SyntaxNode> {
let ExpandResult { value: expanded, err } = match macro_call { let ExpandResult { value: expanded, err } = match macro_call {
@ -170,7 +170,7 @@ fn expand(
sema: &Semantics<'_, RootDatabase>, sema: &Semantics<'_, RootDatabase>,
expanded: SyntaxNode, expanded: SyntaxNode,
error: &mut String, error: &mut String,
result_span_map: &mut SpanMap<SyntaxContextId>, result_span_map: &mut SpanMap<SyntaxContext>,
mut offset_in_original_node: i32, mut offset_in_original_node: i32,
) -> SyntaxNode { ) -> SyntaxNode {
let children = expanded.descendants().filter_map(ast::Item::cast); let children = expanded.descendants().filter_map(ast::Item::cast);
@ -207,7 +207,7 @@ fn format(
kind: SyntaxKind, kind: SyntaxKind,
file_id: FileId, file_id: FileId,
expanded: SyntaxNode, expanded: SyntaxNode,
span_map: &SpanMap<SyntaxContextId>, span_map: &SpanMap<SyntaxContext>,
krate: Crate, krate: Crate,
) -> String { ) -> String {
let expansion = prettify_macro_expansion(db, expanded, span_map, krate).to_string(); let expansion = prettify_macro_expansion(db, expanded, span_map, krate).to_string();

View file

@ -21,7 +21,7 @@ mod benchmark;
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;
use span::{Edition, Span, SyntaxContextId}; use span::{Edition, Span, SyntaxContext};
use syntax_bridge::to_parser_input; use syntax_bridge::to_parser_input;
use tt::iter::TtIter; use tt::iter::TtIter;
use tt::DelimSpan; use tt::DelimSpan;
@ -149,7 +149,7 @@ impl DeclarativeMacro {
/// The old, `macro_rules! m {}` flavor. /// The old, `macro_rules! m {}` flavor.
pub fn parse_macro_rules( pub fn parse_macro_rules(
tt: &tt::TopSubtree<Span>, tt: &tt::TopSubtree<Span>,
ctx_edition: impl Copy + Fn(SyntaxContextId) -> Edition, ctx_edition: impl Copy + Fn(SyntaxContext) -> Edition,
) -> DeclarativeMacro { ) -> DeclarativeMacro {
// Note: this parsing can be implemented using mbe machinery itself, by // Note: this parsing can be implemented using mbe machinery itself, by
// matching against `$($lhs:tt => $rhs:tt);*` pattern, but implementing // matching against `$($lhs:tt => $rhs:tt);*` pattern, but implementing
@ -189,7 +189,7 @@ impl DeclarativeMacro {
pub fn parse_macro2( pub fn parse_macro2(
args: Option<&tt::TopSubtree<Span>>, args: Option<&tt::TopSubtree<Span>>,
body: &tt::TopSubtree<Span>, body: &tt::TopSubtree<Span>,
ctx_edition: impl Copy + Fn(SyntaxContextId) -> Edition, ctx_edition: impl Copy + Fn(SyntaxContext) -> Edition,
) -> DeclarativeMacro { ) -> DeclarativeMacro {
let mut rules = Vec::new(); let mut rules = Vec::new();
let mut err = None; let mut err = None;
@ -262,7 +262,7 @@ impl DeclarativeMacro {
impl Rule { impl Rule {
fn parse( fn parse(
edition: impl Copy + Fn(SyntaxContextId) -> Edition, edition: impl Copy + Fn(SyntaxContext) -> Edition,
src: &mut TtIter<'_, Span>, src: &mut TtIter<'_, Span>,
) -> Result<Self, ParseError> { ) -> Result<Self, ParseError> {
let (_, lhs) = let (_, lhs) =

View file

@ -5,7 +5,7 @@ use std::sync::Arc;
use arrayvec::ArrayVec; use arrayvec::ArrayVec;
use intern::{sym, Symbol}; use intern::{sym, Symbol};
use span::{Edition, Span, SyntaxContextId}; use span::{Edition, Span, SyntaxContext};
use tt::iter::{TtElement, TtIter}; use tt::iter::{TtElement, TtIter};
use crate::ParseError; use crate::ParseError;
@ -28,14 +28,14 @@ pub(crate) struct MetaTemplate(pub(crate) Box<[Op]>);
impl MetaTemplate { impl MetaTemplate {
pub(crate) fn parse_pattern( pub(crate) fn parse_pattern(
edition: impl Copy + Fn(SyntaxContextId) -> Edition, edition: impl Copy + Fn(SyntaxContext) -> Edition,
pattern: TtIter<'_, Span>, pattern: TtIter<'_, Span>,
) -> Result<Self, ParseError> { ) -> Result<Self, ParseError> {
MetaTemplate::parse(edition, pattern, Mode::Pattern) MetaTemplate::parse(edition, pattern, Mode::Pattern)
} }
pub(crate) fn parse_template( pub(crate) fn parse_template(
edition: impl Copy + Fn(SyntaxContextId) -> Edition, edition: impl Copy + Fn(SyntaxContext) -> Edition,
template: TtIter<'_, Span>, template: TtIter<'_, Span>,
) -> Result<Self, ParseError> { ) -> Result<Self, ParseError> {
MetaTemplate::parse(edition, template, Mode::Template) MetaTemplate::parse(edition, template, Mode::Template)
@ -46,7 +46,7 @@ impl MetaTemplate {
} }
fn parse( fn parse(
edition: impl Copy + Fn(SyntaxContextId) -> Edition, edition: impl Copy + Fn(SyntaxContext) -> Edition,
mut src: TtIter<'_, Span>, mut src: TtIter<'_, Span>,
mode: Mode, mode: Mode,
) -> Result<Self, ParseError> { ) -> Result<Self, ParseError> {
@ -179,7 +179,7 @@ enum Mode {
} }
fn next_op( fn next_op(
edition: impl Copy + Fn(SyntaxContextId) -> Edition, edition: impl Copy + Fn(SyntaxContext) -> Edition,
first_peeked: TtElement<'_, Span>, first_peeked: TtElement<'_, Span>,
src: &mut TtIter<'_, Span>, src: &mut TtIter<'_, Span>,
mode: Mode, mode: Mode,
@ -287,7 +287,7 @@ fn next_op(
} }
fn eat_fragment_kind( fn eat_fragment_kind(
edition: impl Copy + Fn(SyntaxContextId) -> Edition, edition: impl Copy + Fn(SyntaxContext) -> Edition,
src: &mut TtIter<'_, Span>, src: &mut TtIter<'_, Span>,
mode: Mode, mode: Mode,
) -> Result<Option<MetaVarKind>, ParseError> { ) -> Result<Option<MetaVarKind>, ParseError> {

View file

@ -3,7 +3,7 @@
// FIXME: Move more of the nameres independent tests from // FIXME: Move more of the nameres independent tests from
// crates\hir-def\src\macro_expansion_tests\mod.rs to this // crates\hir-def\src\macro_expansion_tests\mod.rs to this
use expect_test::expect; use expect_test::expect;
use span::{Edition, EditionedFileId, ErasedFileAstId, FileId, Span, SpanAnchor, SyntaxContextId}; use span::{Edition, EditionedFileId, ErasedFileAstId, FileId, Span, SpanAnchor, SyntaxContext};
use stdx::format_to; use stdx::format_to;
use tt::{TextRange, TextSize}; use tt::{TextRange, TextSize};
@ -26,7 +26,7 @@ fn check_(
file_id: EditionedFileId::new(FileId::from_raw(0), def_edition), file_id: EditionedFileId::new(FileId::from_raw(0), def_edition),
ast_id: ErasedFileAstId::from_raw(0), ast_id: ErasedFileAstId::from_raw(0),
}, },
SyntaxContextId::root(Edition::CURRENT), SyntaxContext::root(Edition::CURRENT),
decl, decl,
) )
.unwrap(); .unwrap();
@ -42,7 +42,7 @@ fn check_(
let arg_tt = syntax_bridge::parse_to_token_tree( let arg_tt = syntax_bridge::parse_to_token_tree(
call_edition, call_edition,
call_anchor, call_anchor,
SyntaxContextId::root(Edition::CURRENT), SyntaxContext::root(Edition::CURRENT),
arg, arg,
) )
.unwrap(); .unwrap();
@ -52,7 +52,7 @@ fn check_(
Span { Span {
range: TextRange::up_to(TextSize::of(arg)), range: TextRange::up_to(TextSize::of(arg)),
anchor: call_anchor, anchor: call_anchor,
ctx: SyntaxContextId::root(Edition::CURRENT), ctx: SyntaxContext::root(Edition::CURRENT),
}, },
def_edition, def_edition,
); );

View file

@ -159,7 +159,7 @@ type ProtocolWrite<W: Write> = for<'o, 'msg> fn(out: &'o mut W, msg: &'msg str)
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use intern::{sym, Symbol}; use intern::{sym, Symbol};
use span::{Edition, ErasedFileAstId, Span, SpanAnchor, SyntaxContextId, TextRange, TextSize}; use span::{Edition, ErasedFileAstId, Span, SpanAnchor, SyntaxContext, TextRange, TextSize};
use tt::{ use tt::{
Delimiter, DelimiterKind, Ident, Leaf, Literal, Punct, Spacing, TopSubtree, Delimiter, DelimiterKind, Ident, Leaf, Literal, Punct, Spacing, TopSubtree,
TopSubtreeBuilder, TopSubtreeBuilder,
@ -180,12 +180,12 @@ mod tests {
open: Span { open: Span {
range: TextRange::empty(TextSize::new(0)), range: TextRange::empty(TextSize::new(0)),
anchor, anchor,
ctx: SyntaxContextId::root(Edition::CURRENT), ctx: SyntaxContext::root(Edition::CURRENT),
}, },
close: Span { close: Span {
range: TextRange::empty(TextSize::new(19)), range: TextRange::empty(TextSize::new(19)),
anchor, anchor,
ctx: SyntaxContextId::root(Edition::CURRENT), ctx: SyntaxContext::root(Edition::CURRENT),
}, },
kind: DelimiterKind::Invisible, kind: DelimiterKind::Invisible,
}); });
@ -196,7 +196,7 @@ mod tests {
span: Span { span: Span {
range: TextRange::at(TextSize::new(0), TextSize::of("struct")), range: TextRange::at(TextSize::new(0), TextSize::of("struct")),
anchor, anchor,
ctx: SyntaxContextId::root(Edition::CURRENT), ctx: SyntaxContext::root(Edition::CURRENT),
}, },
is_raw: tt::IdentIsRaw::No, is_raw: tt::IdentIsRaw::No,
} }
@ -208,7 +208,7 @@ mod tests {
span: Span { span: Span {
range: TextRange::at(TextSize::new(5), TextSize::of("r#Foo")), range: TextRange::at(TextSize::new(5), TextSize::of("r#Foo")),
anchor, anchor,
ctx: SyntaxContextId::root(Edition::CURRENT), ctx: SyntaxContext::root(Edition::CURRENT),
}, },
is_raw: tt::IdentIsRaw::Yes, is_raw: tt::IdentIsRaw::Yes,
} }
@ -219,7 +219,7 @@ mod tests {
span: Span { span: Span {
range: TextRange::at(TextSize::new(10), TextSize::of("\"Foo\"")), range: TextRange::at(TextSize::new(10), TextSize::of("\"Foo\"")),
anchor, anchor,
ctx: SyntaxContextId::root(Edition::CURRENT), ctx: SyntaxContext::root(Edition::CURRENT),
}, },
kind: tt::LitKind::Str, kind: tt::LitKind::Str,
suffix: None, suffix: None,
@ -229,7 +229,7 @@ mod tests {
span: Span { span: Span {
range: TextRange::at(TextSize::new(13), TextSize::of('@')), range: TextRange::at(TextSize::new(13), TextSize::of('@')),
anchor, anchor,
ctx: SyntaxContextId::root(Edition::CURRENT), ctx: SyntaxContext::root(Edition::CURRENT),
}, },
spacing: Spacing::Joint, spacing: Spacing::Joint,
})); }));
@ -238,7 +238,7 @@ mod tests {
Span { Span {
range: TextRange::at(TextSize::new(14), TextSize::of('{')), range: TextRange::at(TextSize::new(14), TextSize::of('{')),
anchor, anchor,
ctx: SyntaxContextId::root(Edition::CURRENT), ctx: SyntaxContext::root(Edition::CURRENT),
}, },
); );
builder.push(Leaf::Literal(Literal { builder.push(Leaf::Literal(Literal {
@ -246,7 +246,7 @@ mod tests {
span: Span { span: Span {
range: TextRange::at(TextSize::new(15), TextSize::of("0u32")), range: TextRange::at(TextSize::new(15), TextSize::of("0u32")),
anchor, anchor,
ctx: SyntaxContextId::root(Edition::CURRENT), ctx: SyntaxContext::root(Edition::CURRENT),
}, },
kind: tt::LitKind::Integer, kind: tt::LitKind::Integer,
suffix: Some(sym::u32.clone()), suffix: Some(sym::u32.clone()),
@ -254,7 +254,7 @@ mod tests {
builder.close(Span { builder.close(Span {
range: TextRange::at(TextSize::new(19), TextSize::of('}')), range: TextRange::at(TextSize::new(19), TextSize::of('}')),
anchor, anchor,
ctx: SyntaxContextId::root(Edition::CURRENT), ctx: SyntaxContext::root(Edition::CURRENT),
}); });
builder.build() builder.build()

View file

@ -40,9 +40,7 @@ use std::collections::VecDeque;
use intern::Symbol; use intern::Symbol;
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use span::{ use span::{EditionedFileId, ErasedFileAstId, Span, SpanAnchor, SyntaxContext, TextRange, TokenId};
EditionedFileId, ErasedFileAstId, Span, SpanAnchor, SyntaxContextId, TextRange, TokenId,
};
use crate::legacy_protocol::msg::{ENCODE_CLOSE_SPAN_VERSION, EXTENDED_LEAF_DATA}; use crate::legacy_protocol::msg::{ENCODE_CLOSE_SPAN_VERSION, EXTENDED_LEAF_DATA};
@ -74,7 +72,7 @@ pub fn deserialize_span_data_index_map(map: &[u32]) -> SpanDataIndexMap {
ast_id: ErasedFileAstId::from_raw(ast_id), ast_id: ErasedFileAstId::from_raw(ast_id),
}, },
range: TextRange::new(start.into(), end.into()), range: TextRange::new(start.into(), end.into()),
ctx: SyntaxContextId::from_u32(e), ctx: SyntaxContext::from_u32(e),
} }
}) })
.collect() .collect()

View file

@ -428,7 +428,7 @@ impl server::Server for RaSpanServer {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use span::{EditionedFileId, FileId, SyntaxContextId}; use span::{EditionedFileId, FileId, SyntaxContext};
use super::*; use super::*;
@ -440,7 +440,7 @@ mod tests {
file_id: EditionedFileId::current_edition(FileId::from_raw(0)), file_id: EditionedFileId::current_edition(FileId::from_raw(0)),
ast_id: span::ErasedFileAstId::from_raw(0), ast_id: span::ErasedFileAstId::from_raw(0),
}, },
ctx: SyntaxContextId::root(span::Edition::CURRENT), ctx: SyntaxContext::root(span::Edition::CURRENT),
}; };
let s = TokenStream { let s = TokenStream {
token_trees: vec![ token_trees: vec![
@ -482,7 +482,7 @@ mod tests {
file_id: EditionedFileId::current_edition(FileId::from_raw(0)), file_id: EditionedFileId::current_edition(FileId::from_raw(0)),
ast_id: span::ErasedFileAstId::from_raw(0), ast_id: span::ErasedFileAstId::from_raw(0),
}, },
ctx: SyntaxContextId::root(span::Edition::CURRENT), ctx: SyntaxContext::root(span::Edition::CURRENT),
}; };
let subtree_paren_a = vec![ let subtree_paren_a = vec![
tt::TokenTree::Subtree(tt::Subtree { tt::TokenTree::Subtree(tt::Subtree {

View file

@ -1,7 +1,7 @@
//! utils used in proc-macro tests //! utils used in proc-macro tests
use expect_test::Expect; use expect_test::Expect;
use span::{EditionedFileId, ErasedFileAstId, FileId, Span, SpanAnchor, SyntaxContextId, TokenId}; use span::{EditionedFileId, ErasedFileAstId, FileId, Span, SpanAnchor, SyntaxContext, TokenId};
use tt::TextRange; use tt::TextRange;
use crate::{dylib, proc_macro_test_dylib_path, EnvSnapshot, ProcMacroSrv}; use crate::{dylib, proc_macro_test_dylib_path, EnvSnapshot, ProcMacroSrv};
@ -17,7 +17,7 @@ fn parse_string(call_site: TokenId, src: &str) -> crate::server_impl::TokenStrea
fn parse_string_spanned( fn parse_string_spanned(
anchor: SpanAnchor, anchor: SpanAnchor,
call_site: SyntaxContextId, call_site: SyntaxContext,
src: &str, src: &str,
) -> crate::server_impl::TokenStream<Span> { ) -> crate::server_impl::TokenStream<Span> {
crate::server_impl::TokenStream::with_subtree(crate::server_impl::TopSubtree( crate::server_impl::TokenStream::with_subtree(crate::server_impl::TopSubtree(
@ -81,7 +81,7 @@ fn assert_expand_impl(
file_id: EditionedFileId::current_edition(FileId::from_raw(41)), file_id: EditionedFileId::current_edition(FileId::from_raw(41)),
ast_id: ErasedFileAstId::from_raw(1), ast_id: ErasedFileAstId::from_raw(1),
}, },
ctx: SyntaxContextId::root(span::Edition::CURRENT), ctx: SyntaxContext::root(span::Edition::CURRENT),
}; };
let call_site = Span { let call_site = Span {
range: TextRange::new(0.into(), 100.into()), range: TextRange::new(0.into(), 100.into()),
@ -89,7 +89,7 @@ fn assert_expand_impl(
file_id: EditionedFileId::current_edition(FileId::from_raw(42)), file_id: EditionedFileId::current_edition(FileId::from_raw(42)),
ast_id: ErasedFileAstId::from_raw(2), ast_id: ErasedFileAstId::from_raw(2),
}, },
ctx: SyntaxContextId::root(span::Edition::CURRENT), ctx: SyntaxContext::root(span::Edition::CURRENT),
}; };
let mixed_site = call_site; let mixed_site = call_site;

View file

@ -23,9 +23,6 @@ use std::fmt;
use crate::{Edition, MacroCallId}; use crate::{Edition, MacroCallId};
// Recursive expansion of interned macro
// ======================================
/// A syntax context describes a hierarchy tracking order of macro definitions. /// A syntax context describes a hierarchy tracking order of macro definitions.
#[derive(Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)] #[derive(Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
pub struct SyntaxContext( pub struct SyntaxContext(
@ -33,22 +30,21 @@ pub struct SyntaxContext(
std::marker::PhantomData<&'static salsa::plumbing::interned::Value<SyntaxContext>>, std::marker::PhantomData<&'static salsa::plumbing::interned::Value<SyntaxContext>>,
); );
/// The underlying data interned by Salsa.
#[derive(Clone, Eq, Debug)]
pub struct SyntaxContextUnderlyingData {
pub outer_expn: Option<MacroCallId>,
pub outer_transparency: Transparency,
pub edition: Edition,
pub parent: SyntaxContext,
pub opaque: SyntaxContext,
pub opaque_and_semitransparent: SyntaxContext,
}
const _: () = { const _: () = {
use salsa::plumbing as zalsa_; use salsa::plumbing as zalsa_;
use salsa::plumbing::interned as zalsa_struct_; use salsa::plumbing::interned as zalsa_struct_;
impl PartialEq for SyntaxContextUnderlyingData { #[derive(Clone, Eq, Debug)]
pub struct SyntaxContextData {
outer_expn: Option<MacroCallId>,
outer_transparency: Transparency,
edition: Edition,
parent: SyntaxContext,
opaque: SyntaxContext,
opaque_and_semitransparent: SyntaxContext,
}
impl PartialEq for SyntaxContextData {
fn eq(&self, other: &Self) -> bool { fn eq(&self, other: &Self) -> bool {
self.outer_expn == other.outer_expn self.outer_expn == other.outer_expn
&& self.outer_transparency == other.outer_transparency && self.outer_transparency == other.outer_transparency
@ -57,7 +53,7 @@ const _: () = {
} }
} }
impl std::hash::Hash for SyntaxContextUnderlyingData { impl std::hash::Hash for SyntaxContextData {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) { fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.outer_expn.hash(state); self.outer_expn.hash(state);
self.outer_transparency.hash(state); self.outer_transparency.hash(state);
@ -71,7 +67,7 @@ const _: () = {
struct StructKey<'db, T0, T1, T2, T3>(T0, T1, T2, T3, std::marker::PhantomData<&'db ()>); struct StructKey<'db, T0, T1, T2, T3>(T0, T1, T2, T3, std::marker::PhantomData<&'db ()>);
impl<'db, T0, T1, T2, T3> zalsa_::interned::HashEqLike<StructKey<'db, T0, T1, T2, T3>> impl<'db, T0, T1, T2, T3> zalsa_::interned::HashEqLike<StructKey<'db, T0, T1, T2, T3>>
for SyntaxContextUnderlyingData for SyntaxContextData
where where
Option<MacroCallId>: zalsa_::interned::HashEqLike<T0>, Option<MacroCallId>: zalsa_::interned::HashEqLike<T0>,
Transparency: zalsa_::interned::HashEqLike<T1>, Transparency: zalsa_::interned::HashEqLike<T1>,
@ -93,7 +89,7 @@ const _: () = {
} }
impl zalsa_struct_::Configuration for SyntaxContext { impl zalsa_struct_::Configuration for SyntaxContext {
const DEBUG_NAME: &'static str = "SyntaxContextData"; const DEBUG_NAME: &'static str = "SyntaxContextData";
type Fields<'a> = SyntaxContextUnderlyingData; type Fields<'a> = SyntaxContextData;
type Struct<'a> = SyntaxContext; type Struct<'a> = SyntaxContext;
fn struct_from_id<'db>(id: salsa::Id) -> Self::Struct<'db> { fn struct_from_id<'db>(id: salsa::Id) -> Self::Struct<'db> {
SyntaxContext(id, std::marker::PhantomData) SyntaxContext(id, std::marker::PhantomData)
@ -189,7 +185,7 @@ const _: () = {
parent, parent,
std::marker::PhantomData, std::marker::PhantomData,
), ),
|id, data| SyntaxContextUnderlyingData { |id, data| SyntaxContextData {
outer_expn: zalsa_::interned::Lookup::into_owned(data.0), outer_expn: zalsa_::interned::Lookup::into_owned(data.0),
outer_transparency: zalsa_::interned::Lookup::into_owned(data.1), outer_transparency: zalsa_::interned::Lookup::into_owned(data.1),
edition: zalsa_::interned::Lookup::into_owned(data.2), edition: zalsa_::interned::Lookup::into_owned(data.2),

View file

@ -11,9 +11,6 @@ pub use self::{
map::{RealSpanMap, SpanMap}, map::{RealSpanMap, SpanMap},
}; };
// Remove this
pub use self::hygiene::{SyntaxContext as SyntaxContextId, SyntaxContextUnderlyingData};
pub use syntax::Edition; pub use syntax::Edition;
pub use text_size::{TextRange, TextSize}; pub use text_size::{TextRange, TextSize};
pub use vfs::FileId; pub use vfs::FileId;
@ -31,7 +28,7 @@ pub const FIXUP_ERASED_FILE_AST_ID_MARKER: ErasedFileAstId =
// is required to be stable for the proc-macro-server // is required to be stable for the proc-macro-server
ErasedFileAstId::from_raw(!0 - 1); ErasedFileAstId::from_raw(!0 - 1);
pub type Span = SpanData<SyntaxContextId>; pub type Span = SpanData<SyntaxContext>;
impl Span { impl Span {
pub fn cover(self, other: Span) -> Span { pub fn cover(self, other: Span) -> Span {

View file

@ -6,7 +6,7 @@ use std::{fmt, hash::Hash};
use stdx::{always, itertools::Itertools}; use stdx::{always, itertools::Itertools};
use crate::{ use crate::{
EditionedFileId, ErasedFileAstId, Span, SpanAnchor, SpanData, SyntaxContextId, TextRange, EditionedFileId, ErasedFileAstId, Span, SpanAnchor, SpanData, SyntaxContext, TextRange,
TextSize, ROOT_ERASED_FILE_AST_ID, TextSize, ROOT_ERASED_FILE_AST_ID,
}; };
@ -208,7 +208,7 @@ impl RealSpanMap {
Span { Span {
range: range - offset, range: range - offset,
anchor: SpanAnchor { file_id: self.file_id, ast_id }, anchor: SpanAnchor { file_id: self.file_id, ast_id },
ctx: SyntaxContextId::root(self.file_id.edition()), ctx: SyntaxContext::root(self.file_id.edition()),
} }
} }
} }

View file

@ -45,7 +45,7 @@ impl<S: Copy, SM: SpanMapper<S>> SpanMapper<S> for &SM {
/// Dummy things for testing where spans don't matter. /// Dummy things for testing where spans don't matter.
pub mod dummy_test_span_utils { pub mod dummy_test_span_utils {
use span::{Span, SyntaxContextId}; use span::{Span, SyntaxContext};
use super::*; use super::*;
@ -58,7 +58,7 @@ pub mod dummy_test_span_utils {
), ),
ast_id: span::ROOT_ERASED_FILE_AST_ID, ast_id: span::ROOT_ERASED_FILE_AST_ID,
}, },
ctx: SyntaxContextId::root(Edition::CURRENT), ctx: SyntaxContext::root(Edition::CURRENT),
}; };
pub struct DummyTestSpanMap; pub struct DummyTestSpanMap;
@ -74,7 +74,7 @@ pub mod dummy_test_span_utils {
), ),
ast_id: span::ROOT_ERASED_FILE_AST_ID, ast_id: span::ROOT_ERASED_FILE_AST_ID,
}, },
ctx: SyntaxContextId::root(Edition::CURRENT), ctx: SyntaxContext::root(Edition::CURRENT),
} }
} }
} }