-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Overlay: Add manual Java overlay annotations & discard predicates #19813
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
base: kaspersv/overlay-java-annotations
Are you sure you want to change the base?
Overlay: Add manual Java overlay annotations & discard predicates #19813
Conversation
6f5bc41
to
8672313
Compare
8672313
to
db52a3c
Compare
db52a3c
to
26896ea
Compare
ea40677
to
052023e
Compare
bdf1bdd
to
3c2c871
Compare
052023e
to
81b677a
Compare
3c2c871
to
0ee6a78
Compare
The |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy with this if @aschackmull is happy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can simplify the boilerplate somewhat.
// numlines is used to restrict attention to fully extracted files and | ||
// ignore skeleton extracted files in the overlay | ||
exists(@locatable l | numlines(l, _, _, _) and file = getRawFile(l)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about adding the following:
} | |
} | |
/** | |
* A `@locatable` in the base variant that should be discarded if its file is | |
* extracted in the overlay variant. | |
*/ | |
overlay[local] | |
abstract class DiscardableLocatable extends @locatable { | |
string getRawFileInBase() { not isOverlay() and result = getRawFile(this) } | |
} | |
overlay[discard_entity] | |
private predicate discardLocatable(@locatable el) { | |
extractedInOverlay(el.(DiscardableLocatable).getRawFileInBase()) | |
} |
I think that can reduce a lot of boilerplate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, for things like @method
we can use:
/**
* A `@locatable` in the base variant that should be discarded if its file is
* extracted in the overlay variant and it is itself not extracted in the
* overlay, that is, it is deleted in the overlay.
*/
overlay[local]
abstract class DiscardableReferableLocatable extends @locatable {
string getRawFileInBase() { not isOverlay() and result = getRawFile(this) }
predicate existsInOverlay() { isOverlay() and exists(this) }
}
overlay[discard_entity]
private predicate discardReferableLocatable(@locatable el) {
exists(DiscardableReferableLocatable drl | drl = el |
extractedInOverlay(drl.getRawFileInBase()) and
not drl.existsInOverlay()
)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. I've added the suggested abstraction for locatables in commit 4. I've left the locations case as is, as there is only one discard predicate for locations currently.
overlay[local] | ||
private predicate discardableExpr(string file, @expr e) { | ||
not isOverlay() and | ||
file = getRawFile(e) | ||
} | ||
|
||
/** Discard base expressions in files fully extracted in the overlay. */ | ||
overlay[discard_entity] | ||
private predicate discardExpr(@expr e) { | ||
exists(string file | discardableExpr(file, e) and extractedInOverlay(file)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the suggested DiscardableLocatable
, this could simply become:
overlay[local] | |
private predicate discardableExpr(string file, @expr e) { | |
not isOverlay() and | |
file = getRawFile(e) | |
} | |
/** Discard base expressions in files fully extracted in the overlay. */ | |
overlay[discard_entity] | |
private predicate discardExpr(@expr e) { | |
exists(string file | discardableExpr(file, e) and extractedInOverlay(file)) | |
} | |
overlay[local] | |
private class DiscardableExpr extends DiscardableLocatable, @expr { } |
I'm unsure whether overlay[local]
is needed here or whether it's inherited from DiscardableLocatable
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overlay[local]
is not inherited from DiscardableLocatable
, but the overlay[local?]
annotation from the top-level module declaration is inherited, so overlay[local]
isn't strictly needed, but does clarify the intend.
overlay[local] | ||
private predicate discardableJavadoc(string file, @javadoc d) { | ||
not isOverlay() and | ||
exists(@member m | file = getRawFile(m) and hasJavadoc(m, d)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe @javadoc
is a @locatable
, so the indirection through hasJavadoc
is unnecessary, I think. Also, with the abstract class this would simply be
private class DiscardableJavadoc extends DiscardableLocatable, @javadoc { }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point; the indirection is unnecessary.
54589c8
to
bcadf31
Compare
This PR builds on top of #19779, adding a few additional manual overlay annotations and defining entity discard predicates for Java.
The
overlay[local?]
annotations in the experimental queries are needed to ensure that virtual dispatch (which depends indirectly onActiveExperimentalModels
) becomes local. In addition to the manualoverlay[local?]
annotations, the PR adds anoverlay[global]
annotation inDataFlowImplCommon.qll
to ensure lambda flow is global.The entity discard predicates defined in this PR are not exhaustive and additional discarding may be needed. The PR adds entity discard predicates to discard the following: