Skip to content

Commit

Permalink
fix: inlining can break module detection
Browse files Browse the repository at this point in the history
It seems that in some curcumstances inlining can break module detection,
resulting in incorrect 'must be called from an FTL module' errors.
  • Loading branch information
stuartwdouglas committed Aug 2, 2024
1 parent a5bb4b9 commit 13748d2
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions go-runtime/ftl/reflection/reflection.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,25 @@ func CallingVerb() schema.RefKey {
// Look through the stack for the outermost FTL module.
pcs := make([]uintptr, 1024)
pcs = pcs[:runtime.Callers(1, pcs)]
frames := runtime.CallersFrames(pcs)

var module string
var verb string
for _, pc := range pcs {
splitName := strings.Split(runtime.FuncForPC(pc).Name(), ".")
for {
frame, more := frames.Next()
if frame.Func.Name() == "" {
continue
}
splitName := strings.Split(frame.Func.Name(), ".")
pkg := splitName[0]
fnName := splitName[1]
if strings.HasPrefix(pkg, "ftl/") {
module = strings.Split(pkg, "/")[1]
verb = fnName
}
if !more {
break
}
}
if module == "" {
debug.PrintStack()
Expand Down

0 comments on commit 13748d2

Please sign in to comment.