diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 99b2128..b22a762 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,6 +32,7 @@ jobs: - run: python3 tests/hosted/source_own_array_content.py - run: python3 tests/hosted/source_array_literals.py - run: python3 tests/hosted/source_inferred_content.py + - run: python3 tests/hosted/source_nonvalue_operands.py - run: python3 tests/hosted/examples.py --stress 200 - run: python3 tests/hosted/source_static_functions.py - run: python3 tests/hosted/source_linear.py diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 191dc01..567722c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -28,6 +28,7 @@ python3 tests/hosted/source_type_positions.py # structural type errors at annota python3 tests/hosted/source_own_array_content.py # Copy content, nominal/generic types and repeated allocations python3 tests/hosted/source_array_literals.py # inferred elements, repetitions, explicit moves and packages python3 tests/hosted/source_inferred_content.py # constructor content, transfers, recovery and package provenance +python3 tests/hosted/source_nonvalue_operands.py # never operands, divergent receivers, traps and package provenance python3 tests/hosted/examples.py --stress 200 # all examples/packages, wire bytes, partial I/O and source/AIR schedules python3 tests/hosted/source_static_functions.py # explicit operations, effects, nominal policy identity and workers python3 tests/hosted/source_linear.py # whole-value owners, canonical AIR and CLI errors diff --git a/docs/agent/README.md b/docs/agent/README.md index 4e57e81..2296c22 100644 --- a/docs/agent/README.md +++ b/docs/agent/README.md @@ -162,3 +162,5 @@ Q-043 dynamic owning-array content (cl100k): Quick Reference stays 8,948; other Q-045 inferred array literals (cl100k): Quick Reference stays 8,948; other source docs 66,827 → 66,906 (+79), full source 75,775 → 75,854 (+0.10%). o200k groups are 8,984 / 67,110 / 76,094; Qwen2.5 9,226 / 68,550 / 77,776. AIR remains 184,628 bytes / 47,445 cl100k tokens; library/std.md is unchanged. Existing member-position and Copy-repetition rules now reject invalid inferred elements before AIR, at the offending value. Lists retain explicit linear transfers; repeated borrows retain E7006 invalid_literal. No new concept, syntax, code, reason, feature or verifier/runtime state is added. Invalid-source diagnostic codes/priority may change; accepted canonical AIR is preserved. No empirical MCC benefit is claimed. Q-046 inferred constructor content (cl100k): Quick Reference stays 8,948; other source docs 66,906 → 67,074 (+168), full source 75,854 → 76,022 (+0.22%). o200k groups are 8,984 / 67,279 / 76,263; Qwen2.5 9,226 / 68,724 / 77,950. AIR remains 184,628 bytes / 47,445 cl100k tokens; library/std.md is unchanged. Existing value/Copy/borrow restrictions now reject at constructor arguments, including generic templates, before malformed AIR or null-block failure. Complete linear packing and recovery remain valid; graph/endpoint feature diagnostics keep their existing precedence. No new concept, syntax, code/reason, feature or verifier/runtime state is added. Accepted canonical AIR is preserved; invalid-source diagnostics may change. No empirical MCC benefit is claimed. + +Q-047 non-value operands (cl100k): Quick Reference stays 8,948; other source docs 67,074 → 67,258 (+184), full source 76,022 → 76,206 (+0.24%). o200k groups are 8,984 / 67,461 / 76,445; Qwen2.5 9,226 / 68,912 / 78,138. AIR remains 184,628 bytes / 47,445 cl100k tokens; library/std.md is unchanged. Typed operation inputs reject never before subsequent emission; divergent returns/branches/statements and variable receivers retain their control flow, and frame receivers skip writes. Store values remain required. Invalid-source diagnostic order may change; accepted canonical AIR is preserved. No new concept, syntax, code/reason, feature or verifier/runtime state is added. No empirical MCC benefit is claimed. diff --git a/docs/design/open-questions.md b/docs/design/open-questions.md index ce36a76..9cd51d6 100644 --- a/docs/design/open-questions.md +++ b/docs/design/open-questions.md @@ -346,3 +346,11 @@ Audit each constructor against its own existing content/position/property rules Q-046 review identified other uses of `never` that reach lowering with no current block. Independently reproduced: `module test.never_operand fn stop() -> never effects [] { trap; } fn main() -> u64 effects [] { return 1u64 + stop(); }` aborts while `Lowerer.binary` calls `def`/`emit` after `stop()` terminated the block. Review also reproduced ordinary call arguments and struct fields; their exact scope remains unverified. Q-046 guards constructor content only. Audit non-value operands in ordinary calls, operators and aggregates against spec 15 before emission. Distinguish value-requiring positions from valid void statements and never-returning control flow. Add source rejection/acceptance and CLI tests, preserving evaluation order, explicit transfers, diagnostics and canonical AIR for valid source. A source program MUST NOT cause a lowering panic; do not infer a new divergence/coercion rule from implementation behavior. + +**Resolved (spec 15 §10):** typed operation inputs reject never with E7005 at the operand (`expected`, `found: never`) before subsequent inputs/emission, while ordinary void mismatches retain their diagnostics. Calls, operators, fields/payloads, conditions, ranges/indices, sizes, atomics, channels and place-store values use this rule. `select` checks a divergent send value before endpoint borrows. Return/tail/statement/branch divergence and existing SSA variable receivers remain valid; divergent assignment by name or `var` initialization in frame storage now performs no store. Binding/annotation checks still precede those receivers. Place writes through `*`, fields or indices require a value; rejecting never before target evaluation prevents formerly invalid targets from being accepted. Unknown target types use `expected: a stored value`, so earlier E7002 can become E7005 at the RHS. `let` retains its existing no-value error. Emission into a terminated block returns E7006 unreachable rather than aborting; a state-machine unit test preserves the terminated block and diagnostic span. AIR acceptance, ownership/lifetime rules, effect/capability contracts, normal-path execution and accepted-source canonical AIR are unchanged. Programs that previously aborted now reject or, for valid variable receivers, diverge normally. Q-048 records a separate store-mode gap. + +## Q-048 — Source place-store access modes + +Q-047 review independently reproduced `fn update(p: ref) -> void effects [] { *p = 1u64; }`: it reaches AIR E1001 (`expected: mut`, `found: ref`) instead of frontend E7xxx, although the mode is determined by source types (spec 15 §10). Review also observed accepted writes to fields of a `let` aggregate. An immutable binding does not necessarily imply immutable owned content; whether that behavior disagrees with the specification remains unverified and MUST NOT be guessed from the binding's `mutable` flag. + +Audit existing place modes and referents against spec 15 §4/§5 and AIR borrow/store rules. Reject fully type-decided incompatibilities at the source, preserving ownership, aliasing/lifetime diagnostics, evaluation order and canonical AIR for valid source. Determine the binding/content distinction from governing text before proposing any semantic restriction. diff --git a/docs/plan/phase-6-source-language.md b/docs/plan/phase-6-source-language.md index dd692ac..a974095 100644 --- a/docs/plan/phase-6-source-language.md +++ b/docs/plan/phase-6-source-language.md @@ -269,3 +269,11 @@ Q-046/spec 15 §10 validates inferred content before forming constructor results The preserved invariants are that second-class borrows cannot become owned content and Copy-only allocation cannot hide or destroy a linear value. AIR independently enforces the same type, property and ownership rules. Allocation authority/budgets, ok/err payloads, explicit release, resource recovery, runtime state and deterministic interpreter behavior are unchanged. Positive runs release linear contents and distinguish successful/failed packing; rejected tests cover nonvalues, borrows, owners, nominal values and tasks. No new syntax, code/reason, feature, verifier state or evaluation input changes. Source bundle growth is recorded in docs/agent/README.md; P6-2 remains open, with the separate Q-044 property-query cost audit outstanding. Validation: full conformance passes 1,422/1,422, units and Zig formatting pass. The 58 new conformance fixtures pass with collection before every instruction; the new CLI suite passes 302 checks across diagnostic commands, exact fields/locations, imported generic templates, source/AIR/hosted runs and formatter fidelity. Existing owning-array, literal and linear CLI suites pass 119, 152 and 49 checks. The formatter corpus passes 4,862 checks on 1,134 public files (1,126 parsed, eight existing syntax errors, 657 identical successful AIR outputs); the two final graph regression fixtures additionally preserve formatted AIR in CLI checks. Independent read-only review by Claude confirmed the constructor-specific rules and identified the existing feature-dependent graph diagnostic, covered by paired fixtures. Comparison with the previous compiler on 1,078 existing public sources changes one invalid region allocation from E1001 to E7005; accepted programs retain byte-identical AIR. The former compiler successfully lowered 642 of these sources, including that invalid program. Source coverage remains 121/121. + +## P6-2 non-value operands (2026-10-08) + +Q-047/spec 15 §10 distinguishes typed operation inputs from divergent control flow. Never-valued operands reject E7005 at the operand with expected/found fields before later inputs or instruction emission; existing void mismatches remain unchanged. This covers calls, operators, aggregate inputs, conditions, ranges/indices, sizes, atomics, channels and stored values. `select` checks send values before endpoint borrows. Return/tail/statement/branch divergence remains valid. Variable assignment by name and var initialization retain ordinary binding/annotation checks; divergence skips a frame store just as it already did an SSA update. Place writes require a value: accepting a divergent RHS would otherwise bypass target checks, a regression found and corrected during independent read-only review with Claude. Attempted emission after unconditional divergence reports E7006 unreachable; a unit test verifies that the terminated block remains intact. + +The preserved invariants are that no missing value becomes an operand or store and no write/borrow is emitted after control flow terminates. AIR independently retains its type, ownership, lifetime and effect/capability rules. Runtime cleanup, abnormal-path resource handling, deterministic execution and accepted-source canonical AIR are unchanged. Positive cases cover variable receivers in SSA/frame storage, normal/trapping branch paths, ownership and returned views; rejected cases cover non-value inputs and malformed place targets. Former compiler aborts now produce a diagnostic or valid variable-receiver divergence. Invalid diagnostic order may change, including place RHS errors before unknown targets. No new syntax, diagnostic code/reason, feature, verifier/runtime state or evaluation input changes. Source bundle growth is recorded in docs/agent/README.md. P6-2 remains open; Q-048 is the separately reproduced store-mode gap, and Q-044 remains an implementation-cost audit. + +Validation: full conformance passes 1,497/1,497; unit tests and Zig formatting pass. The 75 new fixtures pass with collection before every instruction and the CLI suite passes 635 checks, including exact positions/fields across diagnostic commands, source/AIR/hosted trap/return parity, formatting and imported generic reachability. Existing constructor/literal/owning-array/linear CLI suites pass 302/152/119/49 checks. Final comparison on 1,136 preceding public sources (659 successful old lowerings) has zero changed check or canonical lower outputs. The formatter corpus passes 5,098 checks on the first 1,200 public files (1,192 parsed, eight existing syntax errors, 676 identical AIR outputs); CLI formatting covers all 75 new fixtures, including the eleven later additions. Source coverage remains 121/121. diff --git a/docs/spec/15-source-language.md b/docs/spec/15-source-language.md index cccffad..ecc8dc5 100644 --- a/docs/spec/15-source-language.md +++ b/docs/spec/15-source-language.md @@ -406,6 +406,7 @@ A byte string or array used where a `slice` is expected is materialized in f - Copy content of `own_array` and the repeated value of `own.array`; an invalid content type is E7005 at that annotation/value, with `constraint: Copy` and `type_constructor: own_array`. Known linear content in unused generic signatures and static contracts MUST reject; unknown type parameters are checked after substitution. - Inferred array literal elements MUST satisfy the existing member-position rules. Borrowed elements reject E7006 `invalid_literal`; other invalid constructors reject E7005 at the element with `position: member` and `type_constructor`. Lists preserve explicit linear transfers; repetitions MUST satisfy Copy. - Inferred content of `own.new`, `own.pack`, `region.new`, `region.array`, `mutex.make`, `island.create`, `island.alloc` and `arc.new` MUST be a value: `void`/`never` reject E7005 at the content argument, with `position: member` and `type_constructor`. `own.new` and region storage MUST require Copy (E7005 with `constraint: Copy` and `operation`); `own.pack` MUST reject borrowed content (E7005 with `position: member` and `type_constructor`) while preserving complete linear transfers and failure recovery. These checks follow ordinary explicit-move checks and precede allocation authority checks. Graph-content properties, reserved transfers and concurrency checks otherwise retain their verifier diagnostics; `own.array` retains its Copy diagnostic above. +- A typed operand needed by an operation MUST yield a value: `never` rejects E7005 at that operand with `expected` and `found: never`, before later operands or instruction emission. This includes calls, operators, aggregate inputs, conditions, ranges, indices, sizes and the value stored through `*`, a field or an index. For a place store this check precedes borrowing/evaluating the target; an unknown target type uses `expected: a stored value`. Existing void/type mismatches retain their diagnostics. Divergence in returns, tails, statements and if/match arms remains valid. Assignment to a variable by name and `var` initialization MAY diverge after the ordinary binding/annotation checks; no store is emitted for either SSA or frame storage. `let` still requires a value. Expressions emitted after unconditional divergence MUST reject E7006 `unreachable`, never abort the compiler. Source type annotations MUST satisfy the existing AIR type-position rules (spec 07 §8.3/§8.8), including nested constructors. An invalid constructor is E7005 at its annotation, with `position` and `type_constructor` fields. Known constructors in unused generic signatures and static function contracts MUST be checked; restrictions depending on a type parameter are checked after substitution. Graph-content properties and feature gates for otherwise correctly positioned types retain their verifier diagnostics. diff --git a/src/frontend/lower.zig b/src/frontend/lower.zig index a361ec7..7c94cd5 100644 --- a/src/frontend/lower.zig +++ b/src/frontend/lower.zig @@ -900,7 +900,8 @@ const Lowerer = struct { } fn emit(l: *Lowerer, text: []const u8, span: Span) Error!void { - const b = &l.blocks.items[l.cur.?]; + const current = l.cur orelse return l.invalid(.@"unreachable", span, "unreachable expression", &.{}); + const b = &l.blocks.items[current]; try b.insts.append(l.arena, .{ .text = text, .span = span, .constant = l.in_constant }); } @@ -1181,6 +1182,7 @@ const Lowerer = struct { if (x.init) |e| { const v = try l.consuming(e, ty); try l.checkTy(e.span, v.ty, ty); + if (v.ty == .never) return; try l.emit(try l.fmt("local.store %{s}, %{s}", .{ st, v.name }), s.span); } else try l.emit(try l.fmt("local.zero %{s}", .{st}), s.span); try l.bindings.append(l.arena, .{ .name = x.name, .mutable = true, .value = st, .ty = ty, .kind = .storage }); @@ -1204,6 +1206,7 @@ const Lowerer = struct { const v = try l.consuming(x.e, ty); try l.checkTy(x.e.span, v.ty, ty); if (kind == .storage) { + if (v.ty == .never) return; try l.emit(try l.fmt("local.store %{s}, %{s}", .{ storage, v.name }), s.span); } else { // `expr` may have created bindings and blocks; look the binding up again. @@ -1297,6 +1300,20 @@ const Lowerer = struct { return l.fail("E7005", span, "type mismatch", &.{ .{ .name = "expected", .value = l.diagnosticTyText(want) }, .{ .name = "found", .value = l.diagnosticTyText(found) } }); } + /// Operation inputs must yield an actual value, unlike divergent returns + /// or statement receivers. Check before lowering the next input. + fn checkOperandTy(l: *Lowerer, span: Span, found: Ty, want: Ty) Error!void { + if (found == .never) return l.noOperandValue(span, l.diagnosticTyText(want)); + return l.checkTy(span, found, want); + } + + fn noOperandValue(l: *Lowerer, span: Span, expected: []const u8) Error { + return l.fail("E7005", span, "this expression has no value", &.{ + .{ .name = "expected", .value = expected }, + .{ .name = "found", .value = "never" }, + }); + } + /// `while cond { body }` (cond null: `loop { body }`). Carried state: /// every variable visible at the loop. fn whileLoop(l: *Lowerer, span: Span, cond: ?ast.Expr, body: ast.Block, step: ?ForStep) Error!void { @@ -1316,7 +1333,7 @@ const Lowerer = struct { l.rebindToParams(header, vars, 0); if (cond) |c| { const cv = try l.expr(c, .bool); - try l.checkTy(c.span, cv.ty, .bool); + try l.checkOperandTy(c.span, cv.ty, .bool); const body_b = try l.newBlock("body", body.span); try l.term(try l.fmt("cbr %{s}, @{s}(), @{s}{s}", .{ cv.name, l.blocks.items[body_b].name, l.blocks.items[exit].name, try l.argsOf(exit_vars, null) }), c.span); l.cur = body_b; @@ -1351,9 +1368,9 @@ const Lowerer = struct { const ty = l.peekType(lo) orelse l.peekType(hi) orelse return l.fail("E7007", lo.span, "the type of the range cannot be determined; add a suffix such as `0usize`", &.{}); if (ty != .int) return l.fail("E7005", lo.span, "a range needs an integer type", &.{.{ .name = "found", .value = l.diagnosticTyText(ty) }}); const a = try l.expr(lo, ty); - try l.checkTy(lo.span, a.ty, ty); + try l.checkOperandTy(lo.span, a.ty, ty); const b = try l.expr(hi, ty); - try l.checkTy(hi.span, b.ty, ty); + try l.checkOperandTy(hi.span, b.ty, ty); try l.bindings.append(l.arena, .{ .name = "end of range", .mutable = false, .value = b.name, .ty = ty }); try l.bindings.append(l.arena, .{ .name = name, .mutable = true, .value = a.name, .ty = ty }); const cond: ast.Expr = .{ .span = span, .kind = .{ .binary = .{ @@ -1612,7 +1629,7 @@ const Lowerer = struct { for (xs, 0..) |x, i| { const v = try l.consuming(x, ty); try l.arrayElement(x.span, v.ty, false); - if (ty) |t| try l.checkTy(x.span, v.ty, t) else ty = v.ty; + if (ty) |t| try l.checkOperandTy(x.span, v.ty, t) else ty = v.ty; try names.appendSlice(l.arena, try l.fmt("{s}%{s}", .{ if (i == 0) "" else ", ", v.name })); } const at = try l.arrayOf(ty.?, xs.len); @@ -1641,12 +1658,12 @@ const Lowerer = struct { } const z = try l.def("zero", ty, try l.fmt("const.{s} 0", .{ty.int}), e.span); const v = try l.expr(x.*, ty); - try l.checkTy(x.span, v.ty, ty); + try l.checkOperandTy(x.span, v.ty, ty); return l.def("neg", ty, try l.fmt("sub.checked.{s} %{s}, %{s}", .{ ty.int, z.name, v.name }), e.span); }, .not => |x| { const v = try l.expr(x.*, .bool); - try l.checkTy(x.span, v.ty, .bool); + try l.checkOperandTy(x.span, v.ty, .bool); const t = try l.def("c", .bool, "const.bool true", e.span); return l.def("not", .bool, try l.fmt("xor.bool %{s}, %{s}", .{ v.name, t.name }), e.span); }, @@ -1699,7 +1716,7 @@ const Lowerer = struct { .@"and", .@"or" => { // Short-circuit: the right operand runs only when needed. const lv = try l.expr(a, .bool); - try l.checkTy(a.span, lv.ty, .bool); + try l.checkOperandTy(a.span, lv.ty, .bool); const short = try l.def("c", .bool, if (op == .@"and") "const.bool false" else "const.bool true", e.span); const rhs_b = try l.newBlock(if (op == .@"and") "and_rhs" else "or_rhs", b.span); const join = try l.newBlock(if (op == .@"and") "and_end" else "or_end", e.span); @@ -1711,7 +1728,7 @@ const Lowerer = struct { } else try l.term(try l.fmt("cbr %{s}, @{s}(%{s}), @{s}()", .{ lv.name, jn, short.name, l.blocks.items[rhs_b].name }), e.span); l.cur = rhs_b; const rv = try l.expr(b, .bool); - try l.checkTy(b.span, rv.ty, .bool); + try l.checkOperandTy(b.span, rv.ty, .bool); try l.term(try l.fmt("br @{s}(%{s})", .{ jn, rv.name }), e.span); l.cur = join; return .{ .name = rname, .ty = .bool }; @@ -1726,9 +1743,9 @@ const Lowerer = struct { const operand: ?Ty = if (cmp) (l.peekType(a) orelse l.peekType(b)) else if (shift) (want orelse l.peekType(a)) else (want orelse l.peekType(a) orelse l.peekType(b)); const ty = operand orelse return l.fail("E7007", e.span, "the type of this operation cannot be determined; add a suffix or annotation", &.{}); const lv = try l.expr(a, ty); - try l.checkTy(a.span, lv.ty, ty); + try l.checkOperandTy(a.span, lv.ty, ty); const rv = try l.expr(b, ty); - try l.checkTy(b.span, rv.ty, ty); + try l.checkOperandTy(b.span, rv.ty, ty); // `iref` identity (spec 03 §22): equal graph and slot; never a trap. if (ty == .iref) { if (op != .eq and op != .ne) return l.fail("E7005", e.span, "`iref` handles are compared with `==` and `!=` only", &.{}); @@ -1782,7 +1799,7 @@ const Lowerer = struct { if (p.v.ty != .mut) return l.fail("E7005", e.span, "value.swap requires mut", &.{}); const ty = p.v.ty.inner().?; const replacement = try l.consuming(args[1], ty); - try l.checkTy(args[1].span, replacement.ty, ty); + try l.checkOperandTy(args[1].span, replacement.ty, ty); const result = try l.def("old", ty, try l.fmt("value.swap %{s}, %{s}", .{ p.v.name, replacement.name }), e.span); try l.endNow(p.ends, e.span); l.linear_enabled = true; @@ -1842,14 +1859,14 @@ const Lowerer = struct { if (std.mem.eql(u8, name, "assert")) { if (args.len != 1) return l.fail("E7005", e.span, "`assert` takes one boolean", &.{}); const v = try l.expr(args[0], .bool); - try l.checkTy(args[0].span, v.ty, .bool); + try l.checkOperandTy(args[0].span, v.ty, .bool); try l.emit(try l.fmt("assert %{s}", .{v.name}), e.span); return .{ .name = "", .ty = .void }; } if (std.mem.eql(u8, name, "assume")) { if (args.len != 1) return l.fail("E7005", e.span, "`assume` takes one boolean", &.{}); const v = try l.expr(args[0], .bool); - try l.checkTy(args[0].span, v.ty, .bool); + try l.checkOperandTy(args[0].span, v.ty, .bool); l.uses.insert(.unsafe); try l.emit(try l.fmt("assume %{s}", .{v.name}), e.span); return .{ .name = "", .ty = .void }; @@ -1869,7 +1886,7 @@ const Lowerer = struct { for (args, sig.params, 0..) |a, pt, i| { const v = try l.argument(a, pt, &temps); if (sig.from == i) parent = v.name; - try l.checkTy(a.span, v.ty, pt); + try l.checkOperandTy(a.span, v.ty, pt); try arg_names.appendSlice(l.arena, try l.fmt("{s}%{s}", .{ if (i == 0) "" else ", ", v.name })); } const text = try l.fmt("call @{s}({s})", .{ sig.air_name, arg_names.items }); @@ -1910,7 +1927,7 @@ const Lowerer = struct { } else return l.invalid(.invalid_literal, e.span, "missing field", &.{ .{ .name = "type", .value = d.display_name orelse name }, .{ .name = "field", .value = f.name } }); const ft = try l.typeOf(f.ty); const v = try l.consuming(fi.e, ft); - try l.checkTy(fi.e.span, v.ty, ft); + try l.checkOperandTy(fi.e.span, v.ty, ft); try args.appendSlice(l.arena, try l.fmt("{s}%{s}", .{ if (i == 0) "" else ", ", v.name })); } return l.def("s", t, try l.fmt("struct.make {s}({s})", .{ l.tyText(t), args.items }), e.span); @@ -1932,7 +1949,7 @@ const Lowerer = struct { for (args, v.payload, 0..) |a, pt, i| { const ty = try l.typeOf(pt); const av = try l.consuming(a, ty); - try l.checkTy(a.span, av.ty, ty); + try l.checkOperandTy(a.span, av.ty, ty); try names.appendSlice(l.arena, try l.fmt("{s}%{s}", .{ if (i == 0) "" else ", ", av.name })); } return l.def("e", t, try l.fmt("enum.make {s}.{s}({s})", .{ l.tyText(t), variant, names.items }), e.span); @@ -2406,9 +2423,9 @@ const Lowerer = struct { ends = try l.concat(ends, sl.name); } const a = try l.expr(x.lo.*, .{ .int = "usize" }); - try l.checkTy(x.lo.span, a.ty, .{ .int = "usize" }); + try l.checkOperandTy(x.lo.span, a.ty, .{ .int = "usize" }); const b = try l.expr(hi.*, .{ .int = "usize" }); - try l.checkTy(hi.span, b.ty, .{ .int = "usize" }); + try l.checkOperandTy(hi.span, b.ty, .{ .int = "usize" }); const len = try l.def("len", .{ .int = "usize" }, try l.fmt("sub.checked.usize %{s}, %{s}", .{ b.name, a.name }), span); const sub_ = try l.defBorrow("s", sl.ty, try l.fmt("slice.sub %{s}, %{s}, %{s}", .{ sl.name, a.name, len.name }), sl.name, span); return .{ .v = sub_, .ends = try l.concat(ends, sub_.name) }; @@ -2417,7 +2434,7 @@ const Lowerer = struct { const unchecked = l.unchecked; l.unchecked = false; const i = try l.expr(x.lo.*, .{ .int = "usize" }); - try l.checkTy(x.lo.span, i.ty, .{ .int = "usize" }); + try l.checkOperandTy(x.lo.span, i.ty, .{ .int = "usize" }); const proven = for (l.facts.items) |f| { if (std.mem.eql(u8, f.index, i.name) and std.mem.eql(u8, f.slice, base.v.name)) break true; } else false; @@ -2446,11 +2463,13 @@ const Lowerer = struct { if (place.kind == .index and place.kind.index.hi != null) return l.invalid(.invalid_assignment, place.span, "assign elements one by one, or use `slice.copy(mut dst, ref src)`", &.{}); // The value is evaluated first, then the place is borrowed for the // store (spec 15 §4), so `s[i] = s[i] + 1` reads before it writes. - const v = try l.expr(value, l.placeType(place)); + const target_type = l.placeType(place); + const v = try l.expr(value, target_type); + if (v.ty == .never) return l.noOperandValue(value.span, if (target_type) |t| l.diagnosticTyText(t) else "a stored value"); const p = try l.placeBorrow(place, true, false, span); const in = p.v.ty.inner() orelse return l.fail("E7005", place.span, "assignment needs a mutable place", &.{}); if (in == .array and place.kind == .deref) return l.invalid(.invalid_assignment, place.span, "write array elements with `s[i] = …`", &.{}); - try l.checkTy(value.span, v.ty, in); + try l.checkOperandTy(value.span, v.ty, in); try l.emit(try l.fmt("store %{s}, %{s}", .{ p.v.name, v.name }), span); try l.endNow(p.ends, span); } @@ -2520,7 +2539,7 @@ const Lowerer = struct { const p = try l.placeBorrow(base, mutable, true, s.span); if (p.v.ty != .slice and p.v.ty != .slice_mut) return l.fail("E7005", base.span, "`split_at` splits a slice", &.{.{ .name = "found", .value = l.diagnosticTyText(p.v.ty) }}); const k = try l.expr(e.kind.call.args[0], .{ .int = "usize" }); - try l.checkTy(e.kind.call.args[0].span, k.ty, .{ .int = "usize" }); + try l.checkOperandTy(e.kind.call.args[0].span, k.ty, .{ .int = "usize" }); const left = try l.freshName(names[0]); const right = try l.freshName(names[1]); try l.emit(try l.fmt("%{s}, %{s} = slice.split %{s}, %{s}", .{ left, right, p.v.name, k.name }), s.span); @@ -2718,7 +2737,7 @@ const Lowerer = struct { return v; } const operand = try l.expr(args[1], t); - try l.checkTy(args[1].span, operand.ty, t); + try l.checkOperandTy(args[1].span, operand.ty, t); if (eq(u8, p, "atomic.store")) { try l.emit(try l.fmt("atomic.store.{s} %{s}, %{s}", .{ ord, c.name, operand.name }), e.span); try l.endNow(temps.items, e.span); @@ -2740,9 +2759,9 @@ const Lowerer = struct { const c = try l.cellOperand(args[0], &temps); const t = c.ty.inner().?.inner().?; const expected = try l.expr(args[1], t); - try l.checkTy(args[1].span, expected.ty, t); + try l.checkOperandTy(args[1].span, expected.ty, t); const desired = try l.expr(args[2], t); - try l.checkTy(args[2].span, desired.ty, t); + try l.checkOperandTy(args[2].span, desired.ty, t); const succ = try l.ordering(args[3]); const failure = try l.ordering(args[4]); const old = try l.freshName(names[0]); @@ -2798,7 +2817,7 @@ const Lowerer = struct { // by the program, not made for the call (spec 15 §7). if (a.kind == .borrow or a.kind == .bytes) return l.invalid(.invalid_borrow, a.span, "a borrow lent to a task stays lent until the join: bind it first (`mut part = …;`) and pass the name", &.{}); const v = try l.consuming(a, pt); - try l.checkTy(a.span, v.ty, pt); + try l.checkOperandTy(a.span, v.ty, pt); try names.appendSlice(l.arena, try l.fmt("{s}%{s}", .{ if (i == 0) "" else ", ", v.name })); } return try l.def("t", try l.wrap(.task, sig.ret), try l.fmt("task.spawn %{s}, @{s}({s})", .{ scope_name, sig.air_name, names.items }), e.span); @@ -2961,6 +2980,13 @@ const Lowerer = struct { }; if (av.* == null) { const v = try l.consuming(ve, null); + if (v.ty == .never) { + // Values precede endpoint borrows. Inspect a known binding + // without emitting a borrow or evaluating another input. + const endpoint_ty: Ty = if (l.lookup(a.endpoint)) |b| b.ty else .void; + const channel_ty = if (endpoint_ty.isBorrow()) endpoint_ty.inner().? else endpoint_ty; + return l.noOperandValue(ve.span, if (channel_ty == .sender) l.diagnosticTyText(channel_ty.sender.*) else "a channel element"); + } try values.append(l.arena, .{ .key = key, .v = v }); av.* = values.items.len - 1; } @@ -2981,7 +3007,7 @@ const Lowerer = struct { }; if (a.send) { const et = ae.ty.inner().?.sender.*; - try l.checkTy(a.value.?.span, values.items[arm_value[ai].?].v.ty, et); + try l.checkOperandTy(a.value.?.span, values.items[arm_value[ai].?].v.ty, et); } } // Edges: per arm `ok` and `closed`, then `cancelled`. @@ -3252,7 +3278,7 @@ const Lowerer = struct { const source_ty = e.kind.call.type_arg orelse return l.fail("E7005", e.span, "buffer.new needs an explicit content type", &.{}); const ty = try l.memberType(source_ty); const n = try l.expr(args[0], usize_ty); - try l.checkTy(args[0].span, n.ty, usize_ty); + try l.checkOperandTy(args[0].span, n.ty, usize_ty); const cap = try l.expectCap(args[1], "mem.alloc"); return .{ .text = try l.fmt("buffer.new {s} %{s}, %{s}", .{ l.tyText(ty), n.name, cap.name }), .outcomes = try l.outs(&.{ .{ .role = "ok", .params = &.{try l.wrap(.buffer, ty)} }, .{ .role = "err", .params = &.{alloc_err} } }) }; } @@ -3270,12 +3296,12 @@ const Lowerer = struct { const ty = b.ty.inner().?.buffer.*; if (is_push) { const v = try l.consuming(args[1], ty); - try l.checkTy(args[1].span, v.ty, ty); + try l.checkOperandTy(args[1].span, v.ty, ty); return .{ .text = try l.fmt("buffer.push %{s}, %{s}", .{ b.name, v.name }), .outcomes = try l.outs(&.{ .{ .role = "ok", .params = &.{} }, .{ .role = "err", .params = &.{ty} } }) }; } if (is_pop) return .{ .text = try l.fmt("buffer.pop %{s}", .{b.name}), .outcomes = try l.outs(&.{ .{ .role = "ok", .params = &.{ty} }, .{ .role = "err", .params = &.{} } }) }; const n = try l.expr(args[1], usize_ty); - try l.checkTy(args[1].span, n.ty, usize_ty); + try l.checkOperandTy(args[1].span, n.ty, usize_ty); const cap = try l.expectCap(args[2], "mem.alloc"); return .{ .text = try l.fmt("buffer.reserve %{s}, %{s}, %{s}", .{ b.name, n.name, cap.name }), .outcomes = try l.outs(&.{ .{ .role = "ok", .params = &.{} }, .{ .role = "err", .params = &.{alloc_err} } }) }; } @@ -3297,7 +3323,7 @@ const Lowerer = struct { if (std.mem.eql(u8, path, "own.array")) { try want(l, e.span, args, 3, path); const n = try l.expr(args[0], usize_ty); - try l.checkTy(args[0].span, n.ty, usize_ty); + try l.checkOperandTy(args[0].span, n.ty, usize_ty); const v = try l.consuming(args[1], null); if (!verifier_types.isCopy(l.property_module.?, try l.airType(v.ty))) return l.copyArrayError(args[1].span); const c = try l.expectCap(args[2], "mem.alloc"); @@ -3319,7 +3345,7 @@ const Lowerer = struct { try want(l, e.span, args, 3, path); const rb = try l.regionBorrow(args[0]); const n = try l.expr(args[1], usize_ty); - try l.checkTy(args[1].span, n.ty, usize_ty); + try l.checkOperandTy(args[1].span, n.ty, usize_ty); const v = try l.contentValue(args[2]); try l.copyContent(args[2].span, v.ty, path); return .{ .borrow_parent = rb.name, .text = try l.fmt("region.array %{s}, %{s}, %{s}", .{ rb.name, n.name, v.name }), .outcomes = try l.outs(&.{ .{ .role = "ok", .params = &.{try l.wrap(.slice_mut, v.ty)} }, .{ .role = "err", .params = &.{alloc_err} } }) }; @@ -3369,7 +3395,7 @@ const Lowerer = struct { const et = try l.memberType(ta); try l.elementRule(et, ta.span, "a channel element"); const n = try l.expr(args[0], usize_ty); - try l.checkTy(args[0].span, n.ty, usize_ty); + try l.checkOperandTy(args[0].span, n.ty, usize_ty); const c = try l.expectCap(args[1], "mem.alloc"); return .{ .text = try l.fmt("channel.make {s}, %{s}, %{s}", .{ l.tyText(et), n.name, c.name }), .outcomes = try l.outs(&.{ .{ .role = "ok", .params = &.{ try l.wrap(.sender, et), try l.wrap(.receiver, et) } }, .{ .role = "err", .params = &.{alloc_err} } }) }; } @@ -3379,7 +3405,7 @@ const Lowerer = struct { const tx = try l.endpointOperand(args[0], .sender, true, &temps); const et = tx.ty.inner().?.sender.*; const v = try l.consuming(args[1], et); - try l.checkTy(args[1].span, v.ty, et); + try l.checkOperandTy(args[1].span, v.ty, et); return .{ .text = try l.fmt("channel.send %{s}, %{s}", .{ tx.name, v.name }), .outcomes = try l.outs(&.{ .{ .role = "ok", .params = &.{} }, .{ .role = "closed", .params = &.{et} }, .{ .role = "cancelled", .params = &.{et} } }), .temps = temps.items }; } if (std.mem.eql(u8, path, "channel.recv")) { @@ -3410,7 +3436,7 @@ const Lowerer = struct { const c = try l.expr(args[0], null); if (c.ty != .cap) return l.fail("E7005", args[0].span, "a capability is expected here", &.{.{ .name = "found", .value = l.diagnosticTyText(c.ty) }}); const n = try l.expr(args[1], usize_ty); - try l.checkTy(args[1].span, n.ty, usize_ty); + try l.checkOperandTy(args[1].span, n.ty, usize_ty); return .{ .text = try l.fmt("cap.narrow.budget %{s}, %{s}", .{ c.name, n.name }), .outcomes = try l.outs(&.{ .{ .role = "ok", .params = &.{c.ty} }, .{ .role = "err", .params = &.{.{ .builtin = .cap_error }} } }) }; } return l.invalid(.invalid_operation, e.span, "not a fallible operation", &.{.{ .name = "operation", .value = path }}); @@ -3532,7 +3558,7 @@ const Lowerer = struct { const st = l.peekType(c.kind.binary.r.kind.field.e.*); if (st != null and (st.? == .slice or st.? == .slice_mut)) { const iv = try l.expr(c.kind.binary.l.*, .{ .int = "usize" }); - try l.checkTy(c.kind.binary.l.span, iv.ty, .{ .int = "usize" }); + try l.checkOperandTy(c.kind.binary.l.span, iv.ty, .{ .int = "usize" }); const sv = try l.expr(c.kind.binary.r.kind.field.e.*, st.?); const n = try l.def("len", .{ .int = "usize" }, try l.fmt("slice.len %{s}", .{sv.name}), c.kind.binary.r.span); fact = .{ .index = iv.name, .slice = sv.name }; @@ -3541,7 +3567,7 @@ const Lowerer = struct { } break :blk try l.expr(c, .bool); }; - try l.checkTy(x.cond.span, cv.ty, .bool); + try l.checkOperandTy(x.cond.span, cv.ty, .bool); const depth = l.bindings.items.len; const vars = try l.carriedLive(depth, span, .{ .@"if" = x }); const then_b = try l.newBlock("then", x.then.span); @@ -3999,3 +4025,18 @@ fn boundedType(m: air_module.Module, t: air_module.Type, depth: usize) bool { }; return if (t.inner()) |inner| boundedType(m, inner, depth + 1) else true; } + +test "terminated blocks reject further emission with a source diagnostic" { + var scratch = std.heap.ArenaAllocator.init(std.testing.allocator); + defer scratch.deinit(); + var l: Lowerer = .{ .arena = scratch.allocator(), .m = .{ .name = "test", .types = &.{}, .functions = &.{} } }; + const span: Span = .{ .start = .{ .line = 1, .col = 1 }, .end = .{ .line = 1, .col = 2 } }; + l.cur = try l.newBlock("entry", span); + try l.term("trap", span); + try std.testing.expectError(error.Lower, l.emit("ret", span)); + try std.testing.expectEqualStrings("E7006", l.problem.?.code); + try std.testing.expectEqual(InvalidReason.@"unreachable", l.problem.?.reason.?); + try std.testing.expectEqual(span, l.problem.?.span); + try std.testing.expectEqual(@as(usize, 1), l.blocks.items[0].insts.items.len); + try std.testing.expect(l.blocks.items[0].terminated); +} diff --git a/tests/conformance/source/nonvalue_operands/add_left.aji b/tests/conformance/source/nonvalue_operands/add_left.aji new file mode 100644 index 0000000..05cad78 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/add_left.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { return stop() + 1u64; } diff --git a/tests/conformance/source/nonvalue_operands/add_right.aji b/tests/conformance/source/nonvalue_operands/add_right.aji new file mode 100644 index 0000000..e7bfbf7 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/add_right.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { return 1u64 + stop(); } diff --git a/tests/conformance/source/nonvalue_operands/add_right_void.aji b/tests/conformance/source/nonvalue_operands/add_right_void.aji new file mode 100644 index 0000000..8f3f122 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/add_right_void.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { return 1u64 + nothing(); } diff --git a/tests/conformance/source/nonvalue_operands/and_left.aji b/tests/conformance/source/nonvalue_operands/and_left.aji new file mode 100644 index 0000000..1953f9e --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/and_left.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { let x = stop() and true; return 42; } diff --git a/tests/conformance/source/nonvalue_operands/and_right.aji b/tests/conformance/source/nonvalue_operands/and_right.aji new file mode 100644 index 0000000..904f962 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/and_right.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { let x = true and stop(); return 42; } diff --git a/tests/conformance/source/nonvalue_operands/array_size.aji b/tests/conformance/source/nonvalue_operands/array_size.aji new file mode 100644 index 0000000..98d6c9f --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/array_size.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main(heap: cap) -> void effects [mem.alloc] { let x = own.array(stop(), 1u64, heap) or trap; trap; } diff --git a/tests/conformance/source/nonvalue_operands/assert.aji b/tests/conformance/source/nonvalue_operands/assert.aji new file mode 100644 index 0000000..72b97f0 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/assert.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { assert(stop()); return 42; } diff --git a/tests/conformance/source/nonvalue_operands/assignment_never.aji b/tests/conformance/source/nonvalue_operands/assignment_never.aji new file mode 100644 index 0000000..3436be4 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/assignment_never.aji @@ -0,0 +1,12 @@ +// expect: run +// trap: T0001 +// phase: 6 +// spec: docs/spec/15-source-language.md §4/§10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { var x: u64 = 0; x = stop(); } diff --git a/tests/conformance/source/nonvalue_operands/assume.aji b/tests/conformance/source/nonvalue_operands/assume.aji new file mode 100644 index 0000000..1e48870 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/assume.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [unsafe] { assume(stop()); return 42; } diff --git a/tests/conformance/source/nonvalue_operands/atomic_desired.aji b/tests/conformance/source/nonvalue_operands/atomic_desired.aji new file mode 100644 index 0000000..73b15a0 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/atomic_desired.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> void effects [] { let a = atomic.new(1u64); let (old, ok) = atomic.compare_exchange(ref a, 1u64, stop(), seq_cst, seq_cst); trap; } diff --git a/tests/conformance/source/nonvalue_operands/atomic_expected.aji b/tests/conformance/source/nonvalue_operands/atomic_expected.aji new file mode 100644 index 0000000..8cedcf7 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/atomic_expected.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> void effects [] { let a = atomic.new(1u64); let (old, ok) = atomic.compare_exchange(ref a, stop(), 1u64, seq_cst, seq_cst); trap; } diff --git a/tests/conformance/source/nonvalue_operands/atomic_store.aji b/tests/conformance/source/nonvalue_operands/atomic_store.aji new file mode 100644 index 0000000..cf49547 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/atomic_store.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> void effects [] { let a = atomic.new(1u64); atomic.store(ref a, stop(), relaxed); trap; } diff --git a/tests/conformance/source/nonvalue_operands/borrow_branch.aji b/tests/conformance/source/nonvalue_operands/borrow_branch.aji new file mode 100644 index 0000000..4704f58 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/borrow_branch.aji @@ -0,0 +1,8 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §4/§10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn pick(p: ref, c: bool) -> ref from p effects [] { if c { return p; } else { stop(); } } +fn main() -> u64 effects [] { let x = 42u64; ref p = x; ref q = pick(p, true); return *q; } diff --git a/tests/conformance/source/nonvalue_operands/buffer_push.aji b/tests/conformance/source/nonvalue_operands/buffer_push.aji new file mode 100644 index 0000000..c7a6979 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/buffer_push.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main(heap: cap) -> void effects [mem.alloc] { let b = buffer.new(2usize, heap) or trap; mut m = b; buffer.push(m, stop()) or trap; trap; } diff --git a/tests/conformance/source/nonvalue_operands/buffer_reserve.aji b/tests/conformance/source/nonvalue_operands/buffer_reserve.aji new file mode 100644 index 0000000..312ee93 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/buffer_reserve.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main(heap: cap) -> void effects [mem.alloc] { let b = buffer.new(2usize, heap) or trap; mut m = b; buffer.reserve(m, stop(), heap) or trap; trap; } diff --git a/tests/conformance/source/nonvalue_operands/buffer_size.aji b/tests/conformance/source/nonvalue_operands/buffer_size.aji new file mode 100644 index 0000000..b834462 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/buffer_size.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main(heap: cap) -> void effects [mem.alloc] { let x = buffer.new(stop(), heap) or trap; trap; } diff --git a/tests/conformance/source/nonvalue_operands/call_block.aji b/tests/conformance/source/nonvalue_operands/call_block.aji new file mode 100644 index 0000000..d08e9fe --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/call_block.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { return take({ return 42u64; }); } diff --git a/tests/conformance/source/nonvalue_operands/call_first.aji b/tests/conformance/source/nonvalue_operands/call_first.aji new file mode 100644 index 0000000..3121ba9 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/call_first.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { return take(stop()); } diff --git a/tests/conformance/source/nonvalue_operands/call_first_void.aji b/tests/conformance/source/nonvalue_operands/call_first_void.aji new file mode 100644 index 0000000..187dbb8 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/call_first_void.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { return take(nothing()); } diff --git a/tests/conformance/source/nonvalue_operands/call_if.aji b/tests/conformance/source/nonvalue_operands/call_if.aji new file mode 100644 index 0000000..555101e --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/call_if.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { return take(if true { stop() } else { stop() }); } diff --git a/tests/conformance/source/nonvalue_operands/call_later_unknown.aji b/tests/conformance/source/nonvalue_operands/call_later_unknown.aji new file mode 100644 index 0000000..fc1c0c2 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/call_later_unknown.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { return two(stop(), missing); } diff --git a/tests/conformance/source/nonvalue_operands/call_match.aji b/tests/conformance/source/nonvalue_operands/call_match.aji new file mode 100644 index 0000000..0a7a9fe --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/call_match.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { return take(match Choice::None { Choice::Some(x) => stop(), Choice::None => stop(), }); } diff --git a/tests/conformance/source/nonvalue_operands/call_second.aji b/tests/conformance/source/nonvalue_operands/call_second.aji new file mode 100644 index 0000000..6f7f94f --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/call_second.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { return two(1u64, stop()); } diff --git a/tests/conformance/source/nonvalue_operands/cap_budget.aji b/tests/conformance/source/nonvalue_operands/cap_budget.aji new file mode 100644 index 0000000..3555264 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/cap_budget.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main(heap: cap) -> void effects [mem.alloc] { let c = cap.narrow.budget(heap, stop()) or trap; trap; } diff --git a/tests/conformance/source/nonvalue_operands/channel_send.aji b/tests/conformance/source/nonvalue_operands/channel_send.aji new file mode 100644 index 0000000..5d4d534 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/channel_send.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main(heap: cap) -> void effects [mem.alloc, task.wait] { match channel.make(1usize, heap) { ok(tx, rx) => { channel.send(tx, stop()) or trap; trap; } err(e) => { trap; } } } diff --git a/tests/conformance/source/nonvalue_operands/channel_size.aji b/tests/conformance/source/nonvalue_operands/channel_size.aji new file mode 100644 index 0000000..7ed2c9c --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/channel_size.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main(heap: cap) -> void effects [mem.alloc] { let x = channel.make(stop(), heap) or trap; trap; } diff --git a/tests/conformance/source/nonvalue_operands/compare.aji b/tests/conformance/source/nonvalue_operands/compare.aji new file mode 100644 index 0000000..14e365f --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/compare.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { let x = 1u64 < stop(); return 42; } diff --git a/tests/conformance/source/nonvalue_operands/enum.aji b/tests/conformance/source/nonvalue_operands/enum.aji new file mode 100644 index 0000000..926beee --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/enum.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { let x = Choice::Some(stop()); return 42; } diff --git a/tests/conformance/source/nonvalue_operands/enum_void.aji b/tests/conformance/source/nonvalue_operands/enum_void.aji new file mode 100644 index 0000000..4646614 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/enum_void.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { let x = Choice::Some(nothing()); return 42; } diff --git a/tests/conformance/source/nonvalue_operands/field_store.aji b/tests/conformance/source/nonvalue_operands/field_store.aji new file mode 100644 index 0000000..00363d9 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/field_store.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> void effects [] { var x: Pair = Pair { a: 1u64, b: 2u64 }; mut p = x; p.a = stop(); } diff --git a/tests/conformance/source/nonvalue_operands/for_high.aji b/tests/conformance/source/nonvalue_operands/for_high.aji new file mode 100644 index 0000000..f63c3d3 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/for_high.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { for i in 0usize..stop() {} return 42; } diff --git a/tests/conformance/source/nonvalue_operands/frame_assignment.aji b/tests/conformance/source/nonvalue_operands/frame_assignment.aji new file mode 100644 index 0000000..62129b5 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/frame_assignment.aji @@ -0,0 +1,12 @@ +// expect: run +// trap: T0001 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> void effects [] { var x: u64 = 0; { ref p = x; } x = stop(); } diff --git a/tests/conformance/source/nonvalue_operands/frame_branch.aji b/tests/conformance/source/nonvalue_operands/frame_branch.aji new file mode 100644 index 0000000..3fa746b --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/frame_branch.aji @@ -0,0 +1,12 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { var x: u64 = 42; { ref p = x; } if false { x = stop(); } return x; } diff --git a/tests/conformance/source/nonvalue_operands/frame_initialization.aji b/tests/conformance/source/nonvalue_operands/frame_initialization.aji new file mode 100644 index 0000000..30d6013 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/frame_initialization.aji @@ -0,0 +1,12 @@ +// expect: run +// trap: T0001 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> void effects [] { var x: u64 = 42; { ref p = x; } { var x: u64 = stop(); } } diff --git a/tests/conformance/source/nonvalue_operands/frame_initialization_unreachable.aji b/tests/conformance/source/nonvalue_operands/frame_initialization_unreachable.aji new file mode 100644 index 0000000..849cd2a --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/frame_initialization_unreachable.aji @@ -0,0 +1,11 @@ +// expect: reject E7006 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> void effects [] { var x: u64 = stop(); ref p = x; } diff --git a/tests/conformance/source/nonvalue_operands/generic_call.aji b/tests/conformance/source/nonvalue_operands/generic_call.aji new file mode 100644 index 0000000..00c50b6 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/generic_call.aji @@ -0,0 +1,12 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn generic(x: T) -> T effects [] { return x; } +fn main() -> u64 effects [] { return generic::(stop()); } diff --git a/tests/conformance/source/nonvalue_operands/if_arm.aji b/tests/conformance/source/nonvalue_operands/if_arm.aji new file mode 100644 index 0000000..4469feb --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/if_arm.aji @@ -0,0 +1,12 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §4/§10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { let x = if true { 42u64 } else { stop() }; return x; } diff --git a/tests/conformance/source/nonvalue_operands/if_condition.aji b/tests/conformance/source/nonvalue_operands/if_condition.aji new file mode 100644 index 0000000..2e4645e --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/if_condition.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { if stop() { return 42; } else { return 0; } } diff --git a/tests/conformance/source/nonvalue_operands/if_condition_void.aji b/tests/conformance/source/nonvalue_operands/if_condition_void.aji new file mode 100644 index 0000000..bb1fa27 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/if_condition_void.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { if nothing() { return 42; } else { return 0; } } diff --git a/tests/conformance/source/nonvalue_operands/index.aji b/tests/conformance/source/nonvalue_operands/index.aji new file mode 100644 index 0000000..11853fd --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/index.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { var a: [u64; 2] = [21u64; 2]; return a[stop()]; } diff --git a/tests/conformance/source/nonvalue_operands/index_argument.aji b/tests/conformance/source/nonvalue_operands/index_argument.aji new file mode 100644 index 0000000..ccb0843 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/index_argument.aji @@ -0,0 +1,12 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn read(p: ref) -> u64 effects [] { return *p; } +fn main() -> u64 effects [] { var a: [u64; 2] = [21u64; 2]; return read(ref a[stop()]); } diff --git a/tests/conformance/source/nonvalue_operands/index_store.aji b/tests/conformance/source/nonvalue_operands/index_store.aji new file mode 100644 index 0000000..6f4bc7f --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/index_store.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> void effects [] { var x: [u64; 2] = [1u64; 2]; x[0usize] = stop(); } diff --git a/tests/conformance/source/nonvalue_operands/index_void.aji b/tests/conformance/source/nonvalue_operands/index_void.aji new file mode 100644 index 0000000..e1ee865 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/index_void.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { var a: [u64; 2] = [21u64; 2]; return a[nothing()]; } diff --git a/tests/conformance/source/nonvalue_operands/initialization_never.aji b/tests/conformance/source/nonvalue_operands/initialization_never.aji new file mode 100644 index 0000000..3dfa31d --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/initialization_never.aji @@ -0,0 +1,12 @@ +// expect: run +// trap: T0001 +// phase: 6 +// spec: docs/spec/15-source-language.md §4/§10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { var x: u64 = stop(); } diff --git a/tests/conformance/source/nonvalue_operands/linear_branch.aji b/tests/conformance/source/nonvalue_operands/linear_branch.aji new file mode 100644 index 0000000..0fda75a --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/linear_branch.aji @@ -0,0 +1,13 @@ +// expect: run +// result: 42 +// grant: heap=mem.alloc:64 +// phase: 6 +// spec: docs/spec/15-source-language.md §4/§10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main(heap: cap) -> u64 effects [mem.alloc] { let a = own.new(42u64, heap) or trap; let b = if true { move a } else { stop() }; return own.take(move b); } diff --git a/tests/conformance/source/nonvalue_operands/match_arm.aji b/tests/conformance/source/nonvalue_operands/match_arm.aji new file mode 100644 index 0000000..5fb66f8 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/match_arm.aji @@ -0,0 +1,12 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §4/§10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { return match Choice::Some(42u64) { Choice::Some(x) => x, Choice::None => stop(), }; } diff --git a/tests/conformance/source/nonvalue_operands/negate.aji b/tests/conformance/source/nonvalue_operands/negate.aji new file mode 100644 index 0000000..381c6ed --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/negate.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> i64 effects [] { return -stop(); } diff --git a/tests/conformance/source/nonvalue_operands/never_statement.aji b/tests/conformance/source/nonvalue_operands/never_statement.aji new file mode 100644 index 0000000..6ef54b9 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/never_statement.aji @@ -0,0 +1,12 @@ +// expect: run +// trap: T0001 +// phase: 6 +// spec: docs/spec/15-source-language.md §4/§10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { stop(); } diff --git a/tests/conformance/source/nonvalue_operands/never_tail.aji b/tests/conformance/source/nonvalue_operands/never_tail.aji new file mode 100644 index 0000000..774f368 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/never_tail.aji @@ -0,0 +1,12 @@ +// expect: run +// trap: T0001 +// phase: 6 +// spec: docs/spec/15-source-language.md §4/§10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { stop() } diff --git a/tests/conformance/source/nonvalue_operands/not.aji b/tests/conformance/source/nonvalue_operands/not.aji new file mode 100644 index 0000000..54d2464 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/not.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { let x = not stop(); return 42; } diff --git a/tests/conformance/source/nonvalue_operands/not_void.aji b/tests/conformance/source/nonvalue_operands/not_void.aji new file mode 100644 index 0000000..8c6f32d --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/not_void.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { let x = not nothing(); return 42; } diff --git a/tests/conformance/source/nonvalue_operands/or_left.aji b/tests/conformance/source/nonvalue_operands/or_left.aji new file mode 100644 index 0000000..850c934 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/or_left.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { let x = stop() or true; return 42; } diff --git a/tests/conformance/source/nonvalue_operands/or_right.aji b/tests/conformance/source/nonvalue_operands/or_right.aji new file mode 100644 index 0000000..b9bb27a --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/or_right.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { let x = false or stop(); return 42; } diff --git a/tests/conformance/source/nonvalue_operands/range_high.aji b/tests/conformance/source/nonvalue_operands/range_high.aji new file mode 100644 index 0000000..3b45f72 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/range_high.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { var a: [u64; 2] = [21u64; 2]; ref s = a[0usize..stop()]; return 42; } diff --git a/tests/conformance/source/nonvalue_operands/range_low.aji b/tests/conformance/source/nonvalue_operands/range_low.aji new file mode 100644 index 0000000..7ec91c0 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/range_low.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { var a: [u64; 2] = [21u64; 2]; ref s = a[stop()..2usize]; return 42; } diff --git a/tests/conformance/source/nonvalue_operands/region_size.aji b/tests/conformance/source/nonvalue_operands/region_size.aji new file mode 100644 index 0000000..bd91b4c --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/region_size.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main(heap: cap) -> void effects [mem.alloc] { let a = region.create(heap) or trap; ref r = a; let x = region.array(r, stop(), 1u64) or trap; trap; } diff --git a/tests/conformance/source/nonvalue_operands/return_never.aji b/tests/conformance/source/nonvalue_operands/return_never.aji new file mode 100644 index 0000000..5be3a86 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/return_never.aji @@ -0,0 +1,12 @@ +// expect: run +// trap: T0001 +// phase: 6 +// spec: docs/spec/15-source-language.md §4/§10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { return stop(); } diff --git a/tests/conformance/source/nonvalue_operands/return_never_void.aji b/tests/conformance/source/nonvalue_operands/return_never_void.aji new file mode 100644 index 0000000..5095cf5 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/return_never_void.aji @@ -0,0 +1,12 @@ +// expect: run +// trap: T0001 +// phase: 6 +// spec: docs/spec/15-source-language.md §4/§10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> void effects [] { return stop(); } diff --git a/tests/conformance/source/nonvalue_operands/select_binding.aji b/tests/conformance/source/nonvalue_operands/select_binding.aji new file mode 100644 index 0000000..b660cbb --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/select_binding.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main(heap: cap) -> void effects [mem.alloc, task.wait] { match channel.make(1usize, heap) { ok(tx, rx) => { mut t = tx; select { send(t, stop()) { ok => {} closed(x) => {} } cancelled(x) => { trap; } } trap; } err(e) => { trap; } } } diff --git a/tests/conformance/source/nonvalue_operands/select_sender.aji b/tests/conformance/source/nonvalue_operands/select_sender.aji new file mode 100644 index 0000000..cb4c286 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/select_sender.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main(heap: cap) -> void effects [mem.alloc, task.wait] { match channel.make(1usize, heap) { ok(tx, rx) => { select { send(tx, stop()) { ok => {} closed(x) => {} } cancelled(x) => { trap; } } trap; } err(e) => { trap; } } } diff --git a/tests/conformance/source/nonvalue_operands/split.aji b/tests/conformance/source/nonvalue_operands/split.aji new file mode 100644 index 0000000..620b039 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/split.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { var a: [u64; 2] = [21u64; 2]; ref s = a; let (left, right) = s.split_at(stop()); return 42; } diff --git a/tests/conformance/source/nonvalue_operands/statements.aji b/tests/conformance/source/nonvalue_operands/statements.aji new file mode 100644 index 0000000..9d5fe6e --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/statements.aji @@ -0,0 +1,12 @@ +// expect: run +// result: 42 +// phase: 6 +// spec: docs/spec/15-source-language.md §4/§10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { nothing(); scope s { nothing(); } shield { nothing(); } loop { break; } return 42; } diff --git a/tests/conformance/source/nonvalue_operands/static_call.aji b/tests/conformance/source/nonvalue_operands/static_call.aji new file mode 100644 index 0000000..a62fe0b --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/static_call.aji @@ -0,0 +1,12 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn use u64 effects []>(x: u64) -> u64 effects [] { return F(x); } +fn main() -> u64 effects [] { return use::(stop()); } diff --git a/tests/conformance/source/nonvalue_operands/store.aji b/tests/conformance/source/nonvalue_operands/store.aji new file mode 100644 index 0000000..65c730c --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/store.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> void effects [] { var x: u64 = 0; mut p = x; *p = stop(); } diff --git a/tests/conformance/source/nonvalue_operands/store_branch.aji b/tests/conformance/source/nonvalue_operands/store_branch.aji new file mode 100644 index 0000000..21a4b31 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/store_branch.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { var x: u64 = 42; { ref p = x; } if false { mut p = x; *p = stop(); } return x; } diff --git a/tests/conformance/source/nonvalue_operands/struct.aji b/tests/conformance/source/nonvalue_operands/struct.aji new file mode 100644 index 0000000..b580fa5 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/struct.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { let x = Pair { a: stop(), b: 1u64 }; return 42; } diff --git a/tests/conformance/source/nonvalue_operands/struct_order.aji b/tests/conformance/source/nonvalue_operands/struct_order.aji new file mode 100644 index 0000000..9bdef9b --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/struct_order.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { let x = Pair { b: missing, a: stop() }; return 42; } diff --git a/tests/conformance/source/nonvalue_operands/struct_void.aji b/tests/conformance/source/nonvalue_operands/struct_void.aji new file mode 100644 index 0000000..e8f415a --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/struct_void.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { let x = Pair { a: nothing(), b: 1u64 }; return 42; } diff --git a/tests/conformance/source/nonvalue_operands/target_field.aji b/tests/conformance/source/nonvalue_operands/target_field.aji new file mode 100644 index 0000000..147eb9a --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/target_field.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> void effects [] { var x: Pair = Pair { a: 1u64, b: 2u64 }; x.missing = stop(); } diff --git a/tests/conformance/source/nonvalue_operands/target_not_array.aji b/tests/conformance/source/nonvalue_operands/target_not_array.aji new file mode 100644 index 0000000..76c6f05 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/target_not_array.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> void effects [] { var x: u64 = 0; x[0usize] = stop(); } diff --git a/tests/conformance/source/nonvalue_operands/target_not_borrow.aji b/tests/conformance/source/nonvalue_operands/target_not_borrow.aji new file mode 100644 index 0000000..0986237 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/target_not_borrow.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> void effects [] { var x: u64 = 0; *x = stop(); } diff --git a/tests/conformance/source/nonvalue_operands/target_not_struct.aji b/tests/conformance/source/nonvalue_operands/target_not_struct.aji new file mode 100644 index 0000000..23ade85 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/target_not_struct.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> void effects [] { var x: u64 = 0; x.field = stop(); } diff --git a/tests/conformance/source/nonvalue_operands/target_unknown.aji b/tests/conformance/source/nonvalue_operands/target_unknown.aji new file mode 100644 index 0000000..8785491 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/target_unknown.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> void effects [] { missing.field = stop(); } diff --git a/tests/conformance/source/nonvalue_operands/value_swap.aji b/tests/conformance/source/nonvalue_operands/value_swap.aji new file mode 100644 index 0000000..eb83b23 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/value_swap.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { var x: u64 = 0; let old = value.swap(mut x, stop()); return 42; } diff --git a/tests/conformance/source/nonvalue_operands/while_condition.aji b/tests/conformance/source/nonvalue_operands/while_condition.aji new file mode 100644 index 0000000..7942f40 --- /dev/null +++ b/tests/conformance/source/nonvalue_operands/while_condition.aji @@ -0,0 +1,11 @@ +// expect: reject E7005 +// phase: 6 +// spec: docs/spec/15-source-language.md §10 +module test.nonvalue_operands +fn stop() -> never effects [] { trap; } +fn nothing() -> void effects [] {} +fn take(x: u64) -> u64 effects [] { return x; } +fn two(x: u64, y: u64) -> u64 effects [] { return x + y; } +struct Pair { a: u64, b: u64 } +enum Choice { Some(u64), None } +fn main() -> u64 effects [] { while stop() {} return 42; } diff --git a/tests/hosted/source_nonvalue_operands.py b/tests/hosted/source_nonvalue_operands.py new file mode 100644 index 0000000..d2b6c61 --- /dev/null +++ b/tests/hosted/source_nonvalue_operands.py @@ -0,0 +1,103 @@ +#!/usr/bin/env python3 +"""Never operands reject; divergent statements retain control flow and effects.""" +import json +from pathlib import Path +import subprocess +import tempfile + +REPO = Path(__file__).resolve().parents[2] +AJI = REPO / 'zig-out/bin/aji' +CORPUS = REPO / 'tests/conformance/source/nonvalue_operands' +checks = 0 + + +def cli(*args, code=0): + global checks + result = subprocess.run([str(AJI), *map(str, args)], capture_output=True, text=True) + assert result.returncode == code, (args, result.returncode, result.stdout, result.stderr) + checks += 1 + return result.stdout + + +def rejection(path, token, fields, *args, function='fn main', expected_file=None, code='E7005'): + error = json.loads(cli('check', *args, code=1)) + assert error['code'] == code, error + for key, value in fields.items(): + assert error[key] == value, error + lines = path.read_text().splitlines() + line = next(i for i, text in enumerate(lines, 1) if text.startswith(function)) + assert (error['file'], error['line'], error['col']) == ( + expected_file or str(path), line, lines[line - 1].index(token) + 1), error + assert 'air_line' not in error and 'air_col' not in error, error + for command in ('lower', 'run', 'report', 'explore'): + assert json.loads(cli(command, *args, code=1)) == error + + +bool_cases = {'and_left', 'and_right', 'or_left', 'or_right', 'not', + 'if_condition', 'while_condition', 'assert', 'assume'} +usize_cases = {'index', 'index_argument', 'range_low', 'range_high', 'for_high', + 'split', 'array_size', 'buffer_size', 'buffer_reserve', + 'channel_size', 'cap_budget', 'region_size'} +tokens = {'call_if': 'if true', 'call_match': 'match Choice::None', + 'call_block': '{ return 42u64;', 'frame_initialization_unreachable': 'ref p = x'} + +with tempfile.TemporaryDirectory(prefix='aji-nonvalue-operands-') as directory: + root = Path(directory) + for source in sorted(CORPUS.glob('*.aji')): + name, text = source.stem, source.read_text() + if text.startswith('// expect: reject E7005'): + base = name.removesuffix('_void') + wanted = 'a stored value' if name.startswith('target_') else 'bool' if base in bool_cases else 'usize' if base in usize_cases else 'i64' if base == 'negate' else 'u64' + found = 'void' if name.endswith('_void') else 'never' + rejection(source, tokens.get(name, 'nothing()' if found == 'void' else 'stop()'), + {'expected': wanted, 'found': found}, source) + elif text.startswith('// expect: reject E7006'): + rejection(source, tokens[name], {'reason': 'unreachable'}, source, code='E7006') + formatted = root / f'{name}.aji' + formatted.write_text(cli('fmt', source)) + cli('fmt', '--check', formatted) + assert cli('fmt', formatted) == formatted.read_text() + if not text.startswith('// expect: run'): + continue + air = cli('lower', source) + assert cli('lower', formatted) == air + raw = root / f'{name}.air' + raw.write_text(air) + cli('check', source) + cli('check', raw) + trapped = '// trap: T0001' in text + grants = ['--grant', 'heap=mem.alloc:64'] if name == 'linear_branch' else [] + exit_code = 4 if trapped else 0 + expected = json.loads(cli('run', '--fuel', '100000', *grants, source, code=exit_code)) + actual = json.loads(cli('run', '--fuel', '100000', *grants, raw, code=exit_code)) + if trapped: + assert expected['status'] == 'trapped' and expected['code'] == 'T0001', expected + assert expected['source_location']['file'] == str(source), expected + expected.pop('source_location') + else: + assert expected['value'] == 42, expected + assert actual == expected, (name, actual, expected) + result = root / f'{name}.json' + cli('run', '--profile', 'hosted', '--fuel', '100000', *grants, '--result-file', result, + source, code=exit_code) + hosted = json.loads(result.read_text()) + if trapped: + assert hosted['status'] == 'trapped' and hosted['code'] == 'T0001', hosted + else: + assert hosted['value'] == 42, hosted + + entry, library, manifest = (root / name for name in ('main.aji', 'values.aji', 'aji.toml')) + entry.write_text('module app\nimport lib.values;\nfn main() -> u64 effects [] { return lib.values.bad::(); }\n') + library.write_text('module lib.values\nfn stop() -> never effects [] { trap; }\n' + 'fn id(x: T) -> T effects [] { return x; }\n' + 'fn bad() -> T effects [] { return id::(stop()); }\n') + manifest.write_text('[package]\nname = "values"\nversion = "1"\nentry = "main.aji"\n[modules]\nlib.values = "values.aji"\n') + rejection(library, 'stop()', {'expected': 'u64', 'found': 'never'}, '--manifest', manifest, + function='fn bad', expected_file='values.aji') + library.write_text(library.read_text().replace('id::(stop())', 'id::(42u64)')) + assert json.loads(cli('run', '--manifest', manifest))['value'] == 42 + entry.write_text('module app\nfn main() -> u64 effects [] { return 42; }\n') + library.write_text(library.read_text().replace('id::(42u64)', 'id::(stop())')) + assert json.loads(cli('run', '--manifest', manifest))['value'] == 42 + +print(f'nonvalue operand CLI integration passed ({checks} checks)')