Use sources instead of parsed package #1362
Merged
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 splitting up the compiler I noticed that there is an internal structure for storing parsed files called
sources.sourcesis very similar to the structure I addedParsedPackageused to split the parse and compile phases apart. I joined these two into one sharedSourcesstructure 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 rootSourcesis passed intoCompilewhere theSourceswill be sorted, type checked, etc before being compiled into JS.In following tickets the
Sourcessorting, type checking, and the creation of therootCtxwill be moved out ofCompileso that they can be performed on allSourcesat the same time, thus allowing generic information to be passed across package boundaries.This is related to #1013 and #1270
Changes
errorListinto its own package (errorList.ErrorList) so that it can be used by more packages by itself.JSFileinto its own package (jsFile.JSFile).JSFilesFromDirmethod from build/context.go into thejsFilepackage since it relates toJSFile.sourcesinto its own package (sources.Sources) so that it can be used by both thebuildandcompilerpackages.packageImporterused bySourcesinto two parts to reduce dependencies:packageImporterthat useserrorListto collect any errors that occurred.ImportContextasImportsince the cached packages and archives were already onImportContext.ImportContextalready had anImportmethod, I renamed it toImportArchiveso thatImportonImportContextimplementsgo/types.Importerbut allows us to still import an archive.GoLinknameinto its own package (linkname.GoLinkname) so that thesourcespackage can use it.GoLinknameSetandParseGoLinknamesso that they can be used bycompiler.errorAtintolinknamesince it was only being used byGoLinknameat this moment.ParsedPackagewithSourcessinceSourcesalready existed with nearly everything inParsedPackage.Importsmethod toUnresolvedImportswhen moving that method toSources.Dir stringandJSFiles []jsFile.JSFilefields that were missing fromSourcesbut needed byParsedPackage.Sources, e.g. "at this point the sources haven't been sorted".compiler/package.go#Compileto take the rootSourcesinstead of parts from aParsedPackageand remove the original creation of theSourcesthat was done first thing inCompile(after some error handling stuff).