Skip to content

[generics] Grouping by declaration kinds and adding $finishSetup #1380

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

grantnelson-wf
Copy link
Collaborator

@grantnelson-wf grantnelson-wf commented Jul 24, 2025

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 the cat package and import the list package. The type instance List[cat.Cat] is initialized inside the list package. This will cause a failure because cat.Cat hasn't been setup yet since it requires list to be setup first as an import. We can't move List[Cat] to the cat package because List[T] may access unexposed data inside the list package.

This PR breaks up the DeclCode based on kind of code being added. I probably broke up DeclCode more 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 the InitCode).

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 $finishSetup function. The $finishSetup function is called on all the packages once all the packages have been added but before $init is 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 $finishSetup since they call init on 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 $finishSetup so 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 the var declarations from the InitCode and 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


⚠️ A few unrelated things in this PR

  • I updated a few files to fix the golangci-lint issues 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.
  • I also found an issue in the instance collector. To keep from making this PR larger, I'm going to fix that problem in the next PR. I left the test that hits the issue with a TODO(grantnelson-wf) and a skip.

@grantnelson-wf grantnelson-wf changed the title [WIP] Grouping by declaration kinds and adding $finishSetup Grouping by declaration kinds and adding $finishSetup Jul 25, 2025
@grantnelson-wf grantnelson-wf marked this pull request as ready for review July 25, 2025 21:08
@grantnelson-wf grantnelson-wf changed the title Grouping by declaration kinds and adding $finishSetup [generics] Grouping by declaration kinds and adding $finishSetup Jul 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant