-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[red-knot] Meta data for Type::Todo
#14500
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
Conversation
|
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.
Clever!
30b7e60
to
a02a96a
Compare
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.
This is great! Will make debugging so much nicer.
} | ||
Type::Todo => Type::Todo.into(), | ||
Type::Todo(_) => todo_type!().into(), |
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 guess there are some judgment calls about when to propagate a Todo vs create a new one. This could propagate, like we do below in to_instance
and to_meta_type
, but maybe an attribute of a todo feels more like a new todo than an extension of the previous one? Not sure what will be more useful in practice.
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'm going to assume for now that the original todo is more interesting, so I changed the logic here to propagate the incoming todo.
assert!(todo1.is_equivalent_to(&db, todo2)); | ||
assert!(todo3.is_equivalent_to(&db, todo4)); | ||
assert!(todo1.is_equivalent_to(&db, todo3)); | ||
|
||
assert!(todo1.is_subtype_of(&db, todo2)); | ||
assert!(todo2.is_subtype_of(&db, todo1)); | ||
|
||
assert!(todo3.is_subtype_of(&db, todo4)); | ||
assert!(todo4.is_subtype_of(&db, todo3)); | ||
|
||
assert!(todo1.is_subtype_of(&db, todo3)); | ||
assert!(todo3.is_subtype_of(&db, todo1)); |
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 think these are all not actually correct (as discussed in Discord today), but that's orthogonal to this PR; these assertions are consistent with our current handling. So I think it makes sense to leave them as-is for this PR.
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.
Oh, I was about to read that discussion again tomorrow. I thought it was unrelated to my change 😄. I can look into it (not here).
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.
It is unrelated to your change, except that you added some explicit tests that Todo
(which is supposed to be a dynamic type just like Any
or Unknown
) is equivalent to and a subtype of itself, which I don't think we had explicitly tested before, and is not really right. So that makes it related :)
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.
Okay yes, this is what I understood after your first comment. I'll address this in a follow-up and fix these tests accordingly.
Adds meta information to `Type::Todo`, allowing developers to easily trace back the origin of a particular `@Todo` type they encounter. Instead of `Type::Todo`, we now write either `type_todo!()` which creates a `@Todo[path/to/source.rs:123]` type with file and line information, or using `type_todo!("PEP 604 unions not supported")`, which creates a variant with a custom message. `Type::Todo` now contains a `TodoType` field. In release mode, this is just a zero-sized struct, in order not to create any overhead. In debug mode, this is an `enum` that contains the meta information. `Type` implements `Copy`, which means that `TodoType` also needs to be copyable. This limits the design space. We could intern `TodoType`, but I discarded this option, as it would require us to have access to the salsa DB everywhere we want to use `Type::Todo`. And it would have made the macro invocations less ergonomic (requiring us to pass `db`). So for now, the meta information is simply a `&'static str` / u32 for the file/line variant, or a `&'static str` for the custom message. Anything involving a chain/backtrace of several `@Todo`s or similar is therefore currently not implemented. Also because we currently don't see any direct use cases for this, and because all of this will eventually go away. Note that the size of `Type` increases from 16 to 24 bytes, but only in debug mode.
de3f90d
to
8f66ee3
Compare
Summary
Adds meta information to
Type::Todo
, allowing developers to easily trace back the origin of a particular@Todo
type they encounter.Instead of
Type::Todo
, we now write eithertype_todo!()
which creates a@Todo[path/to/source.rs:123]
type with file and line information, or usingtype_todo!("PEP 604 unions not supported")
, which creates a variant with a custom message.Type::Todo
now contains aTodoType
field. In release mode, this is just a zero-sized struct, in order not to create any overhead. In debug mode, this is anenum
that contains the meta information.Type
implementsCopy
, which means thatTodoType
also needs to be copyable. This limits the design space. We could internTodoType
, but I discarded this option, as it would require us to have access to the salsa DB everywhere we want to useType::Todo
. And it would have made the macro invocations less ergonomic (requiring us to passdb
).So for now, the meta information is simply a
&'static str
/u32
for the file/line variant, or a&'static str
for the custom message. Anything involving a chain/backtrace of several@Todo
s or similar is therefore currently not implemented. Also because we currently don't see any direct use cases for this, and because all of this will eventually go away.Note that the size of
Type
increases from 16 to 24 bytes, but only in debug mode.Test Plan
Type::Todo
s that were revealed in the tests@Todo
in release mode and@Todo(function parameter type)
in debug mode.