Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Apply map_kind to existing rules as well as new ones #1425
Apply map_kind to existing rules as well as new ones #1425
Changes from all commits
594e394
0b1f447
8dee9e5
49697e5
94ee030
8241316
c8c2e77
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Question: does the append ordering matter here?
I.e. if in
foo/BUILD
I were to mapa -> b
and infoo/bar/BUILD
I were to mapb -> c
, what would be generated infoo/bar/tee/BUILD
?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's an interesting question! I think ordering of rules doesn't matter here, but there is an interesting edge-case nonetheless:
For each rule, we look up in a pre-generated config for the
map_kind
directive, which was generated in the ordinary way for config. So the config object forfoo/bar/tee/BUILD
will contain:a -> b
andb -> c
but doesn't resolve a transitivea -> c
. Given this is a static pre-generated config, and the mappings aren't affected by the order the rules are consulted, I don't think there's an ordering problem here.This means for things we generate, if we generate an
a
we'll end up with ab
, and if we generate ab
we'll end up with ac
.For things which already existed, if there was an
a
we'll end up with ab
, and if there was ab
we'll end up with ac
. Which means that if you have ana
, and run gazelle twice, you'll end up with different results after each generation.I think if we wanted to fix this, we'd probably add a loop around the
if repl, ok := c.KindMap[r.Kind()]; ok {
to keep mapping until we reach an unmapped rule, or until we detect a loop.I've pushed 0c06eb2 which does this transitive mapping, and which errors if a loop was encountered. I can imagine situations where people may have loops in their
map_kind
directives today, so this may be a breaking change to some.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.
To simplify the interface, you can return the replacement kind here, because the caller of this function can get the result of info from
config.MappedKind
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 not sure on this one - having a fully typed
*config.MappedKind
as a return value feels better documenting as to what the function is doing, and the caller is going to look up the output inc.KindMap
again anyway, so it feels like returning a*config.MappedKind
avoids potential errors such as a different KindMap being passed to the function and being used by the caller?