-
-
Notifications
You must be signed in to change notification settings - Fork 638
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
Pass derivation details through from Rust. #21631
Pass derivation details through from Rust. #21631
Conversation
This allows us to specify which config file each value came from. We intern the details strings, since they are very repetitive from a small set of possible strings. This requires explicit lifetimes in more places, but hey, that's what Rust is for.
fn source_to_details(source: &Source) -> Option<&str> { | ||
match source { | ||
Source::Default => None, | ||
Source::Config { ordinal: _, path } => Some(path), |
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 dispensed with the prefix "from" in these, since it adds no information, and in the case of config file paths it would require storing a "from " string somewhere with an appropriate lifetime, and there is no obvious place for that (other than on the Source itself, but that seems silly).
// intersperse is provided by itertools::Itertools, but is also in the Rust nightly | ||
// as an experimental feature of standard Iterator. If/when that becomes standard we | ||
// can use it, but for now we must squelch the name collision. | ||
Some(PyString::intern_bound( |
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.
We do end up allocating a new Rust String in this case, but it's an uncommon case so that seems fine (and the Python-side interning will still work).
// In ascending rank order, so the last value is the final value of the option. | ||
type OptionValueDerivation<T> = Vec<(T, Vec<isize>)>; | ||
// The derivation of the option value, as a vec of (value, rank, details string) tuples. | ||
type OptionValueDerivation<'py, T> = Vec<(T, isize, Option<Bound<'py, PyString>>)>; |
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.
Note that we may not need that isize after we get rid of the legacy parser. The RankedValue struct on the Python side expects it, but I'm not sure we actually use it.
Easiest reading order for review:
Thanks! |
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.
Nice result 👍
This allows us to specify which config file each value came from.
We intern the details strings, as they are very repetitive. This requires
tying the lifetime of various data structures to that of the GIL.