Skip to content

Conversation

@hvitved
Copy link
Contributor

@hvitved hvitved commented Jun 16, 2025

Avoids a combinatorial explosion when type arguments are not unique.

@github-actions github-actions bot added the C# label Jun 16, 2025
@hvitved hvitved added the no-change-note-required This PR does not need a change note label Jun 16, 2025
@hvitved hvitved marked this pull request as ready for review June 17, 2025 07:17
Copilot AI review requested due to automatic review settings June 17, 2025 07:17
@hvitved hvitved requested a review from a team as a code owner June 17, 2025 07:17
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates QL utilities to use monotonic aggregates and strictconcat when computing generic type argument strings, aiming to prevent combinatorial explosion for non-unique arguments.

  • Enabled language[monotonicAggregates] for two helper functions
  • Replaced direct getFullName/getName calls with strictconcat aggregators

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
csharp/ql/lib/semmle/code/csharp/commons/QualifiedName.qll Added language[monotonicAggregates] and switched to strictconcat in getTypeArgumentsQualifiedName
csharp/ql/lib/semmle/code/csharp/Generics.qll Added language[monotonicAggregates] and switched to strictconcat in getTypeArgumentName
Comments suppressed due to low confidence (2)

csharp/ql/lib/semmle/code/csharp/commons/QualifiedName.qll:54

  • Using a strictconcat over a single-element generator tied to i doesn’t aggregate across all type arguments, so it won’t prevent combinatorial explosion. Consider removing the i parameter and aggregating over cg.getTypeArgument(*) in one call or moving the aggregation into the caller.
result = strictconcat(Type t | t = cg.getTypeArgument(i) | getFullName(t), "/")

csharp/ql/lib/semmle/code/csharp/Generics.qll:116

  • This strictconcat is also scoped to a single i, so you’re effectively concatenating only one element. To handle non-unique arguments correctly, aggregate over all arguments at once rather than indexing per call.
result = strictconcat(Type t | t = cg.getTypeArgument(i) | t.getName(), "/")

strictconcat(Type t, int i | t = cg.getTypeArgument(i) | t.toStringWithTypes(), ", " order by i)
}

language[monotonicAggregates]
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we add comments stating that this is merely a precaution and that we expect he concat to only concat a single name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@hvitved hvitved force-pushed the csharp/type-arg-unique branch from d61a674 to a188adc Compare June 17, 2025 07:31
@hvitved hvitved merged commit 909e95f into github:main Jun 17, 2025
21 checks passed
@hvitved hvitved deleted the csharp/type-arg-unique branch June 17, 2025 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C# no-change-note-required This PR does not need a change note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants