Skip to content

toposort: stack overflow panic in vertexFeatures.addEdges #3710

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
mvdan opened this issue Jan 29, 2025 · 2 comments
Closed

toposort: stack overflow panic in vertexFeatures.addEdges #3710

mvdan opened this issue Jan 29, 2025 · 2 comments
Assignees
Labels

Comments

@mvdan
Copy link
Member

mvdan commented Jan 29, 2025

# Without toposort.
env CUE_EXPERIMENT=evalv3=0,toposort=0
exec cue export input.cue

# With toposort.
env CUE_EXPERIMENT=evalv3=0,toposort=1
exec cue export input.cue

-- input.cue --
package p

#Exporter: {
	_objects: {...}
	_imports: [...]

	objects: [
		for _, objs in _objects {
			objs
		}
		for import in _imports for obj in import._export.objects {
			obj
		}
	]
}

out: #Exporter & {
	_imports: [_app1]
}
_app1: {
	_export: #Exporter & {
		_imports: [_app2]
	}
}
_app2: {
	_export: #Exporter & {
		_objects: leaf: leafField: "leaf value"
	}
}

As of 870bfc2:

# Without toposort. (0.010s)
> env CUE_EXPERIMENT=evalv3=0,toposort=0
> exec cue export input.cue
[stdout]
{
    "out": {
        "objects": [
            {
                "leafField": "leaf value"
            }
        ]
    }
}
# With toposort. (0.361s)
> env CUE_EXPERIMENT=evalv3=0,toposort=1
> exec cue export input.cue
[stderr]
runtime: goroutine stack exceeds 1000000000-byte limit
runtime: sp=0xc020610328 stack=[0xc020610000, 0xc040610000]
fatal error: stack overflow

runtime stack:
runtime.throw({0x109ea13?, 0x755b36f2cd38?})
	/home/mvdan/tip/src/runtime/panic.go:1096 +0x48 fp=0x755b36f2cd08 sp=0x755b36f2ccd8 pc=0x47a9e8
runtime.newstack()
	/home/mvdan/tip/src/runtime/stack.go:1107 +0x5bb fp=0x755b36f2ce40 sp=0x755b36f2cd08 pc=0x45e2db
runtime.morestack()
	/home/mvdan/tip/src/runtime/asm_amd64.s:621 +0x7a fp=0x755b36f2ce48 sp=0x755b36f2ce40 pc=0x48095a

goroutine 1 gp=0xc000002380 m=8 mp=0xc000580008 [running]:
cuelang.org/go/cue/token.(*File).PositionFor(0xc0002601c0?, {0xc0002601c0?, 0xab3?}, 0x1?)
	/home/mvdan/src/c/cue/cue/token/position.go:465 +0xdf fp=0xc020610338 sp=0xc020610330 pc=0x61537f
cuelang.org/go/cue/token.(*File).Position(...)
	/home/mvdan/src/c/cue/cue/token/position.go:479
cuelang.org/go/cue/token.Pos.Position(...)
	/home/mvdan/src/c/cue/cue/token/position.go:107
cuelang.org/go/cue/token.Pos.Filename({0xc0002601c0?, 0x0?})
	/home/mvdan/src/c/cue/cue/token/position.go:100 +0x45 fp=0xc0206103b8 sp=0xc020610338 pc=0x613e25
cuelang.org/go/internal/core/toposort.(*vertexFeatures).addEdges(0xc04060e718, {0x0, 0x0, 0x0}, 0xc0004455a0)
	/home/mvdan/src/c/cue/internal/core/toposort/vertex.go:454 +0x57 fp=0xc020610508 sp=0xc0206103b8 pc=0x7617f7
cuelang.org/go/internal/core/toposort.(*vertexFeatures).addEdges(0xc04060e718, {0x0, 0x0, 0x0}, 0xc0004455a0)
	/home/mvdan/src/c/cue/internal/core/toposort/vertex.go:515 +0x83f fp=0xc020610658 sp=0xc020610508 pc=0x761fdf
cuelang.org/go/internal/core/toposort.(*vertexFeatures).addEdges(0xc04060e718, {0x0, 0x0, 0x0}, 0xc0004455a0)
	/home/mvdan/src/c/cue/internal/core/toposort/vertex.go:515 +0x83f fp=0xc0206107a8 sp=0xc020610658 pc=0x761fdf
[...]
@mvdan mvdan added the panic label Jan 29, 2025
@mvdan mvdan moved this from Backlog to v0.12.0 in Release v0.12 Jan 29, 2025
@mvdan
Copy link
Member Author

mvdan commented Jan 29, 2025

Note that this only affects the old evaluator. Editing this testscript to always use evalv3=1 makes the panic go away.

@mvdan
Copy link
Member Author

mvdan commented Jan 29, 2025

Thanks to @nxcc for reporting this issue via Unity!

@cuematthew cuematthew self-assigned this Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: v0.12.0
Development

No branches or pull requests

2 participants