Skip to content

Shared: Make sure getMadRepresentation is unique #19777

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

Merged
merged 2 commits into from
Jun 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ extensions:
extensible: summaryModel
data:
# Iterator
- ["lang:core", "<[_]>::iter", "Argument[Self].Element", "ReturnValue.Element", "value", "manual"]
- ["lang:core", "<[_]>::iter_mut", "Argument[Self].Element", "ReturnValue.Element", "value", "manual"]
- ["lang:core", "<[_]>::into_iter", "Argument[Self].Element", "ReturnValue.Element", "value", "manual"]
- ["lang:core", "<[_]>::iter", "Argument[self].Element", "ReturnValue.Element", "value", "manual"]
- ["lang:core", "<[_]>::iter_mut", "Argument[self].Element", "ReturnValue.Element", "value", "manual"]
- ["lang:core", "<[_]>::into_iter", "Argument[self].Element", "ReturnValue.Element", "value", "manual"]
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

- ["lang:core", "crate::iter::traits::iterator::Iterator::nth", "Argument[self].Element", "ReturnValue.Field[core::option::Option::Some(0)]", "value", "manual"]
- ["lang:core", "crate::iter::traits::iterator::Iterator::next", "Argument[self].Element", "ReturnValue.Field[core::option::Option::Some(0)]", "value", "manual"]
- ["lang:core", "crate::iter::traits::iterator::Iterator::collect", "Argument[self].Element", "ReturnValue.Element", "value", "manual"]
Expand Down
7 changes: 6 additions & 1 deletion shared/dataflow/codeql/dataflow/internal/FlowSummaryImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,11 @@ module Make<
derivedFluentFlowPush(_, _, _, head, tail, _)
}

pragma[nomagic]
Copy link
Preview

Copilot AI Jun 16, 2025

Choose a reason for hiding this comment

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

Add a doc comment explaining the purpose of getUniqueMadRepresentation and why it appends a trailing / delimiter to ensure uniqueness.

Suggested change
pragma[nomagic]
pragma[nomagic]
/**
* Generates a unique string representation of the given `SummaryComponent`.
*
* This representation is used in MaD (Model and Dataflow) models to uniquely
* identify components. A trailing `/` is appended to ensure that the resulting
* string is distinct from other potential string formats and avoids collisions
* when concatenated with other representations.
*
* @param c The `SummaryComponent` to generate a representation for.
* @return A unique string representation of the component.
*/

Copilot uses AI. Check for mistakes.

Copy link
Contributor

Choose a reason for hiding this comment

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

I have to admit I would really appreciate a description of what's going on here. What would a collision look like?

private string getUniqueMadRepresentation(SummaryComponent c) {
result = strictconcat(string s | s = c.getMadRepresentation() | s, "/")
}

/**
* A (non-empty) stack of summary components.
*
Expand Down Expand Up @@ -732,7 +737,7 @@ module Make<
exists(SummaryComponent head, SummaryComponentStack tail |
head = this.head() and
tail = this.tail() and
result = tail.getMadRepresentation() + "." + head.getMadRepresentation()
result = tail.getMadRepresentation() + "." + getUniqueMadRepresentation(head)
)
or
exists(SummaryComponent c |
Expand Down
Loading