diff options
author | Florian Diebold <[email protected]> | 2019-01-06 22:57:39 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2019-01-06 23:05:19 +0000 |
commit | 71f7d82e45145281b9aec5bcdc694524864e552b (patch) | |
tree | dab214dd290cfb87c85b56b478a477eeaf4edc6e /crates/ra_hir/src/ty.rs | |
parent | cf49a11263c4d48720250db0c448b97dbec3d8b9 (diff) |
Introduce ArenaMap
Diffstat (limited to 'crates/ra_hir/src/ty.rs')
-rw-r--r-- | crates/ra_hir/src/ty.rs | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 6bdfdd7b4..d57990cd2 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -22,8 +22,8 @@ use std::sync::Arc; | |||
22 | use std::{fmt, mem}; | 22 | use std::{fmt, mem}; |
23 | 23 | ||
24 | use log; | 24 | use log; |
25 | use rustc_hash::FxHashMap; | ||
26 | use ena::unify::{InPlaceUnificationTable, UnifyKey, UnifyValue, NoError}; | 25 | use ena::unify::{InPlaceUnificationTable, UnifyKey, UnifyValue, NoError}; |
26 | use ra_arena::map::ArenaMap; | ||
27 | 27 | ||
28 | use ra_db::Cancelable; | 28 | use ra_db::Cancelable; |
29 | 29 | ||
@@ -470,15 +470,15 @@ pub(super) fn type_for_field(db: &impl HirDatabase, def_id: DefId, field: Name) | |||
470 | /// The result of type inference: A mapping from expressions and patterns to types. | 470 | /// The result of type inference: A mapping from expressions and patterns to types. |
471 | #[derive(Clone, PartialEq, Eq, Debug)] | 471 | #[derive(Clone, PartialEq, Eq, Debug)] |
472 | pub struct InferenceResult { | 472 | pub struct InferenceResult { |
473 | type_of_expr: FxHashMap<ExprId, Ty>, | 473 | type_of_expr: ArenaMap<ExprId, Ty>, |
474 | type_of_pat: FxHashMap<PatId, Ty>, | 474 | type_of_pat: ArenaMap<PatId, Ty>, |
475 | } | 475 | } |
476 | 476 | ||
477 | impl Index<ExprId> for InferenceResult { | 477 | impl Index<ExprId> for InferenceResult { |
478 | type Output = Ty; | 478 | type Output = Ty; |
479 | 479 | ||
480 | fn index(&self, expr: ExprId) -> &Ty { | 480 | fn index(&self, expr: ExprId) -> &Ty { |
481 | self.type_of_expr.get(&expr).unwrap_or(&Ty::Unknown) | 481 | self.type_of_expr.get(expr).unwrap_or(&Ty::Unknown) |
482 | } | 482 | } |
483 | } | 483 | } |
484 | 484 | ||
@@ -486,7 +486,7 @@ impl Index<PatId> for InferenceResult { | |||
486 | type Output = Ty; | 486 | type Output = Ty; |
487 | 487 | ||
488 | fn index(&self, pat: PatId) -> &Ty { | 488 | fn index(&self, pat: PatId) -> &Ty { |
489 | self.type_of_pat.get(&pat).unwrap_or(&Ty::Unknown) | 489 | self.type_of_pat.get(pat).unwrap_or(&Ty::Unknown) |
490 | } | 490 | } |
491 | } | 491 | } |
492 | 492 | ||
@@ -499,8 +499,8 @@ struct InferenceContext<'a, D: HirDatabase> { | |||
499 | module: Module, | 499 | module: Module, |
500 | impl_block: Option<ImplBlock>, | 500 | impl_block: Option<ImplBlock>, |
501 | var_unification_table: InPlaceUnificationTable<TypeVarId>, | 501 | var_unification_table: InPlaceUnificationTable<TypeVarId>, |
502 | type_of_expr: FxHashMap<ExprId, Ty>, | 502 | type_of_expr: ArenaMap<ExprId, Ty>, |
503 | type_of_pat: FxHashMap<PatId, Ty>, | 503 | type_of_pat: ArenaMap<PatId, Ty>, |
504 | /// The return type of the function being inferred. | 504 | /// The return type of the function being inferred. |
505 | return_ty: Ty, | 505 | return_ty: Ty, |
506 | } | 506 | } |
@@ -528,8 +528,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
528 | impl_block: Option<ImplBlock>, | 528 | impl_block: Option<ImplBlock>, |
529 | ) -> Self { | 529 | ) -> Self { |
530 | InferenceContext { | 530 | InferenceContext { |
531 | type_of_expr: FxHashMap::default(), | 531 | type_of_expr: ArenaMap::default(), |
532 | type_of_pat: FxHashMap::default(), | 532 | type_of_pat: ArenaMap::default(), |
533 | var_unification_table: InPlaceUnificationTable::new(), | 533 | var_unification_table: InPlaceUnificationTable::new(), |
534 | return_ty: Ty::Unknown, // set in collect_fn_signature | 534 | return_ty: Ty::Unknown, // set in collect_fn_signature |
535 | db, | 535 | db, |
@@ -541,12 +541,12 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
541 | } | 541 | } |
542 | 542 | ||
543 | fn resolve_all(mut self) -> InferenceResult { | 543 | fn resolve_all(mut self) -> InferenceResult { |
544 | let mut expr_types = mem::replace(&mut self.type_of_expr, FxHashMap::default()); | 544 | let mut expr_types = mem::replace(&mut self.type_of_expr, ArenaMap::default()); |
545 | for ty in expr_types.values_mut() { | 545 | for ty in expr_types.values_mut() { |
546 | let resolved = self.resolve_ty_completely(mem::replace(ty, Ty::Unknown)); | 546 | let resolved = self.resolve_ty_completely(mem::replace(ty, Ty::Unknown)); |
547 | *ty = resolved; | 547 | *ty = resolved; |
548 | } | 548 | } |
549 | let mut pat_types = mem::replace(&mut self.type_of_pat, FxHashMap::default()); | 549 | let mut pat_types = mem::replace(&mut self.type_of_pat, ArenaMap::default()); |
550 | for ty in pat_types.values_mut() { | 550 | for ty in pat_types.values_mut() { |
551 | let resolved = self.resolve_ty_completely(mem::replace(ty, Ty::Unknown)); | 551 | let resolved = self.resolve_ty_completely(mem::replace(ty, Ty::Unknown)); |
552 | *ty = resolved; | 552 | *ty = resolved; |
@@ -666,7 +666,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
666 | // resolve locally | 666 | // resolve locally |
667 | let name = path.as_ident().cloned().unwrap_or_else(Name::self_param); | 667 | let name = path.as_ident().cloned().unwrap_or_else(Name::self_param); |
668 | if let Some(scope_entry) = self.scopes.resolve_local_name(expr, name) { | 668 | if let Some(scope_entry) = self.scopes.resolve_local_name(expr, name) { |
669 | let ty = ctry!(self.type_of_pat.get(&scope_entry.pat())); | 669 | let ty = ctry!(self.type_of_pat.get(scope_entry.pat())); |
670 | let ty = self.resolve_ty_as_possible(ty.clone()); | 670 | let ty = self.resolve_ty_as_possible(ty.clone()); |
671 | return Ok(Some(ty)); | 671 | return Ok(Some(ty)); |
672 | }; | 672 | }; |