mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 16:47:28 +01:00
Don't suspend/resume unnecessary local variables
name old speed new speed delta wuffs_adler32_10k/clang 2.42GB/s ± 1% 2.41GB/s ± 0% -0.43% (p=0.000 n=49+10) wuffs_adler32_100k/clang 2.42GB/s ± 1% 2.41GB/s ± 1% -0.56% (p=0.000 n=48+10) wuffs_adler32_10k/gcc 3.22GB/s ± 1% 3.21GB/s ± 0% -0.35% (p=0.000 n=48+10) wuffs_adler32_100k/gcc 3.22GB/s ± 0% 3.20GB/s ± 0% -0.69% (p=0.000 n=48+10) wuffs_crc32_ieee_10k/clang 2.86GB/s ± 0% 2.85GB/s ± 0% -0.44% (p=0.000 n=48+9) wuffs_crc32_ieee_100k/clang 2.88GB/s ± 1% 2.87GB/s ± 0% -0.45% (p=0.000 n=49+10) wuffs_crc32_ieee_10k/gcc 3.35GB/s ± 1% 3.35GB/s ± 0% ~ (p=0.094 n=48+9) wuffs_crc32_ieee_100k/gcc 3.38GB/s ± 1% 3.38GB/s ± 1% ~ (p=0.371 n=45+10) wuffs_deflate_decode_1k/clang 147MB/s ± 1% 137MB/s ± 1% -6.84% (p=0.000 n=50+10) wuffs_deflate_decode_10k/clang 241MB/s ± 0% 227MB/s ± 0% -5.74% (p=0.000 n=48+9) wuffs_deflate_decode_100k/clang 269MB/s ± 0% 258MB/s ± 0% -3.92% (p=0.000 n=49+9) wuffs_deflate_decode_1k/gcc 159MB/s ± 0% 161MB/s ± 1% +1.51% (p=0.000 n=49+10) wuffs_deflate_decode_10k/gcc 269MB/s ± 0% 276MB/s ± 0% +2.51% (p=0.000 n=49+10) wuffs_deflate_decode_100k/gcc 320MB/s ± 0% 316MB/s ± 0% -1.29% (p=0.000 n=46+10) wuffs_gif_decode_1k_bw/clang 252MB/s ± 1% 264MB/s ± 0% +4.56% (p=0.000 n=49+10) wuffs_gif_decode_1k_color/clang 127MB/s ± 1% 122MB/s ± 1% -3.84% (p=0.000 n=47+10) wuffs_gif_decode_10k/clang 152MB/s ± 0% 148MB/s ± 0% -3.12% (p=0.000 n=47+9) wuffs_gif_decode_100k_artificial/clang 431MB/s ± 0% 443MB/s ± 1% +2.95% (p=0.000 n=42+10) wuffs_gif_decode_100k_realistic/clang 170MB/s ± 0% 173MB/s ± 0% +1.39% (p=0.000 n=48+10) wuffs_gif_decode_1000k/clang 172MB/s ± 0% 174MB/s ± 0% +1.27% (p=0.000 n=48+10) wuffs_gif_decode_anim_screencap/clang 917MB/s ± 1% 949MB/s ± 0% +3.44% (p=0.000 n=47+9) wuffs_gif_decode_1k_bw/gcc 265MB/s ± 1% 278MB/s ± 2% +4.87% (p=0.000 n=48+10) wuffs_gif_decode_1k_color/gcc 135MB/s ± 0% 140MB/s ± 2% +4.10% (p=0.000 n=46+10) wuffs_gif_decode_10k/gcc 157MB/s ± 1% 166MB/s ± 0% +5.84% (p=0.000 n=48+8) wuffs_gif_decode_100k_artificial/gcc 446MB/s ± 1% 459MB/s ± 1% +2.89% (p=0.000 n=48+10) wuffs_gif_decode_100k_realistic/gcc 176MB/s ± 0% 186MB/s ± 2% +5.82% (p=0.000 n=46+10) wuffs_gif_decode_1000k/gcc 178MB/s ± 0% 189MB/s ± 1% +6.11% (p=0.000 n=45+9) wuffs_gif_decode_anim_screencap/gcc 962MB/s ± 1% 989MB/s ± 1% +2.83% (p=0.000 n=48+9) wuffs_gzip_decode_10k/clang 212MB/s ± 0% 208MB/s ± 0% -1.67% (p=0.000 n=47+10) wuffs_gzip_decode_100k/clang 240MB/s ± 0% 236MB/s ± 0% -1.68% (p=0.000 n=47+10) wuffs_gzip_decode_10k/gcc 252MB/s ± 0% 246MB/s ± 0% -2.41% (p=0.000 n=47+10) wuffs_gzip_decode_100k/gcc 290MB/s ± 0% 288MB/s ± 0% -0.70% (p=0.000 n=44+10) wuffs_lzw_decode_20k/clang 202MB/s ± 0% 202MB/s ± 0% ~ (p=0.069 n=48+8) wuffs_lzw_decode_100k/clang 332MB/s ± 1% 334MB/s ± 1% +0.54% (p=0.000 n=46+10) wuffs_lzw_decode_20k/gcc 215MB/s ± 1% 223MB/s ± 0% +3.60% (p=0.000 n=49+9) wuffs_lzw_decode_100k/gcc 361MB/s ± 1% 368MB/s ± 0% +2.05% (p=0.000 n=47+10) wuffs_zlib_decode_10k/clang 218MB/s ± 0% 206MB/s ± 0% -5.53% (p=0.000 n=48+9) wuffs_zlib_decode_100k/clang 244MB/s ± 0% 234MB/s ± 0% -4.14% (p=0.000 n=45+10) wuffs_zlib_decode_10k/gcc 252MB/s ± 0% 252MB/s ± 0% ~ (p=0.960 n=49+10) wuffs_zlib_decode_100k/gcc 290MB/s ± 0% 292MB/s ± 0% +0.52% (p=0.000 n=49+10)
This commit is contained in:
1 parent
808d5c1e6c
commit
6ebe99ced9
6 files changed
+507
-125
No files matched your search
@@ -689,7 +689,7 @@ func (g *gen) writeStruct(b *buffer, n *a.Struct) error {
|
||||
b.writes("struct {\n")
|
||||
if k.coroSuspPoint != 0 {
|
||||
b.writes("uint32_t coro_susp_point;\n")
|
||||
if err := g.writeVars(b, o.Body(), true, true); err != nil {
|
||||
if err := g.writeVars(b, &k, true, true, true); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@ type funk struct {
|
||||
|
||||
astFunc *a.Func
|
||||
cName string
|
||||
varList []*a.Var
|
||||
varResumables map[t.ID]bool
|
||||
derivedVars map[t.ID]struct{}
|
||||
jumpTargets map[a.Loop]uint32
|
||||
coroSuspPoint uint32
|
||||
@@ -180,6 +182,10 @@ func (g *gen) gatherFuncImpl(_ *buffer, n *a.Func) error {
|
||||
suspendible: n.Effect().Coroutine(),
|
||||
}
|
||||
|
||||
if err := g.findVars(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := g.writeFuncImplHeader(&g.currFunk.bHeader); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -259,7 +265,7 @@ func (g *gen) writeFuncImplHeader(b *buffer) error {
|
||||
b.writes("\n")
|
||||
|
||||
// Generate the local variables.
|
||||
if err := g.writeVars(b, g.currFunk.astFunc.Body(), false, true); err != nil {
|
||||
if err := g.writeVars(b, &g.currFunk, false, true, false); err != nil {
|
||||
return err
|
||||
}
|
||||
b.writes("\n")
|
||||
@@ -283,11 +289,11 @@ func (g *gen) writeFuncImplBodyResume(b *buffer) error {
|
||||
b.printf("uint32_t coro_susp_point = self->private_impl.%s%s[0].coro_susp_point;\n",
|
||||
cPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
|
||||
b.printf("if (coro_susp_point) {\n")
|
||||
if err := g.writeResumeSuspend(b, g.currFunk.astFunc.Body(), false, false); err != nil {
|
||||
if err := g.writeResumeSuspend(b, &g.currFunk, false, false); err != nil {
|
||||
return err
|
||||
}
|
||||
b.writes("} else {\n")
|
||||
if err := g.writeResumeSuspend(b, g.currFunk.astFunc.Body(), false, true); err != nil {
|
||||
if err := g.writeResumeSuspend(b, &g.currFunk, false, true); err != nil {
|
||||
return err
|
||||
}
|
||||
b.writes("}\n")
|
||||
@@ -323,7 +329,7 @@ func (g *gen) writeFuncImplBodySuspend(b *buffer) error {
|
||||
|
||||
b.printf("self->private_impl.%s%s[0].coro_susp_point = coro_susp_point;\n",
|
||||
cPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
|
||||
if err := g.writeResumeSuspend(b, g.currFunk.astFunc.Body(), true, false); err != nil {
|
||||
if err := g.writeResumeSuspend(b, &g.currFunk, true, false); err != nil {
|
||||
return err
|
||||
}
|
||||
b.writes("\n")
|
||||
|
||||
@@ -0,0 +1,427 @@
|
||||
// Copyright 2018 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package cgen
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
a "github.com/google/wuffs/lang/ast"
|
||||
t "github.com/google/wuffs/lang/token"
|
||||
)
|
||||
|
||||
type subExprFilter uint32
|
||||
|
||||
const (
|
||||
subExprFilterNone = subExprFilter(0)
|
||||
subExprFilterBeforeCoroutine = subExprFilter(1)
|
||||
subExprFilterDuringCoroutine = subExprFilter(2)
|
||||
subExprFilterAfterCoroutine = subExprFilter(3)
|
||||
)
|
||||
|
||||
type resumability uint32
|
||||
|
||||
const (
|
||||
resumabilityNone = resumability(0)
|
||||
resumabilityWeak = resumability(1)
|
||||
resumabilityStrong = resumability(2)
|
||||
)
|
||||
|
||||
type resumabilities []resumability
|
||||
|
||||
func (r resumabilities) clone() resumabilities {
|
||||
return append(resumabilities(nil), r...)
|
||||
}
|
||||
|
||||
func (r resumabilities) merge(s resumabilities) (changed bool) {
|
||||
if len(r) != len(s) {
|
||||
panic("resumabilities have different length")
|
||||
}
|
||||
for i := range r {
|
||||
if r[i] < s[i] {
|
||||
r[i] = s[i]
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
return changed
|
||||
}
|
||||
|
||||
func (r resumabilities) lowerWeakToNone(i int) {
|
||||
if r[i] == resumabilityWeak {
|
||||
r[i] = resumabilityNone
|
||||
}
|
||||
}
|
||||
|
||||
func (r resumabilities) raiseWeakToStrong(i int) {
|
||||
if r[i] == resumabilityWeak {
|
||||
r[i] = resumabilityStrong
|
||||
}
|
||||
}
|
||||
|
||||
func (r resumabilities) raiseNoneToWeak() {
|
||||
for i, x := range r {
|
||||
if x == resumabilityNone {
|
||||
r[i] = resumabilityWeak
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type loopResumable struct {
|
||||
before resumabilities
|
||||
after resumabilities
|
||||
changed bool
|
||||
}
|
||||
|
||||
type resumabilityHelper struct {
|
||||
tm *t.Map
|
||||
vars map[t.ID]int
|
||||
loops map[a.Loop]*loopResumable
|
||||
}
|
||||
|
||||
func (g *gen) findVars() error {
|
||||
h := resumabilityHelper{
|
||||
tm: g.tm,
|
||||
vars: map[t.ID]int{},
|
||||
loops: map[a.Loop]*loopResumable{},
|
||||
}
|
||||
|
||||
f := g.currFunk.astFunc
|
||||
if err := g.visitVars(nil, f.Body(), 0, func(g *gen, b *buffer, n *a.Var) error {
|
||||
name := n.Name()
|
||||
if _, ok := h.vars[name]; !ok {
|
||||
g.currFunk.varList = append(g.currFunk.varList, n)
|
||||
h.vars[name] = len(h.vars)
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if f.Effect().Coroutine() {
|
||||
r := make(resumabilities, len(h.vars))
|
||||
if err := h.doBlock(r, f.Body(), 0); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
g.currFunk.varResumables = map[t.ID]bool{}
|
||||
for i, v := range g.currFunk.varList {
|
||||
g.currFunk.varResumables[v.Name()] = r[i] == resumabilityStrong
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *resumabilityHelper) doBlock(r resumabilities, block []*a.Node, depth uint32) error {
|
||||
if depth > a.MaxBodyDepth {
|
||||
return fmt.Errorf("body recursion depth too large")
|
||||
}
|
||||
depth++
|
||||
|
||||
loop:
|
||||
for _, o := range block {
|
||||
switch o.Kind() {
|
||||
case a.KAssign:
|
||||
if err := h.doAssign(r, o.AsAssign(), depth); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
case a.KExpr:
|
||||
if err := h.doExpr(r, o.AsExpr()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
case a.KIOBind:
|
||||
if err := h.doIOBind(r, o.AsIOBind(), depth); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
case a.KIf:
|
||||
if err := h.doIf(r, o.AsIf(), depth); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
case a.KIterate:
|
||||
if err := h.doIterate(r, o.AsIterate(), depth); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
case a.KJump:
|
||||
if err := h.doJump(r, o.AsJump(), depth); err != nil {
|
||||
return err
|
||||
}
|
||||
break loop
|
||||
|
||||
case a.KRet:
|
||||
if err := h.doRet(r, o.AsRet(), depth); err != nil {
|
||||
return err
|
||||
}
|
||||
if o.AsRet().Keyword() == t.IDReturn {
|
||||
break loop
|
||||
}
|
||||
|
||||
case a.KVar:
|
||||
if err := h.doVar(r, o.AsVar(), depth); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
case a.KWhile:
|
||||
if err := h.doWhile(r, o.AsWhile(), depth); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *resumabilityHelper) doAssign(r resumabilities, n *a.Assign, depth uint32) error {
|
||||
if err := h.doExpr(r, n.RHS()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// If the LHS is not a local variable (e.g. "this.foo[bar] = etc", or if
|
||||
// the LHS is implicitly also on the RHS (e.g. for a += or *= operator),
|
||||
// walk the LHS Expr.
|
||||
if n.LHS().Operator() != 0 || n.Operator() != t.IDEq {
|
||||
if err := h.doExpr(r, n.LHS()); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// If the LHS is just a local variable, then call lowerWeakToNone.
|
||||
if lhs := n.LHS(); lhs.Operator() == 0 {
|
||||
if i, ok := h.vars[lhs.Ident()]; !ok {
|
||||
return fmt.Errorf("unrecognized variable %q", lhs.Ident().Str(h.tm))
|
||||
} else {
|
||||
r.lowerWeakToNone(i)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *resumabilityHelper) doExpr(r resumabilities, n *a.Expr) error {
|
||||
if n.Effect()&a.EffectCoroutine == 0 {
|
||||
return h.doExpr1(r, n, subExprFilterNone, 0)
|
||||
}
|
||||
for sef := subExprFilterBeforeCoroutine; sef <= subExprFilterAfterCoroutine; sef++ {
|
||||
if err := h.doExpr1(r, n, sef, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *resumabilityHelper) doExpr1(r resumabilities, n *a.Expr, sef subExprFilter, depth uint32) error {
|
||||
if depth > a.MaxBodyDepth {
|
||||
return fmt.Errorf("body recursion depth too large")
|
||||
}
|
||||
depth++
|
||||
|
||||
processOnlySubExprs := false
|
||||
if sef != subExprFilterNone {
|
||||
const mask = a.EffectCoroutine | a.EffectRootCause
|
||||
switch sef {
|
||||
case subExprFilterBeforeCoroutine:
|
||||
switch n.Effect() & mask {
|
||||
case a.EffectCoroutine | a.EffectRootCause:
|
||||
sef = subExprFilterNone
|
||||
case a.EffectCoroutine:
|
||||
// No-op.
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
processOnlySubExprs = true
|
||||
|
||||
case subExprFilterDuringCoroutine:
|
||||
if n.Effect()&mask == mask {
|
||||
switch n.Operator() {
|
||||
case t.IDOpenParen:
|
||||
r.raiseNoneToWeak()
|
||||
case t.IDTry:
|
||||
// No-op.
|
||||
default:
|
||||
return fmt.Errorf("unrecognized ast.Expr coroutine operator")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
processOnlySubExprs = true
|
||||
|
||||
case subExprFilterAfterCoroutine:
|
||||
if n.Effect()&mask == mask {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, o := range n.AsNode().AsRaw().SubNodes() {
|
||||
if o != nil && o.Kind() == a.KExpr {
|
||||
if err := h.doExpr1(r, o.AsExpr(), sef, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, o := range n.Args() {
|
||||
e := (*a.Expr)(nil)
|
||||
switch o.Kind() {
|
||||
case a.KArg:
|
||||
e = o.AsArg().Value()
|
||||
case a.KExpr:
|
||||
e = o.AsExpr()
|
||||
default:
|
||||
return fmt.Errorf("unrecognized arg kind")
|
||||
}
|
||||
if err := h.doExpr1(r, e, sef, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if !processOnlySubExprs && n.Operator() == 0 {
|
||||
if i, ok := h.vars[n.Ident()]; ok {
|
||||
r.raiseWeakToStrong(i)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *resumabilityHelper) doIOBind(r resumabilities, n *a.IOBind, depth uint32) error {
|
||||
// Ignore the IOBind fields, as they should be I/O types and therefore not
|
||||
// resumable.
|
||||
return h.doBlock(r, n.Body(), depth)
|
||||
}
|
||||
|
||||
func (h *resumabilityHelper) doIf(r resumabilities, n *a.If, depth uint32) error {
|
||||
scratch := make(resumabilities, len(r))
|
||||
result := make(resumabilities, len(r))
|
||||
for ; n != nil; n = n.ElseIf() {
|
||||
if err := h.doExpr(r, n.Condition()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
copy(scratch, r)
|
||||
if err := h.doBlock(scratch, n.BodyIfTrue(), depth); err != nil {
|
||||
return err
|
||||
}
|
||||
result.merge(scratch)
|
||||
|
||||
copy(scratch, r)
|
||||
if err := h.doBlock(scratch, n.BodyIfFalse(), depth); err != nil {
|
||||
return err
|
||||
}
|
||||
result.merge(scratch)
|
||||
}
|
||||
copy(r, result)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *resumabilityHelper) doIterate(r resumabilities, n *a.Iterate, depth uint32) error {
|
||||
// TODO: ban jumps, rets and coroutine calls inside an iterate. Also ensure
|
||||
// that the iterate variable values are all pure expressions.
|
||||
for _, v := range n.Variables() {
|
||||
v := v.AsVar()
|
||||
if err := h.doExpr(r, v.Value()); err != nil {
|
||||
return err
|
||||
}
|
||||
if i, ok := h.vars[v.Name()]; !ok {
|
||||
return fmt.Errorf("unrecognized variable %q", v.Name().Str(h.tm))
|
||||
} else {
|
||||
r.lowerWeakToNone(i)
|
||||
}
|
||||
}
|
||||
return h.doBlock(r, n.Body(), depth)
|
||||
}
|
||||
|
||||
func (h *resumabilityHelper) doJump(r resumabilities, n *a.Jump, depth uint32) error {
|
||||
l := h.loops[n.JumpTarget()]
|
||||
switch n.Keyword() {
|
||||
case t.IDBreak:
|
||||
l.changed = l.before.merge(r) || l.changed
|
||||
case t.IDContinue:
|
||||
l.changed = l.after.merge(r) || l.changed
|
||||
default:
|
||||
return fmt.Errorf("unrecognized ast.Jump keyword")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *resumabilityHelper) doRet(r resumabilities, n *a.Ret, depth uint32) error {
|
||||
if n.Value() != nil {
|
||||
if err := h.doExpr(r, n.Value()); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
switch n.Keyword() {
|
||||
case t.IDReturn:
|
||||
// No-op.
|
||||
case t.IDYield:
|
||||
r.raiseNoneToWeak()
|
||||
default:
|
||||
return fmt.Errorf("unrecognized ast.Ret keyword")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *resumabilityHelper) doVar(r resumabilities, n *a.Var, depth uint32) error {
|
||||
if n.Value() != nil {
|
||||
if err := h.doExpr(r, n.Value()); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
name := n.Name()
|
||||
if i, ok := h.vars[name]; !ok {
|
||||
return fmt.Errorf("unrecognized variable %q", name.Str(h.tm))
|
||||
} else {
|
||||
r.lowerWeakToNone(i)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *resumabilityHelper) doWhile(r resumabilities, n *a.While, depth uint32) error {
|
||||
l := &loopResumable{
|
||||
before: make(resumabilities, len(r)),
|
||||
after: make(resumabilities, len(r)),
|
||||
changed: false,
|
||||
}
|
||||
h.loops[n] = l
|
||||
|
||||
copy(l.before, r)
|
||||
if err := h.doExpr(r, n.Condition()); err != nil {
|
||||
return err
|
||||
}
|
||||
copy(l.after, r)
|
||||
|
||||
for {
|
||||
copy(r, l.after)
|
||||
if err := h.doBlock(r, n.Body(), depth); err != nil {
|
||||
return err
|
||||
}
|
||||
l.changed = l.before.merge(r) || l.changed
|
||||
|
||||
copy(r, l.before)
|
||||
if err := h.doExpr(r, n.Condition()); err != nil {
|
||||
return err
|
||||
}
|
||||
l.changed = l.after.merge(r) || l.changed
|
||||
|
||||
if !l.changed {
|
||||
break
|
||||
}
|
||||
l.changed = false
|
||||
}
|
||||
|
||||
copy(r, l.after)
|
||||
return nil
|
||||
}
|
||||
@@ -271,7 +271,7 @@ func (g *gen) visitVars(b *buffer, block []*a.Node, depth uint32, f func(*gen, *
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *gen) writeResumeSuspend1(b *buffer, n *a.Var, suspend bool, initBoolTypedVars bool) error {
|
||||
func (g *gen) writeResumeSuspend1(b *buffer, f *funk, n *a.Var, suspend bool, initBoolTypedVars bool) error {
|
||||
local := fmt.Sprintf("%s%s", vPrefix, n.Name().Str(g.tm))
|
||||
|
||||
if typ := n.XType(); typ.HasPointers() {
|
||||
@@ -300,6 +300,25 @@ func (g *gen) writeResumeSuspend1(b *buffer, n *a.Var, suspend bool, initBoolTyp
|
||||
return nil
|
||||
}
|
||||
|
||||
} else if f.varResumables == nil || !f.varResumables[n.Name()] {
|
||||
if !suspend {
|
||||
if initBoolTypedVars && typ.QID() == (t.QID{t.IDBase, t.IDBool}) {
|
||||
b.printf("%s = false;\n", local)
|
||||
return nil
|
||||
}
|
||||
// TODO: drop this (after we stop emitting unnecessary
|
||||
// WUFFS_BASE__COROUTINE_SUSPENSION_POINT lines); we shouldn't need
|
||||
// to zero-initialize these variables.
|
||||
if !initBoolTypedVars {
|
||||
zero := "0"
|
||||
if typ.QID() == (t.QID{t.IDBase, t.IDBool}) {
|
||||
zero = "false"
|
||||
}
|
||||
b.printf("%s = %s;\n", local, zero)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
} else {
|
||||
lhs := local
|
||||
rhs := ""
|
||||
@@ -363,14 +382,14 @@ fail:
|
||||
n.Name().Str(g.tm), n.XType().Str(g.tm))
|
||||
}
|
||||
|
||||
func (g *gen) writeResumeSuspend(b *buffer, block []*a.Node, suspend bool, initBoolTypedVars bool) error {
|
||||
return g.visitVars(b, block, 0, func(g *gen, b *buffer, n *a.Var) error {
|
||||
return g.writeResumeSuspend1(b, n, suspend, initBoolTypedVars)
|
||||
func (g *gen) writeResumeSuspend(b *buffer, f *funk, suspend bool, initBoolTypedVars bool) error {
|
||||
return g.visitVars(b, f.astFunc.Body(), 0, func(g *gen, b *buffer, n *a.Var) error {
|
||||
return g.writeResumeSuspend1(b, f, n, suspend, initBoolTypedVars)
|
||||
})
|
||||
}
|
||||
|
||||
func (g *gen) writeVars(b *buffer, block []*a.Node, skipPointerTypes bool, skipIterateVariables bool) error {
|
||||
return g.visitVars(b, block, 0, func(g *gen, b *buffer, n *a.Var) error {
|
||||
func (g *gen) writeVars(b *buffer, f *funk, skipPointerTypes bool, skipIterateVariables bool, skipNonresumable bool) error {
|
||||
return g.visitVars(b, f.astFunc.Body(), 0, func(g *gen, b *buffer, n *a.Var) error {
|
||||
typ := n.XType()
|
||||
if skipPointerTypes && typ.HasPointers() {
|
||||
return nil
|
||||
@@ -378,6 +397,9 @@ func (g *gen) writeVars(b *buffer, block []*a.Node, skipPointerTypes bool, skipI
|
||||
if skipIterateVariables && n.IterateVariable() {
|
||||
return nil
|
||||
}
|
||||
if skipNonresumable && (f.varResumables == nil || !f.varResumables[n.Name()]) {
|
||||
return nil
|
||||
}
|
||||
name := n.Name().Str(g.tm)
|
||||
if err := g.writeCTypeName(b, typ, vPrefix, name); err != nil {
|
||||
return err
|
||||
|
||||
Reference in new issue
Block a user