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

Some kind of cycle is causing a build failure #924

Closed
alecthomas opened this issue Feb 12, 2024 · 1 comment · Fixed by #927
Closed

Some kind of cycle is causing a build failure #924

alecthomas opened this issue Feb 12, 2024 · 1 comment · Fixed by #927
Assignees
Labels
P0 Work on this now triage Issue needs triaging

Comments

@alecthomas
Copy link
Collaborator

It's strange, because there are no cycles in the FTL data type system itself, only in "calls" which should not impact the Go compiler, but still somehow the Go build will get into a loop like this:

backend | info: Building go module 'foo'
backend | error: Error deploying module /Users/alec/dev/project/backend/modules/foo. Will retry: failed to build module: failed to extract module schema: ftl/foo: /Users/alec/dev/project/backend/modules/foo/foo.go:14:2: could not import ftl/bar (invalid package name: "")
backend | info: Building go module 'bar'
backend | error: Error deploying module /Users/alec/dev/project/backend/modules/bar. Will retry: failed to build module: failed to extract module schema: ftl/bar: /Users/alec/dev/project/backend/modules/bar/bar.go:19:2: could not import ftl/foo (invalid package name: "")

Even stranger is that if we comment out the verbs that trigger it, let everything rebuild, then uncomment them, things seem to work in a flaky kind of way.

@alecthomas alecthomas added the P0 Work on this now label Feb 12, 2024
@github-actions github-actions bot added the triage Issue needs triaging label Feb 12, 2024
@alecthomas alecthomas self-assigned this Feb 12, 2024
@github-actions github-actions bot removed the triage Issue needs triaging label Feb 12, 2024
@alecthomas
Copy link
Collaborator Author

I don't think there's a solution that FTL can provide in the near term. What's happening is actually quite obvious in hindsight, but the errors were really obtuse:

  1. FTL tries to build foo. It fails because it needs to import bar .
  2. FTL tries to build bar. It fails because it needs to import foo.
  3. Repeat.

This cycle is triggered by the ftl.Call()s. In theory we could make the schema extractor fault tolerant to any unresolved imports that aren't part of the module's verb or data type signatures. The Go type analyser is actually fault tolerant and replaces unresolved types with ast.SelectorExpr which has sufficient information for us to resolve to a reference, such that FTL could still extract the types.

That said, this would really only be a bandaid in certain circumstances I think. If you had data types or verbs in different modules that referenced each other in a cycle, this would still break.

I think the real issue here is that the reported errors are useless. We should fix those.

@alecthomas alecthomas closed this as not planned Won't fix, can't repro, duplicate, stale Feb 12, 2024
@alecthomas alecthomas reopened this Feb 12, 2024
@github-actions github-actions bot added the triage Issue needs triaging label Feb 12, 2024
alecthomas added a commit that referenced this issue Feb 12, 2024
Previously:

```
failed to build module: failed to extract module schema: ftl/foo:
/Users/alec/dev/example/backend/modules/foo/foo.go:14:2: could not import
ftl/bar (invalid package name: "")
```

Now:

```
failed to build module: failed to extract module schema:
/Users/alec/dev/example/backend/modules/foo/foo.go:2:1:
/Users/alec/dev/example/backend/modules/foo/foo.go:88:1:
/Users/alec/dev/example/backend/modules/foo/foo.go:88:138:
/Users/alec/dev/example/backend/modules/foo/foo.go:106:2:
/Users/alec/dev/example/backend/modules/foo/foo.go:106:23: call first
argument must be a function but is an unresolved reference to
bar.BarRequest
```

Fixes #924

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P0 Work on this now triage Issue needs triaging
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant