Adding Type Initialization Grouping and Ordering #1378
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 thecat
package and import thelist
package. The type instanceList[cat.Cat]
is initialized inside thelist
package. This will cause a failure becausecat.Cat
hasn't been setup yet since it requireslist
to be setup first as an import. We can't moveList[Cat]
to the cat package becauseList[T]
may access unexposed data inside thelist
package.This is the first part of two (or more) tickets. To solve the type initialization, each declaration will be given a group number. There will be$n$ groups and each group number is $g_i$ where $i \in [0 .. n)$ . For any group, $g_i$ , the prior groups, $\{g_0 ... g_{i-1}\}$ , will have to be initialized first. All the declarations with the same group number are part of the same group. However within that group, the declarations will still need to be initialized in the current ordering where imports are done before importers and types are initialized before they are used in pointers, slices, etc.
This PR determines the grouping and order of the groups, then sets the group number for each
Decl
. This PR mainly consists of two new packages:sequencer
andgrouper
. Thesequencer
is a generalized tool for determining ordering and grouping of items depending on the items' dependencies. Thegrouper
stores information about the declarations' types so that it can use thesequencer
to group and order the declarations based on type.Following ticket(s) will use that group number to populate a "startup map" where the key is the group number and the value is a set of functions that need to be run. Each function will initialize all the
Decl
s for a particular group for a single package. Then once all the packages have been added, the runtime will call each group of functions in order. The details still need to be ironed out.