Skip to content

Commit d987d88

Browse files
committed
internal/core/adt: remove replaceID.add field
This is no longer used. Issue #3981 Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: Id4275f146e85befa29c7465804159496afc4be97 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1218691 Unity-Result: CUE porcuepine <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Daniel Martí <[email protected]>
1 parent f309265 commit d987d88

File tree

5 files changed

+51
-151
lines changed

5 files changed

+51
-151
lines changed

internal/core/adt/constraints.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func (n *nodeContext) insertConstraint(pattern Value, c Conjunct) bool {
104104
src := x.CloseInfo.defID
105105
dst := c.CloseInfo.defID
106106
found = true
107-
n.addReplacement(replaceID{from: dst, to: src, add: true})
107+
n.addReplacement(replaceID{from: dst, to: src})
108108
return false
109109
}
110110
return true

internal/core/adt/debug.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,6 @@ func (m *mermaidContext) vertexInfo(vc *mermaidVertex, recursive bool) {
450450
indentOnNewline(node, 3)
451451
dropID := fmt.Sprintf("%s_drop_%d", m.vertexID(v), i)
452452
flags := ""
453-
if r.add {
454-
flags = "+"
455-
}
456453
fmt.Fprintf(node, "%s((%d->%d%s))\n", dropID, r.from, r.to, flags)
457454
}
458455
indentOnNewline(node, 2)

internal/core/adt/fields.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func (v *Vertex) insertConjunct(ctx *OpContext, c Conjunct, id CloseInfo, mode A
217217
// be possible that different Vertices refer to the same conjuncts. In
218218
// this case, we need to ensure that the current defID also considers
219219
// the ID associated with the original insertion in its set.
220-
n.addReplacement(replaceID{from: id.defID, to: srcRef, add: true})
220+
n.addReplacement(replaceID{from: id.defID, to: srcRef})
221221
}
222222

223223
if v.isInProgress() {

internal/core/adt/typocheck.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ func (c conjunctFlags) hasEllipsis() bool {
262262
type replaceID struct {
263263
from defID
264264
to defID
265-
add bool // If true, add to the set. If false, replace from with to.
266265
}
267266

268267
func (n *nodeContext) addReplacement(x replaceID) {
@@ -366,7 +365,7 @@ func (n *nodeContext) addResolver(v *Vertex, id CloseInfo, forceIgnore bool) Clo
366365
// If we need to activate an enclosing embed group, and the added
367366
// resolver was already before, we need to allocate a new ID and
368367
// add the original ID to the set of the new one.
369-
n.addReplacement(replaceID{from: next, to: dstID, add: true})
368+
n.addReplacement(replaceID{from: next, to: dstID})
370369
}
371370
dstID = next
372371

@@ -383,7 +382,7 @@ func (n *nodeContext) addResolver(v *Vertex, id CloseInfo, forceIgnore bool) Clo
383382
srcID := id.defID
384383
id.defID = dstID
385384

386-
n.addReplacement(replaceID{from: srcID, to: dstID, add: true})
385+
n.addReplacement(replaceID{from: srcID, to: dstID})
387386

388387
return id
389388
}
@@ -400,7 +399,7 @@ func (c *OpContext) subField(ci CloseInfo) CloseInfo {
400399

401400
func (n *nodeContext) newReq(id CloseInfo, kind defIDType) CloseInfo {
402401
dstID := n.ctx.getNextDefID()
403-
n.addReplacement(replaceID{from: id.defID, to: dstID, add: true})
402+
n.addReplacement(replaceID{from: id.defID, to: dstID})
404403

405404
parent := id.defID
406405
id.defID = dstID
@@ -767,9 +766,6 @@ func (a *reqSets) replaceIDs(ctx *OpContext, b ...replaceID) {
767766
}
768767
for _, rule := range b {
769768
info := index[rule.from]
770-
if !rule.add {
771-
info.skip = true
772-
}
773769
if rule.to == deleteID {
774770
info.delete = true
775771
} else {

internal/core/adt/typocheck_test.go

Lines changed: 46 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -26,65 +26,13 @@ func TestReplaceIDs(t *testing.T) {
2626
replace []replaceID
2727
expected reqSets
2828
}{{
29-
name: "replace single set",
30-
reqSets: reqSets{
31-
{id: 1, size: 1},
32-
},
33-
replace: []replaceID{
34-
{from: 1, to: 2},
35-
},
36-
// The group was already added as a requirement, so the original group
37-
// should be deleted.
38-
expected: reqSets{},
39-
}, {
4029
name: "empty result",
4130
reqSets: reqSets{
4231
{id: 1, size: 1},
4332
},
4433
replace: []replaceID{
45-
{from: 1, to: deleteID, add: true},
46-
},
47-
}, {
48-
name: "replace first set",
49-
reqSets: reqSets{
50-
{id: 1, size: 2},
51-
{id: 2},
52-
{id: 3, size: 2},
53-
{id: 4},
54-
},
55-
replace: []replaceID{
56-
{from: 1, to: 5},
57-
},
58-
expected: reqSets{
59-
{id: 3, size: 2},
60-
{id: 4},
61-
},
62-
}, {
63-
name: "replace last set",
64-
reqSets: reqSets{
65-
{id: 1, size: 2},
66-
{id: 2},
67-
{id: 3, size: 2},
68-
{id: 4},
69-
},
70-
replace: []replaceID{
71-
{from: 3, to: 5},
72-
},
73-
expected: reqSets{
74-
{id: 1, size: 2},
75-
{id: 2},
76-
},
77-
}, {
78-
name: "replace multiple ids",
79-
reqSets: reqSets{
80-
{id: 1, size: 1},
81-
{id: 2, size: 1},
82-
},
83-
replace: []replaceID{
84-
{from: 1, to: 3},
85-
{from: 2, to: 4},
34+
{from: 1, to: deleteID},
8635
},
87-
expected: reqSets{},
8836
}, {
8937
name: "replace with zero id",
9038
reqSets: reqSets{
@@ -141,7 +89,7 @@ func TestReplaceIDs(t *testing.T) {
14189
{id: 1, size: 1},
14290
},
14391
replace: []replaceID{
144-
{from: 1, to: 2, add: true},
92+
{from: 1, to: 2},
14593
},
14694
expected: reqSets{
14795
{id: 1, size: 2},
@@ -154,8 +102,8 @@ func TestReplaceIDs(t *testing.T) {
154102
{id: 3, size: 1},
155103
},
156104
replace: []replaceID{
157-
{from: 3, to: 4, add: true},
158-
{from: 1, to: 2, add: true},
105+
{from: 3, to: 4},
106+
{from: 1, to: 2},
159107
},
160108
expected: reqSets{
161109
{id: 1, size: 2},
@@ -167,7 +115,7 @@ func TestReplaceIDs(t *testing.T) {
167115
name: "add new id to empty set",
168116
reqSets: reqSets{},
169117
replace: []replaceID{
170-
{from: 0, to: 1, add: true},
118+
{from: 0, to: 1},
171119
},
172120
expected: reqSets{},
173121
}, {
@@ -176,7 +124,7 @@ func TestReplaceIDs(t *testing.T) {
176124
{id: 1, size: 1},
177125
},
178126
replace: []replaceID{
179-
{from: 2, to: 3, add: true},
127+
{from: 2, to: 3},
180128
},
181129
expected: reqSets{
182130
{id: 1, size: 1},
@@ -188,7 +136,7 @@ func TestReplaceIDs(t *testing.T) {
188136
{id: 3, size: 1},
189137
},
190138
replace: []replaceID{
191-
{from: 1, to: 2, add: true},
139+
{from: 1, to: 2},
192140
{from: 1, to: deleteID},
193141
},
194142
expected: reqSets{
@@ -202,7 +150,7 @@ func TestReplaceIDs(t *testing.T) {
202150
},
203151
replace: []replaceID{
204152
{from: 1, to: deleteID},
205-
{from: 1, to: 2, add: true},
153+
{from: 1, to: 2},
206154
},
207155
expected: reqSets{
208156
{id: 3, size: 1},
@@ -215,9 +163,9 @@ func TestReplaceIDs(t *testing.T) {
215163
{id: 1},
216164
},
217165
replace: []replaceID{
218-
{from: 1, to: 2, add: true},
219-
{from: 2, to: 3, add: true},
220-
{from: 3, to: 4, add: true},
166+
{from: 1, to: 2},
167+
{from: 2, to: 3},
168+
{from: 3, to: 4},
221169
},
222170
expected: reqSets{
223171
{id: 1, size: 4},
@@ -236,9 +184,9 @@ func TestReplaceIDs(t *testing.T) {
236184
{id: 1, size: 1},
237185
},
238186
replace: []replaceID{
239-
{from: 1, to: 3, add: true},
240-
{from: 2, to: 1, add: true},
241-
{from: 3, to: 2, add: true},
187+
{from: 1, to: 3},
188+
{from: 2, to: 1},
189+
{from: 3, to: 2},
242190
},
243191
expected: reqSets{
244192
{id: 4, size: 1},
@@ -256,9 +204,9 @@ func TestReplaceIDs(t *testing.T) {
256204
{id: 1},
257205
},
258206
replace: []replaceID{
259-
{from: 1, to: 3, add: true},
260-
{from: 2, to: 1, add: true},
261-
{from: 3, to: 2, add: true},
207+
{from: 1, to: 3},
208+
{from: 2, to: 1},
209+
{from: 3, to: 2},
262210
},
263211
expected: reqSets{
264212
{id: 1, size: 3},
@@ -269,47 +217,6 @@ func TestReplaceIDs(t *testing.T) {
269217
{id: 3},
270218
{id: 2},
271219
},
272-
}, {
273-
name: "add and drop",
274-
reqSets: reqSets{
275-
// A main group needs to be fully deleted in case of a replacement.
276-
// This corresponds to that #B can be dropped as a requirement
277-
// for `c` in `#B: c: #A` when replacing it with #A.
278-
{id: 1, size: 1}, // add to this set.
279-
{id: 2, size: 2}, // drop this set.
280-
// A replacement of an equivalent id should just add the new id.
281-
// This corresponds to embeddings being additive.
282-
{id: 1},
283-
},
284-
replace: []replaceID{
285-
// A main group needs to be fully deleted in case of a replacement.
286-
// This corresponds to that #B can be dropped as a requirement
287-
// for `c` in `#B: c: #A` when replacing it with #A.
288-
{from: 1, to: 3, add: true},
289-
// A replacement of an equivalent id should just add the new id.
290-
// This corresponds to embeddings being additive.
291-
{from: 2, to: 3},
292-
},
293-
expected: reqSets{
294-
{id: 1, size: 2},
295-
{id: 3},
296-
},
297-
}, {
298-
name: "drop and add",
299-
reqSets: reqSets{
300-
{id: 1, size: 1},
301-
{id: 2, size: 2},
302-
{id: 1},
303-
},
304-
replace: []replaceID{
305-
{from: 1, to: 3},
306-
{from: 1, to: 3, add: true},
307-
},
308-
expected: reqSets{
309-
{id: 2, size: 3},
310-
{id: 1},
311-
{id: 3},
312-
},
313220
}, {
314221
name: "cycle",
315222
reqSets: []reqSet{
@@ -319,11 +226,11 @@ func TestReplaceIDs(t *testing.T) {
319226
{id: 4, size: 1, embed: 2},
320227
},
321228
replace: []replaceID{
322-
{from: 1, to: 2, add: true}, // , headOnly: true},
323-
{from: 2, to: 3, add: true},
324-
{from: 2, to: 4, add: true},
325-
{from: 3, to: 1, add: true},
326-
{from: 4, to: 1, add: true},
229+
{from: 1, to: 2}, // , headOnly: true},
230+
{from: 2, to: 3},
231+
{from: 2, to: 4},
232+
{from: 3, to: 1},
233+
{from: 4, to: 1},
327234
},
328235
expected: reqSets{
329236
{id: 1, size: 4},
@@ -345,9 +252,9 @@ func TestReplaceIDs(t *testing.T) {
345252
{id: 3, size: 1, embed: 2},
346253
},
347254
replace: []replaceID{
348-
{from: 1, to: 2, add: true},
349-
{from: 2, to: 3, add: true},
350-
{from: 3, to: 1, add: true},
255+
{from: 1, to: 2},
256+
{from: 2, to: 3},
257+
{from: 3, to: 1},
351258
},
352259
expected: reqSets{
353260
{id: 3, size: 2, embed: 2},
@@ -362,11 +269,11 @@ func TestReplaceIDs(t *testing.T) {
362269
{id: 8, size: 1, embed: 6},
363270
},
364271
replace: []replaceID{
365-
{from: 5, to: 6, add: true},
366-
{from: 6, to: 7, add: true},
367-
{from: 6, to: 8, add: true},
368-
{from: 7, to: 0, add: true},
369-
{from: 8, to: 0, add: true},
272+
{from: 5, to: 6},
273+
{from: 6, to: 7},
274+
{from: 6, to: 8},
275+
{from: 7, to: 0},
276+
{from: 8, to: 0},
370277
},
371278
expected: reqSets{
372279
{id: 5, size: 4},
@@ -389,12 +296,12 @@ func TestReplaceIDs(t *testing.T) {
389296
{id: 9, size: 1, embed: 7},
390297
},
391298
replace: []replaceID{
392-
{from: 5, to: 6, add: true},
393-
{from: 6, to: 7, add: true},
394-
{from: 7, to: 8, add: true},
395-
{from: 7, to: 9, add: true},
396-
{from: 8, to: 6, add: true},
397-
{from: 9, to: 6, add: true},
299+
{from: 5, to: 6},
300+
{from: 6, to: 7},
301+
{from: 7, to: 8},
302+
{from: 7, to: 9},
303+
{from: 8, to: 6},
304+
{from: 9, to: 6},
398305
},
399306
expected: reqSets{
400307
{id: 5, size: 5},
@@ -427,16 +334,16 @@ func TestReplaceIDs(t *testing.T) {
427334
{id: 14, size: 1, embed: 10},
428335
},
429336
replace: []replaceID{
430-
{from: 8, to: 9, add: true},
431-
{from: 8, to: 10, add: true},
432-
{from: 9, to: 11, add: true},
433-
{from: 11, to: 8, add: true},
434-
{from: 9, to: 12, add: true},
435-
{from: 12, to: 8, add: true},
436-
{from: 10, to: 13, add: true},
437-
{from: 13, to: 8, add: true},
438-
{from: 10, to: 14, add: true},
439-
{from: 14, to: 8, add: true},
337+
{from: 8, to: 9},
338+
{from: 8, to: 10},
339+
{from: 9, to: 11},
340+
{from: 11, to: 8},
341+
{from: 9, to: 12},
342+
{from: 12, to: 8},
343+
{from: 10, to: 13},
344+
{from: 13, to: 8},
345+
{from: 10, to: 14},
346+
{from: 14, to: 8},
440347
},
441348
expected: reqSets{
442349
{id: 8, size: 7},

0 commit comments

Comments
 (0)