Skip to content

compiler: enforce library visibility for pub functions - #205

Merged
dslsdzc merged 1 commit into
developfrom
pub-visibility
Oct 26, 2026
Merged

dslsdzc merged 1 commit into
developfrom
pub-visibility

Conversation

@dslsdzc

@dslsdzc dslsdzc commented Oct 26, 2026

Copy link
Copy Markdown
Owner

概要

pub 函数尾标签现在真正参与可见性判定:库内部默认不可见,跨库只命中 pub。

  • checker 记录函数 AST 所属库;find_sym / find_gsym / find_func 跨库时只命中 pub,非 pub 静默跳过(调用点自然报 N06 Undefined function)。
  • 模块限定调用 m.f() 同样按可见性过滤,隐藏时静默报未定义。
  • 函数注册时把 pub 写入所属库导出表。
  • 库层只在用户代码出现 pub 声明时开启,避免普通编译/标准库自身触发过滤,canary 5/5 不变。
  • bootstrap parser 同步接受 , pub: 尾标签(未知标签响亮报错)。
  • 新增 tests/selfhost/test_pub_visibility.py,覆盖同库内部调用、pub 导出、标准库内部函数不可见。

验证

  • selfhost-tests 全绿
  • bootstrap-tests 全绿
  • check 全绿
  • canary 5/5 不变

- Track the owning library for every function AST node; cross-library
  lookup only resolves pub declarations, same-library internals stay
  callable. Hidden symbols fall through to the existing N06 diagnostic.
- Filter module-qualified calls (`m.f()`) through the same visibility
  check instead of only matching name and file id.
- Register pub functions in their library export table.
- Tag the stdlib public API with the tail `pub` label; internal helpers
  (`_grow_*`, `grow_*`, `fpow2i`, scheduler internals) stay private.
- Teach the bootstrap parser the tail `, pub:` label with loud rejection
  of unknown tags.
- Add test_pub_visibility covering same-library internals, stdlib export
  visibility, and hidden stdlib internals.
- Relock the ccr canary: +7B in STR for the interned `pub` label; the
  canary ELF is byte-identical.
@dslsdzc
dslsdzc merged commit a875d0a into develop Oct 26, 2026
4 checks passed
@dslsdzc
dslsdzc deleted the pub-visibility branch October 26, 2026 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant