-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
red-knot: infer string literal types #13113
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -181,6 +181,8 @@ pub enum Type<'db> { | |
IntLiteral(i64), | ||
/// A boolean literal, either `True` or `False`. | ||
BooleanLiteral(bool), | ||
/// A string literal | ||
StringLiteral(StringLiteralType<'db>), | ||
/// A bytes literal | ||
BytesLiteral(BytesLiteralType<'db>), | ||
// TODO protocols, callable types, overloads, generics, type vars | ||
|
@@ -278,6 +280,11 @@ impl<'db> Type<'db> { | |
Type::Unknown | ||
} | ||
Type::BooleanLiteral(_) => Type::Unknown, | ||
Type::StringLiteral(_) => { | ||
// TODO fix this comment with whatever it is we should say we | ||
// want to do in the future. | ||
Type::Unknown | ||
} | ||
Type::BytesLiteral(_) => { | ||
// TODO defer to Type::Instance(<bytes from typeshed>).member | ||
Type::Unknown | ||
|
@@ -378,6 +385,12 @@ pub struct IntersectionType<'db> { | |
negative: FxOrderSet<Type<'db>>, | ||
} | ||
|
||
#[salsa::interned] | ||
pub struct StringLiteralType<'db> { | ||
#[return_ref] | ||
value: String, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we could use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great call; this is probably worth doing, considering it saves an entire usize of memory, which is eight ascii characters (on a 64-bit system); it could halve the memory used for a lot of small string literal types. (Not really, if you consider the Salsa interning overhead as well. But still, not insignificant if there are lots of small string literals.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah! Yeah, I consistently forget that |
||
} | ||
|
||
#[salsa::interned] | ||
pub struct BytesLiteralType<'db> { | ||
#[return_ref] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I expect this is probably something in the space of what we say for
BytesLiteral
?