-
Notifications
You must be signed in to change notification settings - Fork 381
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
cmd/gazelle: add resolvers for activated languages only #787
cmd/gazelle: add resolvers for activated languages only #787
Conversation
Looks good. Could you update this to the latest master? It looks like |
365632a
to
993ee32
Compare
Whoops, thanks. (I used an earlier release to avoid having to download the newer bazel required by rules_go.) |
993ee32
to
5b77c67
Compare
Apologies, I must have not run the tests. TestConfigLang fails with a NPE. Investigating. |
Oh, this change falls afoul of subsequent directives overriding the default lang restriction to be unrestricted. For example, I can think of a couple ways forward:
Thoughts on those:
What do you think? |
Ah, this is more complicated than I thought it was at first. I wonder if there's another way to address the performance problem you were seeing? What exactly is taking a lot of time? Before this PR, if a language is disabled, we'd be indexing library rules for that language, but we shouldn't be generating any rules for it. And we should only be resolving dependencies for generated rules. I think disabling indexing wouldn't be too difficult, but I wouldn't expect indexing to be too expensive. |
Yeah, good call. I looked into it a bit more, and the underlying reason is that the closure_js implementation of Imports() reads the file to get the list of identifiers provided (which may be imported by other files). That is time consuming. If I update the closure_js rules to have a |
Would you rather add a That might make sense semantically, too: if a language is disabled for a large tree in a repository and that tree contains library rules for that language, it might be surprising if those libraries are indexed and dependencies are resolved to them. |
I think doing both makes sense.
|
Ok let's try skipping the indexing then. One thing to point out: you can update specific directories in a repository by passing positional arguments on the command line. The |
Sounds good -- did you want the filter to work like one of the mechanisms described above ("minimal" or "strict" filter), or something else? I have never tried disabling the -index flag.. I'll give that a shot, but we do have some non-standard rules so I'm not expecting that to work in general. Right now one Gazelle rule covers our whole Go monorepo, rather than app by app. |
I think the "minimal" behavior is better. It's a little more complicated, but not unmanageably so. It seems like we'd need to initialize the index and the meta-resolver using all the languages (regardless of flag or directive), then use the current set of languages to filter calls to (I may be missing something of course; context-switching a lot this morning) |
Apologies for the long hiatus. Looking at this again, I wanted to confirm the functionality you would like. The existing PR implements the "minimal" filter behavior of having a language filter specified on the command line always activated, although additional filters may be set and overridden as directives. It implements that by omitting the resolvers for deactivated languages, which causes rules of that language to be ignored. I think the only change needed for that PR to meet the functional requirement is to update the tests and docs to reflect that behavior. In your comment where you say it should instead do the filtering in (*RuleIndex).AddRule, it would keep all of the resolvers and do the filtering at that later stage per rule, but it would keep the same behavior. Just wanted to confirm that you indeed wanted the "minimal" filter behavior -- asking because the updated implementation you describe seems like would enable the implementation of a flexible filter where directives and flags are treated equivalently and it would be possible to unset the -lang filter using a directive. I would be happy to implement that if so, just want to be sure that I'm doing the right thing. Thanks for the consideration! |
Ah, paging this back in after a while. I don't think we're referring to the same thing as minimal. It looks like the problem with the current implementation is that there's no way to turn a language back on in a subdirectory if it was disabled in the root directory. If there's a directive to change the set of active languages, I think it should be able to do that. So I think the metaresolver should be configured with all available languages, and we should just after calls to |
I didn't think of this before, but this approach changes the meaning of the filter. It's fine for my use case, but I wanted to be sure that the change was clear. The original problem that the language filter solved for us was being able to run Gazelle on our Go sub-tree without generating rules for our JS files. So the original meaning of the -lang filter applied to rule generation. The proposed change would expand the meaning to also not index languages. If someone is using directives to control Gazelle's rule generation in different sub-trees, then potentially they would still want Gazelle to index a language's rules in a sub-tree even if it's not generating them there. I'm not sure if that's an important factor, or whether that would be desirable or undesirable. My use case only uses the -lang flag and invokes Gazelle separately for JS vs Go, so this case doesn't come up. Still SGTY? |
5b77c67
to
6e0b9a8
Compare
I think this makes sense. In this case, the The code looks good, but I'd like to request two additional changes:
|
If a language is disabled via the `-lang` flag or `# gazelle:lang` directive, skip indexing it.
6e0b9a8
to
5ca1df2
Compare
SGTM, updated. Any idea if someone is working on a Java extension? That seems doable-ish and pretty valuable. |
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.
Looks good. Thanks for fixing this!
Not AFAIK. Agreed that it would be useful and relatively doable. The challenge would be dealing with packages with cyclic imports (not allowed by Bazel) and of course, external repos (you might want a There's some discussion on the future home of language extensions in #857 if you're interested. Needs more thought. |
This disables processing of rules for languages which are disabled via the -lang
flag. Concretely, this halves the time it takes for Gazelle to update our Go
rules by skipping processing of all closure_js rules.
That's partially because processing JS is sort of slow, but I think the basic idea here is sound.
Updates #687