frontend: collect independent source diagnostics without cascades
This commit is contained in:
1 parent
2c6c7a3dcd
commit
4cda44823d
47 files changed
+697
-44
No files matched your search
@@ -26,7 +26,6 @@ with tempfile.TemporaryDirectory(prefix='aji-reasons-') as d:
|
||||
('move_copy', 'struct S{x:u64} fn main()->u64 effects [] {let x=S{x:1u64};let y=move x;return 0u64;}'),
|
||||
('move_copy', 'fn main()->u64 effects [] {let x=[1u64;2];let y=move x;return 0u64;}'),
|
||||
('move_borrow', 'fn main()->u64 effects [] {let x=1u64;ref p=x;return move p;}'),
|
||||
('invalid_move', 'fn f(x:void)->u64 effects [] {return move x;} fn main()->u64 effects [] {0u64}'),
|
||||
('loop_control_outside_loop', 'fn main()->void effects [] {break;}'),
|
||||
('zero_not_zeroable', 'fn main()->u64 effects [] {var x:own<u64> = zero;return 0u64;}'),
|
||||
('value_block_statement', 'fn main()->i64 effects [] {{2i64} -3i64}'),
|
||||
@@ -48,6 +47,15 @@ with tempfile.TemporaryDirectory(prefix='aji-reasons-') as d:
|
||||
assert json.loads(invoke('lower', path, code=1)) == error
|
||||
assert invoke('check', path, code=1) == invoke('check', path, code=1)
|
||||
|
||||
# Void parameters are rejected by annotation validation before body
|
||||
# lowering; this must never be attributed to an invalid_move body error.
|
||||
invalid_parameter = root / 'void-parameter.aji'
|
||||
invalid_parameter.write_text('module reasons\nfn f(x:void)->u64 effects [] {return move x;} '
|
||||
'fn main()->u64 effects [] {0u64}\n')
|
||||
error = json.loads(invoke('check', invalid_parameter, code=1))
|
||||
assert (error['code'], error['position'], error['type_constructor']) == ('E7005', 'param', 'void'), error
|
||||
assert 'reason' not in error and json.loads(invoke('lower', invalid_parameter, code=1)) == error
|
||||
|
||||
# Copy substitution in a generic transfer is permitted, not a Copy-move
|
||||
# diagnostic. Borrowed substitution still rejects with its own reason.
|
||||
valid = root / 'generic.aji'
|
||||
@@ -82,7 +90,8 @@ with tempfile.TemporaryDirectory(prefix='aji-reasons-') as d:
|
||||
# Exercise all public standalone E7006 fixtures, without visiting any
|
||||
# benchmark corpus or unrelated untracked directory.
|
||||
registry = (REPO / 'docs/reference/error-codes.md').read_text()
|
||||
reasons = set(re.findall(r'^\| `([a-z_]+)` \|', registry, re.M))
|
||||
reason_section = registry.split('## E7006 reasons\n', 1)[1].split('\n## ', 1)[0]
|
||||
reasons = set(re.findall(r'^\| `([a-z_]+)` \|', reason_section, re.M))
|
||||
fixtures = 0
|
||||
for path in sorted((REPO / 'tests/conformance/source').rglob('*.aji')):
|
||||
if not re.search(r'^// expect: reject E7006\s*$', path.read_text(), re.M):
|
||||
|
||||
@@ -212,7 +212,10 @@ with tempfile.TemporaryDirectory(prefix="aji-format-") as directory:
|
||||
result = subprocess.run([str(AJI), "fmt", str(path)], capture_output=True)
|
||||
checks += 1
|
||||
if result.returncode == 1:
|
||||
assert json.loads(result.stdout)["code"] == "E7001", (path, result.stdout, result.stderr)
|
||||
diagnostics = [json.loads(line) for line in result.stdout.splitlines()]
|
||||
assert diagnostics and len(diagnostics) <= 32, (path, result.stdout, result.stderr)
|
||||
assert all(d["code"] == "E7001" for d in diagnostics), (path, diagnostics)
|
||||
assert [json.loads(line) for line in cli("lower", path, code=1).splitlines()] == diagnostics, path
|
||||
syntax_errors += 1
|
||||
else:
|
||||
assert result.returncode == 0, (path, result.returncode, result.stdout, result.stderr)
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Independent source errors, conservative boundaries, limits and no partial AIR."""
|
||||
import json
|
||||
from pathlib import Path
|
||||
import re
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
REPO = Path(__file__).resolve().parents[2]
|
||||
AJI = REPO / 'zig-out/bin/aji'
|
||||
CORPUS = REPO / 'tests/conformance/source/independent_errors'
|
||||
checks = 0
|
||||
|
||||
|
||||
def cli(*args, code=1):
|
||||
global checks
|
||||
result = subprocess.run([str(AJI), *map(str, args)], capture_output=True, text=True)
|
||||
assert result.returncode == code, (args, result.returncode, result.stdout[:4000], result.stderr[:4000])
|
||||
checks += 1
|
||||
return result.stdout
|
||||
|
||||
|
||||
def records(output):
|
||||
return [json.loads(line) for line in output.splitlines()]
|
||||
|
||||
|
||||
cache = REPO / '.zig-cache/contract-gate'
|
||||
cache.mkdir(parents=True, exist_ok=True)
|
||||
with tempfile.TemporaryDirectory(prefix='independent-', dir=cache) as directory:
|
||||
root = Path(directory)
|
||||
lib, entry, manifest = (root / name for name in ('lib.aji', 'main.aji', 'aji.toml'))
|
||||
entry.write_text('module app\nimport lib.collection;\nfn main() -> void effects [] {}\n')
|
||||
manifest.write_text('[package]\nname = "collection"\nversion = "1"\nentry = "main.aji"\n'
|
||||
'[modules]\nlib.collection = "lib.aji"\n')
|
||||
for path in sorted(CORPUS.glob('*.aji')):
|
||||
source = path.read_text()
|
||||
ds = records(cli('check', path))
|
||||
wanted = re.search(r'// expect: reject (.+)', source)[1].split()
|
||||
assert sorted(d['code'] for d in ds) == sorted(wanted), (path, ds)
|
||||
assert len(ds) <= 32 and ds, ds
|
||||
assert all(d['file'] == str(path) and 'air_line' not in d and 'air_code' not in d for d in ds), ds
|
||||
# Exactly one diagnostic per code and source location, in declaration order.
|
||||
assert len({(d['code'], d['file'], d['line'], d['col']) for d in ds}) == len(ds), ds
|
||||
assert [(d['line'], d['col']) for d in ds] == sorted((d['line'], d['col']) for d in ds), ds
|
||||
for command in ('lower', 'run', 'report', 'explore'):
|
||||
assert records(cli(command, path)) == ds
|
||||
assert records(cli('check', path)) == ds
|
||||
if ds[0]['code'] == 'E7001':
|
||||
for mode in ((), ('--check',), ('--write',)):
|
||||
assert records(cli('fmt', *mode, path)) == ds
|
||||
assert path.read_text() == source # failed fmt --write cannot modify input
|
||||
if path.stem == 'three_syntax':
|
||||
assert [d['repair_candidates'][0]['kind'] for d in ds] == [
|
||||
'boolean_negation', 'annotate_var_type', 'zero_storage'], ds
|
||||
elif path.stem in ('limit_syntax', 'limit_bodies'):
|
||||
assert len(ds) == 32 and ds[-1]['line'] == 36, ds
|
||||
elif path.stem == 'generic_body':
|
||||
assert len(ds) == 1 and ds[0]['name'] == 'missing', ds
|
||||
# Imported parser/body failures preserve the list, spans and advice.
|
||||
if path.stem in ('three_syntax', 'two_types', 'callee', 'generic_body', 'state_reset'):
|
||||
lib.write_text(source.replace('module collection', 'module lib.collection')
|
||||
.replace('fn main(', 'fn user('))
|
||||
package = records(cli('check', '--manifest', manifest))
|
||||
assert package == [dict(d, file='lib.aji') for d in ds], package
|
||||
for command in ('lower', 'run', 'report', 'explore'):
|
||||
assert records(cli(command, '--manifest', manifest)) == package
|
||||
|
||||
# The first failed imported module stops traversal of siblings. Its syntax
|
||||
# list is retained; a root syntax failure instead stops before imports.
|
||||
second = root / 'other.aji'
|
||||
second.write_text('module lib.other\nfn bad() -> bool effects [] { return !false; }\n')
|
||||
lib.write_text('module lib.collection\nfn a() -> bool effects [] { return !false; }\n'
|
||||
'fn b() -> bool effects [] { return !true; }\n')
|
||||
entry.write_text('module app\nimport lib.collection;\nimport lib.other;\n'
|
||||
'fn main() -> void effects [] {}\n')
|
||||
manifest.write_text(manifest.read_text() + 'lib.other = "other.aji"\n')
|
||||
ds = records(cli('check', '--manifest', manifest))
|
||||
assert len(ds) == 2 and all(d['file'] == 'lib.aji' for d in ds), ds
|
||||
entry.write_text(entry.read_text().replace('effects [] {}', 'effects [] { let x = !false; }'))
|
||||
ds = records(cli('check', '--manifest', manifest))
|
||||
assert len(ds) == 1 and ds[0]['file'] == str(entry), ds
|
||||
|
||||
# Unimplemented preserves the previous phase outcome when first, but does
|
||||
# not suppress independent errors once body collection has begun.
|
||||
probe = root / 'probe.aji'
|
||||
unsupported = 'fn unsupported() -> void effects [] { 1u64(); }\n'
|
||||
bad = 'fn bad(n: u64) -> u32 effects [] { return n as u32; }\n'
|
||||
main = 'fn main() -> void effects [] {}\n'
|
||||
probe.write_text('module probe\n' + unsupported + bad + main)
|
||||
assert cli('check', probe, code=3) == ''
|
||||
probe.write_text('module probe\n' + bad + unsupported +
|
||||
'fn later(n: u64) -> u16 effects [] { return n as u16; }\n' + main)
|
||||
ds = records(cli('check', probe))
|
||||
assert [d['code'] for d in ds] == ['E7005', 'E7005'], ds
|
||||
for command in ('lower', 'run', 'report', 'explore'):
|
||||
assert records(cli(command, probe)) == ds
|
||||
|
||||
print(f'independent source errors: {checks} checks passed')
|
||||
@@ -96,6 +96,8 @@ with tempfile.TemporaryDirectory(prefix='source-advice-', dir=cache) as director
|
||||
'fn main() -> void effects [] { let mut x = 1u64; }',
|
||||
'fn f(s: mut u64) -> void effects [] {}',
|
||||
'fn f(s: ref [u8; 3]) -> void effects [] {}',
|
||||
'fn f(s: mut.Other slice<u8>) -> void effects [] {}',
|
||||
'fn f(s: ref.Other slice<u8>) -> void effects [] {}',
|
||||
'fn f(s: &[u8; 3]) -> void effects [] {}',
|
||||
'fn f(s: slice<u8>) -> void effects [] { ref t = s[..2usize]; }',
|
||||
'fn f(s: slice<u8>) -> void effects [] { ref t = s[0usize..=2usize]; }',
|
||||
|
||||
Reference in new issue
Block a user