-
Notifications
You must be signed in to change notification settings - Fork 9
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
chore: refactor go schema extraction #1700
Conversation
@@ -1,5 +1,8 @@ | |||
package compile | |||
|
|||
// TODO: This file is now duplicated in go-runtime/schema/analyzers/parser.go. It should be removed | |||
// from here once the schema extraction refactoring is complete. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just duplicated this file to avoid having to export everything from it's new location (so the legacy extractor can continue using it) only to make it all private again once the refactor is complete
@@ -106,44 +107,34 @@ type ParseResult struct { | |||
Errors []*schema.Error | |||
} | |||
|
|||
// ExtractModuleSchema statically parses Go FTL module source into a schema.Module. | |||
func ExtractModuleSchema(dir string, sch *schema.Schema) (optional.Option[ParseResult], error) { | |||
func legacyExtractModuleSchema(dir string, sch *schema.Schema, out *analyzers.ExtractResult) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got a bit hairy attempting to run the legacy extractor as a completely isolated process since things are so entangled
instead modified the legacy code to accept an output pointer as param (out *analyzers.ExtractResult
). the initial caller provides the partial result from the prior extraction step, which gives the legacy extractor access to details (native names and decls) that it needs. the output/result is updated in-place during the legacy extraction
4546309
to
751069c
Compare
so many |
0f2c7ec
to
7850af9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is amazing Lizzy. This will be so much cleaner.
A couple of thoughts/questions/comments:
This is not an immediate concern, but if we could switch to using the analysis package's Diagnostic system, we'd get cleaner integration with the package.
Typically with the analysis package each pass will produce a distinct type that other analysers can require, and they will then be run in the correct order, and values passed through. It seems we could utilise this system rather than having a single extractorContext
passed through and mutated, and I think (though am not sure) that we would benefit from parallelisation then. For example, the TypeAliasExtractor
could output a []*schema.TypeAlias
.
Another one for later, but I think we could also utilise the facts system. My first thought along those lines is that a first pass could add a schema.Ref
fact to every node that is a reference to an FTL type or value. This would allow latter passes to just retrieve these facts directly from the node, rather than having to recompute them.
But yeah, overall, absolutely awesome.
go-runtime/compile/build.go
Outdated
if err != nil { | ||
return optional.None[analyzers.ExtractResult](), err | ||
} | ||
result, ok := maybeResult.Get() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we just return an error from extract.Extract()
in this case, so we can make these results not be optional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think i got a bit optional-happy 😅
ah in place of shoving the schema errors into the result? will check it out!
currently the extractors actually do produce their own results (rather than mutate a single result), they just share the same type (
i initially had the same thought, actually, to return []*schema.TypeAlias directly. i moved to the current approach to handle transitive visibility, e.g.: pass A: basically everyone producing a partial view of the world; then these get merged and the highest visibility Decl wins out in the case of conflicts. now in thinking about it more, this does feel cleaner as a separate calculation in finalizer that looks at the complete schema and uses refs to update visibility as needed. will take a look at updating tomorrow
amazing idea!! |
a51bf8c
to
6ecedcd
Compare
@alecthomas this has been updated with the following:
|
initial step towards #1518 - integrates with (forked) go/analysis to run static analysis tasks for schema extraction - implements first extraction task, type aliases - refactors existing build stack to use the new extractor, combining results with legacy so we can incrementally migrate - removes typealias extraction logic from legacy code
6ecedcd
to
cb33912
Compare
initial step towards #1518