GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — C#: Overlay extraction support. by michaelnebel · Pull Request #20425 · github/codeql Conversation
|
| catch | ||
| { | ||
| logger.LogError("Overlay: Unexpected error while reading the overlay changes file."); | ||
| } |
Code scanning / CodeQL
Generic catch clause
cd0b31c to
b749636
Compare
6db88cf to
915770b
Compare
5fe0d0e to
6ea8338
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This PR introduces overlay extraction support for C#, enabling incremental database creation. The strategy extracts only signature information (types, methods, parameters) for unchanged files while fully extracting changed files, reusing locations from the base database. Key changes include adding discard predicates, enabling overlay compilation, and modifying the extraction context to skip expression/statement extraction for unchanged files.
Copilot reviewed 59 out of 59 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
csharp/ql/lib/semmlecode.csharp.dbscheme |
Adds databaseMetadata, overlayChangedFiles relations and @locatable type for overlay support |
csharp/ql/lib/semmle/code/csharp/Overlay.qll |
Implements entity discard predicates for overlay analysis |
csharp/ql/lib/semmle/code/csharp/Conversion.qll |
Refactors type constraint logic by extracting typeConstraintToBaseType predicate |
csharp/ql/lib/qlpack.yml |
Enables overlay compilation with compileForOverlayEval: true |
csharp/ql/lib/csharp.qll |
Imports Overlay module |
csharp/extractor/Semmle.Util/EnvironmentVariables.cs |
Adds methods to detect overlay mode and read overlay changes file path |
csharp/extractor/Semmle.Extraction.CSharp/Extractor/OverlayInfo.cs |
Implements overlay information tracking and changed file detection |
csharp/extractor/Semmle.Extraction.CSharp/Extractor/Context.cs |
Adds OnlyScaffold flag to control skeleton extraction for unchanged files |
| Multiple entity extractors | Conditionally skip location extraction when OnlyScaffold is true |
csharp/codeql-extractor.yml |
Declares overlay support version |
| Test files | Adds overlay test infrastructure and expected results |
| Upgrade/downgrade files | Provides database schema migration support |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@jbj : Thank you very much for the feedback! I really appreciate it!
Yes, exactly. We could consider always extracting generated files, if we can't get a mapping between original <-> generated files. As you mention, this is less urgent.
Really good question!
Yes, I think downloading dependencies is a large portion of the overall time. Do you know, whether it will be possible to measure the benefit of cached dependencies using DCA? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I know that |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM, great work 💪
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| display_name: "C#" | ||
| version: 1.22.1 | ||
| column_kind: "utf16" | ||
| overlay_support_version: 20250626 |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
OOI, where does this date come from?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
From here.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| /// ] | ||
| /// } | ||
| /// </summary> | ||
| public record ChangedFiles |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Can it actually be made private?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Yes, it can 😄
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| { | ||
| trapFile.commentblock(this); | ||
| WriteLocationToTrap(trapFile.commentblock_location, this, Context.CreateLocation(Symbol.Location)); | ||
| if (!Context.OnlyScaffold) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Why is it that we not simply return when Context.OnlyScaffold holds?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
For the "named" TRAP entities, I have just tried to avoid re-extracting the source locations. Will try and make the change. In this case the child information is extracted below. I will restructure a bit to streamline implementation.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| location = Context.CreateLocation(Location); | ||
| trapFile.commentline(this, Type == CommentLineType.MultilineContinuation ? CommentLineType.Multiline : Type, Text, RawText); | ||
| WriteLocationToTrap(trapFile.commentline_location, this, location); | ||
| if (!Context.OnlyScaffold) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Same.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| if (info.Symbol is INamespaceSymbol namespaceSymbol) | ||
| { | ||
| var ns = Namespace.Create(Context, namespaceSymbol); | ||
| trapFile.using_namespace_directives(this, ns); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Why are we extracting this in scaffold mode?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Uh, yes, they are indeed * ID elements, so we should probably avoid extracting them altogether when scaffolding. Will try and make that change.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| */ | ||
| overlay[local] | ||
| private class StarEntity = | ||
| @expr or @stmt or @diagnostic or @extractor_message or @using_directive or @type_mention; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
@local_variable uses * as well.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
and, of course, @location.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Only source locations are * entities. Furthermore, a location is not considered a @locatable. There is a separate discard predicate for handling locations.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| private predicate discardStarEntity(@locatable e) { | ||
| e instanceof StarEntity and | ||
| // Entities with *-ids can exist either in base or overlay, but not both. | ||
| exists(DiscardableEntity de | de = e | |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
e = any(DiscardableEntity de | is slightly less verbose.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| private predicate discardNamedEntity(@locatable e) { | ||
| not e instanceof StarEntity and | ||
| // Entities with named IDs can exist both in base, overlay, or both. | ||
| exists(DiscardableEntity de | de = e | |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
same
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
|
|
||
| overlay[local] | ||
| private class PossibleDiscardableEntity extends DiscardableEntity instanceof @locatable { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
instanceof @locatable is redundant.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
We can put all the logic directly in the DiscardableEntity class instead.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| overlay[local] | ||
| abstract private class DiscardableEntity extends @locatable { | ||
| /** Gets the path to the file in which this element occurs. */ | ||
| abstract string getPath(); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
getFilePath would be better, I think.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
1ca50aa to
9d300e3
Compare
There is an increase in e.g.
It looks like we are getting alert duplicates for XML-based queries like |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| trapFile.commentblock(this); | ||
| if (!Context.OnlyScaffold) | ||
| Symbol.CommentLines.ForEach((l, child) => trapFile.commentblock_child(this, l, child)); | ||
| if (Context.OnlyScaffold) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I would have thought that we could simply move this early return up to the beginning of Populate?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Actually, now that I think about it, shouldn't we instead be guarding all the places where we extract comments (such as calls to CommentPopulator.ExtractCommentBlocks,CommentPopulator.ExtractComment, and inside Context.BindComments)?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I would like to move this to the begging on the populate method and then also guard the BindTo method. This should be internally consistent and not cause any dangling references (I will also push the scaffolding guard from CachedEntitiy to the Context for comment binding).
Will add one more commit for this.
Also note that for TypeMentions, the guard has been moved to the top of the populate method (as creating these will not cause any dangling references). Most places in the populate methods the TypeMention creation has been "moved below" the scaffolding early return check (and thus not be created), but I haven't done so in all places as this will create a large amount of extra guarding.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I will also put in the guards the places where you suggest to avoid all the string processing before the actual comments are created.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
This is "just" normal extractor background noise (there is a new run from the weekend where is only one extra extractor error for this project).
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@hvitved Since your last review
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…nterface return type for methods have changed order.
fd25d5d to
43118ec
Compare
a810ba4 to
c44b747
Compare
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
7a2c611 to
11970fb
Compare
11970fb to
3492811
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Looks plausible to me; the manual scaffolding logic in the extractor worries me a bit, but I don't think there is much we can do to avoid it.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.