Skip to content

infinite recursion trying to create recursive function type #2172

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

Closed
dgryski opened this issue Oct 13, 2021 · 6 comments
Closed

infinite recursion trying to create recursive function type #2172

dgryski opened this issue Oct 13, 2021 · 6 comments
Labels
bug Something isn't working core

Comments

@dgryski
Copy link
Member

dgryski commented Oct 13, 2021

Tinygo does not like fnType in the below program:

package main

type fnType func(int) (fnType, error)

func printNode(int) (fnType, error) {
        return nil, nil
}

func main() {
}

tinygo errors with a stack overflow; the callstack is filled with

	/Users/dgryski/go/src/github.com/tinygo-org/tinygo/compiler/func.go:99 +0x8c fp=0xc020d40560 sp=0xc020d40520 pc=0x429c7ec
github.com/tinygo-org/tinygo/compiler.(*compilerContext).makeLLVMType(0xc0005b0000, {0x4413240, 0xc000ca67e0})
	/Users/dgryski/go/src/github.com/tinygo-org/tinygo/compiler/compiler.go:388 +0x2b4 fp=0xc020d40628 sp=0xc020d40560 pc=0x4284cd4
github.com/tinygo-org/tinygo/compiler.(*compilerContext).getLLVMType(0xc0005b0000, {0x4413240, 0xc000ca67e0})
	/Users/dgryski/go/src/github.com/tinygo-org/tinygo/compiler/compiler.go:321 +0x6e fp=0xc020d40668 sp=0xc020d40628 pc=0x428498e
github.com/tinygo-org/tinygo/compiler.(*compilerContext).makeLLVMType(0xc0005b0000, {0x44131f0, 0xc000128e80})
	/Users/dgryski/go/src/github.com/tinygo-org/tinygo/compiler/compiler.go:383 +0x771 fp=0xc020d40730 sp=0xc020d40668 pc=0x4285191
github.com/tinygo-org/tinygo/compiler.(*compilerContext).getLLVMType(0xc0005b0000, {0x44131f0, 0xc000128e80})
	/Users/dgryski/go/src/github.com/tinygo-org/tinygo/compiler/compiler.go:321 +0x6e fp=0xc020d40770 sp=0xc020d40730 pc=0x428498e
github.com/tinygo-org/tinygo/compiler.(*compilerContext).getRawFuncType(0xc0005b0000, 0xc000ca67e0)
	/Users/dgryski/go/src/github.com/tinygo-org/tinygo/compiler/func.go:125 +0x4cf fp=0xc020d40828 sp=0xc020d40770 pc=0x429cd4f
github.com/tinygo-org/tinygo/compiler.(*compilerContext).getFuncType(0xc0005b0000, 0x0)
@dgryski
Copy link
Member Author

dgryski commented Oct 13, 2021

Interesting; this doesn't fail on dev, only on my local branch consisting of dev + #2011 + #2171

Bisecting shows c722426 as the first bad commit.

@dgryski
Copy link
Member Author

dgryski commented Oct 13, 2021

This triggers on dev when building for native. The coroutine-logic prevents it from hitting wasm on dev, but does cause it to trigger for asyncify.

@aykevl
Copy link
Member

aykevl commented Oct 13, 2021

Yeah, I've been aware of this bug for a long time but somehow nobody triggered it, so I was hoping it would never happen.

The issue here is that the function pointer type here is recursive: it has a parameter with a pointer to itself. But you probably figured that out already. Unfortunately, I'm not aware of any way to construct such a type in LLVM: the only type that allows such recursion are structs.

@aykevl
Copy link
Member

aykevl commented Oct 13, 2021

This doesn't normally happen on WebAssembly because function pointers are implemented differently there. Check FuncImplementation. Picking the other one might be a temporary workaround.

@aykevl
Copy link
Member

aykevl commented Oct 13, 2021

Here is a fix: #2175

@deadprogram deadprogram added bug Something isn't working core next-release Will be part of next release labels Oct 30, 2021
@deadprogram
Copy link
Member

I think the request was fulfilled in the new release, so closing. Please reopen if needed. Thanks!

@deadprogram deadprogram removed the next-release Will be part of next release label Nov 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working core
Projects
None yet
Development

No branches or pull requests

3 participants