Skip to content
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

feat: finish migrating schema extraction!!!! #2171

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (

"ftl/builtin"

lib "github.com/TBD54566975/ftl/go-runtime/compile/testdata"
"github.com/TBD54566975/ftl/go-runtime/ftl" // Import the FTL SDK.
lib "github.com/TBD54566975/ftl/go-runtime/schema/testdata"
)

type GetRequest struct {
Expand Down
81 changes: 4 additions & 77 deletions go-runtime/compile/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func Build(ctx context.Context, projectRootDir, moduleDir string, sch *schema.Sc
}

logger.Debugf("Extracting schema")
result, err := ExtractModuleSchema(config.Dir, sch)
result, err := extract.Extract(config.Dir)
if err != nil {
return err
}
Expand Down Expand Up @@ -717,7 +717,7 @@ func writeSchemaErrors(config moduleconfig.ModuleConfig, errors []*schema.Error)
return os.WriteFile(config.Abs().Errors, elBytes, 0600)
}

func getLocalSumTypes(module *schema.Module, nativeNames NativeNames) []goSumType {
func getLocalSumTypes(module *schema.Module, nativeNames extract.NativeNames) []goSumType {
sumTypes := make(map[string]goSumType)
for _, d := range module.Decls {
e, ok := d.(*schema.Enum)
Expand Down Expand Up @@ -772,7 +772,7 @@ func getLocalExternalTypes(module *schema.Module) ([]goExternalType, error) {

// getRegisteredTypesExternalToModule returns all sum types and external types that are not defined in the given module.
// These are the types that must be registered in the main module.
func getRegisteredTypes(module *schema.Module, sch *schema.Schema, nativeNames NativeNames) ([]goSumType, []goExternalType, error) {
func getRegisteredTypes(module *schema.Module, sch *schema.Schema, nativeNames extract.NativeNames) ([]goSumType, []goExternalType, error) {
sumTypes := make(map[string]goSumType)
externalTypes := make(map[string]sets.Set[string])
// register sum types from other modules
Expand Down Expand Up @@ -838,7 +838,7 @@ func getRegisteredTypes(module *schema.Module, sch *schema.Schema, nativeNames N
return stOut, etOut, nil
}

func getGoSumType(enum *schema.Enum, nativeNames NativeNames) optional.Option[goSumType] {
func getGoSumType(enum *schema.Enum, nativeNames extract.NativeNames) optional.Option[goSumType] {
if enum.IsValueEnum() {
return optional.None[goSumType]()
}
Expand Down Expand Up @@ -936,79 +936,6 @@ func getRegisteredTypesExternalToModule(module *schema.Module, sch *schema.Schem
return externalTypes
}

// ExtractModuleSchema statically parses Go FTL module source into a schema.Module
//
// TODO: once migrated off of the legacy extractor, we can inline `extract.Extract(dir)` and delete this
// function
func ExtractModuleSchema(dir string, sch *schema.Schema) (extract.Result, error) {
result, err := extract.Extract(dir)
if err != nil {
return extract.Result{}, err
}

// merge with legacy results for now
if err = legacyExtractModuleSchema(dir, sch, &result); err != nil {
return extract.Result{}, err
}

schema.SortErrorsByPosition(result.Errors)
if schema.ContainsTerminalError(result.Errors) {
return result, nil
}
err = schema.ValidateModule(result.Module)
if err != nil {
return extract.Result{}, err
}
updateVisibility(result.Module)
return result, nil
}

// TODO: delete all of this once it's handled by the finalizer
func updateVisibility(module *schema.Module) {
for _, d := range module.Decls {
if d.IsExported() {
updateTransitiveVisibility(d, module)
}
}
}

// TODO: delete
func updateTransitiveVisibility(d schema.Decl, module *schema.Module) {
if !d.IsExported() {
return
}

_ = schema.Visit(d, func(n schema.Node, next func() error) error { //nolint:errcheck
ref, ok := n.(*schema.Ref)
if !ok {
return next()
}

resolved := module.Resolve(*ref)
if resolved == nil || resolved.Symbol == nil {
return next()
}

if decl, ok := resolved.Symbol.(schema.Decl); ok {
switch t := decl.(type) {
case *schema.Data:
t.Export = true
case *schema.Enum:
t.Export = true
case *schema.TypeAlias:
t.Export = true
case *schema.Topic:
t.Export = true
case *schema.Verb:
t.Export = true
case *schema.Database, *schema.Config, *schema.FSM, *schema.Secret, *schema.Subscription:
}
updateTransitiveVisibility(decl, module)
}
return next()
})
}

func goVerbFromQualifiedName(qualifiedName string) (goVerb, error) {
lastDotIndex := strings.LastIndex(qualifiedName, ".")
if lastDotIndex == -1 {
Expand Down
Loading
Loading