api: lazy format detection (Sniffs.luau): F.detect loads no format module

tools/gen_registry.py now also writes src/Rosetta/Sniffs.luau: each format's sniff copied
(tools/sniff_extract.py) with the top-level locals, types and load-time loops it reaches;
requires outside core/ become proxies that require on first field access. 198 of 199
sniffs are copied (model/fbx reads Binary.MAGIC at load time: its module sniffs).
Registry entries gain sniff (0 copy, 1 copy reaching a codec / container, 2 module) and
variant (the module has variant(r)).

init.luau detect: the extension's formats first, then by sniff cost and registry order;
a sniff runs only while its cap (1, or LATE) could still win, ties to registry order, so
results equal the eager path. F.detect loads the winner only when it has variant().

tests/detect.luau: every copied sniff against its module's on samples of every fixture
module (tools/fixtures/detect.py), scores within 0..1, and F.detect against the eager
reference with no name, the right / wrong / unknown extension and per category.

Outside init / Registry / gen_registry: tools/fixtures.py (LAST generators run after
the others and rerun when their outputs change), tools/lint_rules.py (Sniffs is api
layer, skipped by DUP), docs/STYLE.md and docs/API.md notes, build/ regenerated.
This commit is contained in:
4DBug committed 2026-11-02 21:58:10 -06:00
1 parent dde6be117c
commit e05392ee8e
18 files changed
+16513 -1466

No files matched your search

+6 -3
View File
@@ -9,7 +9,7 @@
# NATIVE native code never throws: a --!native module has no error( / assert( and requires no module that has
# one; an @native function body has no error( / assert(. A format's init.luau is never --!native.
# LAYERS requires go downward: core < Types < host; core, Types < codecs < containers < formats (<category>/<fmt>)
# < ops < api (init, Registry). core / codecs / containers / ops may require their own layer; a format
# < ops < api (init, Registry, Sniffs). core / codecs / containers / ops may require their own layer; a format
# may require its own folder but never another format; only the api requires host.
# codecs live in a domain folder: codecs/<domain>/<Name> (CODEC_DOMAINS).
# DEPS a format folder's requires outside itself are exactly the contract's deps = { ... }.
@@ -19,7 +19,8 @@
# tests/<category>/<fmt>.luau with a fuzz pass (:fuzz().
# DUP no copy-pasted code: a function body of DUP_LINES (12) or more code lines whose tokens (comments and
# whitespace dropped, identifiers kept) equal another module's function body fails; move it down to a
# shared module (core / codecs / containers) and call it from both.
# shared module (core / codecs / containers) and call it from both. Sniffs.luau (generated copies of the
# formats' sniffs) is not compared.
# DOCS docs/STYLE.md's layer block names every codec (codecs/<domain>/<Name>), container and core module in the
# tree; README.md's generated format table and codec list (<!-- formats:begin --> ... <!-- codecs:end -->)
# match tools/gen_registry.py's output; README.md links every docs/guide page, docs/API.md and
@@ -69,7 +70,7 @@ def resolve(target):
def layer(mod):
"""(rank, group) of a module path"""
top = mod.split("/")[0] if mod else ""
if mod in ("", "Registry"):
if mod in ("", "Registry", "Sniffs"):
return 6, "api"
if top == "core":
return 0, "core"
@@ -296,6 +297,8 @@ TOKEN = re.compile(r'"(?:[^"\\]|\\.)*"|\'(?:[^\'\\]|\\.)*\'|\[=*\[.*?\]=*\]|[A-Z
FUNC = re.compile(r"^(\s*)(?:local\s+)?function\b")
bodies = {}
for f, lines in text.items():
if mods[f] == "Sniffs":
continue
for i, line in enumerate(lines):
m = FUNC.match(line)
if not m: