cli: add bounded std copy/search and checked arithmetic
This commit is contained in:
36 files changed
+1533
-7
No files matched your search
@@ -94,3 +94,5 @@ The groups `quick_reference`, `source_docs` and `air_docs` come from the `doc_gr
|
||||
RFC 0016 bootstrap measurement (cl100k): Quick Reference 5,511 → 5,777 (+4.8%); other source docs 28,470 → 30,461 (+7.0%); full source docs excluding AIR 33,981 → 36,238 (+6.6%). The on-demand library page is 1,346 tokens. The AIR bundle stays 160,797 bytes. The RFC also records o200k and Qwen2.5 counts.
|
||||
|
||||
RFC 0017 endian increment (cl100k, relative to bootstrap): Quick Reference 5,777 → 6,000 (+3.9%); other source docs 30,461 → 31,918 (+4.8%); full source docs excluding AIR 36,238 → 37,918 (+4.6%). The library page is 2,533 tokens. AIR remains unchanged. The additional Quick Reference example shows explicit typed success/short-buffer handling; future API catalogs stay on demand.
|
||||
|
||||
RFC 0018 bounded operations (cl100k, relative to endian): Quick Reference 6,000 → 6,082 (+1.4%); other source docs 31,918 → 33,628 (+5.4%); full source docs excluding AIR 37,918 → 39,710 (+4.7%). The library page is 4,223 tokens. AIR remains unchanged. Copy, substring lookup and recoverable arithmetic reuse existing verified primitives; detailed contracts and the checked sizing example stay on demand.
|
||||
@@ -354,3 +354,5 @@ match std.bytes.read_u32_be(ref wire[1..5]) {
|
||||
```
|
||||
|
||||
The usual enum rules apply: missing arm `E7004`, wrong enum/payload `E7005`, unknown type/variant `E7002`. See `/docs/library/std.md` for signatures.
|
||||
|
||||
`std.bytes.copy` returns `WriteResult`; short output is unchanged and overlap rejects. `find_slice` returns `FindResult::found(index)` / `not_found` (empty needle: found at 0). Recoverable `u64`/`usize` arithmetic, split composition and a checked example are in `/docs/library/std.md`; wrapping stays `+%`, `-%`, `*%`.
|
||||
@@ -218,3 +218,9 @@ Found while testing `std.bytes`: the frontend rejects `b""` with `E7006` (“an
|
||||
A plain integer cannot distinguish a decoded zero from a short input. A trap on malformed protocol input is not a recoverable API, and a boolean plus mutable out-parameter leaves an invalid/stale output for callers to track.
|
||||
|
||||
**Resolved in the endian work branch:** spec 16 §2.3 defines width-specific read result enums and one write result enum. Spec 15 §13 defines fully qualified standard enum type names, constructors and patterns using existing AIR enum semantics. RFC 0017 records the proposal. General modules, imported struct literals, generics and a must-use result rule remain outside this change.
|
||||
|
||||
## Q-029 — Bounded byte copy/search/split and recoverable arithmetic surface
|
||||
|
||||
Short destination capacity needs explicit failure without partial mutation. A substring search's empty needle can match the end of empty data, so the existing single-byte length sentinel cannot unambiguously encode all outcomes. A returned split pair would hold borrows inside an aggregate before that source/lifetime surface is available. Arithmetic operators currently either trap or wrap; buffer sizing needs a recoverable overflow result.
|
||||
|
||||
**Resolved in the STD-1b branch:** spec 16 §2.4 reuses `WriteResult` for copy, adds `FindResult` for substring search, and composes splitting from explicit caller-owned slices. Spec 16 §2.1.1 adds checked add/sub/mul for u64 and target-width usize with ordinary result enums. Wrapping stays with existing operators. No new borrowed aggregate, generic type, AIR instruction or arithmetic mode is introduced. RFC 0018 records this API policy; its status remains Proposed until owner acceptance.
|
||||
@@ -48,7 +48,7 @@ SQL/database clients, Redis/Kafka, ORMs, application authentication, gRPC/protob
|
||||
|---|---|---|---|---|
|
||||
| STD-0 | done (branch implementation; RFC Proposed) | bootstrap spec, source std, closed imports, conformance, documentation and complexity measurement | existing source frontend | bootstrap exit criterion above and required repository checks pass |
|
||||
| STD-1a | done (branch implementation; RFC Proposed) | endian u16/u32/u64 and qualified standard enum results | STD-0 | recoverable short-input/output failure, no partial mutation; all short lengths, empty/maximal values, fixtures and rejected alias examples pass |
|
||||
| STD-1b | todo | bounded copy/split/search, checked arithmetic API decisions | STD-1a | contracts define capacity/overflow failure, no partial mutation, empty inputs and aliasing; independent fixtures pass |
|
||||
| STD-1b | done (branch implementation; RFC Proposed) | bounded copy/search, split composition and recoverable arithmetic for u64/usize | STD-1a | contracts define capacity/overflow failure, no partial mutation, empty inputs and aliasing; independent fixtures pass |
|
||||
| STD-2 | todo | UTF-8 validation/iteration, hex/base64 and formatting into supplied buffers | STD-1a/1b | malformed text and insufficient capacity are explicit; no implicit heap; standard vectors and boundary cases pass |
|
||||
| STD-3 | todo | general modules and imported type names (P6-3) | STD-0 | deterministic resolution, collisions/cycles and diagnostics specified and covered |
|
||||
| STD-4 | todo | source generics (P6-4), constraints and option/result | STD-3 | deterministic specialization and rejected constraint examples; source/AIR budgets measured |
|
||||
@@ -83,3 +83,9 @@ Bootstrap result: nine APIs implemented; full conformance, unit/Quick Reference,
|
||||
Twelve additional endian functions and four ordinary Copy enums lower to existing AIR. The invariant remains: no access outside the supplied slice, no escaping borrow, no hidden allocation, and no mutation on insufficient output capacity. The capacity branch precedes every access. Existing verifier/interpreter rules and diagnostics apply; valid/rejected source examples and hand-written AIR fixtures exercise payload typing and read behavior. AIR format 0 is unchanged. Qualified standard enum names implement only a closed-registry subset of STD-3; user modules, imported struct literals, dependencies and generics remain open.
|
||||
|
||||
Run the same required checks as bootstrap. Endian fixtures include independent LE/BE byte vectors, every short length, zero/maximal values, every bit, nonzero offsets, extra input/output bytes, returned enum records, compound types, name collisions, exhaustive matches and forbidden mutable aliasing. RFC 0017 records final checks and complexity measurements.
|
||||
|
||||
## STD-1b verification
|
||||
|
||||
Eight further pure functions reuse existing primitives: `std.bytes.copy` and `find_slice`, plus checked add/sub/mul for `u64` and `usize`. Copy reuses `WriteResult`; three additional ordinary Copy enums represent substring matches and arithmetic results. Wrapping remains an operator. Splitting composes a search with explicit caller-bounded slice operations; no borrowed aggregate, iterator, cursor, compiler/runtime change or hidden allocation is added.
|
||||
|
||||
The preserved invariant is shared-read/exclusive-write access only within the supplied slices, no escaping borrows and no mutation on short output. Existing verifier/call/alias/enum rules and interpreter behavior suffice. Valid/rejected source fixtures and hand-written AIR twins cover the contracts; current diagnostics and AIR format 0 are unchanged. Tests include all 81 input/output length pairs through eight, disjoint split borrows, overlapping and empty short-output aliases, 428 search cases, seven split cases and 320 independently computed arithmetic operand pairs exercised through both widths. The interpreter's numeric vectors use its default `air64`; library usize limits are computed with target-width wrapping subtraction. RFC 0018 records the final repository checks and complexity measurements. STD-2 can now start with UTF-8 and supplied-buffer encodings.
|
||||
@@ -71,3 +71,44 @@ effects []
|
||||
Missing enum arm: `E7004`; duplicate/wildcard enum arm: `E7006`; unknown type/variant or missing import: `E7002`; wrong width/payload, immutable destination or variant from another enum: `E7005`; conflicting destination borrows: `E2101`. Existing `or trap` only applies to fallible built-in operations, so it is not used with these enums.
|
||||
|
||||
The example is checked in `source/quickref/std_endian.aji`; fixtures for every width/order and all short lengths are in `source/std/endian_u*.aji`.
|
||||
|
||||
## Copy and substring search
|
||||
|
||||
| Function | Result and contract |
|
||||
|---|---|
|
||||
| `std.bytes.copy(dst: slice_mut<u8>, src: slice<u8>) -> std.bytes.WriteResult` | `ok` copies the whole input into the output prefix, preserving the suffix; `short_output` leaves the whole output unchanged. Empty input succeeds. Overlap rejects (`E2101`), including on the error path. |
|
||||
| `std.bytes.find_slice(data: slice<u8>, needle: slice<u8>) -> std.bytes.FindResult` | `found(index)` for the first match, or `not_found`. Empty needle is `found(0)`, including empty data. Offset is relative to the passed slice; it need not be a readable element index. |
|
||||
|
||||
Search allocates no heap and uses constant auxiliary storage; the reference algorithm has O(data length × needle length) worst-case comparisons. Interpreter fuel bounds execution. For splitting at the first separator, match the search result, then take `data[0..index]` and `data[index + separator.len..data.len]`, or split at the index and borrow past the separator in the right half. An empty separator leaves the whole data in the right half; repeated splitting needs an explicit progress rule. There is no split iterator or returned pair of borrowed slices.
|
||||
|
||||
## Recoverable arithmetic
|
||||
|
||||
| Operand type | Functions | Result |
|
||||
|---|---|---|
|
||||
| `u64` | `std.math.checked_add_u64`, `std.math.checked_sub_u64`, `std.math.checked_mul_u64` | `std.math.U64Result::ok(u64)` / `overflow` |
|
||||
| `usize` | `std.math.checked_add_usize`, `std.math.checked_sub_usize`, `std.math.checked_mul_usize` | `std.math.UsizeResult::ok(usize)` / `overflow` |
|
||||
|
||||
Every function takes two operands of the indicated type. A representable mathematical result succeeds; unsigned subtraction underflow also returns `overflow`. Multiplication by zero always succeeds with zero. `usize` follows target pointer width. Normal arithmetic operators still trap on overflow; wrapping uses `+%`, `-%`, `*%`, with no library wrappers. These monomorphic APIs do not provide generic or signed arithmetic. Result enums use the same ordinary match rules as the endian results.
|
||||
|
||||
For a zero-terminated byte record, check the complete output size before copying:
|
||||
|
||||
```aji
|
||||
fn encode(dst: slice_mut<u8>, data: slice<u8>) -> usize
|
||||
effects []
|
||||
{
|
||||
match std.math.checked_add_usize(data.len, 1) {
|
||||
std.math.UsizeResult::ok(total) => {
|
||||
if total > dst.len { return 0; }
|
||||
match std.bytes.copy(mut dst, ref data) {
|
||||
std.bytes.WriteResult::ok => { dst[data.len] = 0; return total; }
|
||||
std.bytes.WriteResult::short_output => { return 0; }
|
||||
}
|
||||
}
|
||||
std.math.UsizeResult::overflow => { return 0; }
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
This helper returns the encoded byte count or zero on failure, and leaves the destination unchanged on failure. Import both `std.math` and `std.bytes`. Its zero sentinel is unambiguous because a successful record includes the terminator.
|
||||
|
||||
The checked [bounded example](../../examples/std/bounded.aji) combines overflow-aware output sizing, whole-input copy and delimiter search; it returns 10. Copy/search/split and independent arithmetic fixtures are in `source/std/bounded_*.aji`. Wrong operands/payloads are `E7005`; absent imports/types are `E7002`; missing result arms are `E7004`. No new diagnostic code, syntax, verifier state or runtime primitive is introduced.
|
||||
@@ -0,0 +1,134 @@
|
||||
# RFC 0018: Bounded copy/search and recoverable unsigned arithmetic
|
||||
|
||||
Status: Proposed
|
||||
Scope: STD-1b, safe standard library APIs; existing source and AIR format 0 unchanged
|
||||
Language version: 0.1
|
||||
Supersedes: —
|
||||
|
||||
The proposed spec, reference implementation and tests are integrated on the work branch for review. Only the owner changes an RFC to Accepted. RFCs 0016/0017 remain the historical records for imports and endian operations.
|
||||
|
||||
## Motivation
|
||||
|
||||
Storage and protocol code needs whole-input byte copy with capacity failure, substring lookup with an unambiguous empty-input result, and overflow-aware buffer sizing. Existing primitive copy and arithmetic trap on invalid capacity/overflow; manually repeating guards adds repair work. Standard functions can express these operations using existing verified source.
|
||||
|
||||
This increment improves semantic explicitness, deterministic behavior, memory safety and implementation simplicity. It adds eight functions and three ordinary result enums, with no new language feature or verifier state. A reduction in model capability requirements remains an empirical hypothesis.
|
||||
|
||||
## Precise invariant
|
||||
|
||||
Copy accesses only supplied initialized slices and mutates exactly the source-length prefix of sufficient exclusive output. A short-output result leaves the entire destination unchanged and reads no source elements. Search only reads shared input. No borrowed value escapes, heap allocation occurs, resource is consumed, authority is created or task starts. Arithmetic returns a payload exactly when the mathematical result fits the operand type; neither overflow nor a zero multiplier traps.
|
||||
|
||||
## Normative rule changes
|
||||
|
||||
Integrated text is spec 16 §2.1.1/§2.4, with the primitive-versus-recoverable copy distinction clarified in spec 15 §6:
|
||||
|
||||
- `std.bytes.copy(dst, src)` MUST return `WriteResult::short_output` before any element access when output is short. Success MUST copy the whole input into the output prefix and preserve the remainder. Empty input succeeds. Existing alias rules reject overlapping shared/exclusive borrows regardless of runtime capacity; this is not `memmove`.
|
||||
- `find_slice(data, needle)` MUST return `FindResult::found(index)` at the first match or `not_found`. Empty needle MUST return `found(0)`, including empty data. A found offset may equal the data length and is not necessarily a readable index. No borrow is returned or retained.
|
||||
- Splitting at the first separator composes that search with existing explicit slices or `split_at`. There is no split function returning an aggregate of borrows or implicit cursor. Empty separator gives an empty left part and the whole right part; repeated splitting requires a caller-chosen progress rule.
|
||||
- `checked_add_u64`, `checked_sub_u64`, `checked_mul_u64` return `std.math.U64Result`; the `_usize` forms return `std.math.UsizeResult`. Both enums have `ok(value)` and `overflow`. Representability determines success; unsigned underflow is overflow. `usize` follows target width.
|
||||
- Normal arithmetic still traps on overflow. Wrapping stays with `+%`, `-%`, `*%`; no synonymous library wrappers are added. Generalized widths, signed/saturating arithmetic and generics are outside this increment.
|
||||
|
||||
## Verifier implications
|
||||
|
||||
No new abstract state, transfer function, diagnostic or privilege. Existing slice initialization/lifetime, shared/exclusive alias, call typing and Copy enum payload/match rules apply. Capacity guards do not grant an alias exception. A disjoint `split_at` pair from one allocation can be copied; two sub-slices of the same parent retain the existing conservative overlap rule. Results are ordinary Copy values with no must-use checking.
|
||||
|
||||
## Interpreter / runtime implications
|
||||
|
||||
No runtime change. Copy checks capacity, then calls the existing primitive `slice.copy`. Search checks empty/oversize needles, bounds a scan by `data.len - needle.len`, and uses existing equality and sub-slices. It checks the final start before incrementing, avoiding an overflowing end-plus-one loop bound. Search has constant auxiliary storage and O(data length × needle length) worst-case byte comparisons.
|
||||
|
||||
Unsigned arithmetic uses prechecks before checked operations: add checks available headroom, subtract compares operands, and multiply short-circuits the divisor check when its second operand is zero. The unsigned maximum is computed as `0 -% 1` in the operand type, without host constants or assumptions about pointer width. No implicit widening occurs.
|
||||
|
||||
All APIs are safe `.aji` with `effects []`, no heap/authority/concurrency effect and identical deterministic/hosted behavior. Valid slices and scalar operands do not produce bounds, arithmetic, cast or shift traps. Interpreter fuel remains an environment limit and is not a returned library error; the unchanged-output guarantee applies to `short_output`, not interruption mid-execution.
|
||||
|
||||
## AIR changes
|
||||
|
||||
None. Functions lower to ordinary calls, branches, arithmetic, borrows, `slice.copy`, `enum.make` and `enum.switch`, under the existing published feature closure. There is no new instruction, type kind, feature entry or interpretation. AIR format 0 remains frozen.
|
||||
|
||||
## Valid example
|
||||
|
||||
```aji
|
||||
module example
|
||||
import std.bytes;
|
||||
import std.math;
|
||||
|
||||
fn encode(dst: slice_mut<u8>, data: slice<u8>) -> usize
|
||||
effects []
|
||||
{
|
||||
match std.math.checked_add_usize(data.len, 1) {
|
||||
std.math.UsizeResult::ok(total) => {
|
||||
if total > dst.len { return 0; }
|
||||
match std.bytes.copy(mut dst, ref data) {
|
||||
std.bytes.WriteResult::ok => { dst[data.len] = 0; return total; }
|
||||
std.bytes.WriteResult::short_output => { return 0; }
|
||||
}
|
||||
}
|
||||
std.math.UsizeResult::overflow => { return 0; }
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
`examples/std/bounded.aji` adds a main that encodes a zero-terminated byte record, searches its delimiter and verifies untouched output bytes. The conformance copy returns 10 without grants. `bounded_split.aji` checks first-separator composition, including empty inputs and separators.
|
||||
|
||||
## Rejected example
|
||||
|
||||
```aji
|
||||
module example
|
||||
import std.bytes;
|
||||
|
||||
fn main() -> u8
|
||||
effects []
|
||||
{
|
||||
var buf: [u8; 4] = zero;
|
||||
let result = std.bytes.copy(mut buf, ref buf);
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
Existing `E2101` reports the conflicting shared borrow and the call's argument conflict. `bounded_copy_alias.aji` captures both diagnostics. Holding a shared borrow of the array and copying into its empty prefix is also rejected; runtime capacity checks do not weaken verification.
|
||||
|
||||
## Diagnostics impact
|
||||
|
||||
No new codes. Wrong operands/result payloads use `E7005` (AIR payload typing `E1001`); unknown/absent imports use `E7002`; incomplete matches use `E7004`; conflicting copy borrows use `E2101`. Existing diagnostic counts and source mapping remain unchanged. Capacity and overflow are result variants, not diagnostics or traps.
|
||||
|
||||
## Spec integration
|
||||
|
||||
- Spec 16 §2.1.1: six recoverable arithmetic functions, two result enums, exact representability and operator policy.
|
||||
- Spec 16 §2.4: copy, search result enum, first-separator composition, capacity/empty/alias/profile contracts.
|
||||
- Spec 15 §6: distinguishes primitive trapping copy from recoverable byte copy; no new grammar or lowering rule.
|
||||
- API reference and Quick Reference: signatures, ordinary result handling, source example and on-demand contracts.
|
||||
- Plan and Q-029: bounded split/arithmetic decisions and remaining general-module/generic work.
|
||||
|
||||
## Compatibility and migration
|
||||
|
||||
No source/AIR syntax, ownership, alias, effect, capability, runtime or existing API meaning changes. Existing `find` retains its single-byte length sentinel, including absence on empty data. Substring search uses an enum because an empty needle can successfully match empty data at offset zero. The distinct operations are intentionally documented together, without silently changing `find`'s result type. Import composition now includes eight additional functions and three enums; existing whole-module composition and collision-free names still apply. No migration required.
|
||||
|
||||
## Agent complexity impact
|
||||
|
||||
- New concepts: bounded whole-input copy; first substring offset including empty needles; recoverable scalar overflow. Results reuse ordinary enum handling.
|
||||
- New verifier state: none. No new borrow return/lifetime or cleanup obligation.
|
||||
- New syntax/instructions: none. Eight monomorphic function names and three ordinary result enum names are added, on demand.
|
||||
- Interactions: slice aliases, disjoint split borrows, sub-slice bounds, Copy results, qualified standard type names, target-sized integers, short-circuit evaluation and interpreter fuel.
|
||||
- Repairability: short copies cannot partially overwrite records; arithmetic sizing errors become typed results; search distinguishes absence from an empty match. Explicit splitting keeps borrow scopes visible. Callers can still ignore Copy results under existing rules; no measured compression claim is made.
|
||||
- Existing primitives express all algorithms. No compiler change or trusted intrinsic is needed. Wrapping operators already suffice, so wrappers are omitted.
|
||||
- New source diagnostic codes: zero. General width/signed APIs wait for a separate contract rather than proliferating wrappers.
|
||||
- Quick Reference adds only a short routing paragraph; the signature catalog and full contracts remain in on-demand `library/std.md`.
|
||||
|
||||
Measured against the endian increment (`a2ca293`) with `zig build agent-reference` and `HF_HUB_OFFLINE=1 uv run --with tiktoken --with tokenizers tools/agent_bundle_tokens.py --source`:
|
||||
|
||||
| Group | cl100k before → after | o200k before → after | Qwen2.5 before → after |
|
||||
|---|---|---|---|
|
||||
| Quick Reference (`QUICK.md`, includes navigation) | 6,000 → 6,082 (+1.4%) | 6,019 → 6,102 (+1.4%) | 6,189 → 6,272 (+1.3%) |
|
||||
| Other source docs | 31,918 → 33,628 (+5.4%) | 32,001 → 33,718 (+5.4%) | 32,838 → 34,572 (+5.3%) |
|
||||
| Full source docs without AIR | 37,918 → 39,710 (+4.7%) | 38,020 → 39,820 (+4.7%) | 39,027 → 40,844 (+4.7%) |
|
||||
| AIR docs in the source bundle | 42,454 → 42,454 | 42,602 → 42,602 | 43,827 → 43,827 |
|
||||
|
||||
Standalone AIR remains 160,797 bytes, 48 sections and 19 files. Incremental source bundle growth stays below the 10% warning threshold. The library page grows from 2,533/2,532/2,654 to 4,223/4,229/4,367 tokens: eight APIs need capacity, empty-match, split progress, target-width and overflow contracts, plus one checked sizing/copy example. This is on-demand documentation; the Quick Reference only gains an 82-token routing paragraph (cl100k) instead of a repeated arithmetic catalog. Its approximately 6k target remains a front-door constraint for future increments.
|
||||
|
||||
Branch checks: build, unit tests/Quick Reference extraction, full conformance (505 passed, zero failed/pending), formatting, source coverage (72/72), agent-reference and hosted file/stdin/TCP smoke all pass. The bounded example returns 10 without grants. Twenty-three new conformance tests exercise all 81 length/capacity pairs through eight, disjoint same-allocation copy, overlapping/empty short-output aliases, 428 substring cases, seven split cases and 320 independently computed arithmetic pairs through both u64 and usize APIs. Arithmetic fixtures include zero multipliers, underflow, addition headroom and multiplication near limits, plus seeded fixed random inputs. They use the interpreter's default `air64`; no 32-bit runtime test is claimed. Copy and arithmetic source runs match hand-written AIR; an AIR wrong-payload fixture rejects with `E1001`. All run tests execute twice for determinism, and accepted source lowers canonically and deterministically.
|
||||
|
||||
## Alternatives considered
|
||||
|
||||
An ambiguous length sentinel for substring search needs an extra empty-needle convention from the caller. A numeric result enum directly distinguishes absence. A split iterator or returned slice aggregate adds lifetime state and cursor semantics before imported structs/borrowed aggregates are specified; explicit existing slicing suffices. A silent partial copy makes output validity caller-dependent. A memmove wrapper cannot bypass the existing alias rule. Duplicating wrapping operators expands the API without changing the contract. Adding generics or a generic Result to this increment would substantially enlarge its semantic surface.
|
||||
|
||||
## Unresolved questions
|
||||
|
||||
Q-029 records these API decisions as resolved on the branch. General generics, imported structs, borrowed aggregates and must-use values remain separate work. The reference interpreter currently executes `air64`; arithmetic fixtures use that target, while the usize implementation computes its limit in target width. Q-027's empty byte-literal gap is unchanged; empty tests use existing zero-length slices.
|
||||
@@ -179,7 +179,7 @@ Lowering: structured control flow becomes blocks and terminators. A variable ass
|
||||
| `s.len` | `slice.len`, or the static length of an array |
|
||||
| `s[a..b]` | a sub-slice (`slice.sub` with start `a`, length `b - a`); a borrow, so it is bound or passed, never a value |
|
||||
| `let (left, right) = s.split_at(k);` | `slice.split`: two disjoint borrows of `s`. Besides `atomic.compare_exchange` (§12), the only multi-result binding. There is no general tuple destructuring. |
|
||||
| `slice.copy(mut dst, ref src)` | `slice.copy`, the only copy form |
|
||||
| `slice.copy(mut dst, ref src)` | primitive `slice.copy`; insufficient capacity traps. Recoverable byte copy is `std.bytes.copy` (spec 16 §2.4). |
|
||||
|
||||
**Writes.**
|
||||
|
||||
|
||||
@@ -20,6 +20,19 @@ The built-in registry contains `std.math` and `std.bytes`. Both are implemented
|
||||
|
||||
These are monomorphic functions, not a generic arithmetic facility. Checked/wrapping operators retain their existing semantics (spec 02); importing this module does not alter them.
|
||||
|
||||
#### 2.1.1 Recoverable unsigned arithmetic
|
||||
|
||||
For `T` equal to `u64` or `usize`, `checked_add_T(a: T, b: T)`, `checked_sub_T(a: T, b: T)` and `checked_mul_T(a: T, b: T)` return `std.math.U64Result` or `std.math.UsizeResult`, respectively:
|
||||
|
||||
```aji
|
||||
enum U64Result { ok(u64), overflow }
|
||||
enum UsizeResult { ok(usize), overflow }
|
||||
```
|
||||
|
||||
Each operation MUST return `ok(value)` exactly when its mathematical result is representable in T, and `overflow` otherwise. Unsigned subtraction underflow is `overflow`. A successful zero is distinct from overflow. `usize` uses the target pointer width (spec 02); no fixed-width maximum or implicit cast is allowed. These functions MUST NOT trap for any scalar operands, apart from the execution environment's fuel limit, including multiplication by zero. They allocate no heap and declare `effects []`.
|
||||
|
||||
The functions use ordinary Copy enums and the existing integer and enum rules, with no new verifier/runtime primitive. Failure is handled by an exhaustive qualified enum match; no must-use rule or intrinsic outcome shorthand is added. Normal `+`, `-`, `*` still trap on overflow; wrapping uses `+%`, `-%`, `*%`. The library MUST NOT add synonymous wrapping wrappers for these operators. Signed arithmetic and other widths are outside this monomorphic increment; general numeric APIs require separate contracts.
|
||||
|
||||
### 2.2 `std.bytes`
|
||||
|
||||
Inputs are byte slices, not encoded text. No UTF-8 validation or locale interpretation occurs. Read-only parameters are `slice<u8>`.
|
||||
@@ -53,3 +66,19 @@ These declarations belong to `std.bytes` and are named with that prefix (spec 15
|
||||
Short slices are recoverable enum results, not traps. A successful zero value is distinct from a short input. These APIs declare `effects []`, allocate no heap, retain no borrow and consume no owner/resource. They have no concurrency or authority requirements beyond the ordinary slice borrow contract. All capacity checks precede all accesses/mutations. Valid slices and values MUST NOT produce bounds, arithmetic, cast or shift traps; interpreter fuel exhaustion remains an environment outcome.
|
||||
|
||||
The verifier uses the existing enum payload, call, shared/exclusive borrow, lifetime and bounds rules. There is no new transfer function, runtime primitive or AIR feature. Ordinary enum construction and exhaustive `enum.switch` lower the result handling. Existing `E7002`, `E7004`, `E7005`, `E7006`, `E2101` cover invalid names/matches/calls and aliasing. The behavior is identical in deterministic and hosted profiles. Existing AIR and the existing nine library operations retain their semantics; imported source receives additional declarations pinned to the compiler version.
|
||||
|
||||
### 2.4 Bounded copy, substring search and splitting
|
||||
|
||||
`std.bytes.copy(dst: slice_mut<u8>, src: slice<u8>) -> std.bytes.WriteResult` MUST return `short_output` when `dst.len < src.len`, leaving every destination byte unchanged and reading no source elements. Otherwise it MUST copy exactly `src.len` bytes into the beginning of `dst`, preserve remaining destination bytes and return `ok`. Empty input succeeds, including with an empty output. Capacity is checked before any copy. Source/destination overlap MUST be rejected by the existing shared/exclusive alias rules (`E2101`), even if the output is short or the slices are empty. This operation is not an overlap-safe move.
|
||||
|
||||
`std.bytes.find_slice(data: slice<u8>, needle: slice<u8>) -> std.bytes.FindResult` returns an ordinary Copy enum:
|
||||
|
||||
```aji
|
||||
enum FindResult { found(usize), not_found }
|
||||
```
|
||||
|
||||
It MUST return `found(index)` for the least index at which all needle bytes match, or `not_found` if there is no match. A found index satisfies `index <= data.len` and `needle.len <= data.len - index`. An empty needle MUST return `found(0)` for any data, including empty data, without reading elements. A needle longer than the data MUST return `not_found` without reading elements. Offsets are relative to the passed slice; a found index is an offset, not necessarily an index of a readable element. Search only reads shared slices, retains no borrow and never mutates its input. The reference implementation uses constant auxiliary storage and at most O(data.len × needle.len) byte comparisons; interpreter fuel still bounds execution.
|
||||
|
||||
Splitting at the first byte-string separator uses `find_slice`, then the existing explicit sub-slice or `split_at` forms (spec 15 §6). On `found(index)`, the left part is `data[0..index]`, the separator `data[index..index + separator.len]` and the right part `data[index + separator.len..data.len]`. On `not_found` the caller chooses how to handle an absent separator. An empty separator yields an empty left part and the whole data as the right part; repeated splitting with an empty separator needs a caller-defined progress rule. There is no standard split iterator, returned aggregate of borrows or hidden cursor. Single-byte splitting MAY use the existing `find` length sentinel, checked before slicing.
|
||||
|
||||
Both functions declare `effects []`, allocate no heap, retain no borrow and consume no owner/resource. Valid slices MUST NOT produce bounds or integer traps; fuel exhaustion remains an environment outcome. The invariant is existing shared-read/exclusive-write access within the supplied slices, with no partial mutation on a short-output result. Existing call, alias, lifetime, initialization, capacity/bounds and enum transfer functions apply, with no new privilege, diagnostic code, AIR feature or runtime rule. Deterministic and hosted profiles behave identically. Existing APIs and AIR format 0 retain their contracts.
|
||||
@@ -0,0 +1,35 @@
|
||||
module demo.bounded
|
||||
import std.bytes;
|
||||
import std.math;
|
||||
|
||||
fn encode(dst: slice_mut<u8>, data: slice<u8>) -> usize
|
||||
effects []
|
||||
{
|
||||
match std.math.checked_add_usize(data.len, 1) {
|
||||
std.math.UsizeResult::ok(total) => {
|
||||
if total > dst.len { return 0; }
|
||||
match std.bytes.copy(mut dst, ref data) {
|
||||
std.bytes.WriteResult::ok => { dst[data.len] = 0; return total; }
|
||||
std.bytes.WriteResult::short_output => { return 0; }
|
||||
}
|
||||
}
|
||||
std.math.UsizeResult::overflow => { return 0; }
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> usize
|
||||
effects []
|
||||
{
|
||||
var buf: [u8; 16] = [165; 16];
|
||||
let size = encode(mut buf, b"key=value");
|
||||
assert(size == 10);
|
||||
assert(buf[9] == 0 and buf[10] == 165);
|
||||
match std.bytes.find_slice(ref buf[0..size - 1], b"=") {
|
||||
std.bytes.FindResult::found(index) => {
|
||||
assert(std.bytes.equal(ref buf[0..index], b"key"));
|
||||
assert(std.bytes.equal(ref buf[index + 1..size - 1], b"value"));
|
||||
}
|
||||
std.bytes.FindResult::not_found => { trap; }
|
||||
}
|
||||
return size;
|
||||
}
|
||||
+4
-2
@@ -1,6 +1,6 @@
|
||||
# Aji standard library
|
||||
|
||||
Implementation in ordinary safe `.aji`: `math.aji` and `bytes.aji`, with 21 functions and four public result enums. They are embedded with the compiler and compiled through the normal frontend/verifier when imported. They are library modules, not standalone `main` programs.
|
||||
Implementation in ordinary safe `.aji`: `math.aji` and `bytes.aji`, with 29 functions and seven public result enums. They are embedded with the compiler and compiled through the normal frontend/verifier when imported. They are library modules, not standalone `main` programs.
|
||||
|
||||
```aji
|
||||
module example
|
||||
@@ -21,6 +21,8 @@ Run `zig build`, then `zig-out/bin/aji run --fuel 1000000 examples/std/bytes.aji
|
||||
|
||||
Endian APIs read/write u16/u32/u64 in LE/BE order. Reads return `std.bytes.ReadU16`, `ReadU32` or `ReadU64` (`ok(value)` / `short_input`); writes return `std.bytes.WriteResult` (`ok` / `short_output`). A short write leaves the entire destination unchanged. Pass a sub-slice for an offset. [Endian example](../examples/std/endian.aji) returns 305419896 and needs no grants.
|
||||
|
||||
`std.bytes.copy` reuses `WriteResult` and preserves the whole destination on short output. `find_slice` returns `FindResult::found(index)` / `not_found`; explicit slices compose a split without returned borrows. `std.math.checked_add/sub/mul_u64` and the `_usize` forms return typed `ok(value)` / `overflow` enums; wrapping stays with `+%`, `-%`, `*%`. The [bounded example](../examples/std/bounded.aji) returns 10 without grants.
|
||||
|
||||
The compiler uses its embedded copy, so rebuild after editing these files. An installed compiler needs neither this checkout nor a runtime std search path. Standard enum types use fully qualified names in signatures, constructors and matches. General user imports, imported struct literals, generics and owning collections are still future work.
|
||||
|
||||
[API reference](../docs/reference/std.md) · [Specification](../docs/spec/16-standard-library.md) · [Plan](../docs/plan/standard-library.md) · [Import RFC](../docs/rfcs/0016-standard-library-bootstrap.md) · [Endian RFC](../docs/rfcs/0017-standard-endian-results.md)
|
||||
[API reference](../docs/reference/std.md) · [Specification](../docs/spec/16-standard-library.md) · [Plan](../docs/plan/standard-library.md) · [Import RFC](../docs/rfcs/0016-standard-library-bootstrap.md) · [Endian RFC](../docs/rfcs/0017-standard-endian-results.md) · [Bounded operations RFC](../docs/rfcs/0018-bounded-standard-operations.md)
|
||||
@@ -183,3 +183,30 @@ effects []
|
||||
dst[7] = value as% u8;
|
||||
return std.bytes.WriteResult::ok;
|
||||
}
|
||||
|
||||
fn copy(dst: slice_mut<u8>, src: slice<u8>) -> std.bytes.WriteResult
|
||||
effects []
|
||||
{
|
||||
if dst.len < src.len { return std.bytes.WriteResult::short_output; }
|
||||
slice.copy(mut dst, ref src);
|
||||
return std.bytes.WriteResult::ok;
|
||||
}
|
||||
|
||||
enum FindResult { found(usize), not_found }
|
||||
|
||||
fn find_slice(data: slice<u8>, needle: slice<u8>) -> std.bytes.FindResult
|
||||
effects []
|
||||
{
|
||||
if needle.len == 0 { return std.bytes.FindResult::found(0); }
|
||||
if needle.len > data.len { return std.bytes.FindResult::not_found; }
|
||||
let last = data.len - needle.len;
|
||||
var start: usize = 0;
|
||||
loop {
|
||||
if std.bytes.equal(ref data[start..start + needle.len], ref needle) {
|
||||
return std.bytes.FindResult::found(start);
|
||||
}
|
||||
if start == last { break; }
|
||||
start = start + 1;
|
||||
}
|
||||
return std.bytes.FindResult::not_found;
|
||||
}
|
||||
@@ -20,3 +20,52 @@ effects []
|
||||
assert(lower <= upper);
|
||||
return std.math.min_u64(std.math.max_u64(value, lower), upper);
|
||||
}
|
||||
|
||||
enum U64Result { ok(u64), overflow }
|
||||
enum UsizeResult { ok(usize), overflow }
|
||||
|
||||
fn checked_add_u64(a: u64, b: u64) -> std.math.U64Result
|
||||
effects []
|
||||
{
|
||||
let maximum = 0u64 -% 1u64;
|
||||
if b > maximum - a { return std.math.U64Result::overflow; }
|
||||
return std.math.U64Result::ok(a + b);
|
||||
}
|
||||
|
||||
fn checked_sub_u64(a: u64, b: u64) -> std.math.U64Result
|
||||
effects []
|
||||
{
|
||||
if b > a { return std.math.U64Result::overflow; }
|
||||
return std.math.U64Result::ok(a - b);
|
||||
}
|
||||
|
||||
fn checked_mul_u64(a: u64, b: u64) -> std.math.U64Result
|
||||
effects []
|
||||
{
|
||||
let maximum = 0u64 -% 1u64;
|
||||
if b != 0 and a > maximum / b { return std.math.U64Result::overflow; }
|
||||
return std.math.U64Result::ok(a * b);
|
||||
}
|
||||
|
||||
fn checked_add_usize(a: usize, b: usize) -> std.math.UsizeResult
|
||||
effects []
|
||||
{
|
||||
let maximum = 0usize -% 1usize;
|
||||
if b > maximum - a { return std.math.UsizeResult::overflow; }
|
||||
return std.math.UsizeResult::ok(a + b);
|
||||
}
|
||||
|
||||
fn checked_sub_usize(a: usize, b: usize) -> std.math.UsizeResult
|
||||
effects []
|
||||
{
|
||||
if b > a { return std.math.UsizeResult::overflow; }
|
||||
return std.math.UsizeResult::ok(a - b);
|
||||
}
|
||||
|
||||
fn checked_mul_usize(a: usize, b: usize) -> std.math.UsizeResult
|
||||
effects []
|
||||
{
|
||||
let maximum = 0usize -% 1usize;
|
||||
if b != 0 and a > maximum / b { return std.math.UsizeResult::overflow; }
|
||||
return std.math.UsizeResult::ok(a * b);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// expect: run
|
||||
// result: {"variant":"overflow","payload":[]}
|
||||
// equivalent: std/bounded_arithmetic.air
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.1.1
|
||||
module test.bounded_arithmetic
|
||||
import std.math;
|
||||
|
||||
fn main() -> std.math.U64Result
|
||||
effects []
|
||||
{ return std.math.checked_add_u64(18446744073709551615, 1); }
|
||||
@@ -0,0 +1,44 @@
|
||||
// expect: run
|
||||
// result: 0
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.4
|
||||
module test.bounded
|
||||
import std.bytes;
|
||||
|
||||
fn expect_copy(result: std.bytes.WriteResult, success: bool) -> void
|
||||
effects []
|
||||
{
|
||||
match result {
|
||||
std.bytes.WriteResult::ok => { assert(success); }
|
||||
std.bytes.WriteResult::short_output => { assert(not success); }
|
||||
}
|
||||
}
|
||||
fn main() -> u8
|
||||
effects []
|
||||
{
|
||||
// Every source/output length through eight, including all empty combinations.
|
||||
var src: [u8; 8] = zero;
|
||||
for i in 0..src.len { src[i] = (i * 31 + 7) as! u8; }
|
||||
for count in 0usize..9usize {
|
||||
for capacity in 0usize..9usize {
|
||||
var dst: [u8; 10] = [165; 10];
|
||||
expect_copy(std.bytes.copy(mut dst[1..1 + capacity], ref src[0..count]), capacity >= count);
|
||||
for i in 0..dst.len {
|
||||
if capacity >= count and i >= 1 and i < 1 + count {
|
||||
assert(dst[i] == src[i - 1]);
|
||||
} else { assert(dst[i] == 165); }
|
||||
}
|
||||
for i in 0..src.len { assert(src[i] == (i * 31 + 7) as! u8); }
|
||||
}
|
||||
}
|
||||
// Same allocation is allowed through proven disjoint split borrows.
|
||||
var buf: [u8; 8] = zero;
|
||||
for i in 0..4usize { buf[i] = i as! u8 + 1; }
|
||||
{
|
||||
mut all = buf;
|
||||
let (left, right) = all.split_at(4);
|
||||
expect_copy(std.bytes.copy(mut right, ref left), true);
|
||||
}
|
||||
assert(std.bytes.equal(ref buf, b"\x01\x02\x03\x04\x01\x02\x03\x04"));
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// expect: reject E2101 E2101
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.4
|
||||
module test.bounded
|
||||
import std.bytes;
|
||||
|
||||
fn main() -> u8
|
||||
effects []
|
||||
{ var buf: [u8; 4] = zero; let result = std.bytes.copy(mut buf, ref buf); return 0; }
|
||||
@@ -0,0 +1,9 @@
|
||||
// expect: reject E2101 E2101 E2101
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.4
|
||||
module test.bounded
|
||||
import std.bytes;
|
||||
|
||||
fn main() -> u8
|
||||
effects []
|
||||
{ var buf: [u8; 4] = zero; ref saved = buf; let result = std.bytes.copy(mut buf[0..0], ref saved); return 0; }
|
||||
@@ -0,0 +1,23 @@
|
||||
// expect: run
|
||||
// result: [5,5,5,165]
|
||||
// equivalent: std/bounded_copy.air
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.4
|
||||
module test.bounded_copy
|
||||
import std.bytes;
|
||||
|
||||
fn main() -> [u8; 4]
|
||||
effects []
|
||||
{
|
||||
let src: [u8; 3] = [5; 3];
|
||||
var dst: [u8; 4] = [165; 4];
|
||||
match std.bytes.copy(mut dst[0..2], ref src) {
|
||||
std.bytes.WriteResult::ok => { trap; }
|
||||
std.bytes.WriteResult::short_output => { assert(dst[0] == 165); }
|
||||
}
|
||||
match std.bytes.copy(mut dst, ref src) {
|
||||
std.bytes.WriteResult::ok => {}
|
||||
std.bytes.WriteResult::short_output => { trap; }
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// expect: reject E7005
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.4
|
||||
module test.bounded
|
||||
import std.bytes;
|
||||
|
||||
fn main() -> u8
|
||||
effects []
|
||||
{ var buf: [u8; 4] = zero; let result = std.bytes.copy(ref buf, b"x"); return 0; }
|
||||
@@ -0,0 +1,39 @@
|
||||
// expect: run
|
||||
// result: 10
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.1.1, §2.4
|
||||
module demo.bounded
|
||||
import std.bytes;
|
||||
import std.math;
|
||||
|
||||
fn encode(dst: slice_mut<u8>, data: slice<u8>) -> usize
|
||||
effects []
|
||||
{
|
||||
match std.math.checked_add_usize(data.len, 1) {
|
||||
std.math.UsizeResult::ok(total) => {
|
||||
if total > dst.len { return 0; }
|
||||
match std.bytes.copy(mut dst, ref data) {
|
||||
std.bytes.WriteResult::ok => { dst[data.len] = 0; return total; }
|
||||
std.bytes.WriteResult::short_output => { return 0; }
|
||||
}
|
||||
}
|
||||
std.math.UsizeResult::overflow => { return 0; }
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> usize
|
||||
effects []
|
||||
{
|
||||
var buf: [u8; 16] = [165; 16];
|
||||
let size = encode(mut buf, b"key=value");
|
||||
assert(size == 10);
|
||||
assert(buf[9] == 0 and buf[10] == 165);
|
||||
match std.bytes.find_slice(ref buf[0..size - 1], b"=") {
|
||||
std.bytes.FindResult::found(index) => {
|
||||
assert(std.bytes.equal(ref buf[0..index], b"key"));
|
||||
assert(std.bytes.equal(ref buf[index + 1..size - 1], b"value"));
|
||||
}
|
||||
std.bytes.FindResult::not_found => { trap; }
|
||||
}
|
||||
return size;
|
||||
}
|
||||
@@ -0,0 +1,360 @@
|
||||
// expect: run
|
||||
// result: 0
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.1.1; docs/spec/09-runtime-and-abi.md §9
|
||||
// Numeric vectors use the interpreter's default air64 target.
|
||||
module test.bounded_math
|
||||
import std.math;
|
||||
|
||||
fn check_u64(result: std.math.U64Result, success: bool, expected: u64) -> void
|
||||
effects []
|
||||
{
|
||||
match result {
|
||||
std.math.U64Result::ok(value) => { assert(success); assert(value == expected); }
|
||||
std.math.U64Result::overflow => { assert(not success); }
|
||||
}
|
||||
}
|
||||
fn check_usize(result: std.math.UsizeResult, success: bool, expected: usize) -> void
|
||||
effects []
|
||||
{
|
||||
match result {
|
||||
std.math.UsizeResult::ok(value) => { assert(success); assert(value == expected); }
|
||||
std.math.UsizeResult::overflow => { assert(not success); }
|
||||
}
|
||||
}
|
||||
fn fixture(a: u64, b: u64, add_ok: bool, add: u64, sub_ok: bool, sub: u64, mul_ok: bool, mul: u64) -> void
|
||||
effects []
|
||||
{
|
||||
check_u64(std.math.checked_add_u64(a, b), add_ok, add);
|
||||
check_u64(std.math.checked_sub_u64(a, b), sub_ok, sub);
|
||||
check_u64(std.math.checked_mul_u64(a, b), mul_ok, mul);
|
||||
check_usize(std.math.checked_add_usize(a as! usize, b as! usize), add_ok, add as! usize);
|
||||
check_usize(std.math.checked_sub_usize(a as! usize, b as! usize), sub_ok, sub as! usize);
|
||||
check_usize(std.math.checked_mul_usize(a as! usize, b as! usize), mul_ok, mul as! usize);
|
||||
}
|
||||
fn main() -> u8
|
||||
effects []
|
||||
{
|
||||
// Python arbitrary-precision arithmetic determines representability and values.
|
||||
fixture(0, 0, true, 0, true, 0, true, 0);
|
||||
fixture(0, 1, true, 1, false, 0, true, 0);
|
||||
fixture(0, 2, true, 2, false, 0, true, 0);
|
||||
fixture(0, 3, true, 3, false, 0, true, 0);
|
||||
fixture(0, 255, true, 255, false, 0, true, 0);
|
||||
fixture(0, 256, true, 256, false, 0, true, 0);
|
||||
fixture(0, 65535, true, 65535, false, 0, true, 0);
|
||||
fixture(0, 65536, true, 65536, false, 0, true, 0);
|
||||
fixture(0, 4294967295, true, 4294967295, false, 0, true, 0);
|
||||
fixture(0, 4294967296, true, 4294967296, false, 0, true, 0);
|
||||
fixture(0, 4294967297, true, 4294967297, false, 0, true, 0);
|
||||
fixture(0, 9223372036854775807, true, 9223372036854775807, false, 0, true, 0);
|
||||
fixture(0, 9223372036854775808, true, 9223372036854775808, false, 0, true, 0);
|
||||
fixture(0, 9223372036854775809, true, 9223372036854775809, false, 0, true, 0);
|
||||
fixture(0, 18446744073709551614, true, 18446744073709551614, false, 0, true, 0);
|
||||
fixture(0, 18446744073709551615, true, 18446744073709551615, false, 0, true, 0);
|
||||
fixture(1, 0, true, 1, true, 1, true, 0);
|
||||
fixture(1, 1, true, 2, true, 0, true, 1);
|
||||
fixture(1, 2, true, 3, false, 0, true, 2);
|
||||
fixture(1, 3, true, 4, false, 0, true, 3);
|
||||
fixture(1, 255, true, 256, false, 0, true, 255);
|
||||
fixture(1, 256, true, 257, false, 0, true, 256);
|
||||
fixture(1, 65535, true, 65536, false, 0, true, 65535);
|
||||
fixture(1, 65536, true, 65537, false, 0, true, 65536);
|
||||
fixture(1, 4294967295, true, 4294967296, false, 0, true, 4294967295);
|
||||
fixture(1, 4294967296, true, 4294967297, false, 0, true, 4294967296);
|
||||
fixture(1, 4294967297, true, 4294967298, false, 0, true, 4294967297);
|
||||
fixture(1, 9223372036854775807, true, 9223372036854775808, false, 0, true, 9223372036854775807);
|
||||
fixture(1, 9223372036854775808, true, 9223372036854775809, false, 0, true, 9223372036854775808);
|
||||
fixture(1, 9223372036854775809, true, 9223372036854775810, false, 0, true, 9223372036854775809);
|
||||
fixture(1, 18446744073709551614, true, 18446744073709551615, false, 0, true, 18446744073709551614);
|
||||
fixture(1, 18446744073709551615, false, 0, false, 0, true, 18446744073709551615);
|
||||
fixture(2, 0, true, 2, true, 2, true, 0);
|
||||
fixture(2, 1, true, 3, true, 1, true, 2);
|
||||
fixture(2, 2, true, 4, true, 0, true, 4);
|
||||
fixture(2, 3, true, 5, false, 0, true, 6);
|
||||
fixture(2, 255, true, 257, false, 0, true, 510);
|
||||
fixture(2, 256, true, 258, false, 0, true, 512);
|
||||
fixture(2, 65535, true, 65537, false, 0, true, 131070);
|
||||
fixture(2, 65536, true, 65538, false, 0, true, 131072);
|
||||
fixture(2, 4294967295, true, 4294967297, false, 0, true, 8589934590);
|
||||
fixture(2, 4294967296, true, 4294967298, false, 0, true, 8589934592);
|
||||
fixture(2, 4294967297, true, 4294967299, false, 0, true, 8589934594);
|
||||
fixture(2, 9223372036854775807, true, 9223372036854775809, false, 0, true, 18446744073709551614);
|
||||
fixture(2, 9223372036854775808, true, 9223372036854775810, false, 0, false, 0);
|
||||
fixture(2, 9223372036854775809, true, 9223372036854775811, false, 0, false, 0);
|
||||
fixture(2, 18446744073709551614, false, 0, false, 0, false, 0);
|
||||
fixture(2, 18446744073709551615, false, 0, false, 0, false, 0);
|
||||
fixture(3, 0, true, 3, true, 3, true, 0);
|
||||
fixture(3, 1, true, 4, true, 2, true, 3);
|
||||
fixture(3, 2, true, 5, true, 1, true, 6);
|
||||
fixture(3, 3, true, 6, true, 0, true, 9);
|
||||
fixture(3, 255, true, 258, false, 0, true, 765);
|
||||
fixture(3, 256, true, 259, false, 0, true, 768);
|
||||
fixture(3, 65535, true, 65538, false, 0, true, 196605);
|
||||
fixture(3, 65536, true, 65539, false, 0, true, 196608);
|
||||
fixture(3, 4294967295, true, 4294967298, false, 0, true, 12884901885);
|
||||
fixture(3, 4294967296, true, 4294967299, false, 0, true, 12884901888);
|
||||
fixture(3, 4294967297, true, 4294967300, false, 0, true, 12884901891);
|
||||
fixture(3, 9223372036854775807, true, 9223372036854775810, false, 0, false, 0);
|
||||
fixture(3, 9223372036854775808, true, 9223372036854775811, false, 0, false, 0);
|
||||
fixture(3, 9223372036854775809, true, 9223372036854775812, false, 0, false, 0);
|
||||
fixture(3, 18446744073709551614, false, 0, false, 0, false, 0);
|
||||
fixture(3, 18446744073709551615, false, 0, false, 0, false, 0);
|
||||
fixture(255, 0, true, 255, true, 255, true, 0);
|
||||
fixture(255, 1, true, 256, true, 254, true, 255);
|
||||
fixture(255, 2, true, 257, true, 253, true, 510);
|
||||
fixture(255, 3, true, 258, true, 252, true, 765);
|
||||
fixture(255, 255, true, 510, true, 0, true, 65025);
|
||||
fixture(255, 256, true, 511, false, 0, true, 65280);
|
||||
fixture(255, 65535, true, 65790, false, 0, true, 16711425);
|
||||
fixture(255, 65536, true, 65791, false, 0, true, 16711680);
|
||||
fixture(255, 4294967295, true, 4294967550, false, 0, true, 1095216660225);
|
||||
fixture(255, 4294967296, true, 4294967551, false, 0, true, 1095216660480);
|
||||
fixture(255, 4294967297, true, 4294967552, false, 0, true, 1095216660735);
|
||||
fixture(255, 9223372036854775807, true, 9223372036854776062, false, 0, false, 0);
|
||||
fixture(255, 9223372036854775808, true, 9223372036854776063, false, 0, false, 0);
|
||||
fixture(255, 9223372036854775809, true, 9223372036854776064, false, 0, false, 0);
|
||||
fixture(255, 18446744073709551614, false, 0, false, 0, false, 0);
|
||||
fixture(255, 18446744073709551615, false, 0, false, 0, false, 0);
|
||||
fixture(256, 0, true, 256, true, 256, true, 0);
|
||||
fixture(256, 1, true, 257, true, 255, true, 256);
|
||||
fixture(256, 2, true, 258, true, 254, true, 512);
|
||||
fixture(256, 3, true, 259, true, 253, true, 768);
|
||||
fixture(256, 255, true, 511, true, 1, true, 65280);
|
||||
fixture(256, 256, true, 512, true, 0, true, 65536);
|
||||
fixture(256, 65535, true, 65791, false, 0, true, 16776960);
|
||||
fixture(256, 65536, true, 65792, false, 0, true, 16777216);
|
||||
fixture(256, 4294967295, true, 4294967551, false, 0, true, 1099511627520);
|
||||
fixture(256, 4294967296, true, 4294967552, false, 0, true, 1099511627776);
|
||||
fixture(256, 4294967297, true, 4294967553, false, 0, true, 1099511628032);
|
||||
fixture(256, 9223372036854775807, true, 9223372036854776063, false, 0, false, 0);
|
||||
fixture(256, 9223372036854775808, true, 9223372036854776064, false, 0, false, 0);
|
||||
fixture(256, 9223372036854775809, true, 9223372036854776065, false, 0, false, 0);
|
||||
fixture(256, 18446744073709551614, false, 0, false, 0, false, 0);
|
||||
fixture(256, 18446744073709551615, false, 0, false, 0, false, 0);
|
||||
fixture(65535, 0, true, 65535, true, 65535, true, 0);
|
||||
fixture(65535, 1, true, 65536, true, 65534, true, 65535);
|
||||
fixture(65535, 2, true, 65537, true, 65533, true, 131070);
|
||||
fixture(65535, 3, true, 65538, true, 65532, true, 196605);
|
||||
fixture(65535, 255, true, 65790, true, 65280, true, 16711425);
|
||||
fixture(65535, 256, true, 65791, true, 65279, true, 16776960);
|
||||
fixture(65535, 65535, true, 131070, true, 0, true, 4294836225);
|
||||
fixture(65535, 65536, true, 131071, false, 0, true, 4294901760);
|
||||
fixture(65535, 4294967295, true, 4295032830, false, 0, true, 281470681677825);
|
||||
fixture(65535, 4294967296, true, 4295032831, false, 0, true, 281470681743360);
|
||||
fixture(65535, 4294967297, true, 4295032832, false, 0, true, 281470681808895);
|
||||
fixture(65535, 9223372036854775807, true, 9223372036854841342, false, 0, false, 0);
|
||||
fixture(65535, 9223372036854775808, true, 9223372036854841343, false, 0, false, 0);
|
||||
fixture(65535, 9223372036854775809, true, 9223372036854841344, false, 0, false, 0);
|
||||
fixture(65535, 18446744073709551614, false, 0, false, 0, false, 0);
|
||||
fixture(65535, 18446744073709551615, false, 0, false, 0, false, 0);
|
||||
fixture(65536, 0, true, 65536, true, 65536, true, 0);
|
||||
fixture(65536, 1, true, 65537, true, 65535, true, 65536);
|
||||
fixture(65536, 2, true, 65538, true, 65534, true, 131072);
|
||||
fixture(65536, 3, true, 65539, true, 65533, true, 196608);
|
||||
fixture(65536, 255, true, 65791, true, 65281, true, 16711680);
|
||||
fixture(65536, 256, true, 65792, true, 65280, true, 16777216);
|
||||
fixture(65536, 65535, true, 131071, true, 1, true, 4294901760);
|
||||
fixture(65536, 65536, true, 131072, true, 0, true, 4294967296);
|
||||
fixture(65536, 4294967295, true, 4295032831, false, 0, true, 281474976645120);
|
||||
fixture(65536, 4294967296, true, 4295032832, false, 0, true, 281474976710656);
|
||||
fixture(65536, 4294967297, true, 4295032833, false, 0, true, 281474976776192);
|
||||
fixture(65536, 9223372036854775807, true, 9223372036854841343, false, 0, false, 0);
|
||||
fixture(65536, 9223372036854775808, true, 9223372036854841344, false, 0, false, 0);
|
||||
fixture(65536, 9223372036854775809, true, 9223372036854841345, false, 0, false, 0);
|
||||
fixture(65536, 18446744073709551614, false, 0, false, 0, false, 0);
|
||||
fixture(65536, 18446744073709551615, false, 0, false, 0, false, 0);
|
||||
fixture(4294967295, 0, true, 4294967295, true, 4294967295, true, 0);
|
||||
fixture(4294967295, 1, true, 4294967296, true, 4294967294, true, 4294967295);
|
||||
fixture(4294967295, 2, true, 4294967297, true, 4294967293, true, 8589934590);
|
||||
fixture(4294967295, 3, true, 4294967298, true, 4294967292, true, 12884901885);
|
||||
fixture(4294967295, 255, true, 4294967550, true, 4294967040, true, 1095216660225);
|
||||
fixture(4294967295, 256, true, 4294967551, true, 4294967039, true, 1099511627520);
|
||||
fixture(4294967295, 65535, true, 4295032830, true, 4294901760, true, 281470681677825);
|
||||
fixture(4294967295, 65536, true, 4295032831, true, 4294901759, true, 281474976645120);
|
||||
fixture(4294967295, 4294967295, true, 8589934590, true, 0, true, 18446744065119617025);
|
||||
fixture(4294967295, 4294967296, true, 8589934591, false, 0, true, 18446744069414584320);
|
||||
fixture(4294967295, 4294967297, true, 8589934592, false, 0, true, 18446744073709551615);
|
||||
fixture(4294967295, 9223372036854775807, true, 9223372041149743102, false, 0, false, 0);
|
||||
fixture(4294967295, 9223372036854775808, true, 9223372041149743103, false, 0, false, 0);
|
||||
fixture(4294967295, 9223372036854775809, true, 9223372041149743104, false, 0, false, 0);
|
||||
fixture(4294967295, 18446744073709551614, false, 0, false, 0, false, 0);
|
||||
fixture(4294967295, 18446744073709551615, false, 0, false, 0, false, 0);
|
||||
fixture(4294967296, 0, true, 4294967296, true, 4294967296, true, 0);
|
||||
fixture(4294967296, 1, true, 4294967297, true, 4294967295, true, 4294967296);
|
||||
fixture(4294967296, 2, true, 4294967298, true, 4294967294, true, 8589934592);
|
||||
fixture(4294967296, 3, true, 4294967299, true, 4294967293, true, 12884901888);
|
||||
fixture(4294967296, 255, true, 4294967551, true, 4294967041, true, 1095216660480);
|
||||
fixture(4294967296, 256, true, 4294967552, true, 4294967040, true, 1099511627776);
|
||||
fixture(4294967296, 65535, true, 4295032831, true, 4294901761, true, 281470681743360);
|
||||
fixture(4294967296, 65536, true, 4295032832, true, 4294901760, true, 281474976710656);
|
||||
fixture(4294967296, 4294967295, true, 8589934591, true, 1, true, 18446744069414584320);
|
||||
fixture(4294967296, 4294967296, true, 8589934592, true, 0, false, 0);
|
||||
fixture(4294967296, 4294967297, true, 8589934593, false, 0, false, 0);
|
||||
fixture(4294967296, 9223372036854775807, true, 9223372041149743103, false, 0, false, 0);
|
||||
fixture(4294967296, 9223372036854775808, true, 9223372041149743104, false, 0, false, 0);
|
||||
fixture(4294967296, 9223372036854775809, true, 9223372041149743105, false, 0, false, 0);
|
||||
fixture(4294967296, 18446744073709551614, false, 0, false, 0, false, 0);
|
||||
fixture(4294967296, 18446744073709551615, false, 0, false, 0, false, 0);
|
||||
fixture(4294967297, 0, true, 4294967297, true, 4294967297, true, 0);
|
||||
fixture(4294967297, 1, true, 4294967298, true, 4294967296, true, 4294967297);
|
||||
fixture(4294967297, 2, true, 4294967299, true, 4294967295, true, 8589934594);
|
||||
fixture(4294967297, 3, true, 4294967300, true, 4294967294, true, 12884901891);
|
||||
fixture(4294967297, 255, true, 4294967552, true, 4294967042, true, 1095216660735);
|
||||
fixture(4294967297, 256, true, 4294967553, true, 4294967041, true, 1099511628032);
|
||||
fixture(4294967297, 65535, true, 4295032832, true, 4294901762, true, 281470681808895);
|
||||
fixture(4294967297, 65536, true, 4295032833, true, 4294901761, true, 281474976776192);
|
||||
fixture(4294967297, 4294967295, true, 8589934592, true, 2, true, 18446744073709551615);
|
||||
fixture(4294967297, 4294967296, true, 8589934593, true, 1, false, 0);
|
||||
fixture(4294967297, 4294967297, true, 8589934594, true, 0, false, 0);
|
||||
fixture(4294967297, 9223372036854775807, true, 9223372041149743104, false, 0, false, 0);
|
||||
fixture(4294967297, 9223372036854775808, true, 9223372041149743105, false, 0, false, 0);
|
||||
fixture(4294967297, 9223372036854775809, true, 9223372041149743106, false, 0, false, 0);
|
||||
fixture(4294967297, 18446744073709551614, false, 0, false, 0, false, 0);
|
||||
fixture(4294967297, 18446744073709551615, false, 0, false, 0, false, 0);
|
||||
fixture(9223372036854775807, 0, true, 9223372036854775807, true, 9223372036854775807, true, 0);
|
||||
fixture(9223372036854775807, 1, true, 9223372036854775808, true, 9223372036854775806, true, 9223372036854775807);
|
||||
fixture(9223372036854775807, 2, true, 9223372036854775809, true, 9223372036854775805, true, 18446744073709551614);
|
||||
fixture(9223372036854775807, 3, true, 9223372036854775810, true, 9223372036854775804, false, 0);
|
||||
fixture(9223372036854775807, 255, true, 9223372036854776062, true, 9223372036854775552, false, 0);
|
||||
fixture(9223372036854775807, 256, true, 9223372036854776063, true, 9223372036854775551, false, 0);
|
||||
fixture(9223372036854775807, 65535, true, 9223372036854841342, true, 9223372036854710272, false, 0);
|
||||
fixture(9223372036854775807, 65536, true, 9223372036854841343, true, 9223372036854710271, false, 0);
|
||||
fixture(9223372036854775807, 4294967295, true, 9223372041149743102, true, 9223372032559808512, false, 0);
|
||||
fixture(9223372036854775807, 4294967296, true, 9223372041149743103, true, 9223372032559808511, false, 0);
|
||||
fixture(9223372036854775807, 4294967297, true, 9223372041149743104, true, 9223372032559808510, false, 0);
|
||||
fixture(9223372036854775807, 9223372036854775807, true, 18446744073709551614, true, 0, false, 0);
|
||||
fixture(9223372036854775807, 9223372036854775808, true, 18446744073709551615, false, 0, false, 0);
|
||||
fixture(9223372036854775807, 9223372036854775809, false, 0, false, 0, false, 0);
|
||||
fixture(9223372036854775807, 18446744073709551614, false, 0, false, 0, false, 0);
|
||||
fixture(9223372036854775807, 18446744073709551615, false, 0, false, 0, false, 0);
|
||||
fixture(9223372036854775808, 0, true, 9223372036854775808, true, 9223372036854775808, true, 0);
|
||||
fixture(9223372036854775808, 1, true, 9223372036854775809, true, 9223372036854775807, true, 9223372036854775808);
|
||||
fixture(9223372036854775808, 2, true, 9223372036854775810, true, 9223372036854775806, false, 0);
|
||||
fixture(9223372036854775808, 3, true, 9223372036854775811, true, 9223372036854775805, false, 0);
|
||||
fixture(9223372036854775808, 255, true, 9223372036854776063, true, 9223372036854775553, false, 0);
|
||||
fixture(9223372036854775808, 256, true, 9223372036854776064, true, 9223372036854775552, false, 0);
|
||||
fixture(9223372036854775808, 65535, true, 9223372036854841343, true, 9223372036854710273, false, 0);
|
||||
fixture(9223372036854775808, 65536, true, 9223372036854841344, true, 9223372036854710272, false, 0);
|
||||
fixture(9223372036854775808, 4294967295, true, 9223372041149743103, true, 9223372032559808513, false, 0);
|
||||
fixture(9223372036854775808, 4294967296, true, 9223372041149743104, true, 9223372032559808512, false, 0);
|
||||
fixture(9223372036854775808, 4294967297, true, 9223372041149743105, true, 9223372032559808511, false, 0);
|
||||
fixture(9223372036854775808, 9223372036854775807, true, 18446744073709551615, true, 1, false, 0);
|
||||
fixture(9223372036854775808, 9223372036854775808, false, 0, true, 0, false, 0);
|
||||
fixture(9223372036854775808, 9223372036854775809, false, 0, false, 0, false, 0);
|
||||
fixture(9223372036854775808, 18446744073709551614, false, 0, false, 0, false, 0);
|
||||
fixture(9223372036854775808, 18446744073709551615, false, 0, false, 0, false, 0);
|
||||
fixture(9223372036854775809, 0, true, 9223372036854775809, true, 9223372036854775809, true, 0);
|
||||
fixture(9223372036854775809, 1, true, 9223372036854775810, true, 9223372036854775808, true, 9223372036854775809);
|
||||
fixture(9223372036854775809, 2, true, 9223372036854775811, true, 9223372036854775807, false, 0);
|
||||
fixture(9223372036854775809, 3, true, 9223372036854775812, true, 9223372036854775806, false, 0);
|
||||
fixture(9223372036854775809, 255, true, 9223372036854776064, true, 9223372036854775554, false, 0);
|
||||
fixture(9223372036854775809, 256, true, 9223372036854776065, true, 9223372036854775553, false, 0);
|
||||
fixture(9223372036854775809, 65535, true, 9223372036854841344, true, 9223372036854710274, false, 0);
|
||||
fixture(9223372036854775809, 65536, true, 9223372036854841345, true, 9223372036854710273, false, 0);
|
||||
fixture(9223372036854775809, 4294967295, true, 9223372041149743104, true, 9223372032559808514, false, 0);
|
||||
fixture(9223372036854775809, 4294967296, true, 9223372041149743105, true, 9223372032559808513, false, 0);
|
||||
fixture(9223372036854775809, 4294967297, true, 9223372041149743106, true, 9223372032559808512, false, 0);
|
||||
fixture(9223372036854775809, 9223372036854775807, false, 0, true, 2, false, 0);
|
||||
fixture(9223372036854775809, 9223372036854775808, false, 0, true, 1, false, 0);
|
||||
fixture(9223372036854775809, 9223372036854775809, false, 0, true, 0, false, 0);
|
||||
fixture(9223372036854775809, 18446744073709551614, false, 0, false, 0, false, 0);
|
||||
fixture(9223372036854775809, 18446744073709551615, false, 0, false, 0, false, 0);
|
||||
fixture(18446744073709551614, 0, true, 18446744073709551614, true, 18446744073709551614, true, 0);
|
||||
fixture(18446744073709551614, 1, true, 18446744073709551615, true, 18446744073709551613, true, 18446744073709551614);
|
||||
fixture(18446744073709551614, 2, false, 0, true, 18446744073709551612, false, 0);
|
||||
fixture(18446744073709551614, 3, false, 0, true, 18446744073709551611, false, 0);
|
||||
fixture(18446744073709551614, 255, false, 0, true, 18446744073709551359, false, 0);
|
||||
fixture(18446744073709551614, 256, false, 0, true, 18446744073709551358, false, 0);
|
||||
fixture(18446744073709551614, 65535, false, 0, true, 18446744073709486079, false, 0);
|
||||
fixture(18446744073709551614, 65536, false, 0, true, 18446744073709486078, false, 0);
|
||||
fixture(18446744073709551614, 4294967295, false, 0, true, 18446744069414584319, false, 0);
|
||||
fixture(18446744073709551614, 4294967296, false, 0, true, 18446744069414584318, false, 0);
|
||||
fixture(18446744073709551614, 4294967297, false, 0, true, 18446744069414584317, false, 0);
|
||||
fixture(18446744073709551614, 9223372036854775807, false, 0, true, 9223372036854775807, false, 0);
|
||||
fixture(18446744073709551614, 9223372036854775808, false, 0, true, 9223372036854775806, false, 0);
|
||||
fixture(18446744073709551614, 9223372036854775809, false, 0, true, 9223372036854775805, false, 0);
|
||||
fixture(18446744073709551614, 18446744073709551614, false, 0, true, 0, false, 0);
|
||||
fixture(18446744073709551614, 18446744073709551615, false, 0, false, 0, false, 0);
|
||||
fixture(18446744073709551615, 0, true, 18446744073709551615, true, 18446744073709551615, true, 0);
|
||||
fixture(18446744073709551615, 1, false, 0, true, 18446744073709551614, true, 18446744073709551615);
|
||||
fixture(18446744073709551615, 2, false, 0, true, 18446744073709551613, false, 0);
|
||||
fixture(18446744073709551615, 3, false, 0, true, 18446744073709551612, false, 0);
|
||||
fixture(18446744073709551615, 255, false, 0, true, 18446744073709551360, false, 0);
|
||||
fixture(18446744073709551615, 256, false, 0, true, 18446744073709551359, false, 0);
|
||||
fixture(18446744073709551615, 65535, false, 0, true, 18446744073709486080, false, 0);
|
||||
fixture(18446744073709551615, 65536, false, 0, true, 18446744073709486079, false, 0);
|
||||
fixture(18446744073709551615, 4294967295, false, 0, true, 18446744069414584320, false, 0);
|
||||
fixture(18446744073709551615, 4294967296, false, 0, true, 18446744069414584319, false, 0);
|
||||
fixture(18446744073709551615, 4294967297, false, 0, true, 18446744069414584318, false, 0);
|
||||
fixture(18446744073709551615, 9223372036854775807, false, 0, true, 9223372036854775808, false, 0);
|
||||
fixture(18446744073709551615, 9223372036854775808, false, 0, true, 9223372036854775807, false, 0);
|
||||
fixture(18446744073709551615, 9223372036854775809, false, 0, true, 9223372036854775806, false, 0);
|
||||
fixture(18446744073709551615, 18446744073709551614, false, 0, true, 1, false, 0);
|
||||
fixture(18446744073709551615, 18446744073709551615, false, 0, true, 0, false, 0);
|
||||
fixture(22826, 8367811077280, true, 8367811100106, false, 0, true, 191003655649993280);
|
||||
fixture(51593471070231, 53279520, true, 51593524349751, true, 51593417790711, false, 0);
|
||||
fixture(44221820468, 9167, true, 44221829635, true, 44221811301, true, 405381428230156);
|
||||
fixture(7738, 681, true, 8419, true, 7057, true, 5269578);
|
||||
fixture(1665, 5665, true, 7330, false, 0, true, 9432225);
|
||||
fixture(535130129349569381, 74173, true, 535130129349643554, true, 535130129349495208, false, 0);
|
||||
fixture(39484571, 14368932415, true, 14408416986, false, 0, true, 567351132134268965);
|
||||
fixture(655837162, 0, true, 655837162, true, 655837162, true, 0);
|
||||
fixture(24263945274549, 5922203636850238, true, 5946467582124787, false, 0, false, 0);
|
||||
fixture(1358311, 1589, true, 1359900, true, 1356722, true, 2158356179);
|
||||
fixture(576800471, 70102195884118449, true, 70102196460918920, false, 0, false, 0);
|
||||
fixture(205, 59442931, true, 59443136, false, 0, true, 12185800855);
|
||||
fixture(6713838, 10288843303, true, 10295557141, false, 0, true, 69077627143726914);
|
||||
fixture(113309654, 56964999, true, 170274653, true, 56344655, true, 6454684326800346);
|
||||
fixture(2710646336777, 1327432, true, 2710647664209, true, 2710645009345, true, 3598198688120566664);
|
||||
fixture(102398190504438869, 33455376019343141, true, 135853566523782010, true, 68942814485095728, false, 0);
|
||||
fixture(15110500053195, 1846226806251251761, true, 1846241916751304956, false, 0, false, 0);
|
||||
fixture(92259697, 110072463, true, 202332160, false, 0, true, 10155252084423711);
|
||||
fixture(9189325, 15633344, true, 24822669, false, 0, true, 143659878852800);
|
||||
fixture(229887117848438, 4209657228195905, true, 4439544346044343, false, 0, false, 0);
|
||||
fixture(707, 35394681, true, 35395388, false, 0, true, 25024039467);
|
||||
fixture(366886542353037072, 521603756, true, 366886542874640828, true, 366886541831433316, false, 0);
|
||||
fixture(3149543, 940, true, 3150483, true, 3148603, true, 2960570420);
|
||||
fixture(22251316823, 9960569387575863, true, 9960591638892686, false, 0, false, 0);
|
||||
fixture(44605, 1078529957565922052, true, 1078529957565966657, false, 0, false, 0);
|
||||
fixture(63959489124825692, 1173018, true, 63959489125998710, true, 63959489123652674, false, 0);
|
||||
fixture(22216483, 72615, true, 22289098, true, 22143868, true, 1613249913045);
|
||||
fixture(4809, 377746108198, true, 377746113007, false, 0, true, 1816581034324182);
|
||||
fixture(114572438714163, 1873997096453140, true, 1988569535167303, false, 0, false, 0);
|
||||
fixture(767029847, 324, true, 767030171, true, 767029523, true, 248517670428);
|
||||
fixture(4250932681200, 279793451149599326, true, 279797702082280526, false, 0, false, 0);
|
||||
fixture(198016577350, 770073984820857066, true, 770074182837434416, false, 0, false, 0);
|
||||
fixture(29908, 121, true, 30029, true, 29787, true, 3618868);
|
||||
fixture(339685630, 27, true, 339685657, true, 339685603, true, 9171512010);
|
||||
fixture(435343, 152150, true, 587493, true, 283193, true, 66237437450);
|
||||
fixture(214819840135, 0, true, 214819840135, true, 214819840135, true, 0);
|
||||
fixture(47387502183386252, 494501857556655, true, 47882004040942907, true, 46893000325829597, false, 0);
|
||||
fixture(442452015457818960, 1031972, true, 442452015458850932, true, 442452015456786988, false, 0);
|
||||
fixture(31118767, 7, true, 31118774, true, 31118760, true, 217831369);
|
||||
fixture(664, 49681316821, true, 49681317485, false, 0, true, 32988394369144);
|
||||
fixture(336104835056, 424, true, 336104835480, true, 336104834632, true, 142508450063744);
|
||||
fixture(15647158001728818016, 538507692697, true, 15647158540236510713, true, 15647157463221125319, false, 0);
|
||||
fixture(11501959764, 5636, true, 11501965400, true, 11501954128, true, 64825045229904);
|
||||
fixture(247638850912878, 2552731, true, 247638853465609, true, 247638848360147, false, 0);
|
||||
fixture(217, 24, true, 241, true, 193, true, 5208);
|
||||
fixture(991798435, 57491197064698733, true, 57491198056497168, false, 0, false, 0);
|
||||
fixture(13667425, 96, true, 13667521, true, 13667329, true, 1312072800);
|
||||
fixture(1141625698, 1842638482103948, true, 1842639623729646, false, 0, false, 0);
|
||||
fixture(675441552758543024, 1701504, true, 675441552760244528, true, 675441552756841520, false, 0);
|
||||
fixture(4043227632, 3572158, true, 4046799790, true, 4039655474, true, 14443047931469856);
|
||||
fixture(181, 21747, true, 21928, false, 0, true, 3936207);
|
||||
fixture(347, 51961183391702751, true, 51961183391703098, false, 0, true, 18030530636920854597);
|
||||
fixture(15897801183, 820998858494053947, true, 820998874391855130, false, 0, false, 0);
|
||||
fixture(11102207627936, 3956352, true, 11102211584288, true, 11102203671584, false, 0);
|
||||
fixture(7716, 34, true, 7750, true, 7682, true, 262344);
|
||||
fixture(2525470172558571, 47635234075287, true, 2573105406633858, true, 2477834938483284, false, 0);
|
||||
fixture(1041112819, 29, true, 1041112848, true, 1041112790, true, 30192271751);
|
||||
fixture(43, 18445734596328899, true, 18445734596328942, false, 0, true, 793166587642142657);
|
||||
fixture(4416413916661094, 3, true, 4416413916661097, true, 4416413916661091, true, 13249241749983282);
|
||||
fixture(194105530, 6249, true, 194111779, true, 194099281, true, 1212965456970);
|
||||
fixture(242378907314190932, 4527967589446891778, true, 4770346496761082710, false, 0, false, 0);
|
||||
fixture(307260339, 674682, true, 307935021, true, 306585657, true, 207303020037198);
|
||||
fixture(116240498161, 0, true, 116240498161, true, 116240498161, true, 0);
|
||||
fixture(1292039328228149846, 131256129543, true, 1292039459484279389, true, 1292039196972020303, false, 0);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// expect: reject E7004
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.1.1
|
||||
module test.bounded_math
|
||||
import std.math;
|
||||
fn main() -> std.math.U64Result
|
||||
effects []
|
||||
{ match std.math.checked_add_u64(1, 2) { std.math.U64Result::ok(value) => { return std.math.U64Result::ok(value); } } }
|
||||
@@ -0,0 +1,7 @@
|
||||
// expect: reject E7002
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.1.1
|
||||
module test.bounded_math
|
||||
fn main() -> u64
|
||||
effects []
|
||||
{ return std.math.checked_add_u64(1, 2); }
|
||||
@@ -0,0 +1,8 @@
|
||||
// expect: reject E7005
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.1.1
|
||||
module test.bounded_math
|
||||
import std.math;
|
||||
fn main() -> std.math.U64Result
|
||||
effects []
|
||||
{ return std.math.U64Result::ok(true); }
|
||||
@@ -0,0 +1,8 @@
|
||||
// expect: reject E7005
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.1.1
|
||||
module test.bounded_math
|
||||
import std.math;
|
||||
fn main() -> std.math.U64Result
|
||||
effects []
|
||||
{ let a: u32 = 1; let result = std.math.checked_add_u64(a, 2); return std.math.U64Result::overflow; }
|
||||
@@ -0,0 +1,8 @@
|
||||
// expect: reject E7005
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.1.1
|
||||
module test.bounded_math
|
||||
import std.math;
|
||||
fn main() -> std.math.U64Result
|
||||
effects []
|
||||
{ return std.math.UsizeResult::ok(1); }
|
||||
@@ -0,0 +1,449 @@
|
||||
// expect: run
|
||||
// result: 0
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.4
|
||||
module test.bounded
|
||||
import std.bytes;
|
||||
|
||||
fn check(data: slice<u8>, needle: slice<u8>, found: bool, index: usize) -> void
|
||||
effects []
|
||||
{
|
||||
match std.bytes.find_slice(ref data, ref needle) {
|
||||
std.bytes.FindResult::found(value) => { assert(found); assert(value == index); }
|
||||
std.bytes.FindResult::not_found => { assert(not found); }
|
||||
}
|
||||
}
|
||||
fn main() -> u8
|
||||
effects []
|
||||
{
|
||||
var empty: [u8; 1] = zero;
|
||||
check(ref empty[0..0], ref empty[0..0], true, 0);
|
||||
check(ref empty[0..0], b"x", false, 0);
|
||||
check(b"abc", ref empty[0..0], true, 0);
|
||||
check(b"\x00", b"\x00", true, 0);
|
||||
check(b"\x00", b"\x01", false, 0);
|
||||
check(b"\x00", b"\x00\x00", false, 0);
|
||||
check(b"\x00", b"\x01\x00", false, 0);
|
||||
check(b"\x00", b"\x00\x01", false, 0);
|
||||
check(b"\x00", b"\x01\x01", false, 0);
|
||||
check(b"\x00", b"\x00\x00\x00", false, 0);
|
||||
check(b"\x00", b"\x01\x00\x00", false, 0);
|
||||
check(b"\x00", b"\x00\x01\x00", false, 0);
|
||||
check(b"\x00", b"\x01\x01\x00", false, 0);
|
||||
check(b"\x00", b"\x00\x00\x01", false, 0);
|
||||
check(b"\x00", b"\x01\x00\x01", false, 0);
|
||||
check(b"\x00", b"\x00\x01\x01", false, 0);
|
||||
check(b"\x00", b"\x01\x01\x01", false, 0);
|
||||
check(b"\x01", b"\x00", false, 0);
|
||||
check(b"\x01", b"\x01", true, 0);
|
||||
check(b"\x01", b"\x00\x00", false, 0);
|
||||
check(b"\x01", b"\x01\x00", false, 0);
|
||||
check(b"\x01", b"\x00\x01", false, 0);
|
||||
check(b"\x01", b"\x01\x01", false, 0);
|
||||
check(b"\x01", b"\x00\x00\x00", false, 0);
|
||||
check(b"\x01", b"\x01\x00\x00", false, 0);
|
||||
check(b"\x01", b"\x00\x01\x00", false, 0);
|
||||
check(b"\x01", b"\x01\x01\x00", false, 0);
|
||||
check(b"\x01", b"\x00\x00\x01", false, 0);
|
||||
check(b"\x01", b"\x01\x00\x01", false, 0);
|
||||
check(b"\x01", b"\x00\x01\x01", false, 0);
|
||||
check(b"\x01", b"\x01\x01\x01", false, 0);
|
||||
check(b"\x00\x00", b"\x00", true, 0);
|
||||
check(b"\x00\x00", b"\x01", false, 0);
|
||||
check(b"\x00\x00", b"\x00\x00", true, 0);
|
||||
check(b"\x00\x00", b"\x01\x00", false, 0);
|
||||
check(b"\x00\x00", b"\x00\x01", false, 0);
|
||||
check(b"\x00\x00", b"\x01\x01", false, 0);
|
||||
check(b"\x00\x00", b"\x00\x00\x00", false, 0);
|
||||
check(b"\x00\x00", b"\x01\x00\x00", false, 0);
|
||||
check(b"\x00\x00", b"\x00\x01\x00", false, 0);
|
||||
check(b"\x00\x00", b"\x01\x01\x00", false, 0);
|
||||
check(b"\x00\x00", b"\x00\x00\x01", false, 0);
|
||||
check(b"\x00\x00", b"\x01\x00\x01", false, 0);
|
||||
check(b"\x00\x00", b"\x00\x01\x01", false, 0);
|
||||
check(b"\x00\x00", b"\x01\x01\x01", false, 0);
|
||||
check(b"\x01\x00", b"\x00", true, 1);
|
||||
check(b"\x01\x00", b"\x01", true, 0);
|
||||
check(b"\x01\x00", b"\x00\x00", false, 0);
|
||||
check(b"\x01\x00", b"\x01\x00", true, 0);
|
||||
check(b"\x01\x00", b"\x00\x01", false, 0);
|
||||
check(b"\x01\x00", b"\x01\x01", false, 0);
|
||||
check(b"\x01\x00", b"\x00\x00\x00", false, 0);
|
||||
check(b"\x01\x00", b"\x01\x00\x00", false, 0);
|
||||
check(b"\x01\x00", b"\x00\x01\x00", false, 0);
|
||||
check(b"\x01\x00", b"\x01\x01\x00", false, 0);
|
||||
check(b"\x01\x00", b"\x00\x00\x01", false, 0);
|
||||
check(b"\x01\x00", b"\x01\x00\x01", false, 0);
|
||||
check(b"\x01\x00", b"\x00\x01\x01", false, 0);
|
||||
check(b"\x01\x00", b"\x01\x01\x01", false, 0);
|
||||
check(b"\x00\x01", b"\x00", true, 0);
|
||||
check(b"\x00\x01", b"\x01", true, 1);
|
||||
check(b"\x00\x01", b"\x00\x00", false, 0);
|
||||
check(b"\x00\x01", b"\x01\x00", false, 0);
|
||||
check(b"\x00\x01", b"\x00\x01", true, 0);
|
||||
check(b"\x00\x01", b"\x01\x01", false, 0);
|
||||
check(b"\x00\x01", b"\x00\x00\x00", false, 0);
|
||||
check(b"\x00\x01", b"\x01\x00\x00", false, 0);
|
||||
check(b"\x00\x01", b"\x00\x01\x00", false, 0);
|
||||
check(b"\x00\x01", b"\x01\x01\x00", false, 0);
|
||||
check(b"\x00\x01", b"\x00\x00\x01", false, 0);
|
||||
check(b"\x00\x01", b"\x01\x00\x01", false, 0);
|
||||
check(b"\x00\x01", b"\x00\x01\x01", false, 0);
|
||||
check(b"\x00\x01", b"\x01\x01\x01", false, 0);
|
||||
check(b"\x01\x01", b"\x00", false, 0);
|
||||
check(b"\x01\x01", b"\x01", true, 0);
|
||||
check(b"\x01\x01", b"\x00\x00", false, 0);
|
||||
check(b"\x01\x01", b"\x01\x00", false, 0);
|
||||
check(b"\x01\x01", b"\x00\x01", false, 0);
|
||||
check(b"\x01\x01", b"\x01\x01", true, 0);
|
||||
check(b"\x01\x01", b"\x00\x00\x00", false, 0);
|
||||
check(b"\x01\x01", b"\x01\x00\x00", false, 0);
|
||||
check(b"\x01\x01", b"\x00\x01\x00", false, 0);
|
||||
check(b"\x01\x01", b"\x01\x01\x00", false, 0);
|
||||
check(b"\x01\x01", b"\x00\x00\x01", false, 0);
|
||||
check(b"\x01\x01", b"\x01\x00\x01", false, 0);
|
||||
check(b"\x01\x01", b"\x00\x01\x01", false, 0);
|
||||
check(b"\x01\x01", b"\x01\x01\x01", false, 0);
|
||||
check(b"\x00\x00\x00", b"\x00", true, 0);
|
||||
check(b"\x00\x00\x00", b"\x01", false, 0);
|
||||
check(b"\x00\x00\x00", b"\x00\x00", true, 0);
|
||||
check(b"\x00\x00\x00", b"\x01\x00", false, 0);
|
||||
check(b"\x00\x00\x00", b"\x00\x01", false, 0);
|
||||
check(b"\x00\x00\x00", b"\x01\x01", false, 0);
|
||||
check(b"\x00\x00\x00", b"\x00\x00\x00", true, 0);
|
||||
check(b"\x00\x00\x00", b"\x01\x00\x00", false, 0);
|
||||
check(b"\x00\x00\x00", b"\x00\x01\x00", false, 0);
|
||||
check(b"\x00\x00\x00", b"\x01\x01\x00", false, 0);
|
||||
check(b"\x00\x00\x00", b"\x00\x00\x01", false, 0);
|
||||
check(b"\x00\x00\x00", b"\x01\x00\x01", false, 0);
|
||||
check(b"\x00\x00\x00", b"\x00\x01\x01", false, 0);
|
||||
check(b"\x00\x00\x00", b"\x01\x01\x01", false, 0);
|
||||
check(b"\x01\x00\x00", b"\x00", true, 1);
|
||||
check(b"\x01\x00\x00", b"\x01", true, 0);
|
||||
check(b"\x01\x00\x00", b"\x00\x00", true, 1);
|
||||
check(b"\x01\x00\x00", b"\x01\x00", true, 0);
|
||||
check(b"\x01\x00\x00", b"\x00\x01", false, 0);
|
||||
check(b"\x01\x00\x00", b"\x01\x01", false, 0);
|
||||
check(b"\x01\x00\x00", b"\x00\x00\x00", false, 0);
|
||||
check(b"\x01\x00\x00", b"\x01\x00\x00", true, 0);
|
||||
check(b"\x01\x00\x00", b"\x00\x01\x00", false, 0);
|
||||
check(b"\x01\x00\x00", b"\x01\x01\x00", false, 0);
|
||||
check(b"\x01\x00\x00", b"\x00\x00\x01", false, 0);
|
||||
check(b"\x01\x00\x00", b"\x01\x00\x01", false, 0);
|
||||
check(b"\x01\x00\x00", b"\x00\x01\x01", false, 0);
|
||||
check(b"\x01\x00\x00", b"\x01\x01\x01", false, 0);
|
||||
check(b"\x00\x01\x00", b"\x00", true, 0);
|
||||
check(b"\x00\x01\x00", b"\x01", true, 1);
|
||||
check(b"\x00\x01\x00", b"\x00\x00", false, 0);
|
||||
check(b"\x00\x01\x00", b"\x01\x00", true, 1);
|
||||
check(b"\x00\x01\x00", b"\x00\x01", true, 0);
|
||||
check(b"\x00\x01\x00", b"\x01\x01", false, 0);
|
||||
check(b"\x00\x01\x00", b"\x00\x00\x00", false, 0);
|
||||
check(b"\x00\x01\x00", b"\x01\x00\x00", false, 0);
|
||||
check(b"\x00\x01\x00", b"\x00\x01\x00", true, 0);
|
||||
check(b"\x00\x01\x00", b"\x01\x01\x00", false, 0);
|
||||
check(b"\x00\x01\x00", b"\x00\x00\x01", false, 0);
|
||||
check(b"\x00\x01\x00", b"\x01\x00\x01", false, 0);
|
||||
check(b"\x00\x01\x00", b"\x00\x01\x01", false, 0);
|
||||
check(b"\x00\x01\x00", b"\x01\x01\x01", false, 0);
|
||||
check(b"\x01\x01\x00", b"\x00", true, 2);
|
||||
check(b"\x01\x01\x00", b"\x01", true, 0);
|
||||
check(b"\x01\x01\x00", b"\x00\x00", false, 0);
|
||||
check(b"\x01\x01\x00", b"\x01\x00", true, 1);
|
||||
check(b"\x01\x01\x00", b"\x00\x01", false, 0);
|
||||
check(b"\x01\x01\x00", b"\x01\x01", true, 0);
|
||||
check(b"\x01\x01\x00", b"\x00\x00\x00", false, 0);
|
||||
check(b"\x01\x01\x00", b"\x01\x00\x00", false, 0);
|
||||
check(b"\x01\x01\x00", b"\x00\x01\x00", false, 0);
|
||||
check(b"\x01\x01\x00", b"\x01\x01\x00", true, 0);
|
||||
check(b"\x01\x01\x00", b"\x00\x00\x01", false, 0);
|
||||
check(b"\x01\x01\x00", b"\x01\x00\x01", false, 0);
|
||||
check(b"\x01\x01\x00", b"\x00\x01\x01", false, 0);
|
||||
check(b"\x01\x01\x00", b"\x01\x01\x01", false, 0);
|
||||
check(b"\x00\x00\x01", b"\x00", true, 0);
|
||||
check(b"\x00\x00\x01", b"\x01", true, 2);
|
||||
check(b"\x00\x00\x01", b"\x00\x00", true, 0);
|
||||
check(b"\x00\x00\x01", b"\x01\x00", false, 0);
|
||||
check(b"\x00\x00\x01", b"\x00\x01", true, 1);
|
||||
check(b"\x00\x00\x01", b"\x01\x01", false, 0);
|
||||
check(b"\x00\x00\x01", b"\x00\x00\x00", false, 0);
|
||||
check(b"\x00\x00\x01", b"\x01\x00\x00", false, 0);
|
||||
check(b"\x00\x00\x01", b"\x00\x01\x00", false, 0);
|
||||
check(b"\x00\x00\x01", b"\x01\x01\x00", false, 0);
|
||||
check(b"\x00\x00\x01", b"\x00\x00\x01", true, 0);
|
||||
check(b"\x00\x00\x01", b"\x01\x00\x01", false, 0);
|
||||
check(b"\x00\x00\x01", b"\x00\x01\x01", false, 0);
|
||||
check(b"\x00\x00\x01", b"\x01\x01\x01", false, 0);
|
||||
check(b"\x01\x00\x01", b"\x00", true, 1);
|
||||
check(b"\x01\x00\x01", b"\x01", true, 0);
|
||||
check(b"\x01\x00\x01", b"\x00\x00", false, 0);
|
||||
check(b"\x01\x00\x01", b"\x01\x00", true, 0);
|
||||
check(b"\x01\x00\x01", b"\x00\x01", true, 1);
|
||||
check(b"\x01\x00\x01", b"\x01\x01", false, 0);
|
||||
check(b"\x01\x00\x01", b"\x00\x00\x00", false, 0);
|
||||
check(b"\x01\x00\x01", b"\x01\x00\x00", false, 0);
|
||||
check(b"\x01\x00\x01", b"\x00\x01\x00", false, 0);
|
||||
check(b"\x01\x00\x01", b"\x01\x01\x00", false, 0);
|
||||
check(b"\x01\x00\x01", b"\x00\x00\x01", false, 0);
|
||||
check(b"\x01\x00\x01", b"\x01\x00\x01", true, 0);
|
||||
check(b"\x01\x00\x01", b"\x00\x01\x01", false, 0);
|
||||
check(b"\x01\x00\x01", b"\x01\x01\x01", false, 0);
|
||||
check(b"\x00\x01\x01", b"\x00", true, 0);
|
||||
check(b"\x00\x01\x01", b"\x01", true, 1);
|
||||
check(b"\x00\x01\x01", b"\x00\x00", false, 0);
|
||||
check(b"\x00\x01\x01", b"\x01\x00", false, 0);
|
||||
check(b"\x00\x01\x01", b"\x00\x01", true, 0);
|
||||
check(b"\x00\x01\x01", b"\x01\x01", true, 1);
|
||||
check(b"\x00\x01\x01", b"\x00\x00\x00", false, 0);
|
||||
check(b"\x00\x01\x01", b"\x01\x00\x00", false, 0);
|
||||
check(b"\x00\x01\x01", b"\x00\x01\x00", false, 0);
|
||||
check(b"\x00\x01\x01", b"\x01\x01\x00", false, 0);
|
||||
check(b"\x00\x01\x01", b"\x00\x00\x01", false, 0);
|
||||
check(b"\x00\x01\x01", b"\x01\x00\x01", false, 0);
|
||||
check(b"\x00\x01\x01", b"\x00\x01\x01", true, 0);
|
||||
check(b"\x00\x01\x01", b"\x01\x01\x01", false, 0);
|
||||
check(b"\x01\x01\x01", b"\x00", false, 0);
|
||||
check(b"\x01\x01\x01", b"\x01", true, 0);
|
||||
check(b"\x01\x01\x01", b"\x00\x00", false, 0);
|
||||
check(b"\x01\x01\x01", b"\x01\x00", false, 0);
|
||||
check(b"\x01\x01\x01", b"\x00\x01", false, 0);
|
||||
check(b"\x01\x01\x01", b"\x01\x01", true, 0);
|
||||
check(b"\x01\x01\x01", b"\x00\x00\x00", false, 0);
|
||||
check(b"\x01\x01\x01", b"\x01\x00\x00", false, 0);
|
||||
check(b"\x01\x01\x01", b"\x00\x01\x00", false, 0);
|
||||
check(b"\x01\x01\x01", b"\x01\x01\x00", false, 0);
|
||||
check(b"\x01\x01\x01", b"\x00\x00\x01", false, 0);
|
||||
check(b"\x01\x01\x01", b"\x01\x00\x01", false, 0);
|
||||
check(b"\x01\x01\x01", b"\x00\x01\x01", false, 0);
|
||||
check(b"\x01\x01\x01", b"\x01\x01\x01", true, 0);
|
||||
check(b"\x00\x00\x00\x00", b"\x00", true, 0);
|
||||
check(b"\x00\x00\x00\x00", b"\x01", false, 0);
|
||||
check(b"\x00\x00\x00\x00", b"\x00\x00", true, 0);
|
||||
check(b"\x00\x00\x00\x00", b"\x01\x00", false, 0);
|
||||
check(b"\x00\x00\x00\x00", b"\x00\x01", false, 0);
|
||||
check(b"\x00\x00\x00\x00", b"\x01\x01", false, 0);
|
||||
check(b"\x00\x00\x00\x00", b"\x00\x00\x00", true, 0);
|
||||
check(b"\x00\x00\x00\x00", b"\x01\x00\x00", false, 0);
|
||||
check(b"\x00\x00\x00\x00", b"\x00\x01\x00", false, 0);
|
||||
check(b"\x00\x00\x00\x00", b"\x01\x01\x00", false, 0);
|
||||
check(b"\x00\x00\x00\x00", b"\x00\x00\x01", false, 0);
|
||||
check(b"\x00\x00\x00\x00", b"\x01\x00\x01", false, 0);
|
||||
check(b"\x00\x00\x00\x00", b"\x00\x01\x01", false, 0);
|
||||
check(b"\x00\x00\x00\x00", b"\x01\x01\x01", false, 0);
|
||||
check(b"\x01\x00\x00\x00", b"\x00", true, 1);
|
||||
check(b"\x01\x00\x00\x00", b"\x01", true, 0);
|
||||
check(b"\x01\x00\x00\x00", b"\x00\x00", true, 1);
|
||||
check(b"\x01\x00\x00\x00", b"\x01\x00", true, 0);
|
||||
check(b"\x01\x00\x00\x00", b"\x00\x01", false, 0);
|
||||
check(b"\x01\x00\x00\x00", b"\x01\x01", false, 0);
|
||||
check(b"\x01\x00\x00\x00", b"\x00\x00\x00", true, 1);
|
||||
check(b"\x01\x00\x00\x00", b"\x01\x00\x00", true, 0);
|
||||
check(b"\x01\x00\x00\x00", b"\x00\x01\x00", false, 0);
|
||||
check(b"\x01\x00\x00\x00", b"\x01\x01\x00", false, 0);
|
||||
check(b"\x01\x00\x00\x00", b"\x00\x00\x01", false, 0);
|
||||
check(b"\x01\x00\x00\x00", b"\x01\x00\x01", false, 0);
|
||||
check(b"\x01\x00\x00\x00", b"\x00\x01\x01", false, 0);
|
||||
check(b"\x01\x00\x00\x00", b"\x01\x01\x01", false, 0);
|
||||
check(b"\x00\x01\x00\x00", b"\x00", true, 0);
|
||||
check(b"\x00\x01\x00\x00", b"\x01", true, 1);
|
||||
check(b"\x00\x01\x00\x00", b"\x00\x00", true, 2);
|
||||
check(b"\x00\x01\x00\x00", b"\x01\x00", true, 1);
|
||||
check(b"\x00\x01\x00\x00", b"\x00\x01", true, 0);
|
||||
check(b"\x00\x01\x00\x00", b"\x01\x01", false, 0);
|
||||
check(b"\x00\x01\x00\x00", b"\x00\x00\x00", false, 0);
|
||||
check(b"\x00\x01\x00\x00", b"\x01\x00\x00", true, 1);
|
||||
check(b"\x00\x01\x00\x00", b"\x00\x01\x00", true, 0);
|
||||
check(b"\x00\x01\x00\x00", b"\x01\x01\x00", false, 0);
|
||||
check(b"\x00\x01\x00\x00", b"\x00\x00\x01", false, 0);
|
||||
check(b"\x00\x01\x00\x00", b"\x01\x00\x01", false, 0);
|
||||
check(b"\x00\x01\x00\x00", b"\x00\x01\x01", false, 0);
|
||||
check(b"\x00\x01\x00\x00", b"\x01\x01\x01", false, 0);
|
||||
check(b"\x01\x01\x00\x00", b"\x00", true, 2);
|
||||
check(b"\x01\x01\x00\x00", b"\x01", true, 0);
|
||||
check(b"\x01\x01\x00\x00", b"\x00\x00", true, 2);
|
||||
check(b"\x01\x01\x00\x00", b"\x01\x00", true, 1);
|
||||
check(b"\x01\x01\x00\x00", b"\x00\x01", false, 0);
|
||||
check(b"\x01\x01\x00\x00", b"\x01\x01", true, 0);
|
||||
check(b"\x01\x01\x00\x00", b"\x00\x00\x00", false, 0);
|
||||
check(b"\x01\x01\x00\x00", b"\x01\x00\x00", true, 1);
|
||||
check(b"\x01\x01\x00\x00", b"\x00\x01\x00", false, 0);
|
||||
check(b"\x01\x01\x00\x00", b"\x01\x01\x00", true, 0);
|
||||
check(b"\x01\x01\x00\x00", b"\x00\x00\x01", false, 0);
|
||||
check(b"\x01\x01\x00\x00", b"\x01\x00\x01", false, 0);
|
||||
check(b"\x01\x01\x00\x00", b"\x00\x01\x01", false, 0);
|
||||
check(b"\x01\x01\x00\x00", b"\x01\x01\x01", false, 0);
|
||||
check(b"\x00\x00\x01\x00", b"\x00", true, 0);
|
||||
check(b"\x00\x00\x01\x00", b"\x01", true, 2);
|
||||
check(b"\x00\x00\x01\x00", b"\x00\x00", true, 0);
|
||||
check(b"\x00\x00\x01\x00", b"\x01\x00", true, 2);
|
||||
check(b"\x00\x00\x01\x00", b"\x00\x01", true, 1);
|
||||
check(b"\x00\x00\x01\x00", b"\x01\x01", false, 0);
|
||||
check(b"\x00\x00\x01\x00", b"\x00\x00\x00", false, 0);
|
||||
check(b"\x00\x00\x01\x00", b"\x01\x00\x00", false, 0);
|
||||
check(b"\x00\x00\x01\x00", b"\x00\x01\x00", true, 1);
|
||||
check(b"\x00\x00\x01\x00", b"\x01\x01\x00", false, 0);
|
||||
check(b"\x00\x00\x01\x00", b"\x00\x00\x01", true, 0);
|
||||
check(b"\x00\x00\x01\x00", b"\x01\x00\x01", false, 0);
|
||||
check(b"\x00\x00\x01\x00", b"\x00\x01\x01", false, 0);
|
||||
check(b"\x00\x00\x01\x00", b"\x01\x01\x01", false, 0);
|
||||
check(b"\x01\x00\x01\x00", b"\x00", true, 1);
|
||||
check(b"\x01\x00\x01\x00", b"\x01", true, 0);
|
||||
check(b"\x01\x00\x01\x00", b"\x00\x00", false, 0);
|
||||
check(b"\x01\x00\x01\x00", b"\x01\x00", true, 0);
|
||||
check(b"\x01\x00\x01\x00", b"\x00\x01", true, 1);
|
||||
check(b"\x01\x00\x01\x00", b"\x01\x01", false, 0);
|
||||
check(b"\x01\x00\x01\x00", b"\x00\x00\x00", false, 0);
|
||||
check(b"\x01\x00\x01\x00", b"\x01\x00\x00", false, 0);
|
||||
check(b"\x01\x00\x01\x00", b"\x00\x01\x00", true, 1);
|
||||
check(b"\x01\x00\x01\x00", b"\x01\x01\x00", false, 0);
|
||||
check(b"\x01\x00\x01\x00", b"\x00\x00\x01", false, 0);
|
||||
check(b"\x01\x00\x01\x00", b"\x01\x00\x01", true, 0);
|
||||
check(b"\x01\x00\x01\x00", b"\x00\x01\x01", false, 0);
|
||||
check(b"\x01\x00\x01\x00", b"\x01\x01\x01", false, 0);
|
||||
check(b"\x00\x01\x01\x00", b"\x00", true, 0);
|
||||
check(b"\x00\x01\x01\x00", b"\x01", true, 1);
|
||||
check(b"\x00\x01\x01\x00", b"\x00\x00", false, 0);
|
||||
check(b"\x00\x01\x01\x00", b"\x01\x00", true, 2);
|
||||
check(b"\x00\x01\x01\x00", b"\x00\x01", true, 0);
|
||||
check(b"\x00\x01\x01\x00", b"\x01\x01", true, 1);
|
||||
check(b"\x00\x01\x01\x00", b"\x00\x00\x00", false, 0);
|
||||
check(b"\x00\x01\x01\x00", b"\x01\x00\x00", false, 0);
|
||||
check(b"\x00\x01\x01\x00", b"\x00\x01\x00", false, 0);
|
||||
check(b"\x00\x01\x01\x00", b"\x01\x01\x00", true, 1);
|
||||
check(b"\x00\x01\x01\x00", b"\x00\x00\x01", false, 0);
|
||||
check(b"\x00\x01\x01\x00", b"\x01\x00\x01", false, 0);
|
||||
check(b"\x00\x01\x01\x00", b"\x00\x01\x01", true, 0);
|
||||
check(b"\x00\x01\x01\x00", b"\x01\x01\x01", false, 0);
|
||||
check(b"\x01\x01\x01\x00", b"\x00", true, 3);
|
||||
check(b"\x01\x01\x01\x00", b"\x01", true, 0);
|
||||
check(b"\x01\x01\x01\x00", b"\x00\x00", false, 0);
|
||||
check(b"\x01\x01\x01\x00", b"\x01\x00", true, 2);
|
||||
check(b"\x01\x01\x01\x00", b"\x00\x01", false, 0);
|
||||
check(b"\x01\x01\x01\x00", b"\x01\x01", true, 0);
|
||||
check(b"\x01\x01\x01\x00", b"\x00\x00\x00", false, 0);
|
||||
check(b"\x01\x01\x01\x00", b"\x01\x00\x00", false, 0);
|
||||
check(b"\x01\x01\x01\x00", b"\x00\x01\x00", false, 0);
|
||||
check(b"\x01\x01\x01\x00", b"\x01\x01\x00", true, 1);
|
||||
check(b"\x01\x01\x01\x00", b"\x00\x00\x01", false, 0);
|
||||
check(b"\x01\x01\x01\x00", b"\x01\x00\x01", false, 0);
|
||||
check(b"\x01\x01\x01\x00", b"\x00\x01\x01", false, 0);
|
||||
check(b"\x01\x01\x01\x00", b"\x01\x01\x01", true, 0);
|
||||
check(b"\x00\x00\x00\x01", b"\x00", true, 0);
|
||||
check(b"\x00\x00\x00\x01", b"\x01", true, 3);
|
||||
check(b"\x00\x00\x00\x01", b"\x00\x00", true, 0);
|
||||
check(b"\x00\x00\x00\x01", b"\x01\x00", false, 0);
|
||||
check(b"\x00\x00\x00\x01", b"\x00\x01", true, 2);
|
||||
check(b"\x00\x00\x00\x01", b"\x01\x01", false, 0);
|
||||
check(b"\x00\x00\x00\x01", b"\x00\x00\x00", true, 0);
|
||||
check(b"\x00\x00\x00\x01", b"\x01\x00\x00", false, 0);
|
||||
check(b"\x00\x00\x00\x01", b"\x00\x01\x00", false, 0);
|
||||
check(b"\x00\x00\x00\x01", b"\x01\x01\x00", false, 0);
|
||||
check(b"\x00\x00\x00\x01", b"\x00\x00\x01", true, 1);
|
||||
check(b"\x00\x00\x00\x01", b"\x01\x00\x01", false, 0);
|
||||
check(b"\x00\x00\x00\x01", b"\x00\x01\x01", false, 0);
|
||||
check(b"\x00\x00\x00\x01", b"\x01\x01\x01", false, 0);
|
||||
check(b"\x01\x00\x00\x01", b"\x00", true, 1);
|
||||
check(b"\x01\x00\x00\x01", b"\x01", true, 0);
|
||||
check(b"\x01\x00\x00\x01", b"\x00\x00", true, 1);
|
||||
check(b"\x01\x00\x00\x01", b"\x01\x00", true, 0);
|
||||
check(b"\x01\x00\x00\x01", b"\x00\x01", true, 2);
|
||||
check(b"\x01\x00\x00\x01", b"\x01\x01", false, 0);
|
||||
check(b"\x01\x00\x00\x01", b"\x00\x00\x00", false, 0);
|
||||
check(b"\x01\x00\x00\x01", b"\x01\x00\x00", true, 0);
|
||||
check(b"\x01\x00\x00\x01", b"\x00\x01\x00", false, 0);
|
||||
check(b"\x01\x00\x00\x01", b"\x01\x01\x00", false, 0);
|
||||
check(b"\x01\x00\x00\x01", b"\x00\x00\x01", true, 1);
|
||||
check(b"\x01\x00\x00\x01", b"\x01\x00\x01", false, 0);
|
||||
check(b"\x01\x00\x00\x01", b"\x00\x01\x01", false, 0);
|
||||
check(b"\x01\x00\x00\x01", b"\x01\x01\x01", false, 0);
|
||||
check(b"\x00\x01\x00\x01", b"\x00", true, 0);
|
||||
check(b"\x00\x01\x00\x01", b"\x01", true, 1);
|
||||
check(b"\x00\x01\x00\x01", b"\x00\x00", false, 0);
|
||||
check(b"\x00\x01\x00\x01", b"\x01\x00", true, 1);
|
||||
check(b"\x00\x01\x00\x01", b"\x00\x01", true, 0);
|
||||
check(b"\x00\x01\x00\x01", b"\x01\x01", false, 0);
|
||||
check(b"\x00\x01\x00\x01", b"\x00\x00\x00", false, 0);
|
||||
check(b"\x00\x01\x00\x01", b"\x01\x00\x00", false, 0);
|
||||
check(b"\x00\x01\x00\x01", b"\x00\x01\x00", true, 0);
|
||||
check(b"\x00\x01\x00\x01", b"\x01\x01\x00", false, 0);
|
||||
check(b"\x00\x01\x00\x01", b"\x00\x00\x01", false, 0);
|
||||
check(b"\x00\x01\x00\x01", b"\x01\x00\x01", true, 1);
|
||||
check(b"\x00\x01\x00\x01", b"\x00\x01\x01", false, 0);
|
||||
check(b"\x00\x01\x00\x01", b"\x01\x01\x01", false, 0);
|
||||
check(b"\x01\x01\x00\x01", b"\x00", true, 2);
|
||||
check(b"\x01\x01\x00\x01", b"\x01", true, 0);
|
||||
check(b"\x01\x01\x00\x01", b"\x00\x00", false, 0);
|
||||
check(b"\x01\x01\x00\x01", b"\x01\x00", true, 1);
|
||||
check(b"\x01\x01\x00\x01", b"\x00\x01", true, 2);
|
||||
check(b"\x01\x01\x00\x01", b"\x01\x01", true, 0);
|
||||
check(b"\x01\x01\x00\x01", b"\x00\x00\x00", false, 0);
|
||||
check(b"\x01\x01\x00\x01", b"\x01\x00\x00", false, 0);
|
||||
check(b"\x01\x01\x00\x01", b"\x00\x01\x00", false, 0);
|
||||
check(b"\x01\x01\x00\x01", b"\x01\x01\x00", true, 0);
|
||||
check(b"\x01\x01\x00\x01", b"\x00\x00\x01", false, 0);
|
||||
check(b"\x01\x01\x00\x01", b"\x01\x00\x01", true, 1);
|
||||
check(b"\x01\x01\x00\x01", b"\x00\x01\x01", false, 0);
|
||||
check(b"\x01\x01\x00\x01", b"\x01\x01\x01", false, 0);
|
||||
check(b"\x00\x00\x01\x01", b"\x00", true, 0);
|
||||
check(b"\x00\x00\x01\x01", b"\x01", true, 2);
|
||||
check(b"\x00\x00\x01\x01", b"\x00\x00", true, 0);
|
||||
check(b"\x00\x00\x01\x01", b"\x01\x00", false, 0);
|
||||
check(b"\x00\x00\x01\x01", b"\x00\x01", true, 1);
|
||||
check(b"\x00\x00\x01\x01", b"\x01\x01", true, 2);
|
||||
check(b"\x00\x00\x01\x01", b"\x00\x00\x00", false, 0);
|
||||
check(b"\x00\x00\x01\x01", b"\x01\x00\x00", false, 0);
|
||||
check(b"\x00\x00\x01\x01", b"\x00\x01\x00", false, 0);
|
||||
check(b"\x00\x00\x01\x01", b"\x01\x01\x00", false, 0);
|
||||
check(b"\x00\x00\x01\x01", b"\x00\x00\x01", true, 0);
|
||||
check(b"\x00\x00\x01\x01", b"\x01\x00\x01", false, 0);
|
||||
check(b"\x00\x00\x01\x01", b"\x00\x01\x01", true, 1);
|
||||
check(b"\x00\x00\x01\x01", b"\x01\x01\x01", false, 0);
|
||||
check(b"\x01\x00\x01\x01", b"\x00", true, 1);
|
||||
check(b"\x01\x00\x01\x01", b"\x01", true, 0);
|
||||
check(b"\x01\x00\x01\x01", b"\x00\x00", false, 0);
|
||||
check(b"\x01\x00\x01\x01", b"\x01\x00", true, 0);
|
||||
check(b"\x01\x00\x01\x01", b"\x00\x01", true, 1);
|
||||
check(b"\x01\x00\x01\x01", b"\x01\x01", true, 2);
|
||||
check(b"\x01\x00\x01\x01", b"\x00\x00\x00", false, 0);
|
||||
check(b"\x01\x00\x01\x01", b"\x01\x00\x00", false, 0);
|
||||
check(b"\x01\x00\x01\x01", b"\x00\x01\x00", false, 0);
|
||||
check(b"\x01\x00\x01\x01", b"\x01\x01\x00", false, 0);
|
||||
check(b"\x01\x00\x01\x01", b"\x00\x00\x01", false, 0);
|
||||
check(b"\x01\x00\x01\x01", b"\x01\x00\x01", true, 0);
|
||||
check(b"\x01\x00\x01\x01", b"\x00\x01\x01", true, 1);
|
||||
check(b"\x01\x00\x01\x01", b"\x01\x01\x01", false, 0);
|
||||
check(b"\x00\x01\x01\x01", b"\x00", true, 0);
|
||||
check(b"\x00\x01\x01\x01", b"\x01", true, 1);
|
||||
check(b"\x00\x01\x01\x01", b"\x00\x00", false, 0);
|
||||
check(b"\x00\x01\x01\x01", b"\x01\x00", false, 0);
|
||||
check(b"\x00\x01\x01\x01", b"\x00\x01", true, 0);
|
||||
check(b"\x00\x01\x01\x01", b"\x01\x01", true, 1);
|
||||
check(b"\x00\x01\x01\x01", b"\x00\x00\x00", false, 0);
|
||||
check(b"\x00\x01\x01\x01", b"\x01\x00\x00", false, 0);
|
||||
check(b"\x00\x01\x01\x01", b"\x00\x01\x00", false, 0);
|
||||
check(b"\x00\x01\x01\x01", b"\x01\x01\x00", false, 0);
|
||||
check(b"\x00\x01\x01\x01", b"\x00\x00\x01", false, 0);
|
||||
check(b"\x00\x01\x01\x01", b"\x01\x00\x01", false, 0);
|
||||
check(b"\x00\x01\x01\x01", b"\x00\x01\x01", true, 0);
|
||||
check(b"\x00\x01\x01\x01", b"\x01\x01\x01", true, 1);
|
||||
check(b"\x01\x01\x01\x01", b"\x00", false, 0);
|
||||
check(b"\x01\x01\x01\x01", b"\x01", true, 0);
|
||||
check(b"\x01\x01\x01\x01", b"\x00\x00", false, 0);
|
||||
check(b"\x01\x01\x01\x01", b"\x01\x00", false, 0);
|
||||
check(b"\x01\x01\x01\x01", b"\x00\x01", false, 0);
|
||||
check(b"\x01\x01\x01\x01", b"\x01\x01", true, 0);
|
||||
check(b"\x01\x01\x01\x01", b"\x00\x00\x00", false, 0);
|
||||
check(b"\x01\x01\x01\x01", b"\x01\x00\x00", false, 0);
|
||||
check(b"\x01\x01\x01\x01", b"\x00\x01\x00", false, 0);
|
||||
check(b"\x01\x01\x01\x01", b"\x01\x01\x00", false, 0);
|
||||
check(b"\x01\x01\x01\x01", b"\x00\x00\x01", false, 0);
|
||||
check(b"\x01\x01\x01\x01", b"\x01\x00\x01", false, 0);
|
||||
check(b"\x01\x01\x01\x01", b"\x00\x01\x01", false, 0);
|
||||
check(b"\x01\x01\x01\x01", b"\x01\x01\x01", true, 0);
|
||||
check(b"\x78\x78\x61\x62\x63\x61\x62\x63", b"\x61\x62\x63", true, 2);
|
||||
check(b"\x61\x61\x61\x61\x61\x62", b"\x61\x61\x61\x62", true, 2);
|
||||
check(b"\x61\x62\x63", b"\x61\x62\x63\x64", false, 0);
|
||||
check(b"\xff\x00\x80\xff", b"\x80\xff", true, 2);
|
||||
check(b"\x61\x62\x63", b"\x63", true, 2);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// expect: reject E7004
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.4
|
||||
module test.bounded
|
||||
import std.bytes;
|
||||
|
||||
fn main() -> usize
|
||||
effects []
|
||||
{ match std.bytes.find_slice(b"abc", b"b") { std.bytes.FindResult::found(index) => { return index; } } }
|
||||
@@ -0,0 +1,8 @@
|
||||
// expect: reject E7002
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.4
|
||||
module test.bounded
|
||||
|
||||
fn main() -> u8
|
||||
effects []
|
||||
{ let result = std.bytes.find_slice(b"a", b"a"); return 0; }
|
||||
@@ -0,0 +1,19 @@
|
||||
// expect: run
|
||||
// result: 2
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.4
|
||||
module test.bounded_offset
|
||||
import std.bytes;
|
||||
|
||||
fn locate(data: slice<u8>) -> usize
|
||||
effects []
|
||||
{
|
||||
match std.bytes.find_slice(ref data[2..data.len], b"ab") {
|
||||
std.bytes.FindResult::found(index) => { return index; }
|
||||
std.bytes.FindResult::not_found => { trap; }
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> usize
|
||||
effects []
|
||||
{ return locate(b"xxzzab"); }
|
||||
@@ -0,0 +1,9 @@
|
||||
// expect: reject E7005
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.4
|
||||
module test.bounded
|
||||
import std.bytes;
|
||||
|
||||
fn main() -> std.bytes.FindResult
|
||||
effects []
|
||||
{ return std.bytes.FindResult::found(true); }
|
||||
@@ -0,0 +1,9 @@
|
||||
// expect: reject E7005
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.4
|
||||
module test.bounded
|
||||
import std.bytes;
|
||||
|
||||
fn main() -> u8
|
||||
effects []
|
||||
{ var words: [u16; 2] = zero; let result = std.bytes.find_slice(ref words, b"x"); return 0; }
|
||||
@@ -0,0 +1,34 @@
|
||||
// expect: run
|
||||
// result: 0
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.4; docs/spec/15-source-language.md §6
|
||||
module test.bounded_split
|
||||
import std.bytes;
|
||||
|
||||
fn check(data: slice<u8>, separator: slice<u8>, expected_left: slice<u8>, expected_right: slice<u8>) -> void
|
||||
effects []
|
||||
{
|
||||
match std.bytes.find_slice(ref data, ref separator) {
|
||||
std.bytes.FindResult::found(index) => {
|
||||
let (left, tail) = data.split_at(index);
|
||||
ref right = tail[separator.len..tail.len];
|
||||
assert(std.bytes.equal(ref left, ref expected_left));
|
||||
assert(std.bytes.equal(ref right, ref expected_right));
|
||||
}
|
||||
std.bytes.FindResult::not_found => { trap; }
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> u8
|
||||
effects []
|
||||
{
|
||||
var storage: [u8; 1] = zero;
|
||||
check(b"key=value", b"=", b"key", b"value");
|
||||
check(b"=value", b"=", ref storage[0..0], b"value");
|
||||
check(b"key=", b"=", b"key", ref storage[0..0]);
|
||||
check(b"==", b"=", ref storage[0..0], b"=");
|
||||
check(b"key::value::tail", b"::", b"key", b"value::tail");
|
||||
check(b"abc", ref storage[0..0], ref storage[0..0], b"abc");
|
||||
check(ref storage[0..0], ref storage[0..0], ref storage[0..0], ref storage[0..0]);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
; expect: run
|
||||
; result: {"variant":"overflow","payload":[]}
|
||||
; phase: 0
|
||||
; spec: docs/spec/16-standard-library.md §2.1.1; docs/spec/07a-air-instructions.md
|
||||
module test.bounded_arithmetic
|
||||
air 0
|
||||
lang 0.1
|
||||
features [effects]
|
||||
|
||||
type @U64Result = enum { ok(u64), overflow }
|
||||
|
||||
fn @main() -> @U64Result
|
||||
effects []
|
||||
entry:
|
||||
%a = const.u64 18446744073709551615
|
||||
%b = const.u64 1
|
||||
%result = call @checked_add(%a, %b)
|
||||
ret %result
|
||||
|
||||
fn @checked_add(%a: u64, %b: u64) -> @U64Result
|
||||
effects []
|
||||
entry:
|
||||
%maximum = const.u64 18446744073709551615
|
||||
%remaining = sub.checked.u64 %maximum, %a
|
||||
%overflows = gt.u64 %b, %remaining
|
||||
cbr %overflows, @failure(), @success()
|
||||
failure:
|
||||
%error = enum.make @U64Result.overflow()
|
||||
ret %error
|
||||
success:
|
||||
%sum = add.checked.u64 %a, %b
|
||||
%ok = enum.make @U64Result.ok(%sum)
|
||||
ret %ok
|
||||
@@ -0,0 +1,16 @@
|
||||
; expect: reject E1001
|
||||
; phase: 0
|
||||
; spec: docs/spec/16-standard-library.md §2.1.1; docs/spec/07a-air-instructions.md
|
||||
module test.bounded_payload
|
||||
air 0
|
||||
lang 0.1
|
||||
features []
|
||||
|
||||
type @U64Result = enum { ok(u64), overflow }
|
||||
|
||||
fn @main() -> @U64Result
|
||||
effects []
|
||||
entry:
|
||||
%wrong = const.bool true
|
||||
%result = enum.make @U64Result.ok(%wrong)
|
||||
ret %result
|
||||
@@ -0,0 +1,64 @@
|
||||
; expect: run
|
||||
; result: [5,5,5,165]
|
||||
; phase: 1
|
||||
; spec: docs/spec/16-standard-library.md §2.4; docs/spec/07a-air-instructions.md
|
||||
module test.bounded_copy
|
||||
air 0
|
||||
lang 0.1
|
||||
features [arrays, effects, ownership]
|
||||
|
||||
type @WriteResult = enum { ok, short_output }
|
||||
|
||||
fn @main() -> array<u8, 4>
|
||||
effects []
|
||||
entry:
|
||||
%src_storage = local.alloc array<u8, 3>
|
||||
%dst_storage = local.alloc array<u8, 4>
|
||||
%five = const.u8 5
|
||||
%marker = const.u8 165
|
||||
%src_value = array.splat array<u8, 3> %five
|
||||
%dst_value = array.splat array<u8, 4> %marker
|
||||
local.store %src_storage, %src_value
|
||||
local.store %dst_storage, %dst_value
|
||||
%r = borrow.ref %src_storage
|
||||
%src = slice.make %r
|
||||
%m = borrow.mut %dst_storage
|
||||
%dst = slice.make %m
|
||||
%zero = const.usize 0
|
||||
%two = const.usize 2
|
||||
%short_dst = slice.sub %dst, %zero, %two
|
||||
%short = call @copy(%short_dst, %src)
|
||||
borrow.end %short_dst
|
||||
%first = borrow.index %dst, %zero
|
||||
%untouched = load %first
|
||||
borrow.end %first
|
||||
%same = eq.u8 %untouched, %marker
|
||||
assert %same
|
||||
enum.switch @WriteResult %short, ok -> @bad, short_output -> @copy_all
|
||||
bad:
|
||||
trap
|
||||
copy_all:
|
||||
%full = call @copy(%dst, %src)
|
||||
enum.switch @WriteResult %full, ok -> @done, short_output -> @bad
|
||||
done:
|
||||
borrow.end %dst
|
||||
borrow.end %m
|
||||
borrow.end %src
|
||||
borrow.end %r
|
||||
%result = local.load %dst_storage
|
||||
ret %result
|
||||
|
||||
fn @copy(%dst: slice_mut<u8>, %src: slice<u8>) -> @WriteResult
|
||||
effects []
|
||||
entry:
|
||||
%capacity = slice.len %dst
|
||||
%count = slice.len %src
|
||||
%short = lt.usize %capacity, %count
|
||||
cbr %short, @failure(), @success()
|
||||
failure:
|
||||
%error = enum.make @WriteResult.short_output()
|
||||
ret %error
|
||||
success:
|
||||
slice.copy %dst, %src
|
||||
%ok = enum.make @WriteResult.ok()
|
||||
ret %ok
|
||||
@@ -20,9 +20,9 @@ TESTS = os.path.join(ROOT, "tests", "conformance", "source")
|
||||
|
||||
# (area, construct, regex, needs a reject test)
|
||||
CHECKLIST = [
|
||||
("stdlib", "qualified standard enum type", r": std\.bytes\.(ReadU(?:16|32|64)|WriteResult)\b", True),
|
||||
("stdlib", "qualified standard enum constructor", r"std\.bytes\.(ReadU(?:16|32|64)|WriteResult)::\w+(?:\(|;)", True),
|
||||
("stdlib", "qualified standard enum match", r"std\.bytes\.(ReadU(?:16|32|64)|WriteResult)::\w+(?:\([^)]*\))? =>", True),
|
||||
("stdlib", "qualified standard enum type", r": std\.(?:bytes|math)\.[A-Z]\w*\b", True),
|
||||
("stdlib", "qualified standard enum constructor", r"std\.(?:bytes|math)\.[A-Z]\w*::\w+(?:\(|;)", True),
|
||||
("stdlib", "qualified standard enum match", r"std\.(?:bytes|math)\.[A-Z]\w*::\w+(?:\([^)]*\))? =>", True),
|
||||
("stdlib", "built-in module import", r"^import std\.", True),
|
||||
("stdlib", "qualified standard call", r"std\.(bytes|math)\.\w+\(", True),
|
||||
("scalars", "checked arithmetic", r"[^%]\+ [a-z0-9]", False),
|
||||
|
||||
Reference in new issue
Block a user