mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-24 16:52:18 +01:00
Drop old facts after an impure function call
This commit is contained in:
1 parent
4848859f97
commit
10146b75dd
3 files changed
+43
-4
No files matched your search
+41
-2
@@ -434,6 +434,14 @@ func (q *checker) bcheckAssert(n *a.Assert) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (q *checker) bcheckAssignment(lhs *a.Expr, op t.ID, rhs *a.Expr) error {
|
func (q *checker) bcheckAssignment(lhs *a.Expr, op t.ID, rhs *a.Expr) error {
|
||||||
|
oldFacts := (map[*a.Expr]struct{})(nil)
|
||||||
|
if (rhs.Operator() == t.IDOpenParen) && rhs.Effect().Impure() {
|
||||||
|
oldFacts = map[*a.Expr]struct{}{}
|
||||||
|
for _, x := range q.facts {
|
||||||
|
oldFacts[x] = struct{}{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
lTyp := (*a.TypeExpr)(nil)
|
lTyp := (*a.TypeExpr)(nil)
|
||||||
if lhs != nil {
|
if lhs != nil {
|
||||||
if _, err := q.bcheckExpr(lhs, 0); err != nil {
|
if _, err := q.bcheckExpr(lhs, 0); err != nil {
|
||||||
@@ -447,8 +455,39 @@ func (q *checker) bcheckAssignment(lhs *a.Expr, op t.ID, rhs *a.Expr) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if rhs.Effect().Coroutine() && (op != t.IDEqQuestion) {
|
if (rhs.Operator() == t.IDOpenParen) && rhs.Effect().Impure() {
|
||||||
if err := q.facts.update(updateFactsForSuspension); err != nil {
|
if rhs.Effect().Coroutine() && (op != t.IDEqQuestion) {
|
||||||
|
if err := q.facts.update(updateFactsForSuspension); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
recv := rhs.LHS().AsExpr().LHS().AsExpr()
|
||||||
|
if err := q.facts.update(func(x *a.Expr) (*a.Expr, error) {
|
||||||
|
if _, ok := oldFacts[x]; !ok {
|
||||||
|
// No-op. Don't drop any newly minted facts.
|
||||||
|
} else {
|
||||||
|
// Drop any old facts involving the receiver.
|
||||||
|
if x.Mentions(recv) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
// Drop any facts involving a pass-by-reference argument.
|
||||||
|
for _, arg := range rhs.Args() {
|
||||||
|
v := arg.AsArg().Value()
|
||||||
|
if typ := v.MType(); typ.IsBool() || typ.IsNullptr() ||
|
||||||
|
typ.IsNumTypeOrIdeal() || typ.IsStatus() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// TODO: take extra care if v is a slice? For example,
|
||||||
|
// facts involving "v.length()" aren't affected by passing
|
||||||
|
// v to an impure function.
|
||||||
|
if x.Mentions(v) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return x, nil
|
||||||
|
}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32404,6 +32404,7 @@ wuffs_png__decoder__decode_ihdr(
|
|||||||
uint8_t t_3 = *iop_a_src++;
|
uint8_t t_3 = *iop_a_src++;
|
||||||
self->private_impl.f_color_type = t_3;
|
self->private_impl.f_color_type = t_3;
|
||||||
}
|
}
|
||||||
|
self->private_impl.f_bytes_per_row = 0;
|
||||||
wuffs_png__decoder__calculate_bytes_per_row(self);
|
wuffs_png__decoder__calculate_bytes_per_row(self);
|
||||||
if (self->private_impl.f_bytes_per_row == 0) {
|
if (self->private_impl.f_bytes_per_row == 0) {
|
||||||
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_file);
|
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_file);
|
||||||
|
|||||||
@@ -247,8 +247,7 @@ pri func decoder.decode_ihdr?(src: base.io_reader) {
|
|||||||
|
|
||||||
// Color.
|
// Color.
|
||||||
this.color_type = args.src.read_u8?()
|
this.color_type = args.src.read_u8?()
|
||||||
// TODO: uncomment.
|
this.bytes_per_row = 0
|
||||||
// this.bytes_per_row = 0
|
|
||||||
this.calculate_bytes_per_row!()
|
this.calculate_bytes_per_row!()
|
||||||
if this.bytes_per_row == 0 {
|
if this.bytes_per_row == 0 {
|
||||||
return "#unsupported PNG file"
|
return "#unsupported PNG file"
|
||||||
|
|||||||
Reference in new issue
Block a user