Rename I/O available methods to length

This commit is contained in:
Nigel Tao committed 2020-08-13 23:26:08 +10:00
1 parent 79b923c322
commit be8542e313
15 files changed
+149 -152

No files matched your search

+9 -9
View File
@@ -346,8 +346,8 @@ var Funcs = []string{
"io_reader.read_u64be?() u64",
"io_reader.read_u64le?() u64",
// TODO: these should have an explicit pre-condition "available() >= N".
// For now, that's implicitly checked (i.e. hard coded).
// TODO: these should have an explicit pre-condition "length() >= N". For
// now, that's implicitly checked (i.e. hard coded).
//
// io_reader has peek_etc methods and skip_u32_fast, not read_etc_fast,
// because we sometimes advance the pointer by less than what's read. See
@@ -387,9 +387,9 @@ var Funcs = []string{
// in practice.
"io_reader.peek_u64le_at(offset: u32[..= 0xFFF8]) u64",
"io_reader.available() u64",
"io_reader.count_since(mark: u64) u64",
"io_reader.is_closed() bool",
"io_reader.length() u64",
"io_reader.mark() u64",
"io_reader.match7(a: u64) u32[..= 2]",
"io_reader.position() u64",
@@ -402,7 +402,7 @@ var Funcs = []string{
"io_reader.skip_u32?(n: u32)",
// TODO: this should have explicit pre-conditions "actual <= worst_case"
// and "worst_case <= available()". For now, that's all implicitly checked
// and "worst_case <= length()". For now, that's all implicitly checked
// (i.e. hard coded).
"io_reader.skip_u32_fast!(actual: u32, worst_case: u32)",
@@ -424,8 +424,8 @@ var Funcs = []string{
"io_writer.write_u64be?(a: u64)",
"io_writer.write_u64le?(a: u64)",
// TODO: these should have an explicit pre-condition "available() >= N".
// For now, that's implicitly checked (i.e. hard coded).
// TODO: these should have an explicit pre-condition "length() >= N". For
// now, that's implicitly checked (i.e. hard coded).
//
// io_writer has write_etc_fast methods, not poke_etc and skip_u32_fast,
// because skip_u32_fast could leave uninitialized bytes in the io_buffer.
@@ -445,9 +445,9 @@ var Funcs = []string{
"io_writer.write_u64be_fast!(a: u64)",
"io_writer.write_u64le_fast!(a: u64)",
"io_writer.available() u64",
"io_writer.count_since(mark: u64) u64",
"io_writer.history_available() u64",
"io_writer.length() u64",
"io_writer.mark() u64",
"io_writer.position() u64",
"io_writer.since(mark: u64) slice u8",
@@ -458,7 +458,7 @@ var Funcs = []string{
"io_writer.limited_copy_u32_from_slice!(up_to: u32, s: slice u8) u32",
// TODO: this should have explicit pre-conditions:
// - up_to <= this.available()
// - up_to <= this.length()
// - distance > 0
// - distance <= this.since_mark().length()
// For now, that's all implicitly checked (i.e. hard coded).
@@ -473,7 +473,7 @@ var Funcs = []string{
"value_extension: u64[..= 0x3FFF_FFFF_FFFF]," +
"continued: u32[..= 0x1], length: u32[..= 0xFFFF])",
"token_writer.available() u64",
"token_writer.length() u64",
// ---- frame_config
+6 -6
View File
@@ -1085,7 +1085,7 @@ func (q *checker) bcheckExprCallSpecialCases(n *a.Expr, depth uint32) (bounds, e
} else {
adv = advanceExpr.Str(q.tm)
}
return bounds{}, fmt.Errorf("check: could not prove %s pre-condition: %s.available() >= %s",
return bounds{}, fmt.Errorf("check: could not prove %s pre-condition: %s.length() >= %s",
method.Str(q.tm), recv.Str(q.tm), adv)
}
// TODO: drop other recv-related facts?
@@ -1120,7 +1120,7 @@ func (q *checker) canUndoByte(recv *a.Expr) error {
func (q *checker) canLimitedCopyU32FromHistoryFast(recv *a.Expr, args []*a.Node) error {
// As per cgen's io-private.h, there are three pre-conditions:
// - n <= this.available()
// - n <= this.length()
// - distance > 0
// - distance <= this.history_available()
@@ -1130,7 +1130,7 @@ func (q *checker) canLimitedCopyU32FromHistoryFast(recv *a.Expr, args []*a.Node)
n := args[0].AsArg().Value()
distance := args[1].AsArg().Value()
// Check "n <= this.available()".
// Check "n <= this.length()".
check0:
for {
for _, x := range q.facts {
@@ -1148,9 +1148,9 @@ check0:
continue
}
// Check that the RHS is "recv.available()".
// Check that the RHS is "recv.length()".
y, method, yArgs := splitReceiverMethodArgs(x.RHS().AsExpr())
if method != t.IDAvailable || len(yArgs) != 0 {
if method != t.IDLength || len(yArgs) != 0 {
continue
}
if !y.Eq(recv) {
@@ -1159,7 +1159,7 @@ check0:
break check0
}
return fmt.Errorf("check: could not prove n <= %s.available()", recv.Str(q.tm))
return fmt.Errorf("check: could not prove n <= %s.length()", recv.Str(q.tm))
}
// Check "distance > 0".
+7 -7
View File
@@ -55,7 +55,7 @@ func (q *checker) optimizeIOMethodAdvance(receiver *a.Expr, advance *big.Int, ad
retErr = q.facts.update(func(x *a.Expr) (*a.Expr, error) {
// TODO: update (discard?) any facts that merely mention
// receiver.available(), even if they aren't an exact match.
// receiver.length(), even if they aren't an exact match.
op := x.Operator()
if op != t.IDXBinaryGreaterEq && op != t.IDXBinaryGreaterThan {
@@ -67,13 +67,13 @@ func (q *checker) optimizeIOMethodAdvance(receiver *a.Expr, advance *big.Int, ad
return x, nil
}
// Check that lhs is "receiver.available()".
// Check that lhs is "receiver.length()".
lhs := x.LHS().AsExpr()
if lhs.Operator() != t.IDOpenParen || len(lhs.Args()) != 0 {
return x, nil
}
lhs = lhs.LHS().AsExpr()
if lhs.Operator() != t.IDDot || lhs.Ident() != t.IDAvailable {
if lhs.Operator() != t.IDDot || lhs.Ident() != t.IDLength {
return x, nil
}
lhs = lhs.LHS().AsExpr()
@@ -102,7 +102,7 @@ func (q *checker) optimizeIOMethodAdvance(receiver *a.Expr, advance *big.Int, ad
if rcv.Cmp(advance) == 0 {
// TODO: delete the (adjusted) fact, as newRCV will be zero, and
// "foo.available() >= 0" is redundant.
// "foo.length() >= 0" is redundant.
}
// Create a new a.Expr to hold the adjusted RHS constant value, newRCV.
@@ -121,20 +121,20 @@ func (q *checker) optimizeIOMethodAdvance(receiver *a.Expr, advance *big.Int, ad
func (q *checker) optimizeIOMethodAdvanceExpr(receiver *a.Expr, advanceExpr *a.Expr, update bool) (retOK bool, retErr error) {
retErr = q.facts.update(func(x *a.Expr) (*a.Expr, error) {
// TODO: update (discard?) any facts that merely mention
// receiver.available(), even if they aren't an exact match.
// receiver.length(), even if they aren't an exact match.
op := x.Operator()
if op != t.IDXBinaryGreaterEq && op != t.IDXBinaryGreaterThan {
return x, nil
}
// Check that lhs is "receiver.available()".
// Check that lhs is "receiver.length()".
lhs := x.LHS().AsExpr()
if lhs.Operator() != t.IDOpenParen || len(lhs.Args()) != 0 {
return x, nil
}
lhs = lhs.LHS().AsExpr()
if lhs.Operator() != t.IDDot || lhs.Ident() != t.IDAvailable {
if lhs.Operator() != t.IDDot || lhs.Ident() != t.IDLength {
return x, nil
}
lhs = lhs.LHS().AsExpr()
-4
View File
@@ -651,8 +651,6 @@ const (
IDIsOK = ID(0x231)
IDIsSuspension = ID(0x232)
IDAvailable = ID(0x250)
IDData = ID(0x240)
IDHeight = ID(0x241)
IDIO = ID(0x242)
@@ -1016,8 +1014,6 @@ var builtInsByID = [nBuiltInIDs]string{
IDIsOK: "is_ok",
IDIsSuspension: "is_suspension",
IDAvailable: "available",
IDData: "data",
IDHeight: "height",
IDIO: "io",