From 85c4de47b990def743d8e94883733914b40ee523 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Sun, 8 Jul 2018 21:48:50 +1000 Subject: [PATCH] Remove ProvenNotToSuspend and BoundsCheckOptimized --- cmd/wuffs-c/internal/cgen/statement.go | 49 +--------------------- lang/ast/ast.go | 58 ++++++++------------------ 2 files changed, 19 insertions(+), 88 deletions(-) diff --git a/cmd/wuffs-c/internal/cgen/statement.go b/cmd/wuffs-c/internal/cgen/statement.go index 55afc7d3..3af9359d 100644 --- a/cmd/wuffs-c/internal/cgen/statement.go +++ b/cmd/wuffs-c/internal/cgen/statement.go @@ -15,7 +15,6 @@ package cgen import ( - "errors" "fmt" "strings" @@ -486,12 +485,7 @@ func (g *gen) writeSuspendibles(b *buffer, n *a.Expr, depth uint32) error { if !n.Suspendible() { return nil } - err := g.mightActuallySuspend(n, depth) - if err != nil && err != errMightActuallySuspend { - return err - } - mightActuallySuspend := err != nil - if mightActuallySuspend && n.Operator() != t.IDTry { + if n.Operator() != t.IDTry { if err := g.writeCoroSuspPoint(b, false); err != nil { return err } @@ -499,45 +493,6 @@ func (g *gen) writeSuspendibles(b *buffer, n *a.Expr, depth uint32) error { return g.writeCallSuspendibles(b, n, depth) } -// errMightActuallySuspend is the absence of ProvenNotToSuspend. -// -// TODO: find better, less clumsy names for this concept. -var errMightActuallySuspend = errors.New("internal: might actually suspend") - -// TODO: this would be simpler with a call keyword and an explicit "foo = call -// bar?()" syntax. -func (g *gen) mightActuallySuspend(n *a.Expr, depth uint32) error { - if depth > a.MaxExprDepth { - return fmt.Errorf("expression recursion depth too large") - } - depth++ - - // The evaluation order for suspendible calls (which can have side effects) - // is important here: LHS, MHS, RHS, Args and finally the node itself. - if !n.CallSuspendible() { - for _, o := range n.AsNode().AsRaw().SubNodes() { - if o != nil && o.Kind() == a.KExpr { - if err := g.mightActuallySuspend(o.AsExpr(), depth); err != nil { - return err - } - } - } - for _, o := range n.Args() { - if o != nil && o.Kind() == a.KExpr { - if err := g.mightActuallySuspend(o.AsExpr(), depth); err != nil { - return err - } - } - } - return nil - } - - if n.ProvenNotToSuspend() { - return nil - } - return errMightActuallySuspend -} - func (g *gen) writeCallSuspendibles(b *buffer, n *a.Expr, depth uint32) error { if depth > a.MaxExprDepth { return fmt.Errorf("expression recursion depth too large") @@ -607,8 +562,6 @@ func (g *gen) writeReadUXX(b *buffer, n *a.Expr, name string, size uint32, endia return fmt.Errorf("internal error: bad writeReadUXX endianness %q", endianness) } - // TODO: look at n.ProvenNotToSuspend(). - if g.currFunk.tempW > maxTemp-1 { return fmt.Errorf("too many temporary variables required") } diff --git a/lang/ast/ast.go b/lang/ast/ast.go index 5b4e5023..3e4e2078 100644 --- a/lang/ast/ast.go +++ b/lang/ast/ast.go @@ -111,24 +111,6 @@ const ( flagsThatMatterForEq = Flags(0x0000FFFF) ) -// These flags are set by the bounds checker to generate optimized code. -const ( - // FlagsProvenNotToSuspend notes that a method such as read_u8 or - // write_u16le is proven not to suspend. For example, if it's guaranteed - // that there enough buffer space for an I/O method to succeed. - // - // Some methods, such as unread_u8, are called with the question mark, as - // "r.unread_u8?()", so nominally can suspend, but their semantics also - // guarantee to either succeed or fail, never suspend and retry later. - FlagsProvenNotToSuspend = Flags(0x00010000) - // FlagsBoundsCheckOptimized similarly means that some code gen's run time - // bounds checks or null pointer checks can be skipped, although such - // methods are not called with the question mark. Specifically, those - // methods are: - // - since_mark - FlagsBoundsCheckOptimized = Flags(0x00020000) -) - type Effect uint32 func (e Effect) String() string { @@ -346,33 +328,29 @@ const MaxExprDepth = 255 // keyword, ID1 is the package and ID2 is the message. type Expr Node -func (n *Expr) AsNode() *Node { return (*Node)(n) } -func (n *Expr) Effect() Effect { return Effect(n.flags & flagEffect) } -func (n *Expr) Pure() bool { return n.flags&FlagsImpure == 0 } -func (n *Expr) Impure() bool { return n.flags&FlagsImpure != 0 } -func (n *Expr) Suspendible() bool { return n.flags&FlagsSuspendible != 0 } -func (n *Expr) CallImpure() bool { return n.flags&FlagsCallImpure != 0 } -func (n *Expr) CallSuspendible() bool { return n.flags&FlagsCallSuspendible != 0 } -func (n *Expr) GlobalIdent() bool { return n.flags&FlagsGlobalIdent != 0 } -func (n *Expr) ProvenNotToSuspend() bool { return n.flags&FlagsProvenNotToSuspend != 0 } -func (n *Expr) BoundsCheckOptimized() bool { return n.flags&FlagsBoundsCheckOptimized != 0 } -func (n *Expr) ConstValue() *big.Int { return n.constValue } -func (n *Expr) MBounds() Bounds { return n.mBounds } -func (n *Expr) MType() *TypeExpr { return n.mType } -func (n *Expr) Operator() t.ID { return n.id0 } -func (n *Expr) StatusQID() t.QID { return t.QID{n.id1, n.id2} } -func (n *Expr) Ident() t.ID { return n.id2 } -func (n *Expr) LHS() *Node { return n.lhs } -func (n *Expr) MHS() *Node { return n.mhs } -func (n *Expr) RHS() *Node { return n.rhs } -func (n *Expr) Args() []*Node { return n.list0 } +func (n *Expr) AsNode() *Node { return (*Node)(n) } +func (n *Expr) Effect() Effect { return Effect(n.flags & flagEffect) } +func (n *Expr) Pure() bool { return n.flags&FlagsImpure == 0 } +func (n *Expr) Impure() bool { return n.flags&FlagsImpure != 0 } +func (n *Expr) Suspendible() bool { return n.flags&FlagsSuspendible != 0 } +func (n *Expr) CallImpure() bool { return n.flags&FlagsCallImpure != 0 } +func (n *Expr) CallSuspendible() bool { return n.flags&FlagsCallSuspendible != 0 } +func (n *Expr) GlobalIdent() bool { return n.flags&FlagsGlobalIdent != 0 } +func (n *Expr) ConstValue() *big.Int { return n.constValue } +func (n *Expr) MBounds() Bounds { return n.mBounds } +func (n *Expr) MType() *TypeExpr { return n.mType } +func (n *Expr) Operator() t.ID { return n.id0 } +func (n *Expr) StatusQID() t.QID { return t.QID{n.id1, n.id2} } +func (n *Expr) Ident() t.ID { return n.id2 } +func (n *Expr) LHS() *Node { return n.lhs } +func (n *Expr) MHS() *Node { return n.mhs } +func (n *Expr) RHS() *Node { return n.rhs } +func (n *Expr) Args() []*Node { return n.list0 } -func (n *Expr) SetBoundsCheckOptimized() { n.flags |= FlagsBoundsCheckOptimized } func (n *Expr) SetConstValue(x *big.Int) { n.constValue = x } func (n *Expr) SetGlobalIdent() { n.flags |= FlagsGlobalIdent } func (n *Expr) SetMBounds(x Bounds) { n.mBounds = x } func (n *Expr) SetMType(x *TypeExpr) { n.mType = x } -func (n *Expr) SetProvenNotToSuspend() { n.flags |= FlagsProvenNotToSuspend } func NewExpr(flags Flags, operator t.ID, statusPkg t.ID, ident t.ID, lhs *Node, mhs *Node, rhs *Node, args []*Node) *Expr { if lhs != nil {