diff --git a/crates/red_knot/src/lib.rs b/crates/red_knot/src/lib.rs index 126c21789d5cb..b04d8ed8a56d6 100644 --- a/crates/red_knot/src/lib.rs +++ b/crates/red_knot/src/lib.rs @@ -1,6 +1,4 @@ -use std::fmt::Formatter; use std::hash::BuildHasherDefault; -use std::ops::Deref; use std::path::{Path, PathBuf}; use rustc_hash::{FxHashSet, FxHasher}; @@ -68,41 +66,3 @@ impl Workspace { self.open_files.contains(&file_id) } } - -#[derive(Debug, Clone, Eq, PartialEq, Hash)] -pub struct Name(smol_str::SmolStr); - -impl Name { - #[inline] - pub fn new(name: &str) -> Self { - Self(smol_str::SmolStr::new(name)) - } - - pub fn as_str(&self) -> &str { - self.0.as_str() - } -} - -impl Deref for Name { - type Target = str; - - #[inline] - fn deref(&self) -> &Self::Target { - self.as_str() - } -} - -impl From for Name -where - T: Into, -{ - fn from(value: T) -> Self { - Self(value.into()) - } -} - -impl std::fmt::Display for Name { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - f.write_str(self.as_str()) - } -} diff --git a/crates/red_knot/src/semantic.rs b/crates/red_knot/src/semantic.rs index 0af2f9beefe10..73d57c8e33adf 100644 --- a/crates/red_knot/src/semantic.rs +++ b/crates/red_knot/src/semantic.rs @@ -11,7 +11,6 @@ use crate::files::FileId; use crate::module::Module; use crate::module::ModuleName; use crate::parse::parse; -use crate::Name; pub(crate) use definitions::Definition; use definitions::{ImportDefinition, ImportFromDefinition}; pub(crate) use flow_graph::ConstrainedDefinition; @@ -437,7 +436,7 @@ impl SourceOrderVisitor<'_> for SemanticIndexer { }; let def = Definition::ImportFrom(ImportFromDefinition { module: module.clone(), - name: Name::new(&alias.name.id), + name: alias.name.id.clone(), level: *level, }); self.add_or_update_symbol_with_def(symbol_name, def); diff --git a/crates/red_knot/src/semantic/definitions.rs b/crates/red_knot/src/semantic/definitions.rs index b1bd7a3ca2f1e..149fcb4bf2845 100644 --- a/crates/red_knot/src/semantic/definitions.rs +++ b/crates/red_knot/src/semantic/definitions.rs @@ -1,7 +1,7 @@ use crate::ast_ids::TypedNodeKey; use crate::semantic::ModuleName; -use crate::Name; use ruff_python_ast as ast; +use ruff_python_ast::name::Name; // TODO storing TypedNodeKey for definitions means we have to search to find them again in the AST; // this is at best O(log n). If looking up definitions is a bottleneck we should look for diff --git a/crates/red_knot/src/semantic/symbol_table.rs b/crates/red_knot/src/semantic/symbol_table.rs index bb57f19bea29f..a272a6ae4e075 100644 --- a/crates/red_knot/src/semantic/symbol_table.rs +++ b/crates/red_knot/src/semantic/symbol_table.rs @@ -9,11 +9,11 @@ use hashbrown::hash_map::{Keys, RawEntryMut}; use rustc_hash::{FxHashMap, FxHasher}; use ruff_index::{newtype_index, IndexVec}; +use ruff_python_ast::name::Name; use crate::ast_ids::NodeKey; use crate::module::ModuleName; use crate::semantic::{Definition, ExpressionId}; -use crate::Name; type Map = hashbrown::HashMap; diff --git a/crates/red_knot/src/semantic/types.rs b/crates/red_knot/src/semantic/types.rs index f6c4288f09776..a9bf11241b897 100644 --- a/crates/red_knot/src/semantic/types.rs +++ b/crates/red_knot/src/semantic/types.rs @@ -6,7 +6,7 @@ use crate::module::{Module, ModuleName}; use crate::semantic::{ resolve_global_symbol, semantic_index, GlobalSymbolId, ScopeId, ScopeKind, SymbolId, }; -use crate::{FxDashMap, FxIndexSet, Name}; +use crate::{FxDashMap, FxIndexSet}; use ruff_index::{newtype_index, IndexVec}; use ruff_python_ast as ast; use rustc_hash::FxHashMap; @@ -14,6 +14,7 @@ use rustc_hash::FxHashMap; pub(crate) mod infer; pub(crate) use infer::{infer_definition_type, infer_symbol_public_type}; +use ruff_python_ast::name::Name; /// unique ID for a type #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] diff --git a/crates/red_knot/src/semantic/types/infer.rs b/crates/red_knot/src/semantic/types/infer.rs index 3e671912bc862..1aa8ac8808762 100644 --- a/crates/red_knot/src/semantic/types/infer.rs +++ b/crates/red_knot/src/semantic/types/infer.rs @@ -13,7 +13,7 @@ use crate::semantic::{ resolve_global_symbol, semantic_index, ConstrainedDefinition, Definition, GlobalSymbolId, ImportDefinition, ImportFromDefinition, }; -use crate::{FileId, Name}; +use crate::FileId; // FIXME: Figure out proper dead-lock free synchronisation now that this takes `&db` instead of `&mut db`. /// Resolve the public-facing type for a symbol (the type seen by other scopes: other modules, or @@ -315,7 +315,7 @@ fn infer_expr_type(db: &dyn SemanticDb, file_id: FileId, expr: &ast::Expr) -> Qu } ast::Expr::Attribute(ast::ExprAttribute { value, attr, .. }) => { let value_type = infer_expr_type(db, file_id, value)?; - let attr_name = &Name::new(&attr.id); + let attr_name = &attr.id; value_type .get_member(db, attr_name) .map(|ty| ty.unwrap_or(Type::Unknown)) @@ -343,6 +343,7 @@ fn infer_expr_type(db: &dyn SemanticDb, file_id: FileId, expr: &ast::Expr) -> Qu #[cfg(test)] mod tests { + use ruff_python_ast::name::Name; use std::path::PathBuf; use crate::db::tests::TestDb; @@ -351,7 +352,6 @@ mod tests { resolve_module, set_module_search_paths, ModuleName, ModuleResolutionInputs, }; use crate::semantic::{infer_symbol_public_type, resolve_global_symbol, Type}; - use crate::Name; // TODO with virtual filesystem we shouldn't have to write files to disk for these // tests @@ -476,7 +476,7 @@ mod tests { }; let member_ty = class_id - .get_own_class_member(&case.db, &Name::new("f")) + .get_own_class_member(&case.db, &Name::new_static("f")) .expect("C.f to resolve"); let Some(Type::Function(func_id)) = member_ty else {