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

Implement global registry + code-genned registration in the external_module.go template #1457

Closed
matt2e opened this issue May 9, 2024 · 0 comments · Fixed by #1560
Closed
Assignees
Labels
intermediate A task requiring an intermediate level of knowledge

Comments

@matt2e
Copy link
Contributor

matt2e commented May 9, 2024

We discussed this in the daily sync and there are a couple of limitations with the current approach:

  1. The type registry is effectively static for the lifetime of a module's execution, but the registry is dynamically constructed and requires a context.Context to use.
  2. Related to 1, this implies that it cannot be used by methods that don't pass a context around, including the stdlib's encoding/json.
  3. Currently the registry is only constructed in the generated main.go, which doesn't exist during tests, and thus the type registry cannot be used with ftltest at all.

A proposed solution is to:

  1. Remove the existing context-scoped code and code-generation.
  2. Modify the type registry to be globally scoped.
  3. Extend the external_module.go template to register its types in an init() function.

eg.

func init() {
  typeregistry.Register(
    typeregistry.SumType[MySumType](*new(Variant1), *new(Variant2)),
  )
}

This will automatically register the module's types whenever it is imported.

@github-actions github-actions bot added the triage Issue needs triaging label May 9, 2024
@alecthomas alecthomas mentioned this issue May 9, 2024
@alecthomas alecthomas added intermediate A task requiring an intermediate level of knowledge next Work that will be be picked up next and removed triage Issue needs triaging labels May 17, 2024
@github-actions github-actions bot removed the next Work that will be be picked up next label May 17, 2024
@alecthomas alecthomas changed the title Discuss if global type registry in go-runtime is a good idea Implement global registry + code-genned registration in the external_module.go template May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
intermediate A task requiring an intermediate level of knowledge
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants