From 58fa1d71b68b687e666a76f0506c842f65e578a2 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Mon, 17 Nov 2025 10:01:21 +0100 Subject: [PATCH] [ty] Use `CompactStr` for `StringLiteralType` (#21497) --- crates/ty_python_semantic/src/types.rs | 7 ++++--- crates/ty_server/src/server/api.rs | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/ty_python_semantic/src/types.rs b/crates/ty_python_semantic/src/types.rs index cb63e03ef6..a79c0c33c5 100644 --- a/crates/ty_python_semantic/src/types.rs +++ b/crates/ty_python_semantic/src/types.rs @@ -1,3 +1,4 @@ +use compact_str::{CompactString, ToCompactString}; use infer::nearest_enclosing_class; use itertools::{Either, Itertools}; 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::KnownInstance(known_instance) => Type::StringLiteral(StringLiteralType::new( db, - known_instance.repr(db).to_string().into_boxed_str(), + known_instance.repr(db).to_compact_string(), )), // TODO: handle more complex types _ => 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::KnownInstance(known_instance) => Type::StringLiteral(StringLiteralType::new( db, - known_instance.repr(db).to_string().into_boxed_str(), + known_instance.repr(db).to_compact_string(), )), // TODO: handle more complex types _ => KnownClass::Str.to_instance(db), @@ -12388,7 +12389,7 @@ impl<'db> IntersectionType<'db> { #[derive(PartialOrd, Ord)] pub struct StringLiteralType<'db> { #[returns(deref)] - value: Box, + value: CompactString, } // The Salsa heap is tracked separately. diff --git a/crates/ty_server/src/server/api.rs b/crates/ty_server/src/server/api.rs index fe5d28909f..326c3eeef9 100644 --- a/crates/ty_server/src/server/api.rs +++ b/crates/ty_server/src/server/api.rs @@ -436,7 +436,7 @@ where .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( id: &RequestId, result: Result<<::RequestType as Request>::Result>,