Skip to content

Use the value not the label for the print ast node#666

Merged
aeisenberg merged 1 commit into
github:mainfrom
aeisenberg:aeisenberg/printast-value
Nov 13, 2020
Merged

Use the value not the label for the print ast node#666
aeisenberg merged 1 commit into
github:mainfrom
aeisenberg:aeisenberg/printast-value

Conversation

@aeisenberg
Copy link
Copy Markdown
Contributor

Fixes #659

Checklist

  • [n/a] CHANGELOG.md has been updated to incorporate all user visible changes made by this pull request.
  • Issues have been created for any UI or other user-facing changes made by this pull request.
  • [n/a] @github/docs-content-dsp has been cc'd in all issues for UI or other user-facing changes made by this pull request.

@aeisenberg aeisenberg added the Complexity: Low A good task for newcomers to learn, or experienced team members to complete quickly. label Nov 3, 2020
Copy link
Copy Markdown
Contributor

@adityasharad adityasharad left a comment

Choose a reason for hiding this comment

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

Generally looks good, some questions about fallback behaviour and testing.

const item = {
id,
label: entity.label,
label: value,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What happens if we have an AST query that doesn't set semmle.label on its nodes? For example

query predicate nodes(Node node) { ... }

In that case I would expect value here to be falsy, and I suggest we fall back to entity.label in that default case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sounds reasonable.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

To clarify: I think we should handle that in the default: case too, in case semmle.label is not set at all.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think that's the behaviour we want. Right now, I don't know what the other kind of labels there are, but we don't want them to overwrite whatever is in the semmle.label. And more importantly, we don't even know what would be in the value field and if it makes any sense to display.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we can assume all AST queries follow this pattern:

query predicate nodes(Node node, string key, string value) {
  key = "semmle.label" and ...
}

then the nodes table will have tuples with semmle.label set, and this PR is good to go.

I am trying to be cautious about the possibility that no such label is set, which will happen if you write:

query predicate nodes(Node node) { ... }

In that case I think we'd have to create an item under the default: case of the switch in this code, which uses entity.label. Perhaps that's not something we need to handle in this PR if we know it won't arise from any of the implementations.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If an entity does not have a semmle.label tupleType, then I think this is a bug. As far as I know existing languages all borrow from the cpp implementation which always creates a semmle.label for each node. This is not mentioned in the specs and maybe we should clarify.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@aeisenberg aeisenberg force-pushed the aeisenberg/printast-value branch from 71a7642 to e7ad3e4 Compare November 9, 2020 19:59
@aeisenberg aeisenberg force-pushed the aeisenberg/printast-value branch from e7ad3e4 to 3b39e6e Compare November 9, 2020 22:44
Copy link
Copy Markdown
Contributor

@adityasharad adityasharad left a comment

Choose a reason for hiding this comment

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

I'm convinced! Ship it.

@aeisenberg aeisenberg merged commit 4f76e9d into github:main Nov 13, 2020
@aeisenberg aeisenberg deleted the aeisenberg/printast-value branch November 13, 2020 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complexity: Low A good task for newcomers to learn, or experienced team members to complete quickly.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AST viewer uses node.toString for labels and ignores value

2 participants