Skip to content
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

Merged
merged 2 commits into from
Oct 26, 2023

Conversation

jketema
Copy link
Contributor

@jketema jketema commented Oct 24, 2023

No description provided.

@github-actions github-actions bot added the C++ label Oct 24, 2023
@MathiasVP MathiasVP added the depends on internal PR This PR should only be merged in sync with an internal Semmle PR label Oct 24, 2023
Copy link
Contributor

@MathiasVP MathiasVP left a 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()

@jketema
Copy link
Contributor Author

jketema commented Oct 24, 2023

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) }
Copy link
Contributor

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?

Suggested change
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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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 a isBefore605FrontendUpgrade() predicate so that the exists(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, ...

Copy link
Contributor

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.

Copy link
Contributor

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)

Copy link
Contributor Author

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.

Copy link
Contributor Author

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?

@jketema jketema force-pushed the ir-backwards branch 2 times, most recently from 59be4e2 to 5b4c275 Compare October 25, 2023 18:30
MathiasVP
MathiasVP previously approved these changes Oct 26, 2023
Copy link
Contributor

@MathiasVP MathiasVP left a comment

Choose a reason for hiding this comment

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

LGTM!

@jketema jketema marked this pull request as ready for review October 26, 2023 08:41
@jketema jketema requested a review from a team as a code owner October 26, 2023 08:41
@jketema jketema added the no-change-note-required This PR does not need a change note label Oct 26, 2023
@jketema jketema merged commit dbb4167 into github:main Oct 26, 2023
8 checks passed
@jketema jketema deleted the ir-backwards branch October 26, 2023 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C++ depends on internal PR This PR should only be merged in sync with an internal Semmle PR 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.

3 participants