-
-
Notifications
You must be signed in to change notification settings - Fork 646
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
Add path to cache key for Rust dep inference, for relative imports #19630
Conversation
bfe02bd
to
5498b2d
Compare
)), | ||
|_workunit| async move { | ||
let result: ParsedPythonDependencies = get_or_create_inferred_dependencies( | ||
core, | ||
&store, | ||
prepared_inference_request, | ||
|content, request| python::get_dependencies(content, request.path), | ||
|content, request| { | ||
python::get_dependencies(content, request.inner.input_file_path.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.
Per the PR description, this is the additional String -> PathBuf conversion. We can avoid this in a few ways:
- use and manipulate
String
in theget_dependencies
functions directly, instead ofPathBuf
, which seems reasonable given the functions do a&Path
->&str
conversion internally anyway (although this would lose some convenience helpers for manipulating the paths) - have a protobuf type that maps to
PathBuf
directly
Or... just not worry about it, because this conversion is fast.
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.
🙏 You rock! Thanks!
src/python/pants/backend/python/dependency_inference/rules_test.py
Outdated
Show resolved
Hide resolved
src/python/pants/backend/python/dependency_inference/rules_test.py
Outdated
Show resolved
Hide resolved
src/rust/engine/src/intrinsics.rs
Outdated
/// The request that's guaranteed to have been constructed via ::prepare(). | ||
/// | ||
/// NB. this `inner` value is used as the cache key, so anything that can influence the dep | ||
/// inference should (also) be inside it, not just a key on this struct |
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 tried to automatically cherry-pick this change back to each relevant milestone, so that it is available in those older releases of Pants. ❌ 2.17.xI was unable to cherry-pick this PR to 2.17.x, likely due to merge-conflicts. Steps to Cherry-Pick locallyTo resolve:
Please note that I cannot re-run CI if a job fails. Please work with your PR approver(s) to re-run CI if necessary. When you're done manually cherry-picking, please remove the Thanks again for your contributions! |
…herry-pick of #19630) (#19640) This adds the file path for the file being dependency-inferred to the cache key for the Rust dep inference. Without this, the same file contents appearing multiple times in different places will give the wrong results for relative imports, because the dep inference process mashes together the file path and the relative import. The circumstances here seem most likely to occur in the real world if a file is moved, with the inference results from before the move reused for the file _after_ the move too. I've tested this manually on the reproducer in #19618 (comment), in addition to comparing the before (fails) and after (passes) behaviour of the new test. To try to make this code more resilient to this sort of mistake, I've removed the top level `PreparedInferenceRequest.path` key, in favour of using the new `input_file_path` on the request protobuf struct, at the cost of an additional `String` -> `PathBuf` conversion when doing the inference. Fixes #19618 This is a cherry pick of #19630, but is essentially a slightly weird rewrite that partially cherry-picks #19001 too, by copying over the whole `DependencyInferenceRequest` protobuf type as is (even with some fields that are unused) because that's the easiest way to generate appropriate bytes for turning into the digest for use in the cache-key. I think it's okay to have this "weird" behaviour in the 2.17 branch, with the real/normal code in main/2.18?
…19630) This adds the file path for the file being dependency-inferred to the cache key for the Rust dep inference. Without this, the same file contents appearing multiple times in different places will give the wrong results for relative imports, because the dep inference process mashes together the file path and the relative import. The circumstances here seem most likely to occur in the real world if a file is moved, with the inference results from before the move reused for the file _after_ the move too. I've tested this manually on the reproducer in #19618 (comment), in addition to comparing the before (fails) and after (passes) behaviour of the new test. To try to make this code more resilient to this sort of mistake, I've removed the top level `PreparedInferenceRequest.path` key, in favour of using the new `input_file_path` on the request protobuf struct, at the cost of an additional `String` -> `PathBuf` conversion when doing the inference. Fixes #19618
I tried to automatically cherry-pick this change back to each relevant milestone, so that it is available in those older releases of Pants. ✔️ 2.18.xSuccessfully opened #19690. Thanks again for your contributions! |
…herry-pick of #19630) (#19690) This adds the file path for the file being dependency-inferred to the cache key for the Rust dep inference. Without this, the same file contents appearing multiple times in different places will give the wrong results for relative imports, because the dep inference process mashes together the file path and the relative import. The circumstances here seem most likely to occur in the real world if a file is moved, with the inference results from before the move reused for the file _after_ the move too. I've tested this manually on the reproducer in #19618 (comment), in addition to comparing the before (fails) and after (passes) behaviour of the new test. To try to make this code more resilient to this sort of mistake, I've removed the top level `PreparedInferenceRequest.path` key, in favour of using the new `input_file_path` on the request protobuf struct, at the cost of an additional `String` -> `PathBuf` conversion when doing the inference. Fixes #19618 Co-authored-by: Huon Wilson <huon@exoflare.io>
This adds the file path for the file being dependency-inferred to the cache key for the Rust dep inference. Without this, the same file contents appearing multiple times in different places will give the wrong results for relative imports, because the dep inference process mashes together the file path and the relative import.
The circumstances here seem most likely to occur in the real world if a file is moved, with the inference results from before the move reused for the file after the move too.
I've tested this manually on the reproducer in #19618 (comment), in addition to comparing the before (fails) and after (passes) behaviour of the new test.
To try to make this code more resilient to this sort of mistake, I've removed the top level
PreparedInferenceRequest.path
key, in favour of using the newinput_file_path
on the request protobuf struct, at the cost of an additionalString
->PathBuf
conversion when doing the inference.Fixes #19618