utilizing trailing type annotations more

This commit is contained in:
ed
2026-08-19 23:35:57 -04:00
parent 449216967b
commit 2a087f735e
18 changed files with 2785 additions and 5468 deletions
+25 -33
View File
@@ -3,36 +3,32 @@
--- @class DuffleExport
--- bag: open module-export keys from duffle_scan / duffle_isa / duffle_emit
--- @type DuffleExport
local scan = require("duffle_scan")
--- @type DuffleExport
local isa = require("duffle_isa")
--- @type DuffleExport
local emit = require("duffle_emit")
--- @type DuffleExport
local M = {}
local scan = require("duffle_scan") ---@type DuffleExport
local isa = require("duffle_isa") ---@type DuffleExport
local emit = require("duffle_emit") ---@type DuffleExport
local M = {} ---@type DuffleExport
--- @alias Path string
--- @alias LineNum integer
--- @alias ByteOff integer
--- @alias Path string
--- @alias LineNum integer
--- @alias ByteOff integer
--- @alias MacroName string
--- @alias AtomName string
--- @alias Severity string
--- @alias AtomName string
--- @alias Severity string
--- @class SourceFile
--- @field path Path
--- @field text string
--- @field dir string
--- @field path Path
--- @field text string
--- @field dir string
--- @field basename string
--- @field scan SourceScan|nil
--- @field scan SourceScan|nil
--- @class CorpusView
--- @field register_alias_registry table<string, AliasEntry>
--- @field type_name_registry table<string, TypeNameEntry>
--- @field register_alias_registry table<string, AliasEntry>
--- @field type_name_registry table<string, TypeNameEntry>
--- @field atom_views table<AtomName, AtomViewEntry>
--- @field atom_ctxs table<AtomName, AtomCtxEntry>
--- @field atom_phases table<string, AtomPhaseGroup>
--- @field binds_by_name table<string, BindsEntry>
--- @field atom_phases table<string, AtomPhaseGroup>
--- @field binds_by_name table<string, BindsEntry>
--- @field atoms_by_name table<AtomName, AtomEntry>
--- @field atom_infos AtomInfoEntry[]
--- @field components table<string, ComponentDef>
@@ -42,12 +38,11 @@ local M = {}
--- @field source_order SourceFile[]
--- @field collisions CorpusCollision[]
--- @param src DuffleExport
--- @param src DuffleExport
--- @param label string
--- @return nil
local function merge(src, label)
--- @type string, any
for k, v in pairs(src) do
for k, v in pairs(src) do ---@type string, any
if M[k] ~= nil and M[k] ~= v then
error("duffle facade name collision on " .. tostring(k) .. " from " .. label, 0)
end
@@ -62,8 +57,7 @@ merge(emit, "duffle_emit")
--- @param ctx PassCtx
--- @return CorpusView
function M.corpus_view(ctx)
--- @type Corpus
local corpus = ctx and ctx.shared and ctx.shared.corpus
local corpus = ctx and ctx.shared and ctx.shared.corpus ---@type Corpus
if not corpus then error("requires ctx.shared.corpus", 0) end
return {
register_alias_registry = corpus.register_alias_registry or {},
@@ -83,17 +77,15 @@ function M.corpus_view(ctx)
}
end
--- @param rules CheckRule[]
--- @param phase string
--- @param item AtomEntry|SourceFile
--- @param rules CheckRule[]
--- @param phase string
--- @param item AtomEntry|SourceFile
--- @param pipe_ctx PipeCtx
--- @param findings CheckFinding[]
--- @return nil
function M.run_check_rules(rules, phase, item, pipe_ctx, findings)
--- @type integer, CheckRule
for _, rule in ipairs(rules) do
--- @type (fun(item: AtomEntry|SourceFile, pipe_ctx: PipeCtx, findings: CheckFinding[]): nil)|nil
local fn = rule[phase]
for _, rule in ipairs(rules) do ---@type integer, CheckRule
local fn = rule[phase] ---@type (fun(item: AtomEntry|SourceFile, pipe_ctx: PipeCtx, findings: CheckFinding[]): nil)|nil
if fn then fn(item, pipe_ctx, findings) end
end
end