Add choose

wuffs_png_decode_filter_1_sub/clang9       905MB/s ± 0%  1339MB/s ± 0%  +48.05%  (p=0.008 n=5+5)
wuffs_png_decode_filter_1_sub/gcc10       1.12GB/s ± 0%  1.85GB/s ± 0%  +64.80%  (p=0.016 n=5+4)
This commit is contained in:
Nigel Tao committed 2021-01-06 23:16:16 +11:00
1 parent 364c396ae8
commit beaf3ef11f
11 files changed
+235 -22

No files matched your search

+3
View File
@@ -245,6 +245,9 @@ func (q *checker) bcheckStatement(n *a.Node) error {
return err
}
case a.KChoose:
// No-op.
case a.KIOBind:
n := n.AsIOBind()
if _, err := q.bcheckExpr(n.IO(), 0); err != nil {
+1
View File
@@ -34,6 +34,7 @@ var (
typeExprGeneric2 = a.NewTypeExpr(0, t.IDBase, t.IDDagger2, nil, nil, nil)
typeExprIdeal = a.NewTypeExpr(0, t.IDBase, t.IDQIdeal, nil, nil, nil)
typeExprList = a.NewTypeExpr(0, t.IDBase, t.IDComma, nil, nil, nil)
typeExprNonNullptr = a.NewTypeExpr(0, t.IDBase, t.IDQNonNullptr, nil, nil, nil)
typeExprNullptr = a.NewTypeExpr(0, t.IDBase, t.IDQNullptr, nil, nil, nil)
typeExprPackage = a.NewTypeExpr(0, t.IDBase, t.IDQPackage, nil, nil, nil)
typeExprPlaceholder = a.NewTypeExpr(0, t.IDBase, t.IDQPlaceholder, nil, nil, nil)
+28
View File
@@ -63,6 +63,11 @@ func (q *checker) tcheckStatement(n *a.Node) error {
return err
}
case a.KChoose:
if err := q.tcheckChoose(n.AsChoose()); err != nil {
return err
}
case a.KIf:
for n := n.AsIf(); n != nil; n = n.ElseIf() {
cond := n.Condition()
@@ -1061,6 +1066,29 @@ swtch:
return nil
}
func (q *checker) tcheckChoose(n *a.Choose) error {
qqid := q.astFunc.QQID()
fQQID := t.QQID{qqid[0], qqid[1], n.Name()}
f := q.c.funcs[fQQID]
if f == nil {
return fmt.Errorf("check: no function named %q", fQQID.Str(q.tm))
}
for _, o := range n.Args() {
o := o.AsExpr()
gQQID := t.QQID{qqid[0], qqid[1], o.Ident()}
g := q.c.funcs[gQQID]
if g == nil {
return fmt.Errorf("check: no function named %q", gQQID.Str(q.tm))
} else if err := f.CheckChooseCompatible(g); err != nil {
return fmt.Errorf("check: incompatible choose functions %q and %q: %v",
fQQID.Str(q.tm), gQQID.Str(q.tm), err)
}
o.SetMBounds(bounds{one, one})
o.SetMType(typeExprNonNullptr)
}
return nil
}
var comparisonOps = [...]bool{
t.IDXBinaryNotEq: true,
t.IDXBinaryLessThan: true,