Skip to content

Commit

Permalink
use hashmap, not indexvec, for expressions in TypeInference
Browse files Browse the repository at this point in the history
  • Loading branch information
carljm committed Jul 13, 2024
1 parent 47d4983 commit 864aee6
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions crates/red_knot_python_semantic/src/types/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ use salsa;

use red_knot_module_resolver::{resolve_module, ModuleName};
use ruff_db::files::File;
use ruff_index::IndexVec;
use ruff_python_ast as ast;
use ruff_python_ast::{ExprContext, TypeParams};

use crate::semantic_index::ast_ids::{HasScopedUseId, ScopedExpressionId};
use crate::semantic_index::ast_ids::{HasScopedAstId, HasScopedUseId, ScopedExpressionId};
use crate::semantic_index::definition::{Definition, DefinitionKind};
use crate::semantic_index::expression::Expression;
use crate::semantic_index::symbol::{NodeWithScopeRef, ScopeId};
Expand Down Expand Up @@ -72,7 +71,7 @@ pub(crate) enum InferenceRegion<'db> {
#[derive(Debug, Eq, PartialEq, Default, Clone)]
pub(crate) struct TypeInference<'db> {
/// The types of every expression in this region.
expressions: IndexVec<ScopedExpressionId, Type<'db>>,
expressions: FxHashMap<ScopedExpressionId, Type<'db>>,

/// The types of every definition in this region.
definitions: FxHashMap<Definition<'db>, Type<'db>>,
Expand All @@ -81,7 +80,7 @@ pub(crate) struct TypeInference<'db> {
impl<'db> TypeInference<'db> {
#[allow(unused)]
pub(crate) fn expression_ty(&self, expression: ScopedExpressionId) -> Type<'db> {
self.expressions[expression]
self.expressions[&expression]
}

pub(crate) fn definition_ty(&self, definition: Definition<'db>) -> Type<'db> {
Expand Down Expand Up @@ -518,7 +517,8 @@ impl<'db> TypeInferenceBuilder<'db> {
_ => todo!("expression type resolution for {:?}", expression),
};

self.types.expressions.push(ty);
let expr_id = expression.scoped_ast_id(self.db, self.scope);
self.types.expressions.insert(expr_id, ty);

ty
}
Expand Down

0 comments on commit 864aee6

Please sign in to comment.