diag: explain pointer-sized cast restrictions in source advice
This commit is contained in:
1 parent
8a714ba6de
commit
6a02659f31
23 files changed
+96
-8
No files matched your search
@@ -176,3 +176,5 @@ Q-052 CFG resource provenance (DD-024): Quick Reference and other/full source do
|
||||
P6-7 factual source E4202 fields (cl100k): Quick Reference stays 8,955; other source docs 68,323 → 68,353 (+30), full source 77,278 → 77,308 (+0.04%). o200k groups are 8,991 / 68,556 / 77,547; Qwen2.5 9,233 / 70,024 / 79,257. Only language/concurrency.md grows; AIR and library/std.md are unchanged. Concrete `found` and `use` fields distinguish ordinary atomic reads without message parsing. No new syntax, code, feature or verifier/runtime state is introduced; no empirical MCC benefit is claimed.
|
||||
|
||||
Spec 15 scope corrections (cl100k): Quick Reference stays 8,955 tokens despite the E1002 → E7005 correction; other source docs 68,353 → 68,403 (+50), full source 77,308 → 77,358 (+0.06%). o200k full source grows 77,547 → 77,594 (+47); Qwen2.5 79,257 → 79,315 (+58). AIR and std are unchanged. Existing source diagnostics, unpacking, escapes, buffers and borrow returns replace obsolete baseline descriptions; no semantic or implementation change.
|
||||
|
||||
Pointer-sized cast guidance (2026-10-09): Quick Reference grows 9,255 → 9,276 cl100k (+21); other source docs 69,817 → 69,863 (+46), full source 79,072 → 79,139 (+67, +0.085%). o200k grows by the same +21/+46/+67 (full 79,373); Qwen2.5 by +21/+47/+68 (full 81,127). AIR grows 188,993 → 189,078 bytes and +22 tokens for each tokenizer (48,398 cl100k / 48,551 o200k / 49,956 Qwen2.5). The existing target-independent ban on usize/isize widening is explained in the registered numeric-cast hint and source cast table. No new concept, syntax, feature, diagnostic code/kind or verifier/runtime state is introduced. Pointer identity casts now reject with source E7005/advice before AIR E1002; the accepted set is unchanged. No empirical reduction in repair rounds is claimed.
|
||||
@@ -86,7 +86,7 @@ return x + y + w; // also: `trap;`
|
||||
| `+% -% *%` | wrapping |
|
||||
| `& \| ^ << >>` | bitwise; shift ≥ width traps `T0005` |
|
||||
| `== != < <= > >=`, `and or not` | comparisons, booleans |
|
||||
| `x as T` | lossless widening only (else `E7005`) |
|
||||
| `x as T` | lossless fixed-width widening only; `usize`/`isize` use `as!` or `as%` (else `E7005`) |
|
||||
| `x as! T` | checked conversion, traps `T0006` |
|
||||
| `x as% T` | wrapping conversion |
|
||||
| `42`, `42u8`, `0xff`, `1_000` | literals; type from context or suffix (else `E7007`) |
|
||||
|
||||
@@ -388,3 +388,9 @@ The [AIR binding candidate](../design/contract-air-bindings.md) supplies prefix/
|
||||
The [runtime/context candidate](../design/contract-runtime-and-context.md) specifies frame continuations, normal completion only after validation, free normalization before quantum checks, depth/fuel precedence, traced pending roots and exact additive failure context. Six ordinary groups pass 16 CLI runs at quantum 1; nine fixture variants pass GC-every-step record comparison (13 schedule cases, 26 interpreter runs). Six hypothetical schema components are explicitly unimplemented. Claude independently reproduced the CLI records and reviewed the rules; corrections fixed old/make/modify modes, race context and AIR-only byte-identity exploration. No normative/compiler/registry/bundle changes are made. Source reasons, compatibility/model adoption, RFC 0040 observations and full vertical runtime tests remain gates; RFC 0039 stays Draft and full P6-6 remains doing.
|
||||
|
||||
The [source rejection/compatibility audit](../design/contract-source-errors-and-compatibility.md) proposes eight new E7006 reasons and retains existing source type/name/transfer codes, error collection and mapped verifier obligations. Ten executed current-language AIR0 probes preserve full diagnostics and distinguish dependent undefined results from independent SSA errors; neither the historical parser nor contract semantics is executed. Owner selection of the module-state model, Q-055 compatibility/version policy and RFC representations remains necessary before normative integration and vertical implementation. No fresh Claude review was available for this increment. RFC 0039 remains Draft; P6-6 remains doing.
|
||||
|
||||
## P6-12 pointer-sized cast guidance (2026-10-09)
|
||||
|
||||
Public development feedback identifies u8 → usize and usize → u64 casts rejected without explaining the target-independent rule. Spec 02 §2 already excludes usize/isize from widen, including conversions that fit under every current target. The registered numeric_cast_modes hint now states that rule, keeping the original E7005 message/fields and checked/wrapping alternatives. Source/Quick Reference cast tables explain it too; no semantic widening extension is adopted. Pointer identity as casts now follow the same source rejection instead of leaking AIR E1002 without advice. Six rejection fixtures and an explicit checked/wrapping runtime case cover the rule; hosted advice tests pass 208 checks including source API parity and fixed-width identities. Bundle growth is measured in agent/README.md. Parameter-mutability and array-to-slice advice from the same feedback remain open work; no new dev/model experiment or repair-round benefit is claimed.
|
||||
|
||||
Validation of cast guidance: units/format checks and all 1,776 conformance cases pass. Comparison of 1,403 pre-existing source files changes only the registered hint; all 500 accepted lowerings remain byte-identical.
|
||||
@@ -126,7 +126,7 @@ These stable kinds use spec 10 §3. `hint` MUST equal the registered text. Alter
|
||||
| `borrow_argument` | E7001 | Write `ref place` or `mut place` for an inline borrow argument. | prefix |
|
||||
| `borrow_binding` | E7001 | Bind a borrow with `ref name = place;` or `mut name = place;`, rather than a let/var initializer. | none |
|
||||
| `zero_storage` | E7001 | `zero` is only a whole var initializer: `var name: T = zero;`; T must be zeroable. | none |
|
||||
| `numeric_cast_modes` | E7005 | Choose `as!` for a checked conversion (T0006 on overflow) or `as%` for a wrapping conversion. | operator |
|
||||
| `numeric_cast_modes` | E7005 | The target-independent `as` rule excludes `usize`/`isize`, even when the value fits. Choose `as!` for a checked conversion (T0006 on overflow) or `as%` for a wrapping conversion. | operator |
|
||||
|
||||
Closed applicability:
|
||||
|
||||
|
||||
@@ -146,7 +146,7 @@ Lowering: structured control flow becomes blocks and terminators. A variable ass
|
||||
|
||||
| Source | AIR |
|
||||
|---|---|
|
||||
| `x as T` | `cast.widen`; only where every value is representable, otherwise source `E7005` (§10; AIR `E1002`) |
|
||||
| `x as T` | `cast.widen`; lossless fixed-width integers only; `usize`/`isize` require `as!` or `as%` (spec 02 §2); otherwise source `E7005` (§10; AIR `E1002`) |
|
||||
| `x as! T` | `cast.checked` (`T0006`) |
|
||||
| `x as% T` | `cast.wrap` |
|
||||
|
||||
|
||||
+1
-1
@@ -209,7 +209,7 @@ pub const SourceRepairKind = enum {
|
||||
.borrow_argument => "Write `ref place` or `mut place` for an inline borrow argument.",
|
||||
.borrow_binding => "Bind a borrow with `ref name = place;` or `mut name = place;`, rather than a let/var initializer.",
|
||||
.zero_storage => "`zero` is only a whole var initializer: `var name: T = zero;`; T must be zeroable.",
|
||||
.numeric_cast_modes => "Choose `as!` for a checked conversion (T0006 on overflow) or `as%` for a wrapping conversion.",
|
||||
.numeric_cast_modes => "The target-independent `as` rule excludes `usize`/`isize`, even when the value fits. Choose `as!` for a checked conversion (T0006 on overflow) or `as%` for a wrapping conversion.",
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1737,7 +1737,7 @@ const Lowerer = struct {
|
||||
if (x.mode == .widen) {
|
||||
const a = std.meta.stringToEnum(air_module.IntType, v.ty.int).?;
|
||||
const b = std.meta.stringToEnum(air_module.IntType, to.int).?;
|
||||
if (a != b and !verifier_types.lossless(a, b))
|
||||
if (!verifier_types.lossless(a, b))
|
||||
return l.invalidWidening(e.span, &.{ .{ .name = "from", .value = v.ty.int }, .{ .name = "to", .value = to.int } });
|
||||
}
|
||||
const mode = switch (x.mode) {
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// expect: run
|
||||
// result: 84
|
||||
// phase: 6
|
||||
// spec: docs/spec/02-types-and-values.md §2; docs/spec/15-source-language.md §5
|
||||
module cast.explicit
|
||||
fn same(x: isize) -> isize effects [] { return x as! isize; }
|
||||
fn main() -> u64 effects [] {
|
||||
let x: usize = 42u8 as! usize;
|
||||
let y: u64 = x as! u64;
|
||||
let z: isize = 42i8 as% isize;
|
||||
let q: i64 = same(z) as! i64;
|
||||
return y + (q as! u64);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// expect: reject E7005
|
||||
// phase: 6
|
||||
// spec: docs/spec/02-types-and-values.md §2; docs/spec/15-source-language.md §5
|
||||
module cast.rejection
|
||||
fn f(x: i8) -> isize effects [] { return x as isize; }
|
||||
fn main() -> void effects [] {}
|
||||
@@ -0,0 +1 @@
|
||||
[{"kind":"numeric_cast_modes","hint":"The target-independent `as` rule excludes `usize`/`isize`, even when the value fits. Choose `as!` for a checked conversion (T0006 on overflow) or `as%` for a wrapping conversion.","alternatives":["as!","as%"]}]
|
||||
@@ -0,0 +1,6 @@
|
||||
// expect: reject E7005
|
||||
// phase: 6
|
||||
// spec: docs/spec/02-types-and-values.md §2; docs/spec/15-source-language.md §5
|
||||
module cast.rejection
|
||||
fn f(x: isize) -> i64 effects [] { return x as i64; }
|
||||
fn main() -> void effects [] {}
|
||||
@@ -0,0 +1 @@
|
||||
[{"kind":"numeric_cast_modes","hint":"The target-independent `as` rule excludes `usize`/`isize`, even when the value fits. Choose `as!` for a checked conversion (T0006 on overflow) or `as%` for a wrapping conversion.","alternatives":["as!","as%"]}]
|
||||
@@ -0,0 +1,6 @@
|
||||
// expect: reject E7005
|
||||
// phase: 6
|
||||
// spec: docs/spec/02-types-and-values.md §2; docs/spec/15-source-language.md §5
|
||||
module cast.rejection
|
||||
fn f(x: isize) -> isize effects [] { return x as isize; }
|
||||
fn main() -> void effects [] {}
|
||||
@@ -0,0 +1 @@
|
||||
[{"kind":"numeric_cast_modes","hint":"The target-independent `as` rule excludes `usize`/`isize`, even when the value fits. Choose `as!` for a checked conversion (T0006 on overflow) or `as%` for a wrapping conversion.","alternatives":["as!","as%"]}]
|
||||
@@ -0,0 +1,6 @@
|
||||
// expect: reject E7005
|
||||
// phase: 6
|
||||
// spec: docs/spec/02-types-and-values.md §2; docs/spec/15-source-language.md §5
|
||||
module cast.rejection
|
||||
fn f(x: u8) -> usize effects [] { return x as usize; }
|
||||
fn main() -> void effects [] {}
|
||||
@@ -0,0 +1 @@
|
||||
[{"kind":"numeric_cast_modes","hint":"The target-independent `as` rule excludes `usize`/`isize`, even when the value fits. Choose `as!` for a checked conversion (T0006 on overflow) or `as%` for a wrapping conversion.","alternatives":["as!","as%"]}]
|
||||
@@ -0,0 +1,6 @@
|
||||
// expect: reject E7005
|
||||
// phase: 6
|
||||
// spec: docs/spec/02-types-and-values.md §2; docs/spec/15-source-language.md §5
|
||||
module cast.rejection
|
||||
fn f(x: usize) -> u64 effects [] { return x as u64; }
|
||||
fn main() -> void effects [] {}
|
||||
@@ -0,0 +1 @@
|
||||
[{"kind":"numeric_cast_modes","hint":"The target-independent `as` rule excludes `usize`/`isize`, even when the value fits. Choose `as!` for a checked conversion (T0006 on overflow) or `as%` for a wrapping conversion.","alternatives":["as!","as%"]}]
|
||||
@@ -0,0 +1,6 @@
|
||||
// expect: reject E7005
|
||||
// phase: 6
|
||||
// spec: docs/spec/02-types-and-values.md §2; docs/spec/15-source-language.md §5
|
||||
module cast.rejection
|
||||
fn f(x: usize) -> usize effects [] { return x as usize; }
|
||||
fn main() -> void effects [] {}
|
||||
@@ -0,0 +1 @@
|
||||
[{"kind":"numeric_cast_modes","hint":"The target-independent `as` rule excludes `usize`/`isize`, even when the value fits. Choose `as!` for a checked conversion (T0006 on overflow) or `as%` for a wrapping conversion.","alternatives":["as!","as%"]}]
|
||||
@@ -1,2 +1,2 @@
|
||||
[{"kind":"numeric_cast_modes","hint":"Choose `as!` for a checked conversion (T0006 on overflow) or `as%` for a wrapping conversion.","alternatives":["as!","as%"]}]
|
||||
[{"kind":"numeric_cast_modes","hint":"Choose `as!` for a checked conversion (T0006 on overflow) or `as%` for a wrapping conversion.","alternatives":["as!","as%"]}]
|
||||
[{"kind":"numeric_cast_modes","hint":"The target-independent `as` rule excludes `usize`/`isize`, even when the value fits. Choose `as!` for a checked conversion (T0006 on overflow) or `as%` for a wrapping conversion.","alternatives":["as!","as%"]}]
|
||||
[{"kind":"numeric_cast_modes","hint":"The target-independent `as` rule excludes `usize`/`isize`, even when the value fits. Choose `as!` for a checked conversion (T0006 on overflow) or `as%` for a wrapping conversion.","alternatives":["as!","as%"]}]
|
||||
@@ -1 +1 @@
|
||||
[{"kind":"numeric_cast_modes","hint":"Choose `as!` for a checked conversion (T0006 on overflow) or `as%` for a wrapping conversion.","alternatives":["as!","as%"]}]
|
||||
[{"kind":"numeric_cast_modes","hint":"The target-independent `as` rule excludes `usize`/`isize`, even when the value fits. Choose `as!` for a checked conversion (T0006 on overflow) or `as%` for a wrapping conversion.","alternatives":["as!","as%"]}]
|
||||
@@ -157,4 +157,29 @@ with tempfile.TemporaryDirectory(prefix='source-advice-', dir=cache) as director
|
||||
probe.write_text('module probe\n' + body + '\n')
|
||||
advice(json.loads(cli('check', probe, code=1)), kind)
|
||||
|
||||
# Pointer-sized widening is rejected independently of target/value range.
|
||||
# Identity casts follow the same source rule instead of leaking AIR E1002.
|
||||
for source_type, target_type in [
|
||||
('u8', 'usize'), ('usize', 'u64'), ('i8', 'isize'),
|
||||
('isize', 'i64'), ('usize', 'usize'), ('isize', 'isize'),
|
||||
]:
|
||||
base = (f'module probe\nfn f(x: {source_type}) -> {target_type} effects [] '
|
||||
'{ return x OP ' + target_type + '; }\n'
|
||||
'fn main() -> void effects [] {}\n')
|
||||
probe.write_text(base.replace('OP', 'as'))
|
||||
error = json.loads(cli('check', probe, code=1))
|
||||
advice(error, 'numeric_cast_modes', ['as!', 'as%'])
|
||||
assert (error['from'], error['to']) == (source_type, target_type), 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, probe, code=1)) == error
|
||||
for spelling in ('as!', 'as%'):
|
||||
probe.write_text(base.replace('OP', spelling))
|
||||
cli('check', probe)
|
||||
for spelling in ('u8', 'u64', 'i64'):
|
||||
probe.write_text(f'module probe\nfn f(x: {spelling}) -> {spelling} effects [] '
|
||||
f'{{ return x as {spelling}; }}\n'
|
||||
'fn main() -> void effects [] {}\n')
|
||||
cli('check', probe)
|
||||
|
||||
print(f'source repair advice: {checks} checks passed')
|
||||
Reference in new issue
Block a user