[ty] Use `CompactStr` for `StringLiteralType` (#21497)

This commit is contained in:
Micha Reiser 2025-11-17 10:01:21 +01:00 committed by GitHub
parent d9fc0f08b4
commit 58fa1d71b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 4 deletions

View File

@ -1,3 +1,4 @@
use compact_str::{CompactString, ToCompactString};
use infer::nearest_enclosing_class; use infer::nearest_enclosing_class;
use itertools::{Either, Itertools}; use itertools::{Either, Itertools};
use ruff_db::parsed::parsed_module; use ruff_db::parsed::parsed_module;
@ -7497,7 +7498,7 @@ impl<'db> Type<'db> {
Type::SpecialForm(special_form) => Type::string_literal(db, special_form.repr()), Type::SpecialForm(special_form) => Type::string_literal(db, special_form.repr()),
Type::KnownInstance(known_instance) => Type::StringLiteral(StringLiteralType::new( Type::KnownInstance(known_instance) => Type::StringLiteral(StringLiteralType::new(
db, db,
known_instance.repr(db).to_string().into_boxed_str(), known_instance.repr(db).to_compact_string(),
)), )),
// TODO: handle more complex types // TODO: handle more complex types
_ => KnownClass::Str.to_instance(db), _ => KnownClass::Str.to_instance(db),
@ -7519,7 +7520,7 @@ impl<'db> Type<'db> {
Type::SpecialForm(special_form) => Type::string_literal(db, special_form.repr()), Type::SpecialForm(special_form) => Type::string_literal(db, special_form.repr()),
Type::KnownInstance(known_instance) => Type::StringLiteral(StringLiteralType::new( Type::KnownInstance(known_instance) => Type::StringLiteral(StringLiteralType::new(
db, db,
known_instance.repr(db).to_string().into_boxed_str(), known_instance.repr(db).to_compact_string(),
)), )),
// TODO: handle more complex types // TODO: handle more complex types
_ => KnownClass::Str.to_instance(db), _ => KnownClass::Str.to_instance(db),
@ -12388,7 +12389,7 @@ impl<'db> IntersectionType<'db> {
#[derive(PartialOrd, Ord)] #[derive(PartialOrd, Ord)]
pub struct StringLiteralType<'db> { pub struct StringLiteralType<'db> {
#[returns(deref)] #[returns(deref)]
value: Box<str>, value: CompactString,
} }
// The Salsa heap is tracked separately. // The Salsa heap is tracked separately.

View File

@ -436,7 +436,7 @@ where
.with_failure_code(server::ErrorCode::InternalError) .with_failure_code(server::ErrorCode::InternalError)
} }
/// Sends back a response to the server, but only if the request wasn't cancelled. /// Sends back a response to the client, but only if the request wasn't cancelled.
fn respond<Req>( fn respond<Req>(
id: &RequestId, id: &RequestId,
result: Result<<<Req as RequestHandler>::RequestType as Request>::Result>, result: Result<<<Req as RequestHandler>::RequestType as Request>::Result>,