-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
C++: Define an extractor version table and use in IR generation #14579
Conversation
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.
The code changes LGTM! As far as I can tell this brings us back to a pre-frontend upgrade state when not exists(getExtractorVersion())
holds, and to a post-frontend upgrade state when exists(getExtractorVersion())
holds. Let's see what DCA says 🤞
I guess CI is failing because we're in the strange position where:
- The frontend has been upgraded, and
- There isn't a result for
getExtractorVersion()
Correct. It's the internal CI that'll give the real verdict here, but that was failing because of a missing stats file. |
*/ | ||
|
||
/** Get the extractor version */ | ||
int getExtractorVersion() { extractor_version(result) } |
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.
wouldn't it get simpler to use by avoiding having to write lots of exists(getExtractorVersion())
if we had a default return value when the version is not in the DB?
int getExtractorVersion() { extractor_version(result) } | |
int getExtractorVersion() { | |
extractor_version(result) or (not exists(int v | extractor_version(v)) and result = -1) | |
} |
(or 0 if actual versions start from 1).
Then checks like getExtractorVersion() < n
would work as expected.
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.
That seems like a very imperative way of thinking about this. Is that what we want?
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 agree with Jeroen, I think. I don't see why we should have a default value here (default values is not a thing we tend to use in QL since a predicate with "no value" "propagates outwards" so that whatever clause that uses getExtractorVersion()
also produces no values).
With that said, @andersfugmann had a less controversial suggestion: Maybe the TranslatedExpr.qll
should define a isBefore605FrontendUpgrade()
predicate so that the exists(getExtractorVersion())
could be replaced with something slightly more meaningful.
I don't think we should do ^ in this PR since I'd like to avoid unnecessary submodule bumps wherever possible.
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 that said, @andersfugmann had a less controversial suggestion: Maybe the
TranslatedExpr.qll
should define aisBefore605FrontendUpgrade()
predicate so that theexists(getExtractorVersion())
could be replaced with something slightly more meaningful.
That makes sense to me. I can do that in this PR, since I need to rebase anyway, ...
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.
Yeah, a more explicit predicate name like isBefore605FrontendUpgrade
sounds a very good alternative. Maybe we should make getExtractorVersion
private
within ExtractorVersion.qll
and only expose such predicates with descriptive names from it?
About the default value, as a less experienced QL writer I know I could be bitten by writing for example getExtractorVersion() < 5
. And that even if I was not bitten by it, I would have to rewrite the logic to something like getExtractorVersion() >= 5
or a worse not exists(getExtractorVersion()) or getExtractorVersion() < 5
. But I am a less experienced QL writer 🙂
Btw, getLocation()
does define a default in QL with UknownLocation
, so I wasn't aware defaults are frowned upon.
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.
getLocation()
is special because it interacts with non-QL things (like the VSCode extension)
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.
Maybe we should make getExtractorVersion private within ExtractorVersion.qll and only expose such predicates with descriptive names from it?
Note that the file is marked as internal, so as a QL query writer you shouldn't even come near it.
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've updated the PR with a somewhat more declarative predicate name. Do I need to re-run DCA for this?
59be4e2
to
5b4c275
Compare
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.
LGTM!
No description provided.