Skip to content
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

Rust: Use PathResolution module in data flow #18609

Merged
merged 3 commits into from
Feb 4, 2025

Conversation

hvitved
Copy link
Contributor

@hvitved hvitved commented Jan 28, 2025

This PR updates our data flow library to use the newly introduced PathResolution library for identifying record and variant constructions. We still need a workaround for built-in types like Option, until we extract the relevant source code.

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Jan 28, 2025
@hvitved hvitved force-pushed the rust/dataflow-path-resolution branch from 88186da to 515bc76 Compare January 28, 2025 14:15
@hvitved hvitved force-pushed the rust/dataflow-path-resolution branch 2 times, most recently from 225e0e2 to 014f9e5 Compare January 31, 2025 10:15
@hvitved hvitved force-pushed the rust/dataflow-path-resolution branch from 014f9e5 to d56bf65 Compare January 31, 2025 12:30
@hvitved hvitved marked this pull request as ready for review February 3, 2025 08:53
@paldepind paldepind self-assigned this Feb 3, 2025
(
crate.asSome() = r.getResolvedCrateOrigin()
/** A canonical path pointing to an enum variant. */
class VariantLib extends MkVariantLib {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about using VariantInLib or VariantFromLib or something of that sort? My first reading of this was "a QL library for variants" 😅

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also be VariantInStdLib assuming we don't extend to take this special casing further than that.

path = r.getResolvedPath() and
(
crate.asSome() = r.getResolvedCrateOrigin()
/** A canonical path pointing to an enum variant. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** A canonical path pointing to an enum variant. */
/** An enum variant and its canonical path in the standard library. */

string toString() { result = name }
}

predicate variantLibPos(VariantLib::VariantLib v, int pos) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be a member predicate on VariantLib?

resolveExtendedCanonicalPath(p, crate, path) and
s = MkStructCanonicalPath(crate, path)
)
private predicate pathResolveToStruct(PathAstNode p, Struct s) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change pathResolveToStruct and pathResolveToVariant are both very simple and identical in implementation. Would it make sense to drop them and inline them or to combine them into one generalized predicate?

or
// Pattern destructs a struct.
structDestruction(pat.getPat(), c.(StructFieldContent).getStructCanonicalPath(field))
structDestruction(pat.getPat(), c.(StructFieldContent).getStruct(field))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this getStruct (and getVariant) a bit hard to read. It looks like it gets a struct for field. The name hasFieldAndGetStruct would have been a more clear. But it's the same on main, so this is more an idea for a future refactor (that I could do). I think separating this into a getField\0 and getSruct\0 would be easier to read (but more verbose).

@paldepind
Copy link
Contributor

Would we have to revert this in case we decide to keep path resolution in the extractor (e.g., if the performance turns out ok)?

@hvitved
Copy link
Contributor Author

hvitved commented Feb 3, 2025

Would we have to revert this in case we decide to keep path resolution in the extractor (e.g., if the performance turns out ok)?

It would have to be partly reverted, yes, though I think once we have the extractor properly extracting library code, we would want an interface similar to resolvePath anyway, to avoid the overhead of canonical paths as strings.

@hvitved hvitved requested a review from paldepind February 3, 2025 13:13
Co-authored-by: Simon Friis Vindum <paldepind@github.com>
@hvitved hvitved merged commit 90944d5 into github:main Feb 4, 2025
15 checks passed
@hvitved hvitved deleted the rust/dataflow-path-resolution branch February 4, 2025 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants