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

evaluator: Regression: result.#_list.0: #in.c1 undefined as #in is incomplete (type _): #2113

Closed
bttk opened this issue Nov 21, 2022 · 6 comments

Comments

@bttk
Copy link

bttk commented Nov 21, 2022

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

0.5.0-beta.1

Does this issue reproduce with the latest release?

Yes

What did you do?

-- cue.mod/module.cue --
module: "bttk.dev/cuebug"
-- input.cue --
table: "table_1_csv_import": {
        header: ["c1", "c2", "c3"]
        rows: [{
                c1: "V 1"
                c2: "V 2"
                c3: "V 3"
        }, {
                c1: "W 1"
                c2: "W 2"
                c3: "W 3"
        }, {
                c1: "X 1"
                c2: "X 2"
                c3: "X 3"
        }]
}
-- tools/cue/mapper/apply.cue --
package apply

import (
        "bttk.dev/cuebug/tools/cue/mapper"
        "list"
)

FUNC=func: [string]: mapper.#Func
table: [string]: rows: [...]

_mapperType:                  *"list" | "text" @tag(mapper)
_joinStr:                     string | *"\n"   @tag(join)
TABLE_NAME=_tableName:        string | *""     @tag(table)
OUT_TABLE_NAME=_outTableName: string | *""     @tag(outTable)
FUNC_NAME=_funcName:          string | *""     @tag(func)

result: [
        if _mapperType == "list" {mapper.#ListMapper},
        if _mapperType == "text" {mapper.#TextMapper & {#join: _joinStr, _}},
][0] & {
        let TABLE = table
        #in: TABLE[TABLE_NAME].rows
        #fn: FUNC[FUNC_NAME]

        _
}

resultTable: table: "\(OUT_TABLE_NAME)": rows: result
flatTable: table: "\(OUT_TABLE_NAME)": rows:   list.FlattenN(result, 1)
-- tools/cue/mapper/mapper.cue --
package mapper

import "strings"

#Schema: func: [_]: #Func

#Func: {
        #in: _
        _
        ...
}

#ListMapper: {
        IN=#in: [...]
        FN=#fn: #Func

        [ for r in IN {
                FN & {#in: r, _}
        }]
}

#TextMapper: {
        IN=#in: [...]
        FN=#fn: #Func
        #join:  string | *"\n"

        #_list: #ListMapper & {#in: IN, #fn: FN, [...string]}
        strings.Join(#_list, #join)
}
-- tools/cue/test/testdata/func_1.cue --
import (
        "bttk.dev/cuebug/tools/cue/mapper"
)

func: [string]: mapper.#Func

func: "func_1": {
        IN=#in: {[string]: _}

        IN.c1
}

What did you expect to see?

$ go run cuelang.org/go/cmd/[email protected] export --all-errors --verbose '--out=text' --inject 'table=table_1_csv_import' --inject 'func=func_1' --inject 'mapper=text' --inject 'join=|' --inject 'outTable=table_1_csv_import' --expression result input.cue tools/cue/test/testdata/func_1.cue tools/cue/mapper/apply.cue

V 1|W 1|X 1

What did you see instead?

$ go run cuelang.org/go/cmd/[email protected] export --all-errors --verbose '--out=text' --inject 'table=table_1_csv_import' --inject 'func=func_1' --inject 'mapper=text' --inject 'join=|' --inject 'outTable=table_1_csv_import' --expression result input.cue tools/cue/test/testdata/func_1.cue tools/cue/mapper/apply.cue

result.#_list.0: #in.c1 undefined as #in is incomplete (type _):
    ./tools/cue/test/testdata/func_1.cue:10:2
exit status 1
@bttk bttk added NeedsInvestigation Triage Requires triage/attention labels Nov 21, 2022
@myitcv myitcv removed the Triage Requires triage/attention label Nov 21, 2022
@myitcv myitcv changed the title Regression: result.#_list.0: #in.c1 undefined as #in is incomplete (type _): evaluator: Regression: result.#_list.0: #in.c1 undefined as #in is incomplete (type _): Nov 21, 2022
@myitcv
Copy link
Member

myitcv commented Nov 21, 2022

Thanks for the report, @bttk. Investigating now.

@myitcv myitcv added this to the v0.5.0 comprehension rework milestone Nov 21, 2022
@myitcv
Copy link
Member

myitcv commented Nov 21, 2022

I've reduced this down to the follow.

What did you do?

exec cue export '--out=text' -e result x.cue
cmp stdout stdout.golden

-- x.cue --
package apply

import (
	"strings"
)

// This appears to be critical to reproducing the error
#Func: {
	#in: _
	_
}

#TextMapper: {
	#in: [...]
	#fn:   #Func
	#join: string
	_#list: [ for r in #in {
		#fn & {#in: r, _}
	}]
	strings.Join(_#list, #join)
}

result: #TextMapper & {
	#join: "|"
	#in: [{c1: "V 1"}]
	#fn: {
		#in: _
		#in.c1
	}
	_
}
-- stdout.golden --
V 1

What did you expect to see?

A passing test. This passes with v0.4.3

What did you see instead?

$ ts repro.txtar
> exec cue export '--out=text' -e result x.cue
[stderr]
result._#list.0: #in.c1 undefined as #in is incomplete (type _):
    ./x.cue:28:3
[exit status 1]
FAIL: /tmp/testscript3972114924/repro.txtar/script.txtar:1: unexpected command failure

Bisected to 748a685

Marking as v0.5.0.

@mpvl
Copy link
Member

mpvl commented Nov 21, 2022

Simpler reproducer:

c: [1, 2]
a: {
    for k, v in c {
        {x: 1}
        if a.x != _|_ {
        }
    }
}

cueckoo pushed a commit that referenced this issue Nov 24, 2022
Issue #2113
Issue #2131

Signed-off-by: Marcel van Lohuizen <[email protected]>
Change-Id: I94cf1a28c3261f13dfef6b7214b59baed1ef0a62
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/546597
Unity-Result: CUEcueckoo <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
Reviewed-by: Roger Peppe <[email protected]>
cueckoo pushed a commit that referenced this issue Nov 24, 2022
There were some cases where conjuncts could be added after
the Conjuncts state had been reached. This is okay, as there
is a separate mechanism to verify such additions are legal.
But not adding those can lead to lost information.

Tests for this were added before and will be fixed after
removing a workaround that worked around the issue fixed
here, but introduced errors itself.

Issue #2113
Fixes #2131

Signed-off-by: Marcel van Lohuizen <[email protected]>
Change-Id: I74522731007393b96c6ba69acc688ca044067f3f
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/546598
Reviewed-by: Roger Peppe <[email protected]>
Unity-Result: CUEcueckoo <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
cueckoo pushed a commit that referenced this issue Nov 28, 2022
With the merging of handing the Partial and Conjuncts state,
this special casing is no longer necessary. As the special
casing is actually incorrect, this fixes a couple of bugs.

This fixes the original issue reported in 2113. We leave it open,
though, as there is still a related issue outstanding.

Issue #2113

Signed-off-by: Marcel van Lohuizen <[email protected]>
Change-Id: I365658a63528ad340d0b4506fc4a7b4bd1566e33
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/546611
Reviewed-by: Roger Peppe <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
@myitcv
Copy link
Member

myitcv commented Nov 28, 2022

A different reproducer:

#Func: {
	#in2: _
	_
}

#fn: #Func
#fn: {
	#in2: _
	#in2.c1
}
x: #fn & {#in2: {c1: "V 1"}, _}

Again, the constraint #fn: #Func is critical here.

Per @mpvl this (also) appears to be an ordering thing.

cueckoo pushed a commit that referenced this issue Nov 30, 2022
Issue #2113

Signed-off-by: Marcel van Lohuizen <[email protected]>
Change-Id: Ie30cdbb2bd9e6444de646b6b3ea8369ce4aee060
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/546856
Reviewed-by: Paul Jolly <[email protected]>
Unity-Result: CUEcueckoo <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
cueckoo pushed a commit that referenced this issue Nov 30, 2022
This prevents non-monotonic checks to be evaluated
too early.

Issue #2113

Signed-off-by: Marcel van Lohuizen <[email protected]>
Change-Id: I4e63d67152452b5df5184de65e0a679251c83826
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/546858
Unity-Result: CUEcueckoo <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
Reviewed-by: Paul Jolly <[email protected]>
cueckoo pushed a commit that referenced this issue Nov 30, 2022
This improves one error message. It's main purpose
is to ultimately pass the state to various evaluation
functions.

It takes a somewhat conservative stance to not pass the
state for calls where this is not necessary. For instance,
the Partial mode is typically used to get a scalar value
as further evaluation is unnecessary. In fact, elevating
the evaluation may thwart the ability to resolve cycles
in that case.

Issue #2113

Signed-off-by: Marcel van Lohuizen <[email protected]>
Change-Id: I504aaacc976e9f1a07460c680456fc45004b575f
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/546857
Reviewed-by: Paul Jolly <[email protected]>
Unity-Result: CUEcueckoo <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
cueckoo pushed a commit that referenced this issue Nov 30, 2022
Issue #2113

Signed-off-by: Marcel van Lohuizen <[email protected]>
Change-Id: I3f868e3c8a9ac88d79d70aa60110318ad18e1c5a
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/546859
Reviewed-by: Paul Jolly <[email protected]>
Unity-Result: CUEcueckoo <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
cueckoo pushed a commit that referenced this issue Nov 30, 2022
Before this CL it may be set too early.

Some of the tests that are added are still broken, and
will be fixed in subsequent CLs.

Issue #2113

Signed-off-by: Marcel van Lohuizen <[email protected]>
Change-Id: I763a4046ad11d7de407b6be188f3d3bbbe2669d3
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/546860
Reviewed-by: Paul Jolly <[email protected]>
Unity-Result: CUEcueckoo <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
cueckoo pushed a commit that referenced this issue Nov 30, 2022
See comments in internal/core/adt/context.go.

This fixes broken tests in scalars/embed.txtar

Issue #2113

Signed-off-by: Marcel van Lohuizen <[email protected]>
Change-Id: I32c1a34bc91e3df7d7daf7da209e89204eaba19d
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/546861
Reviewed-by: Paul Jolly <[email protected]>
Unity-Result: CUEcueckoo <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
@bttk
Copy link
Author

bttk commented Nov 30, 2022

looks like it's fixed in v0.5.0-beta.2

go run cuelang.org/go/cmd/[email protected] export --all-errors --verbose '--out=text' --inject 'table=table_1_csv_import' --inject 'func=func_1' --i nject 'mapper=text' --inject 'join=|' --inject 'outTable=table_1_csv_import' --expression result input.cue tools/cue/test/testdata/func_1.cue tools/cue/mapper/apply.cue

V 1|W 1|X 1

@myitcv
Copy link
Member

myitcv commented Nov 30, 2022

Yes indeed, @bttk! You can see above the list of fixes that went into this one. Thanks again for raising, I will mark this as closed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants