Skip to content

Commit ed336a2

Browse files
committed
name/sortedname: Fix wrong sort inference.
Value for sending should be NameSort not VarSort.
1 parent 92815dd commit ed336a2

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

name/sortedname/infer.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func InferSortsByUsage(p asyncpi.Process) error {
3232
if err := upgrade(p); err != nil {
3333
return errInferSort(errors.Wrap(err, "cannot upgrade process Names to SortedNames"))
3434
}
35-
nameVar := make(map[asyncpi.Name]bool)
35+
isVarSort := make(map[asyncpi.Name]bool)
3636
procs := []asyncpi.Process{p}
3737
for len(procs) > 0 {
3838
p, procs = procs[0], procs[1:]
@@ -45,7 +45,7 @@ func InferSortsByUsage(p asyncpi.Process) error {
4545
procs = append(procs, p.Procs...)
4646
case *asyncpi.Recv:
4747
for i := range p.Vars {
48-
nameVar[p.Vars[i]] = true
48+
isVarSort[p.Vars[i]] = true
4949
if s, canSetSort := p.Vars[i].(setter); canSetSort {
5050
s.SetSort(VarSort)
5151
} else {
@@ -55,17 +55,17 @@ func InferSortsByUsage(p asyncpi.Process) error {
5555
procs = append(procs, p.Cont)
5656
case *asyncpi.Send:
5757
for i := range p.Vals {
58-
if _, ok := nameVar[p.Vals[i]]; !ok {
59-
nameVar[p.Vals[i]] = true
58+
if _, ok := isVarSort[p.Vals[i]]; !ok { // if not seen
59+
isVarSort[p.Vals[i]] = false
6060
if s, canSetSort := p.Vals[i].(setter); canSetSort {
61-
s.SetSort(VarSort)
61+
s.SetSort(NameSort)
6262
} else {
6363
return errInferSort(asyncpi.ImmutableNameError{Name: p.Vals[i]})
6464
}
6565
}
6666
}
6767
case *asyncpi.Restrict:
68-
nameVar[p.Name] = false // new name = not var
68+
isVarSort[p.Name] = false // new name = not var
6969
procs = append(procs, p.Proc)
7070
default:
7171
return errInferSort(asyncpi.UnknownProcessError{Proc: p})

name/sortedname/sortedname_test.go

+6-10
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ func TestParSort(t *testing.T) {
4545
}
4646
t.Logf("fn(%s) = %s", p.Calculi(), p.FreeNames())
4747
t.Logf("fv(%s) = %s", p.Calculi(), p.FreeVars())
48-
if expect, got := 2, len(p.FreeNames()); expect != got {
48+
if expect, got := 5, len(p.FreeNames()); expect != got {
4949
t.Errorf("Expecting %s to have %d free names but got %d.",
5050
p.Calculi(), expect, got)
5151
}
52-
if expect, got := 3, len(p.FreeVars()); expect != got {
52+
if expect, got := 0, len(p.FreeVars()); expect != got {
5353
t.Errorf("Expecting %s to have %d free vars but got %d",
5454
p.Calculi(), expect, got)
5555
}
@@ -65,11 +65,11 @@ func TestParSortOverlap(t *testing.T) {
6565
}
6666
t.Logf("fn(%s) = %s", p.Calculi(), p.FreeNames())
6767
t.Logf("fv(%s) = %s", p.Calculi(), p.FreeVars())
68-
if expect, got := 1, len(p.FreeNames()); expect != got {
68+
if expect, got := 4, len(p.FreeNames()); expect != got {
6969
t.Errorf("Expecting %s to have %d free names but got %d.",
7070
p.Calculi(), expect, got)
7171
}
72-
if expect, got := 3, len(p.FreeVars()); expect != got {
72+
if expect, got := 0, len(p.FreeVars()); expect != got {
7373
t.Errorf("Expecting %s to have %d free vars but got %d.",
7474
p.Calculi(), expect, got)
7575
}
@@ -117,22 +117,18 @@ func TestSendSort(t *testing.T) {
117117
}
118118
t.Logf("fn(%s) = %s", p.Calculi(), p.FreeNames())
119119
t.Logf("fv(%s) = %s", p.Calculi(), p.FreeVars())
120-
if expect, got := 1, len(p.FreeNames()); expect != got {
120+
if expect, got := 2, len(p.FreeNames()); expect != got {
121121
t.Errorf("Expecting %s to have %d free names but got %d.",
122122
p.Calculi(), expect, got)
123123
}
124124
if p.FreeNames()[0] != p.Chan {
125125
t.Errorf("Expecting fn(%s) to be %s but got %s",
126126
p.Calculi(), p.Chan, p.FreeNames()[0])
127127
}
128-
if expect, got := 1, len(p.FreeVars()); expect != got {
128+
if expect, got := 0, len(p.FreeVars()); expect != got {
129129
t.Errorf("Expecting %s to have %d free vars but got %d",
130130
p.Calculi(), expect, got)
131131
}
132-
if p.FreeVars()[0] != p.Vals[0] {
133-
t.Errorf("Expecting fv(%s) to be %s but got %s",
134-
p.Calculi(), p.Vals[0], p.FreeVars()[0])
135-
}
136132
}
137133

138134
func TestRecvSort(t *testing.T) {

0 commit comments

Comments
 (0)