[generics] Grouping by declaration kinds and adding $finishSetup #1380
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.
When the JS packages are being setup, type instances could require type information from packages which have not been setup yet. For example,
list.List[Cat]could be defined inside thecatpackage and import thelistpackage. The type instanceList[cat.Cat]is initialized inside thelistpackage. This will cause a failure becausecat.Cathasn't been setup yet since it requireslistto be setup first as an import. We can't moveList[Cat]to the cat package becauseList[T]may access unexposed data inside thelistpackage.This PR breaks up the
DeclCodebased on kind of code being added. I probably broke upDeclCodemore than needed to, but I figured if I was going to pick out some of the kinds, might as well split them out more so we have more simple groups instead of fewer less obvious groups (I didn't break up theInitCode).Then this writes the named types, type exports, and other kinds that other packages may depend on first. It puts the anonymous types along with some other declarations that may need all the packages to handle generics into the
$finishSetupfunction. The$finishSetupfunction is called on all the packages once all the packages have been added but before$initis called.This change should allow all the types that need types from inverted dependencies caused by instances of generic to have a reference to the non-nil type so it can finish setting up the types. The named types and type exports are needed first so that those can be used by anonymous types (pointers, slices, maps, etc). The anonymous types are added in
$finishSetupsince they calliniton themselves which requires the non-nil type references. Since methods and functions may need type information for parameters and returns including anonymous types, those are put after the anonymous types. Linking is also put in$finishSetupso that links can be made to the functions and methods added at that time. (If we wanted to add linking to vars/const, it appears we could by breaking thevardeclarations from theInitCodeand putting them before linking, but I didn't try that yet so I'm not sure if that'd work or not.)This is related to #1013 and #1270
golangci-lintissues on master. I'm not sure why those didn't show up in the PR but did on master. I'm guessing it's because of PR read permissions in ci.yaml, so I added that.TODO(grantnelson-wf)and a skip.