cue-lang / cue

The home of the CUE language! Validate and define text-based and dynamic configuration
https://cuelang.org
Apache License 2.0
5.02k stars 287 forks source link

Imported cue.mod/gen package with circular import reference causes infinite loop #1261

Open jabinb opened 3 years ago

jabinb commented 3 years ago

What version of CUE are you using (cue version)?

$ cue version
cue version v0.4.0 linux/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

Created a generated cue module into cue.mod/gen and then imported it from an entrypoint on the root.

-- cue.mod/gen/zhmodern.com/Server/Mobiles/Mobiles.cue --

package Mobiles
import (
    "zhmodern.com/Server"
)
-- cue.mod/gen/zhmodern.com/Server/Server.cue --

package Server
import (
    "zhmodern.com/Server/Mobiles"
)

#TextDefinition: false | null
-- cue.mod/gen/zhmodern.com/cue.mod/module.cue --
module: "zhmodern.com"
-- cue.mod/module.cue --
module: "example.com"
-- entry.cue --
import (
    Server "zhmodern.com/Server"
)

Test: Server.#TextDefinition
Test: "None"
$ cue eval entry.cue

What did you expect to see?

Any output at all, or some kind of error indicating what's happening. Verbose/trace flags seem to produce no output either.

What did you see instead?

The cue cli uses up 7% of my 16 core system and continually grows in memory footprint. After a few minutes it reaches 1gb of RAM usage without finishing, and presumably would consume all resources if I left it running.

In the tartxt example it takes a lot longer to build up in RAM footprint, in my real project environment with a lot more packages in cue.mod/gen it consumes RAM at a much faster rate. This suggests to me it might be stuck in some kind of import loop, however I can't see any disk activity to support that.

verdverm commented 3 years ago

Do you have some example Go code that this minimal example is generated from?

Curious what the cyclic import is being generated from. I tried to set up something and can't get it to generate, rather erroring with a cycle error on cue get go. It is also odd that there are imports without usage in the generated files, which would trigger error on their own. Those generated filenames don't match how cue generates filenames as well.

jabinb commented 3 years ago

Oh sorry, I should have been more explicit; I'm generating those files myself with an internal tool and placing them into cue.mod/gen.

Am I misusing it? The docs do say it's where the cue tools output to but I figured it was okay for other generated files. Although same behaviour happens if I place them in cue.mod/usr.

It is also odd that there are imports without usage in the generated files, which would trigger error on their own.

The Server.cue and Mobiles.cue did have some structs inside them originally but in order to make the txtar smaller I removed them as the issue seems to happen regardless.

verdverm commented 3 years ago

Circular imports are not allowed in CUE. Your runtime experience could be better, but cyclic imports are not allowed is the underlying issue. Unused imports are an error as well.

jabinb commented 3 years ago

I see thanks I'll try and figure out a way to remove the cyclical imports in my generator. For my future reference can you point me to where in the documentation I can missed that? I read this part https://cuelang.org/docs/concepts/logic/#file-organization directly below the Cycles explanation and took it to mean they would get flattened or otherwise resolved.

In any case I would have expected an error instead of entering into an infinite loop condition that consumes all my RAM.

verdverm commented 3 years ago

This is a slightly simpler reproducer

exec cue eval entry.cue

-- Server/Mobiles/Mobiles.cue --
package Mobiles

import (
    "example.com/Server"
)
-- Server/Server.cue --
package Server

import (
    "example.com/Server/Mobiles"
)

#TextDefinition: false | null
-- cue.mod/module.cue --
module: "example.com"
-- entry.cue --
import (
        "example.com/Server"
)

Test: Server.#TextDefinition
Test: "None"

Expected output would be something about import cycle not allowed

verdverm commented 3 years ago

The part you read is that values in separate files but the same package do not need imports to reference each other.

You have multiple packages, which do require imports. I'm not sure where cyclic imports are documented, I'm not finding anything myself.

For your understanding, CUE's module, package, (and eventual dep mgmt) heavily borrow from Go's. There is an interesting addition that packages can span directories and you can evaluate a subset of a package by specifying the files to include. This is from the CLI and doesn't translate onto the imports afaik.

jabinb commented 3 years ago

Ahh I see, that makes sense now, thanks for the explanation. I'm not familiar with Go's imports, for reference I'm converting .NET types to CUE structs.

The files are organized by the types full name (e.g. Server.TextDefintion or Server.Mobiles.Example) which looks to be incompatible with Go/Cue's import structure.

Just for clarification is it OK for non-cue tools to place generated files in cue.mod/gen or should I be using cue.mod/usr ?

jabinb commented 3 years ago

This is the stack trace after letting it run without stopping (16m 19s):

runtime: goroutine stack exceeds 1000000000-byte limit
runtime: sp=0xc02e300360 stack=[0xc02e300000, 0xc04e300000]
fatal error: stack overflow

runtime stack:
runtime.throw(0xca43cb, 0xe)
    /usr/local/go/src/runtime/panic.go:1117 +0x72
runtime.newstack()
    /usr/local/go/src/runtime/stack.go:1069 +0x7ed
runtime.morestack()
    /usr/local/go/src/runtime/asm_amd64.s:458 +0x8f

goroutine 1 [running]:
cuelang.org/go/internal/core/adt.(*nodeContext).expandOne(0xc052466e00, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:1851 +0x1ea fp=0xc02e300370 sp=0xc02e300368 pc=0x6d014a
cuelang.org/go/internal/core/adt.(*nodeContext).postDisjunct(0xc052466e00, 0x3)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:430 +0x4e fp=0xc02e300420 sp=0xc02e300370 pc=0x6c658e
cuelang.org/go/internal/core/adt.(*nodeContext).expandDisjuncts(0xc052466e00, 0xc0535a7903, 0xc052466e00, 0x0, 0x6c0100)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/disjunct.go:151 +0x15e8 fp=0xc02e300cb0 sp=0xc02e300420 pc=0x6c0d28
cuelang.org/go/internal/core/adt.(*OpContext).Unify(0xc0535a7930, 0xc052469560, 0xc000390203)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:281 +0x479 fp=0xc02e300f58 sp=0xc02e300cb0 pc=0x6c5439
cuelang.org/go/internal/core/adt.(*nodeContext).addVertexConjuncts(0xc052467180, 0xc052f41e00, 0xc053140a80, 0xda0000, 0xda4338, 0xc000390240, 0xc052469560, 0xd9ef00)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:1379 +0x529 fp=0xc02e301040 sp=0xc02e300f58 pc=0x6cbf49
cuelang.org/go/internal/core/adt.(*nodeContext).evalExpr(0xc052467180, 0xc052f41e00, 0xd98fa0, 0xc000390240, 0xc0531409e0, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:1238 +0x70d fp=0xc02e3011b0 sp=0xc02e301040 pc=0x6cb66d
cuelang.org/go/internal/core/adt.(*nodeContext).addExprConjunct(0xc052467180, 0xc052f41e00, 0xd98fa0, 0xc000390240, 0xc0531409e0, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:1198 +0x2a5 fp=0xc02e3012a0 sp=0xc02e3011b0 pc=0x6caaa5
cuelang.org/go/internal/core/adt.(*nodeContext).addVertexConjuncts(0xc052467180, 0xc052f402d0, 0xc0531409e0, 0x7f1a50340000, 0xda41f8, 0xc00033ac70, 0xc052432480, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:1397 +0x429 fp=0xc02e301388 sp=0xc02e3012a0 pc=0x6cbe49
cuelang.org/go/internal/core/adt.(*nodeContext).evalExpr(0xc052467180, 0xc052f402d0, 0xd98cd0, 0xc00038d350, 0xc053140440, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:1238 +0x70d fp=0xc02e3014f8 sp=0xc02e301388 pc=0x6cb66d
cuelang.org/go/internal/core/adt.(*nodeContext).addExprConjunct(0xc052467180, 0xc052f402d0, 0xd98cd0, 0xc00038d350, 0xc053140440, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:1198 +0x2a5 fp=0xc02e3015e8 sp=0xc02e3014f8 pc=0x6caaa5
cuelang.org/go/internal/core/adt.(*nodeContext).insertConjuncts(0xc052467180)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:367 +0xfb fp=0xc02e301660 sp=0xc02e3015e8 pc=0x6c5fdb
cuelang.org/go/internal/core/adt.(*OpContext).Unify(0xc0535a7930, 0xc052458d80, 0xc000391a03)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:227 +0x27f fp=0xc02e301908 sp=0xc02e301660 pc=0x6c523f
cuelang.org/go/internal/core/adt.(*nodeContext).addVertexConjuncts(0xc052466a80, 0xc052f41950, 0xc0531409a0, 0xda0000, 0xda44b8, 0xc000391a20, 0xc052458d80, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:1379 +0x529 fp=0xc02e3019f0 sp=0xc02e301908 pc=0x6cbf49
cuelang.org/go/internal/core/adt.(*nodeContext).evalExpr(0xc052466a80, 0xc052f41950, 0xd990e0, 0xc000391a20, 0xc053140980, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:1238 +0x70d fp=0xc02e301b60 sp=0xc02e3019f0 pc=0x6cb66d
cuelang.org/go/internal/core/adt.(*nodeContext).addExprConjunct(0xc052466a80, 0xc052f41950, 0xd990e0, 0xc000391a20, 0xc053140980, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:1198 +0x2a5 fp=0xc02e301c50 sp=0xc02e301b60 pc=0x6caaa5
cuelang.org/go/internal/core/adt.(*nodeContext).addStruct(0xc052466a80, 0xc052f40050, 0xc000395170, 0xc053140960, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:1746 +0xbbb fp=0xc02e301de0 sp=0xc02e301c50 pc=0x6cf67b
cuelang.org/go/internal/core/adt.(*nodeContext).addExprConjunct(0xc052466a80, 0xc052f40050, 0xd98e38, 0xc000391ac0, 0xc053140380, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:1188 +0x265 fp=0xc02e301ed0 sp=0xc02e301de0 pc=0x6caa65
cuelang.org/go/internal/core/adt.(*nodeContext).insertConjuncts(0xc052466a80)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:367 +0xfb fp=0xc02e301f48 sp=0xc02e301ed0 pc=0x6c5fdb
cuelang.org/go/internal/core/adt.(*OpContext).Unify(0xc0535a7930, 0xc052458e10, 0xc000391a03)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:227 +0x27f fp=0xc02e3021f0 sp=0xc02e301f48 pc=0x6c523f
cuelang.org/go/internal/core/adt.(*nodeContext).addVertexConjuncts(0xc052454e00, 0xc052f41900, 0xc053140940, 0xda0000, 0xda44b8, 0xc000391ae0, 0xc052458e10, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:1379 +0x529 fp=0xc02e3022d8 sp=0xc02e3021f0 pc=0x6cbf49
cuelang.org/go/internal/core/adt.(*nodeContext).evalExpr(0xc052454e00, 0xc052f41900, 0xd990e0, 0xc000391ae0, 0xc053140900, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:1238 +0x70d fp=0xc02e302448 sp=0xc02e3022d8 pc=0x6cb66d
cuelang.org/go/internal/core/adt.(*nodeContext).addExprConjunct(0xc052454e00, 0xc052f41900, 0xd990e0, 0xc000391ae0, 0xc053140900, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:1198 +0x2a5 fp=0xc02e302538 sp=0xc02e302448 pc=0x6caaa5
cuelang.org/go/internal/core/adt.(*nodeContext).addStruct(0xc052454e00, 0xc052f40050, 0xc000395200, 0xc0531408e0, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:1746 +0xbbb fp=0xc02e3026c8 sp=0xc02e302538 pc=0x6cf67b
cuelang.org/go/internal/core/adt.(*nodeContext).addExprConjunct(0xc052454e00, 0xc052f40050, 0xd98e38, 0xc000391c00, 0xc053140380, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:1188 +0x265 fp=0xc02e3027b8 sp=0xc02e3026c8 pc=0x6caa65
cuelang.org/go/internal/core/adt.(*nodeContext).insertConjuncts(0xc052454e00)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:367 +0xfb fp=0xc02e302830 sp=0xc02e3027b8 pc=0x6c5fdb
cuelang.org/go/internal/core/adt.(*OpContext).Unify(0xc0535a7930, 0xc052458ea0, 0xc000390503)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:227 +0x27f fp=0xc02e302ad8 sp=0xc02e302830 pc=0x6c523f
cuelang.org/go/internal/core/adt.(*nodeContext).addVertexConjuncts(0xc052466380, 0xc052f418b0, 0xc0531408c0, 0xda0000, 0xda44b8, 0xc000390540, 0xc052458ea0, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:1379 +0x529 fp=0xc02e302bc0 sp=0xc02e302ad8 pc=0x6cbf49
cuelang.org/go/internal/core/adt.(*nodeContext).evalExpr(0xc052466380, 0xc052f418b0, 0xd990e0, 0xc000390540, 0x0, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:1238 +0x70d fp=0xc02e302d30 sp=0xc02e302bc0 pc=0x6cb66d
cuelang.org/go/internal/core/adt.(*nodeContext).addExprConjunct(0xc052466380, 0xc052f418b0, 0xd990e0, 0xc000390540, 0x0, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:1198 +0x2a5 fp=0xc02e302e20 sp=0xc02e302d30 pc=0x6caaa5
cuelang.org/go/internal/core/adt.(*nodeContext).expandDisjuncts(0xc052467500, 0xc0535a7905, 0xc052467500, 0x0, 0xc053140100)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/disjunct.go:228 +0x425 fp=0xc02e3036b0 sp=0xc02e302e20 pc=0x6bfb65
cuelang.org/go/internal/core/adt.(*OpContext).Unify(0xc0535a7930, 0xc052468c60, 0x6c3305)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:281 +0x479 fp=0xc02e303958 sp=0xc02e3036b0 pc=0x6c5439
cuelang.org/go/internal/core/adt.(*nodeContext).completeArcs(0xc052454a80, 0x5)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:669 +0x13d fp=0xc02e303a18 sp=0xc02e303958 pc=0x6c779d
cuelang.org/go/internal/core/adt.(*nodeContext).postDisjunct(0xc052454a80, 0xc052454a05)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:565 +0x525 fp=0xc02e303ac8 sp=0xc02e303a18 pc=0x6c6a65
cuelang.org/go/internal/core/adt.(*nodeContext).expandDisjuncts(0xc052454a80, 0xc0535a7905, 0xc052454a80, 0x0, 0x100)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/disjunct.go:151 +0x15e8 fp=0xc02e304358 sp=0xc02e303ac8 pc=0x6c0d28
cuelang.org/go/internal/core/adt.(*OpContext).Unify(0xc0535a7930, 0xc052468510, 0x6c3305)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:281 +0x479 fp=0xc02e304600 sp=0xc02e304358 pc=0x6c5439
cuelang.org/go/internal/core/adt.(*nodeContext).completeArcs(0xc052454380, 0x5)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:669 +0x13d fp=0xc02e3046c0 sp=0xc02e304600 pc=0x6c779d
cuelang.org/go/internal/core/adt.(*nodeContext).postDisjunct(0xc052454380, 0xc052454305)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:565 +0x525 fp=0xc02e304770 sp=0xc02e3046c0 pc=0x6c6a65
cuelang.org/go/internal/core/adt.(*nodeContext).expandDisjuncts(0xc052454380, 0xc0535a7905, 0xc052454380, 0x0, 0x100)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/disjunct.go:151 +0x15e8 fp=0xc02e305000 sp=0xc02e304770 pc=0x6c0d28
cuelang.org/go/internal/core/adt.(*OpContext).Unify(0xc0535a7930, 0xc052458000, 0x6c3305)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:281 +0x479 fp=0xc02e3052a8 sp=0xc02e305000 pc=0x6c5439
cuelang.org/go/internal/core/adt.(*nodeContext).completeArcs(0xc052429880, 0x5)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:669 +0x13d fp=0xc02e305368 sp=0xc02e3052a8 pc=0x6c779d
cuelang.org/go/internal/core/adt.(*nodeContext).postDisjunct(0xc052429880, 0xc052429805)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:565 +0x525 fp=0xc02e305418 sp=0xc02e305368 pc=0x6c6a65
cuelang.org/go/internal/core/adt.(*nodeContext).expandDisjuncts(0xc052429880, 0xc0535a7905, 0xc052429880, 0x0, 0x100)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/disjunct.go:151 +0x15e8 fp=0xc02e305ca8 sp=0xc02e305418 pc=0x6c0d28
cuelang.org/go/internal/core/adt.(*OpContext).Unify(0xc0535a7930, 0xc052432510, 0x6c3305)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:281 +0x479 fp=0xc02e305f50 sp=0xc02e305ca8 pc=0x6c5439
cuelang.org/go/internal/core/adt.(*nodeContext).completeArcs(0xc052429500, 0x5)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:669 +0x13d fp=0xc02e306010 sp=0xc02e305f50 pc=0x6c779d
cuelang.org/go/internal/core/adt.(*nodeContext).postDisjunct(0xc052429500, 0xc05336f105)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:565 +0x525 fp=0xc02e3060c0 sp=0xc02e306010 pc=0x6c6a65
cuelang.org/go/internal/core/adt.(*nodeContext).expandDisjuncts(0xc052429500, 0xc0535a7905, 0xc052429500, 0x0, 0x780100)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/disjunct.go:151 +0x15e8 fp=0xc02e306950 sp=0xc02e3060c0 pc=0x6c0d28
cuelang.org/go/internal/core/adt.(*OpContext).Unify(0xc0535a7930, 0xc0524322d0, 0x5)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/eval.go:281 +0x479 fp=0xc02e306bf8 sp=0xc02e306950 pc=0x6c5439
cuelang.org/go/internal/core/adt.(*Vertex).Finalize(...)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/core/adt/composite.go:445
cuelang.org/go/cue.Value.Unify(0xc000285bb0, 0xc0002befc0, 0x0, 0xc000285bb0, 0xc0003c75f0, 0x0, 0xc000285bb0, 0xc0003c75f0, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/types.go:1827 +0x11a fp=0xc02e306c60 sp=0xc02e306bf8 pc=0x78485a
cuelang.org/go/internal/filetypes.parseType(0x0, 0x0, 0x0, 0x0, 0x0, 0x41, 0x0, 0xc0535a72e8, 0xc051f08500, 0xc02e306e70, ...)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/filetypes/filetypes.go:287 +0x147 fp=0xc02e306dc8 sp=0xc02e306c60 pc=0x995907
cuelang.org/go/internal/filetypes.ParseFile(0xc051f08e51, 0xa, 0x0, 0xc053140060, 0x2, 0x2)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/internal/filetypes/filetypes.go:242 +0x2e5 fp=0xc02e306f00 sp=0xc02e306dc8 pc=0x994905
cuelang.org/go/cue/load.(*loader).importPkg(0xc00032c2d0, 0xc05448df80, 0x1f4, 0xc0520881e0, 0x0, 0x0, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/load/import.go:185 +0xec5 fp=0xc02e3076c0 sp=0xc02e306f00 pc=0xa11e45
cuelang.org/go/cue/load.(*loader).loadFunc.func1(0xc05448df80, 0x1f4, 0xc02413f981, 0x13, 0xc0522a61e8)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/load/import.go:262 +0x4f7 fp=0xc02e307988 sp=0xc02e3076c0 pc=0xa20a77
cuelang.org/go/cue/build.(*Instance).complete(0xc052088000, 0xc000010010, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/build/import.go:103 +0x12bb fp=0xc02e307dd8 sp=0xc02e307988 pc=0x70881b
cuelang.org/go/cue/build.(*Instance).Complete(0xc052088000, 0xc000036004, 0x20)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/build/context.go:69 +0x45 fp=0xc02e307e18 sp=0xc02e307dd8 pc=0x7071e5
cuelang.org/go/cue/load.(*loader).importPkg(0xc00032c2d0, 0xc054ea35e0, 0x1e4, 0xc052088000, 0x0, 0x0, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/load/import.go:231 +0x890 fp=0xc02e3085d8 sp=0xc02e307e18 pc=0xa11810
cuelang.org/go/cue/load.(*loader).loadFunc.func1(0xc054ea35e0, 0x1e4, 0xc0509d8361, 0x1b, 0xc05132faa8)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/load/import.go:262 +0x4f7 fp=0xc02e3088a0 sp=0xc02e3085d8 pc=0xa20a77
cuelang.org/go/cue/build.(*Instance).complete(0xc04e641e00, 0xc000010010, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/build/import.go:103 +0x12bb fp=0xc02e308cf0 sp=0xc02e3088a0 pc=0x70881b
cuelang.org/go/cue/build.(*Instance).Complete(0xc04e641e00, 0xc000036004, 0x20)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/build/context.go:69 +0x45 fp=0xc02e308d30 sp=0xc02e308cf0 pc=0x7071e5
cuelang.org/go/cue/load.(*loader).importPkg(0xc00032c2d0, 0xc054b67180, 0x1f4, 0xc04e641e00, 0x0, 0x0, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/load/import.go:231 +0x890 fp=0xc02e3094f0 sp=0xc02e308d30 pc=0xa11810
cuelang.org/go/cue/load.(*loader).loadFunc.func1(0xc054b67180, 0x1f4, 0xc0547498f1, 0x13, 0xc05132f528)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/load/import.go:262 +0x4f7 fp=0xc02e3097b8 sp=0xc02e3094f0 pc=0xa20a77
cuelang.org/go/cue/build.(*Instance).complete(0xc04e641c20, 0xc000010010, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/build/import.go:103 +0x12bb fp=0xc02e309c08 sp=0xc02e3097b8 pc=0x70881b
cuelang.org/go/cue/build.(*Instance).Complete(0xc04e641c20, 0xc000036004, 0x20)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/build/context.go:69 +0x45 fp=0xc02e309c48 sp=0xc02e309c08 pc=0x7071e5
cuelang.org/go/cue/load.(*loader).importPkg(0xc00032c2d0, 0xc0545a2a80, 0x1e4, 0xc04e641c20, 0x0, 0x0, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/load/import.go:231 +0x890 fp=0xc02e30a408 sp=0xc02e309c48 pc=0xa11810
cuelang.org/go/cue/load.(*loader).loadFunc.func1(0xc0545a2a80, 0x1e4, 0xc02af6c821, 0x1b, 0xc05132ee48)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/load/import.go:262 +0x4f7 fp=0xc02e30a6d0 sp=0xc02e30a408 pc=0xa20a77
cuelang.org/go/cue/build.(*Instance).complete(0xc04e641a40, 0xc000010010, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/build/import.go:103 +0x12bb fp=0xc02e30ab20 sp=0xc02e30a6d0 pc=0x70881b
cuelang.org/go/cue/build.(*Instance).Complete(0xc04e641a40, 0xc000036004, 0x20)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/build/context.go:69 +0x45 fp=0xc02e30ab60 sp=0xc02e30ab20 pc=0x7071e5
cuelang.org/go/cue/load.(*loader).importPkg(0xc00032c2d0, 0xc054324070, 0x1f4, 0xc04e641a40, 0x0, 0x0, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/load/import.go:231 +0x890 fp=0xc02e30b320 sp=0xc02e30ab60 pc=0xa11810
cuelang.org/go/cue/load.(*loader).loadFunc.func1(0xc054324070, 0x1f4, 0xc0544af699, 0x13, 0xc05132e8c8)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/load/import.go:262 +0x4f7 fp=0xc02e30b5e8 sp=0xc02e30b320 pc=0xa20a77
cuelang.org/go/cue/build.(*Instance).complete(0xc04e641860, 0xc000010010, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/build/import.go:103 +0x12bb fp=0xc02e30ba38 sp=0xc02e30b5e8 pc=0x70881b
cuelang.org/go/cue/build.(*Instance).Complete(0xc04e641860, 0xc000036004, 0x20)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/build/context.go:69 +0x45 fp=0xc02e30ba78 sp=0xc02e30ba38 pc=0x7071e5
cuelang.org/go/cue/load.(*loader).importPkg(0xc00032c2d0, 0xc0548b4a80, 0x1e4, 0xc04e641860, 0x0, 0x0, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/load/import.go:231 +0x890 fp=0xc02e30c238 sp=0xc02e30ba78 pc=0xa11810
cuelang.org/go/cue/load.(*loader).loadFunc.func1(0xc0548b4a80, 0x1e4, 0xc054fcade1, 0x1b, 0xc05132e1e8)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/load/import.go:262 +0x4f7 fp=0xc02e30c500 sp=0xc02e30c238 pc=0xa20a77
cuelang.org/go/cue/build.(*Instance).complete(0xc04e641680, 0xc000010010, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/build/import.go:103 +0x12bb fp=0xc02e30c950 sp=0xc02e30c500 pc=0x70881b
cuelang.org/go/cue/build.(*Instance).Complete(0xc04e641680, 0xc000036004, 0x20)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/build/context.go:69 +0x45 fp=0xc02e30c990 sp=0xc02e30c950 pc=0x7071e5
cuelang.org/go/cue/load.(*loader).importPkg(0xc00032c2d0, 0xc054377e30, 0x1f4, 0xc04e641680, 0x0, 0x0, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/load/import.go:231 +0x890 fp=0xc02e30d150 sp=0xc02e30c990 pc=0xa11810
cuelang.org/go/cue/load.(*loader).loadFunc.func1(0xc054377e30, 0x1f4, 0xc0299a5021, 0x13, 0xc050387c08)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/load/import.go:262 +0x4f7 fp=0xc02e30d418 sp=0xc02e30d150 pc=0xa20a77
cuelang.org/go/cue/build.(*Instance).complete(0xc04e6414a0, 0xc000010010, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/build/import.go:103 +0x12bb fp=0xc02e30d868 sp=0xc02e30d418 pc=0x70881b
cuelang.org/go/cue/build.(*Instance).Complete(0xc04e6414a0, 0xc000036004, 0x20)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/build/context.go:69 +0x45 fp=0xc02e30d8a8 sp=0xc02e30d868 pc=0x7071e5
cuelang.org/go/cue/load.(*loader).importPkg(0xc00032c2d0, 0xc054c4bc00, 0x1e4, 0xc04e6414a0, 0x0, 0x0, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/load/import.go:231 +0x890 fp=0xc02e30e068 sp=0xc02e30d8a8 pc=0xa11810
cuelang.org/go/cue/load.(*loader).loadFunc.func1(0xc054c4bc00, 0x1e4, 0xc0513d2741, 0x1b, 0xc050387528)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/load/import.go:262 +0x4f7 fp=0xc02e30e330 sp=0xc02e30e068 pc=0xa20a77
cuelang.org/go/cue/build.(*Instance).complete(0xc04e6412c0, 0xc000010010, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/build/import.go:103 +0x12bb fp=0xc02e30e780 sp=0xc02e30e330 pc=0x70881b
cuelang.org/go/cue/build.(*Instance).Complete(0xc04e6412c0, 0xc000036004, 0x20)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/build/context.go:69 +0x45 fp=0xc02e30e7c0 sp=0xc02e30e780 pc=0x7071e5
cuelang.org/go/cue/load.(*loader).importPkg(0xc00032c2d0, 0xc0547a0b60, 0x1f4, 0xc04e6412c0, 0x0, 0x0, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/load/import.go:231 +0x890 fp=0xc02e30ef80 sp=0xc02e30e7c0 pc=0xa11810
cuelang.org/go/cue/load.(*loader).loadFunc.func1(0xc0547a0b60, 0x1f4, 0xc02adc3381, 0x13, 0xc050386fa8)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/load/import.go:262 +0x4f7 fp=0xc02e30f248 sp=0xc02e30ef80 pc=0xa20a77
cuelang.org/go/cue/build.(*Instance).complete(0xc04e6410e0, 0xc000010010, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/build/import.go:103 +0x12bb fp=0xc02e30f698 sp=0xc02e30f248 pc=0x70881b
cuelang.org/go/cue/build.(*Instance).Complete(0xc04e6410e0, 0xc000036004, 0x20)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/build/context.go:69 +0x45 fp=0xc02e30f6d8 sp=0xc02e30f698 pc=0x7071e5
cuelang.org/go/cue/load.(*loader).importPkg(0xc00032c2d0, 0xc0535e65b0, 0x1e4, 0xc04e6410e0, 0x0, 0x0, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/load/import.go:231 +0x890 fp=0xc02e30fe98 sp=0xc02e30f6d8 pc=0xa11810
cuelang.org/go/cue/load.(*loader).loadFunc.func1(0xc0535e65b0, 0x1e4, 0xc0543aa9a1, 0x1b, 0xc0503868c8)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/load/import.go:262 +0x4f7 fp=0xc02e310160 sp=0xc02e30fe98 pc=0xa20a77
cuelang.org/go/cue/build.(*Instance).complete(0xc04e640f00, 0xc000010010, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/build/import.go:103 +0x12bb fp=0xc02e3105b0 sp=0xc02e310160 pc=0x70881b
cuelang.org/go/cue/build.(*Instance).Complete(0xc04e640f00, 0xc000036004, 0x20)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/build/context.go:69 +0x45 fp=0xc02e3105f0 sp=0xc02e3105b0 pc=0x7071e5
cuelang.org/go/cue/load.(*loader).importPkg(0xc00032c2d0, 0xc053556ee0, 0x1f4, 0xc04e640f00, 0x0, 0x0, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/load/import.go:231 +0x890 fp=0xc02e310db0 sp=0xc02e3105f0 pc=0xa11810
cuelang.org/go/cue/load.(*loader).loadFunc.func1(0xc053556ee0, 0x1f4, 0xc05789f2f1, 0x13, 0xc050386348)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/load/import.go:262 +0x4f7 fp=0xc02e311078 sp=0xc02e310db0 pc=0xa20a77
cuelang.org/go/cue/build.(*Instance).complete(0xc04e640d20, 0xc000010010, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/build/import.go:103 +0x12bb fp=0xc02e3114c8 sp=0xc02e311078 pc=0x70881b
cuelang.org/go/cue/build.(*Instance).Complete(0xc04e640d20, 0xc000036004, 0x20)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/build/context.go:69 +0x45 fp=0xc02e311508 sp=0xc02e3114c8 pc=0x7071e5
cuelang.org/go/cue/load.(*loader).importPkg(0xc00032c2d0, 0xc053c6c4d0, 0x1e4, 0xc04e640d20, 0x0, 0x0, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/load/import.go:231 +0x890 fp=0xc02e311cc8 sp=0xc02e311508 pc=0xa11810
cuelang.org/go/cue/load.(*loader).loadFunc.func1(0xc053c6c4d0, 0x1e4, 0xc05792b8e1, 0x1b, 0xc04ee8dc08)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/load/import.go:262 +0x4f7 fp=0xc02e311f90 sp=0xc02e311cc8 pc=0xa20a77
cuelang.org/go/cue/build.(*Instance).complete(0xc04e640b40, 0xc000010010, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/build/import.go:103 +0x12bb fp=0xc02e3123e0 sp=0xc02e311f90 pc=0x70881b
cuelang.org/go/cue/build.(*Instance).Complete(0xc04e640b40, 0xc000036004, 0x20)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/build/context.go:69 +0x45 fp=0xc02e312420 sp=0xc02e3123e0 pc=0x7071e5
cuelang.org/go/cue/load.(*loader).importPkg(0xc00032c2d0, 0xc053b243f0, 0x1f4, 0xc04e640b40, 0x0, 0x0, 0x0)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/load/import.go:231 +0x890 fp=0xc02e312be0 sp=0xc02e312420 pc=0xa11810
cuelang.org/go/cue/load.(*loader).loadFunc.func1(0xc053b243f0, 0x1f4, 0xc057707ed9, 0x13, 0xc04ee8d688)
    /home/jabin/go/pkg/mod/cuelang.org/go@v0.4.0/cue/load/import.go:262 +0x4f7 fp=0xc02e312ea8 sp=0xc02e312be0 pc=0xa20a77

goroutine 18 [chan receive]:
github.com/golang/glog.(*loggingT).flushDaemon(0x11c7200)
    /home/jabin/go/pkg/mod/github.com/golang/glog@v0.0.0-20160126235308-23def4e6c14b/glog.go:882 +0x8b
created by github.com/golang/glog.init.0
    /home/jabin/go/pkg/mod/github.com/golang/glog@v0.0.0-20160126235308-23def4e6c14b/glog.go:410 +0x274
verdverm commented 3 years ago

That is interesting, the reverse came up (without being specific to C# but I was thinking about it) in generating OOP types from CUE.

Just for clarification is it OK for non-cue tools to place generated files in cue.mod/gen or should I be using cue.mod/usr ?

I think generally the cue.mod directory is largely managed by the cue tool. The usr directory is for augmenting gen and there are some special semantics going on there. So I wouldn't generate into usr. Why not a directory outside of cue.mod?

Aside from an occasional addition to the usr subdirectory or tweak to module.cue, this directory is predominantly managed by the cue tool.

(from https://cuelang.org/docs/concepts/packages/#the-cuemod-directory)

mpvl commented 2 years ago

There is a cycle detector, so it shouldn't crash.

If there is a serious issue with not allowing cyclic package dependencies, it would be great to hear about it. There are some great simplifications by not allowing it, and changing this behavior would require some significant work and investigation. But in principle it is something that could be possible.

rogpeppe commented 2 years ago

Here's a reproducer that's simpler still:

exec cue export ./a

-- a/a.cue --
package a

import "example.com/b"
-- b/b.cue --
package b

import "example.com/a"
-- cue.mod/module.cue --
module: "example.com"
myitcv commented 1 year ago

Dropping the now meaningless v0.4.x milestone. Instead moved to the v0.x.x milestone which indicates relatively low-hanging fruit we can pick up in the next minor/patch release.