Skip to content

Use sources instead of parsed package #1362

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

Merged

Conversation

grantnelson-wf
Copy link
Collaborator

@grantnelson-wf grantnelson-wf commented Feb 20, 2025

When splitting up the compiler I noticed that there is an internal structure for storing parsed files called sources. sources is very similar to the structure I added ParsedPackage used to split the parse and compile phases apart. I joined these two into one shared Sources structure to save some moving of information around and complexity.

These changes should not affect functionality. It is a refactor to simplify and organize how data prior to the Archives is stored.

After this change: Build will load all the packages needed for a project into Sources. The root Sources is passed into Compile where the Sources will be sorted, type checked, etc before being compiled into JS.

In following tickets the Sources sorting, type checking, and the creation of the rootCtx will be moved out of Compile so that they can be performed on all Sources at the same time, thus allowing generic information to be passed across package boundaries.

This is related to #1013 and #1270

Changes

  • Moved errorList into its own package (errorList.ErrorList) so that it can be used by more packages by itself.
  • Moved JSFile into its own package (jsFile.JSFile).
    • moved the JSFilesFromDir method from build/context.go into the jsFile package since it relates to JSFile.
  • Moved sources into its own package (sources.Sources) so that it can be used by both the build and compiler packages.
    • split the packageImporter used by Sources into two parts to reduce dependencies:
      • The first became packageImporter that uses errorList to collect any errors that occurred.
      • The second part got added to ImportContext as Import since the cached packages and archives were already on ImportContext.
    • Since ImportContext already had an Import method, I renamed it to ImportArchive so that Import on ImportContext implements go/types.Importer but allows us to still import an archive.
  • Moved GoLinkname into its own package (linkname.GoLinkname) so that the sources package can use it.
    • exposed GoLinknameSet and ParseGoLinknames so that they can be used by compiler.
    • moved errorAt into linkname since it was only being used by GoLinkname at this moment.
  • Replaced ParsedPackage with Sources since Sources already existed with nearly everything in ParsedPackage.
    • per request in prior ticket (Separate Parsing and Compiling #1361) I renamed the Imports method to UnresolvedImports when moving that method to Sources.
    • added the Dir string and JSFiles []jsFile.JSFile fields that were missing from Sources but needed by ParsedPackage.
    • added some comments to indicate the state of the Sources, e.g. "at this point the sources haven't been sorted".
  • I update compiler/package.go#Compile to take the root Sources instead of parts from a ParsedPackage and remove the original creation of the Sources that was done first thing in Compile (after some error handling stuff).

@grantnelson-wf grantnelson-wf force-pushed the sourceInsteadOfParsedPackage branch from 7ae4567 to 5740abf Compare February 26, 2025 17:45
@grantnelson-wf grantnelson-wf self-assigned this Feb 26, 2025
@grantnelson-wf grantnelson-wf changed the title [WIP] Use sources instead of parsed package Use sources instead of parsed package Feb 26, 2025
@grantnelson-wf grantnelson-wf marked this pull request as ready for review February 26, 2025 18:12
@grantnelson-wf grantnelson-wf force-pushed the sourceInsteadOfParsedPackage branch from 074e48b to 6c48e04 Compare February 27, 2025 22:45
@grantnelson-wf grantnelson-wf merged commit bd9aac3 into gopherjs:master Mar 4, 2025
10 checks passed
@grantnelson-wf grantnelson-wf deleted the sourceInsteadOfParsedPackage branch March 4, 2025 18:16
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.

2 participants