Link manifest-selected source graphs with module-local names, qualified structs/enums/functions and task workers through ordinary AIR verification. Keep source inputs bounded, reject source symlinks and preserve explicit grants, diagnostics and deterministic canonical lowering. Integrate spec 12/15, RFC 0021, source reference budgets, roadmap, examples and CI coverage. Validate 579 conformance tests, unit tests, 76 source constructs, hosted smoke, 36 package CLI checks and task schedule stress.
136 lines
8.0 KiB
Python
136 lines
8.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Source construct coverage (Phase 6A freeze criterion).
|
|
|
|
Every construct of `.aji` 0.1 (spec 15) must appear in at least one `.aji`
|
|
conformance test that is accepted or run, and, where the construct has
|
|
rules that reject programs, in at least one reject test. The checklist is
|
|
below; each construct is a regular expression over the test's source (header
|
|
comments removed).
|
|
|
|
python3 tools/source_coverage.py # table; exit 1 if a row fails
|
|
"""
|
|
|
|
import glob
|
|
import os
|
|
import re
|
|
import sys
|
|
|
|
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
TESTS = os.path.join(ROOT, "tests", "conformance", "source")
|
|
|
|
# (area, construct, regex, needs a reject test)
|
|
CHECKLIST = [
|
|
("modules", "package module import", r"^import app\.", True),
|
|
("modules", "qualified package call", r"app\.\w+\.[a-z]\w*\(", True),
|
|
("modules", "qualified struct literal", r"app\.\w+\.[A-Z]\w* \{", True),
|
|
("modules", "qualified task worker", r"task\.spawn\(\w+, app\.", True),
|
|
("stdlib", "qualified standard enum type", r": std\.(?:bytes|fmt|math|utf8|encoding\.(?:hex|base64))\.[A-Z]\w*\b", True),
|
|
("stdlib", "qualified standard enum constructor", r"std\.(?:bytes|fmt|math|utf8|encoding\.(?:hex|base64))\.[A-Z]\w*::\w+(?:\(|;)", True),
|
|
("stdlib", "qualified standard enum match", r"std\.(?:bytes|fmt|math|utf8|encoding\.(?:hex|base64))\.[A-Z]\w*::\w+(?:\([^)]*\))? =>", True),
|
|
("stdlib", "built-in module import", r"^import std\.", True),
|
|
("stdlib", "qualified standard call", r"std\.(?:bytes|fmt|math|utf8|encoding\.(?:hex|base64))\.\w+\(", True),
|
|
("scalars", "checked arithmetic", r"[^%]\+ [a-z0-9]", False),
|
|
("scalars", "wrapping arithmetic `+%`", r"\+%", False),
|
|
("scalars", "`as` (lossless widening)", r"\bas [ui]\d", True),
|
|
("scalars", "`as!` (checked conversion)", r"\bas! ", False),
|
|
("scalars", "`as%` (wrapping conversion)", r"\bas% ", False),
|
|
("scalars", "bitwise and shifts", r"<<|>>| & | \^ ", False),
|
|
("control flow", "`let`", r"\blet ", False),
|
|
("control flow", "`var`", r"\bvar ", False),
|
|
("control flow", "assignment", r"^\s*[a-z_][a-z0-9_]* = ", False),
|
|
("control flow", "`if`/`else`", r"\bif .*\{.*\belse\b|\} else \{", False),
|
|
("control flow", "`while`", r"\bwhile ", False),
|
|
("control flow", "`for … in a..b`", r"\bfor \w+ in ", False),
|
|
("control flow", "`loop`", r"\bloop \{", False),
|
|
("control flow", "`break` / `continue`", r"\bbreak;|\bcontinue;", True),
|
|
("control flow", "`return`", r"\breturn\b", True),
|
|
("control flow", "`assert`", r"\bassert\(", False),
|
|
("struct/enum/match", "struct declaration and literal", r"\bstruct \w+ \{", True),
|
|
("struct/enum/match", "enum declaration and `Enum::Variant`", r"\w+::\w+", True),
|
|
("struct/enum/match", "enum `match`", r"match .*\{[^}]*\w+::\w+", True),
|
|
("struct/enum/match", "integer `match` with `_`", r"\b_ =>", True),
|
|
("struct/enum/match", "`match` as an expression", r"= match ", False),
|
|
("arrays/slices", "`[e; N]`", r"\[[^\]]+; \d+\]", False),
|
|
("arrays/slices", "indexing `s[i]`", r"\w\[[a-z0-9_]+\]", True),
|
|
("arrays/slices", "ranges `s[a..b]`", r"\[[^\]]*\.\.[^\]]*\]", False),
|
|
("arrays/slices", "`split_at`", r"\.split_at\(", False),
|
|
("arrays/slices", "`slice.copy`", r"slice\.copy\(", True),
|
|
("arrays/slices", "byte strings", r'b"', False),
|
|
("borrow/move", "`ref r = …;` / `mut r = …;`", r"^\s*(ref|mut) \w+ = ", True),
|
|
("borrow/move", "`ref`/`mut` arguments", r"\((ref|mut) \w+|, (ref|mut) \w+", True),
|
|
("borrow/move", "`*r` load and store", r"\*\w+ = |= \*\w+", True),
|
|
("borrow/move", "`move`", r"\bmove \w+", True),
|
|
("own/region", "`own.new` / `own.take` / `own.free`", r"own\.(new|take|free)\(", True),
|
|
("own/region", "`own.array`", r"own\.array\(", False),
|
|
("own/region", "regions", r"region\.(create|new|array|reset|destroy)\(", True),
|
|
("own/region", "`cap.narrow.budget`", r"cap\.narrow\.budget\(", False),
|
|
("failure", "outcome `match`", r"\bok\(\w*\)? =>|\bok =>", True),
|
|
("failure", "`or trap`", r"\bor trap\b", False),
|
|
("failure", "built-in error enums", r"(alloc_error|io_error|cap_error)::", False),
|
|
("resources/I/O", "stdin/stdout", r"io\.(stdin_read|stdout_write)\(", True),
|
|
("resources/I/O", "files", r"fs\.(open_read|create|read|write_all|close)\(", True),
|
|
("resources/I/O", "TCP", r"net\.(listen|connect|accept|recv|send_all)\(", False),
|
|
("resources/I/O", "`clock`/`random`", r"(clock\.monotonic|random\.fill)\(", True),
|
|
("resources/I/O", "`cap.narrow.prefix`", r"cap\.narrow\.prefix\(", False),
|
|
("tasks/channels", "`scope` and `task.spawn`/`join`", r"\bscope \w+ \{", True),
|
|
("tasks/channels", "`task.cancel` / `task.cancelled`", r"task\.cancel(led)?\(", False),
|
|
("tasks/channels", "`channel.make` / `send` / `recv`", r"channel\.(make|send|recv)", True),
|
|
("tasks/channels", "`channel.dup`", r"channel\.dup\(", False),
|
|
("tasks/channels", "`close_receiver` and `pending`", r"close_receiver\(", True),
|
|
("mutex/select", "`lock … cancelled`", r"\block ref \w+ as \w+", True),
|
|
("mutex/select", "`mutex.make` / `mutex.take`", r"mutex\.(make|take)\(", True),
|
|
("mutex/select", "`select`", r"\bselect \{", True),
|
|
("cancellation", "`shield`", r"\bshield \{", False),
|
|
("cancellation", "`task.check_cancel`", r"task\.check_cancel\(", False),
|
|
("cancellation", "`task.join_cancel`", r"task\.join_cancel\(", True),
|
|
("graphs", "`island.create` / `island.alloc` / `island.at`", r"island\.(create|alloc|at)\(", True),
|
|
("graphs", "`island.freeze` / `frozen.at` / `frozen.release`", r"island\.freeze\(|frozen\.(at|release)\(", True),
|
|
("graphs", "`arc.from_frozen` / `arc.clone` / `arc.release` / `arc.at`", r"arc\.(from_frozen|clone|release|at)\(", True),
|
|
("graphs", "`iref` equality", r"(?s)(?:island|frozen|arc)\.root\(.*\b\w+ (?:==|!=) (?:\w+|arc\.root\(\w+\)) \{", False),
|
|
("graphs", "graphs through channels and tasks", r"channel\.make<(island|arc)<", True),
|
|
("atomics", "`atomic.new` / `atomic.take`", r"atomic\.(new|take)\(", True),
|
|
("atomics", "`atomic.load` / `atomic.store` with an ordering", r"atomic\.(load|store)\([^)]*(relaxed|acquire|release|seq_cst)\)", True),
|
|
("atomics", "read-modify-write (`swap`, `add.wrap`, `sub.wrap`, `and`, `or`, `xor`)", r"atomic\.(swap|add\.wrap|sub\.wrap|and|or|xor)\(", False),
|
|
("atomics", "`let (old, exchanged) = atomic.compare_exchange(…)`", r"let \(\w+, \w+\) = atomic\.compare_exchange\(", True),
|
|
("atomics", "`atomic.fence`", r"atomic\.fence\(", False),
|
|
("atomics", "cells lent to tasks (`ref c = cell;`)", r"(?s)ref \w+ = \w+;.*task\.spawn\(.*atomic\.", True),
|
|
("unsafe", "`ref unchecked` / `assume`", r"\bunchecked\b|\bassume\(", True),
|
|
("unsafe", "`trusted` rejected", r"\btrusted\b", True),
|
|
]
|
|
|
|
|
|
def load():
|
|
runs, rejects = [], []
|
|
for path in sorted(glob.glob(os.path.join(TESTS, "**", "*.aji"), recursive=True)):
|
|
with open(path, encoding="utf-8") as f:
|
|
text = f.read()
|
|
m = re.search(r"^// expect: (\w+)", text, re.M)
|
|
if not m:
|
|
continue
|
|
body = "\n".join(l for l in text.splitlines() if not l.lstrip().startswith("//"))
|
|
(rejects if m.group(1) == "reject" else runs).append((os.path.relpath(path, TESTS), body))
|
|
return runs, rejects
|
|
|
|
|
|
def main():
|
|
runs, rejects = load()
|
|
failed = 0
|
|
print("| area | construct | run/accept tests | reject tests | status |")
|
|
print("|---|---|---:|---:|---|")
|
|
for area, name, rx, need_reject in CHECKLIST:
|
|
pat = re.compile(rx, re.M)
|
|
nr = sum(1 for _, b in runs if pat.search(b))
|
|
nj = sum(1 for _, b in rejects if pat.search(b))
|
|
ok = nr > 0 and (nj > 0 or not need_reject)
|
|
if name == "`trusted` rejected":
|
|
ok = nj > 0
|
|
failed += not ok
|
|
print(f"| {area} | {name} | {nr} | {nj}{'' if need_reject else ' (not required)'} | {'covered' if ok else 'MISSING'} |")
|
|
print(f"\n{len(CHECKLIST) - failed}/{len(CHECKLIST)} constructs covered "
|
|
f"({len(runs)} run/accept and {len(rejects)} reject `.aji` tests)")
|
|
sys.exit(1 if failed else 0)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|