Repository navigation
compiler: complete the pub library boundary - #211
Merged
Merged
Conversation
- Visibility is always enforced (g_lib_on retired): same-library declarations are visible, cross-library ones only through the target library export table. - Types, methods and globals join functions: type symbols carry their declaration line, method lookup checks the raw function owner, globals resolve through the export table. Non-pub declarations fail closed with N01/N06/N08. - pub syntax: function/global tail `, pub`; type `pub struct`/`pub enum` (or tail `, pub`). stdlib public types, methods and globals are tagged. - LSP completion runs with the document library and filters through sym_visible/func_visible; test_lsp_visibility pins pub members and hides internals. - Move arena_globals into stdlib/arena.cr: those three globals were runtime-shared state leaking across the @core/@std boundary. - Export sets reset per compilation so long-lived LSP sessions do not accumulate stale pub declarations. - Performance: cache the owning library per source line, keep export sets sorted with binary-search lookup, and store owner/pub directly in symbol rows. check src/compiler is back to ~20s (from ~40s with the naive per-symbol path scan); selfhost-tests is ~3m50s. - Docs updated; canary relocked with attribution (static STR -17B, BSS page -4096B).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
把
pub从“函数级过滤”补成完整的库边界,不再依赖g_lib_on开关或绕过路径。1. 可见性始终生效
g_lib_on/lib_prepare_from_pub/g_saw_pub:普通用户程序(没有pub)也执行库可见性过滤。lib_export_find_kind),非pub静默不可见。2. 类型 / 方法 / 全局
, pub;方法表命中后用未过滤查找取真实 owner,跨库且不在导出表 →N08 Undefined method。struct/enum/type声明携带真实声明行;跨库非 pub 类型 →N01 Undefined type。公开类型可用pub struct/pub enum(bootstrap 兼容)或尾部, pub。, pub标签写入导出表;非 pub 全局 →N01。Bits32、IntMap、CliCmd、CliFlag、MemLayout)、公开方法、公开常量都已标记pub。3. LSP 同源
analysis_completion以文档所属库(@user)为上下文,候选经过sym_visible/func_visible过滤。test_lsp_visibility.py:import hashmap后补全必须出现IntMap.put/get/...,且不得出现IntMap.findKey/findSlot/grow。4. 库归属修正
src/runtime/arena_globals.cr的三个全局移入src/stdlib/arena.cr:它们是 arena 库的共享状态,不是@core与@std之间的公共面。rt.cr/arena.cr删除import arena_globals;build 清单同步移除。src/compiler无尾斜杠)正确映射到库根,corec check src/compiler不再误判@user。5. 文档
docs/developer/syntax.md/docs/maintainer/design/frontend-semantics.md改为“顶层默认库内部,pub跨库导出”。判据
tests/selfhost/test_pub_visibility.py扩展:Bits32/BITS32_MASK/IntMap.put公开可用;Argv4非 pub 类型 →N01;IntMap.findKey非 pub 方法 →N08;g_current_arena非 pub 全局 →N01;struct Argv4仍可用。tests/selfhost/test_lsp_visibility.py:补全白名单/黑名单。selfhost-tests/bootstrap-tests/check全绿。canaryD1 5/5,值已按内容面变化重锁:.ccr−17B:STR 段少arena_globals(4B 长度 + 13B 字符);.ccr逐字节不变。不做
g_lib_on或“只在有 pub 时过滤”的旧路径。test_diag_gate的chan_test改由 arena 全局归 stdlib 解决。