mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 11:20:54 +00:00
Merge pull request #20169 from Veykril/push-quvvsupnqqwv
Skip unnecessary `eq` work in `BodySourceMap`
This commit is contained in:
commit
b7fc040576
@ -93,7 +93,7 @@ pub type TypeSource = InFile<TypePtr>;
|
|||||||
pub type LifetimePtr = AstPtr<ast::Lifetime>;
|
pub type LifetimePtr = AstPtr<ast::Lifetime>;
|
||||||
pub type LifetimeSource = InFile<LifetimePtr>;
|
pub type LifetimeSource = InFile<LifetimePtr>;
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub struct ExpressionStore {
|
pub struct ExpressionStore {
|
||||||
pub exprs: Arena<Expr>,
|
pub exprs: Arena<Expr>,
|
||||||
pub pats: Arena<Pat>,
|
pub pats: Arena<Pat>,
|
||||||
@ -114,7 +114,7 @@ pub struct ExpressionStore {
|
|||||||
ident_hygiene: FxHashMap<ExprOrPatId, HygieneId>,
|
ident_hygiene: FxHashMap<ExprOrPatId, HygieneId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Default)]
|
#[derive(Debug, Eq, Default)]
|
||||||
pub struct ExpressionStoreSourceMap {
|
pub struct ExpressionStoreSourceMap {
|
||||||
// AST expressions can create patterns in destructuring assignments. Therefore, `ExprSource` can also map
|
// AST expressions can create patterns in destructuring assignments. Therefore, `ExprSource` can also map
|
||||||
// to `PatId`, and `PatId` can also map to `ExprSource` (the other way around is unaffected).
|
// to `PatId`, and `PatId` can also map to `ExprSource` (the other way around is unaffected).
|
||||||
@ -127,19 +127,20 @@ pub struct ExpressionStoreSourceMap {
|
|||||||
label_map: FxHashMap<LabelSource, LabelId>,
|
label_map: FxHashMap<LabelSource, LabelId>,
|
||||||
label_map_back: ArenaMap<LabelId, LabelSource>,
|
label_map_back: ArenaMap<LabelId, LabelSource>,
|
||||||
|
|
||||||
binding_definitions: FxHashMap<BindingId, SmallVec<[PatId; 4]>>,
|
|
||||||
|
|
||||||
/// We don't create explicit nodes for record fields (`S { record_field: 92 }`).
|
|
||||||
/// Instead, we use id of expression (`92`) to identify the field.
|
|
||||||
field_map_back: FxHashMap<ExprId, FieldSource>,
|
|
||||||
pat_field_map_back: FxHashMap<PatId, PatFieldSource>,
|
|
||||||
|
|
||||||
types_map_back: ArenaMap<TypeRefId, TypeSource>,
|
types_map_back: ArenaMap<TypeRefId, TypeSource>,
|
||||||
types_map: FxHashMap<TypeSource, TypeRefId>,
|
types_map: FxHashMap<TypeSource, TypeRefId>,
|
||||||
|
|
||||||
lifetime_map_back: ArenaMap<LifetimeRefId, LifetimeSource>,
|
lifetime_map_back: ArenaMap<LifetimeRefId, LifetimeSource>,
|
||||||
lifetime_map: FxHashMap<LifetimeSource, LifetimeRefId>,
|
lifetime_map: FxHashMap<LifetimeSource, LifetimeRefId>,
|
||||||
|
|
||||||
|
binding_definitions:
|
||||||
|
ArenaMap<BindingId, SmallVec<[PatId; 2 * size_of::<usize>() / size_of::<PatId>()]>>,
|
||||||
|
|
||||||
|
/// We don't create explicit nodes for record fields (`S { record_field: 92 }`).
|
||||||
|
/// Instead, we use id of expression (`92`) to identify the field.
|
||||||
|
field_map_back: FxHashMap<ExprId, FieldSource>,
|
||||||
|
pat_field_map_back: FxHashMap<PatId, PatFieldSource>,
|
||||||
|
|
||||||
template_map: Option<Box<FormatTemplate>>,
|
template_map: Option<Box<FormatTemplate>>,
|
||||||
|
|
||||||
pub expansions: FxHashMap<InFile<MacroCallPtr>, MacroCallId>,
|
pub expansions: FxHashMap<InFile<MacroCallPtr>, MacroCallId>,
|
||||||
@ -149,6 +150,43 @@ pub struct ExpressionStoreSourceMap {
|
|||||||
pub diagnostics: Vec<ExpressionStoreDiagnostics>,
|
pub diagnostics: Vec<ExpressionStoreDiagnostics>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl PartialEq for ExpressionStoreSourceMap {
|
||||||
|
fn eq(&self, other: &Self) -> bool {
|
||||||
|
// we only need to compare one of the two mappings
|
||||||
|
// as the other is a reverse mapping and thus will compare
|
||||||
|
// the same as normal mapping
|
||||||
|
let Self {
|
||||||
|
expr_map: _,
|
||||||
|
expr_map_back,
|
||||||
|
pat_map: _,
|
||||||
|
pat_map_back,
|
||||||
|
label_map: _,
|
||||||
|
label_map_back,
|
||||||
|
types_map_back,
|
||||||
|
types_map: _,
|
||||||
|
lifetime_map_back,
|
||||||
|
lifetime_map: _,
|
||||||
|
// If this changed, our pattern data must have changed
|
||||||
|
binding_definitions: _,
|
||||||
|
// If this changed, our expression data must have changed
|
||||||
|
field_map_back: _,
|
||||||
|
// If this changed, our pattern data must have changed
|
||||||
|
pat_field_map_back: _,
|
||||||
|
template_map,
|
||||||
|
expansions,
|
||||||
|
diagnostics,
|
||||||
|
} = self;
|
||||||
|
*expr_map_back == other.expr_map_back
|
||||||
|
&& *pat_map_back == other.pat_map_back
|
||||||
|
&& *label_map_back == other.label_map_back
|
||||||
|
&& *types_map_back == other.types_map_back
|
||||||
|
&& *lifetime_map_back == other.lifetime_map_back
|
||||||
|
&& *template_map == other.template_map
|
||||||
|
&& *expansions == other.expansions
|
||||||
|
&& *diagnostics == other.diagnostics
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The body of an item (function, const etc.).
|
/// The body of an item (function, const etc.).
|
||||||
#[derive(Debug, Eq, PartialEq, Default)]
|
#[derive(Debug, Eq, PartialEq, Default)]
|
||||||
pub struct ExpressionStoreBuilder {
|
pub struct ExpressionStoreBuilder {
|
||||||
@ -698,7 +736,7 @@ impl ExpressionStoreSourceMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn patterns_for_binding(&self, binding: BindingId) -> &[PatId] {
|
pub fn patterns_for_binding(&self, binding: BindingId) -> &[PatId] {
|
||||||
self.binding_definitions.get(&binding).map_or(&[], Deref::deref)
|
self.binding_definitions.get(binding).map_or(&[], Deref::deref)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn node_label(&self, node: InFile<&ast::Label>) -> Option<LabelId> {
|
pub fn node_label(&self, node: InFile<&ast::Label>) -> Option<LabelId> {
|
||||||
|
@ -535,7 +535,7 @@ fn foo() {
|
|||||||
|
|
||||||
let resolved = scopes.resolve_name_in_scope(expr_scope, &name_ref.as_name()).unwrap();
|
let resolved = scopes.resolve_name_in_scope(expr_scope, &name_ref.as_name()).unwrap();
|
||||||
let pat_src = source_map
|
let pat_src = source_map
|
||||||
.pat_syntax(*source_map.binding_definitions[&resolved.binding()].first().unwrap())
|
.pat_syntax(*source_map.binding_definitions[resolved.binding()].first().unwrap())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let local_name = pat_src.value.syntax_node_ptr().to_node(file.syntax());
|
let local_name = pat_src.value.syntax_node_ptr().to_node(file.syntax());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user