Don't store SyntheticSyntax in the reverse maps in BodySourceMap
They are ZSTs which we can just create on missing access instead.
This commit is contained in:
parent
c6b7f45308
commit
fe0a106256
@ -264,10 +264,10 @@ pub struct Body {
|
|||||||
#[derive(Default, Debug, Eq, PartialEq)]
|
#[derive(Default, Debug, Eq, PartialEq)]
|
||||||
pub struct BodySourceMap {
|
pub struct BodySourceMap {
|
||||||
expr_map: FxHashMap<ExprSource, ExprId>,
|
expr_map: FxHashMap<ExprSource, ExprId>,
|
||||||
expr_map_back: ArenaMap<ExprId, Result<ExprSource, SyntheticSyntax>>,
|
expr_map_back: ArenaMap<ExprId, ExprSource>,
|
||||||
|
|
||||||
pat_map: FxHashMap<PatSource, PatId>,
|
pat_map: FxHashMap<PatSource, PatId>,
|
||||||
pat_map_back: ArenaMap<PatId, Result<PatSource, SyntheticSyntax>>,
|
pat_map_back: ArenaMap<PatId, PatSource>,
|
||||||
|
|
||||||
label_map: FxHashMap<LabelSource, LabelId>,
|
label_map: FxHashMap<LabelSource, LabelId>,
|
||||||
label_map_back: ArenaMap<LabelId, LabelSource>,
|
label_map_back: ArenaMap<LabelId, LabelSource>,
|
||||||
@ -420,7 +420,7 @@ fn index(&self, label: LabelId) -> &Label {
|
|||||||
// Perhaps `expr_syntax` and `expr_id`?
|
// Perhaps `expr_syntax` and `expr_id`?
|
||||||
impl BodySourceMap {
|
impl BodySourceMap {
|
||||||
pub fn expr_syntax(&self, expr: ExprId) -> Result<ExprSource, SyntheticSyntax> {
|
pub fn expr_syntax(&self, expr: ExprId) -> Result<ExprSource, SyntheticSyntax> {
|
||||||
self.expr_map_back[expr].clone()
|
self.expr_map_back.get(expr).cloned().ok_or(SyntheticSyntax)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn node_expr(&self, node: InFile<&ast::Expr>) -> Option<ExprId> {
|
pub fn node_expr(&self, node: InFile<&ast::Expr>) -> Option<ExprId> {
|
||||||
@ -434,7 +434,7 @@ pub fn node_macro_file(&self, node: InFile<&ast::MacroCall>) -> Option<HirFileId
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn pat_syntax(&self, pat: PatId) -> Result<PatSource, SyntheticSyntax> {
|
pub fn pat_syntax(&self, pat: PatId) -> Result<PatSource, SyntheticSyntax> {
|
||||||
self.pat_map_back[pat].clone()
|
self.pat_map_back.get(pat).cloned().ok_or(SyntheticSyntax)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn node_pat(&self, node: InFile<&ast::Pat>) -> Option<PatId> {
|
pub fn node_pat(&self, node: InFile<&ast::Pat>) -> Option<PatId> {
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
adt::StructKind,
|
adt::StructKind,
|
||||||
body::{Body, BodySourceMap, Expander, LabelSource, PatPtr, SyntheticSyntax},
|
body::{Body, BodySourceMap, Expander, LabelSource, PatPtr},
|
||||||
body::{BodyDiagnostic, ExprSource, PatSource},
|
body::{BodyDiagnostic, ExprSource, PatSource},
|
||||||
builtin_type::{BuiltinFloat, BuiltinInt, BuiltinUint},
|
builtin_type::{BuiltinFloat, BuiltinInt, BuiltinUint},
|
||||||
db::DefDatabase,
|
db::DefDatabase,
|
||||||
@ -152,19 +152,19 @@ fn ctx(&self) -> LowerCtx<'_> {
|
|||||||
|
|
||||||
fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr<ast::Expr>) -> ExprId {
|
fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr<ast::Expr>) -> ExprId {
|
||||||
let src = self.expander.to_source(ptr);
|
let src = self.expander.to_source(ptr);
|
||||||
let id = self.make_expr(expr, Ok(src.clone()));
|
let id = self.make_expr(expr, src.clone());
|
||||||
self.source_map.expr_map.insert(src, id);
|
self.source_map.expr_map.insert(src, id);
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
// desugared exprs don't have ptr, that's wrong and should be fixed
|
// desugared exprs don't have ptr, that's wrong and should be fixed
|
||||||
// somehow.
|
// somehow.
|
||||||
fn alloc_expr_desugared(&mut self, expr: Expr) -> ExprId {
|
fn alloc_expr_desugared(&mut self, expr: Expr) -> ExprId {
|
||||||
self.make_expr(expr, Err(SyntheticSyntax))
|
self.body.exprs.alloc(expr)
|
||||||
}
|
}
|
||||||
fn missing_expr(&mut self) -> ExprId {
|
fn missing_expr(&mut self) -> ExprId {
|
||||||
self.alloc_expr_desugared(Expr::Missing)
|
self.alloc_expr_desugared(Expr::Missing)
|
||||||
}
|
}
|
||||||
fn make_expr(&mut self, expr: Expr, src: Result<ExprSource, SyntheticSyntax>) -> ExprId {
|
fn make_expr(&mut self, expr: Expr, src: ExprSource) -> ExprId {
|
||||||
let id = self.body.exprs.alloc(expr);
|
let id = self.body.exprs.alloc(expr);
|
||||||
self.source_map.expr_map_back.insert(id, src);
|
self.source_map.expr_map_back.insert(id, src);
|
||||||
id
|
id
|
||||||
@ -172,14 +172,14 @@ fn make_expr(&mut self, expr: Expr, src: Result<ExprSource, SyntheticSyntax>) ->
|
|||||||
|
|
||||||
fn alloc_pat(&mut self, pat: Pat, ptr: PatPtr) -> PatId {
|
fn alloc_pat(&mut self, pat: Pat, ptr: PatPtr) -> PatId {
|
||||||
let src = self.expander.to_source(ptr);
|
let src = self.expander.to_source(ptr);
|
||||||
let id = self.make_pat(pat, Ok(src.clone()));
|
let id = self.make_pat(pat, src.clone());
|
||||||
self.source_map.pat_map.insert(src, id);
|
self.source_map.pat_map.insert(src, id);
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
fn missing_pat(&mut self) -> PatId {
|
fn missing_pat(&mut self) -> PatId {
|
||||||
self.make_pat(Pat::Missing, Err(SyntheticSyntax))
|
self.body.pats.alloc(Pat::Missing)
|
||||||
}
|
}
|
||||||
fn make_pat(&mut self, pat: Pat, src: Result<PatSource, SyntheticSyntax>) -> PatId {
|
fn make_pat(&mut self, pat: Pat, src: PatSource) -> PatId {
|
||||||
let id = self.body.pats.alloc(pat);
|
let id = self.body.pats.alloc(pat);
|
||||||
self.source_map.pat_map_back.insert(id, src);
|
self.source_map.pat_map_back.insert(id, src);
|
||||||
id
|
id
|
||||||
|
Loading…
Reference in New Issue
Block a user