feat(lang): module NAME uses A, B - a module reaches only the modules it names
A reference from a module that declares uses into a module it does not name is refused, exported or not, naming the use and the fix. A module with no uses clause keeps the old rule; a package's module is always usable; a friend is not held to it; a cycle in the declared graph is refused; LUDIC_VIS_REPORT=1 lists the violations as uses: lines. Reseed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
dd6a449921
commit
f4533331e7
19 changed files with 53571 additions and 50826 deletions
|
|
@ -1,10 +1,13 @@
|
|||
# emit_vis.ludic — L3: module scope. A file belongs to the module its own `module NAME` line or
|
||||
# its importer's names (frontend/parse.ludic, module_of); a file in no module is public. A
|
||||
# reference from one module to another module's function, global, record or event needs that
|
||||
# declaration `export`ed, unless the referring module is a `friend module` (a test harness).
|
||||
# LUDIC_VIS_REPORT=1 prints every violation as `vis: <file>: <module>.<name>` and goes on, so a
|
||||
# tool can add the exports a codebase needs before the rule is switched on for it.
|
||||
# declaration `export`ed, and - when the referring module says `uses` - that module named there
|
||||
# (frontend/modules.ludic), unless the referring module is a friend of it (a test harness).
|
||||
# LUDIC_VIS_REPORT=1 prints every violation as `vis: <file>: <module>.<name>` (a private name) or
|
||||
# `uses: <file>: ...` (a module not in the uses list) and goes on, so a tool can add the exports
|
||||
# and the uses a codebase needs before the rule is switched on for it.
|
||||
var g_vis_report: int = -1
|
||||
var g_vis_off: bool = false # a port's binding: checked where it is written (ports.ludic)
|
||||
function vis_reporting() -> bool {
|
||||
if g_vis_report < 0 {
|
||||
g_vis_report = 0
|
||||
|
|
@ -12,14 +15,6 @@ function vis_reporting() -> bool {
|
|||
}
|
||||
return g_vis_report == 1
|
||||
}
|
||||
function vis_allowed(d: Node, from: pointer) -> bool {
|
||||
if d.vis == 1 { return true }
|
||||
if d.file == null { return true }
|
||||
let to = module_of(d.file)
|
||||
if to == "" { return true }
|
||||
if from == to { return true }
|
||||
return module_is_friend(from)
|
||||
}
|
||||
# `what` is the name as written at the reference
|
||||
# a generic function's instance is named for its type arguments (grow$int); a message names grow
|
||||
function vis_plain(what: pointer) -> pointer {
|
||||
|
|
@ -30,17 +25,30 @@ function vis_plain(what: pointer) -> pointer {
|
|||
}
|
||||
return what
|
||||
}
|
||||
function vis_say(m: pointer) -> void {
|
||||
file_write(file_stderr(), m, len(m))
|
||||
}
|
||||
function vis_check(d: Node, what0: pointer) -> void {
|
||||
if d == null { return }
|
||||
if g_vis_off { return }
|
||||
if d.file == null { return }
|
||||
let what = vis_plain(what0)
|
||||
var here = g_err_file
|
||||
if here == null { return }
|
||||
let from = module_of(here)
|
||||
if vis_allowed(d, from) { return }
|
||||
let to = module_of(d.file)
|
||||
if (to == "") or (from == to) { return }
|
||||
if module_friend_of(from, to) { return }
|
||||
if not module_may_use(from, to) {
|
||||
if vis_reporting() {
|
||||
vis_say(`uses: {d.file}:{itoa(d.line)}: {to}.{what} used from {here} (module {from})\n`)
|
||||
} else {
|
||||
perr(`{from} uses {to}.{what} ({d.file}:{itoa(d.line)}): add 'uses {to}' to {from}'s module line, or take it through a port`)
|
||||
}
|
||||
}
|
||||
if d.vis == 1 { return }
|
||||
if vis_reporting() {
|
||||
let m = `vis: {d.file}:{itoa(d.line)}: {to}.{what} used from {here}\n`
|
||||
file_write(file_stderr(), m, len(m))
|
||||
vis_say(`vis: {d.file}:{itoa(d.line)}: {to}.{what} used from {here}\n`)
|
||||
return
|
||||
}
|
||||
perr(`{what} is private to module {to}; mark it 'export' where it is declared ({d.file})`)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue