Skip to content

Conversation

@paldepind
Copy link
Contributor

@paldepind paldepind commented Jan 29, 2025

  • Adds the setup for model generation based on C# and Java.
  • Instantiates the model generation signature. Some parts are not implemented yet, but enough is there to get simple models and models using variants to work.

@github-actions github-actions bot added documentation Rust Pull requests that update Rust code labels Jan 29, 2025
p = source.getNode() and
p.asParameter() = api.getAParameter()
select sink.getNode(), source, sink, "There is flow from a $@ to $@.", source.getNode(),
"parameter", sink.getNode(), "intermediate value"

Check warning

Code scanning / CodeQL

Alert message style violation Warning

Don't repeat the alert location as a link.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are debug queries copy pasted from C#, so I'm inclined to ignore this?

Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't worry about this too much, assuming we're not expecting users to use these queries directly. We might want to make it clearer what these queries are for though (e.g. in the @description) in case users do find them?

returnNodeExt = sink.getNode() and
exists(captureThroughFlow0(api, p, returnNodeExt))
select sink.getNode(), source, sink, "There is flow from $@ to the $@.", source.getNode(),
"parameter", sink.getNode(), "return value"

Check warning

Code scanning / CodeQL

Alert message style violation Warning

Don't repeat the alert location as a link.
/**
* Gets the underlying type of the content `c`.
*/
Type getUnderlyingContentType(DataFlow::ContentSet c) { result = any(Type t) and exists(c) }

Check warning

Code scanning / CodeQL

Redundant cast Warning

Redundant cast to
Unit
.
@paldepind paldepind force-pushed the rust-flow-summary-generation branch from ecf32a1 to 360c5eb Compare January 30, 2025 07:54
@paldepind paldepind force-pushed the rust-flow-summary-generation branch from 360c5eb to f76647f Compare January 30, 2025 10:45
@paldepind paldepind marked this pull request as ready for review January 30, 2025 10:53
}

// MISSING: summary=repo::test;<crate::summaries::MyStruct>::get_foo;Argument[self].Struct[crate::summaries::MyStruct::foo];ReturnValue;value;dfc-generated
pub fn get_foo(self) -> i64 {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd have expected this to work, but I'll investigate later. Right now variants are more interesting, as generating models for Option is the current goal.

Copy link
Contributor

Choose a reason for hiding this comment

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

I like the way these tests are set up, by the way. I suspect we'll want more of them as we debug things, but it's a really nice setup.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Absolutely, and I completely agree. It's all thanks to @michaelnebel 🎉

@paldepind paldepind force-pushed the rust-flow-summary-generation branch from 03ec4ee to 0a9b864 Compare February 3, 2025 08:06
@paldepind
Copy link
Contributor Author

CI complains about missing QLdoc, but it's the same in C# and Java, so I think it's ok to ignore.

Copy link
Contributor

@hvitved hvitved left a comment

Choose a reason for hiding this comment

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

Looks great, oh my that ModelGeneratorInputSig interface is complex... My main comment is about only using content-based (precise) summary generation.

/** Gets the parameter that this node corresponds to. */
ParamBase getParameter() { result = super.getParameter().getParamBase() }
}
final class ParameterNode = Node::SourceParameterNode;
Copy link
Contributor

Choose a reason for hiding this comment

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

This made me realize that we are already now exposing internal implementation details in the public DataFlow::Node class, which I want to avoid. So I would like for this to be reverted back 🙏

@@ -0,0 +1,13 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure we'll want this query, I hope that CaptureContentSummaryModels.ql should be enough for us.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't have strong feelings but I'd be inclined to leave the files in places because:
1/ The shared Python script assumes that these files are there.
2/ For consistency with C# and Java
3/ We might never have to ever use them, but perhaps it could come in handy for debugging or experimenting through the generation script.

@@ -0,0 +1,13 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment.

import utils.test.InlineMadTest

module InlineMadTestConfig implements InlineMadTestConfigSig {
string getCapturedModel(Function c) { result = captureMixedFlow(c, _) }
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, I think we just want ContentSensitive::captureFlow for Rust.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes no difference in the tests, so let's just do that yes 👍

@geoffw0
Copy link
Contributor

geoffw0 commented Feb 3, 2025

I'm looking forward to seeing early results from the model generator, which I gather is going to come a bit later.

@paldepind
Copy link
Contributor Author

I'm looking forward to seeing early results from the model generator, which I gather is going to come a bit later.

After this PR I'll create one adding flow for higher-order functions. With that we get around 50 lines of yaml for Option that it would probably make sense to commit at that point! 👍

@paldepind paldepind force-pushed the rust-flow-summary-generation branch from ffaad99 to cf4f657 Compare February 4, 2025 09:42
@paldepind paldepind requested a review from hvitved February 4, 2025 09:51
@paldepind paldepind merged commit 8d01bbc into github:main Feb 4, 2025
16 of 17 checks passed
@paldepind paldepind deleted the rust-flow-summary-generation branch February 4, 2025 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants