Skip to content

lib: give colliding functions and methods library-qualified link names - #218

Merged
dslsdzc merged 1 commit into
developfrom
lib-function-link-names
Oct 27, 2026
Merged

dslsdzc merged 1 commit into
developfrom
lib-function-link-names

Conversation

@dslsdzc

@dslsdzc dslsdzc commented Oct 27, 2026

Copy link
Copy Markdown
Owner

背景

上一批(#217)让 struct/global 同名声明拥有独立身份,但函数/方法同名仍按 N11 拒绝:IR_CALL 和 .ccr 函数表只有源名,两个同名函数在链接面无法区分。

修法

  • 新增 g_func_link 平行表;add_func 默认 link = 源名。
  • 跨库同名函数/方法分配 name@lib#fnN link;monomorph 实例继承限定前缀。
  • 源名仍是查找/导出键;IR_CALL、函数 SYM 行、.cir 缓存元数据使用 link。
  • checker 在调用点写入解析后的 link;IR 直调优先读节点 data,方法调用同样;dyn 分派存方法名而不是 link。
  • find_func 增加 link 回退,供 IR 侧查询;符号/导出保持源名。
  • 插值改写和直调 data 哨兵同步为 -1,避免把 0 当 link。

判据

  • 用户 fn fpow2i 遮蔽 stdlib 非 pub 内部名:编译并返回 42。
  • 用户 fn print 遮蔽 io.print,stdlib println 仍走自己的 print(输出 hello)。
  • 用户 impl IntMap.put 与 hashmap.IntMap.put 并存:两者各自调用自己的函数体,组合用例返回 42。
  • selfhost-tests / bootstrap-tests / check 全绿。
  • canary 5/5 不变。

Source names remain the lookup and export key; IR_CALL and the .ccr function
table now carry a link name. When two libraries declare the same function or
method name, each declaration gets a unique link name, so the call target is no
longer ambiguous at the codegen/link boundary.

- g_func_link parallel table; add_func defaults it to the source name.
- Cross-library collisions get name@lib#fnN links; monomorph instances inherit
  the qualified prefix.
- Checker writes the resolved link into the call node; IR direct calls prefer
  it, method calls use it in node data, and dyn dispatch stores the method name
  (not a link).
- find_func falls back to link names for IR-side queries; function SYM rows and
  cache-hit metadata use the link, while symbols/exports stay source-named.
- Interpolation rewrites and direct-call sentinel fixed for the new node data.

Tests: user fpow2i and print shadow stdlib names; user IntMap.put coexists with
hashmap IntMap.put and both dispatch to their own bodies. Canary 5/5 unchanged;
selfhost/bootstrap/check green.
@dslsdzc
dslsdzc merged commit 5d03fa1 into develop Oct 27, 2026
4 checks passed
@dslsdzc
dslsdzc deleted the lib-function-link-names branch October 27, 2026 01: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