# Tests that repeated references to the same type in a struct (e.g. #ref twice,
# _ | {} twice) do not cause exponential blowup in conjuncts/disjuncts.
# https://cuelang.org/issue/758
# https://cuelang.org/issue/1044

// TODO(perf): reduce number of conjunctions and disjunctions.
-- in.cue --
A: #Task
B: #steps: #Script & {mount: [A]}
C: #steps: #Script & {mount: [B]}

#Script: {mount: [...#Task]}

#Task: {
	// Without the proper constructs, repeating the below results
	// in exponential runtime.
	#ref
	#ref
	_ | {}
	_ | {}
	#steps: #Script
	...
}

#ref: {a: 1} | {b: 2}
-- out/compile --
--- in.cue
{
  A: 〈0;#Task〉
  B: {
    #steps: (〈1;#Script〉 & {
      mount: [
        〈3;A〉,
      ]
    })
  }
  C: {
    #steps: (〈1;#Script〉 & {
      mount: [
        〈3;B〉,
      ]
    })
  }
  #Script: {
    mount: [
      ...〈2;#Task〉,
    ]
  }
  #Task: {
    〈1;#ref〉
    〈1;#ref〉
    (_|{})
    (_|{})
    #steps: 〈1;#Script〉
    ...
  }
  #ref: ({
    a: 1
  }|{
    b: 2
  })
}
