Repository navigation
compiler: make := bindings immutable and use tail pub tags - #212
Merged
Merged
Conversation
- `:=` and un-tagged `: T =` are immutable bindings, per the language syntax plan. Assigning to one now fails closed with TA04 (Cannot assign to immutable variable). Parameters, match bindings and loop variables keep their compatible mutable default. - Migrate the whole tree: 470 inferred declarations and 40 explicit declarations that are reassigned now use `: ., mut =` / `: T, mut =`. Test fixtures with inline Core sources are migrated the same way. - Type declarations use tail labels: `struct S, pub:`, `enum E, pub:`, `interface I, pub:`. The bootstrap and corec parsers both accept the tail form; the prefix `pub struct` remains only as source compatibility. - Interface types join the pub boundary: declaration line + export table visibility, with a same-library interface test. - Docs updated. Canary 5/5 unchanged; selfhost/bootstrap/check green.
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.
概要
按语言语法计划补齐两条被实现绕开的规则。
1.
:=/: T =是不可变绑定docs/superpowers/plans/2026-09-01-language-syntax-rewrite.md:140明确:x := 42推断为不可变,x : ., mut = 0才是可变写法。mut位(per-binding,不新增全局名字表)。EXPR_LET注册时写入声明的mut位;顶层全局同理。EXPR_ASSIGN对标识符目标读取mut位:不可变 →TA04 Cannot assign to immutable variable,不再静默接受。mut语法不在本批范围)。全仓迁移(否则检查会正确地报错):
name :=→name : ., mut =;name : T =→name : T, mut =;tests/**/*.py内嵌 Core 测试夹具(单行/三引号)同步迁移;2. 类型
pub使用尾部标签不再写
pub struct Bits32::struct/enum/interface/type alias也补齐为同一语法。pub struct前缀仅保留旧源兼容路径,文档不再推荐。3. interface 边界
interface 现在和 struct/enum/type alias 一样携带声明行并写入导出表:
非
pubinterface 跨库不可见;同库 interface 测试通过。验证
selfhost-tests/bootstrap-tests/check全绿canary5/5 不变(迁移只改绑定可变性位与标签,发射面零变化)test_pub_visibility:interface 同库使用;test_bits/test_intmap/test_optional/test_multibranch_v10/test_ccr_v7/test_live_ranges/test_named_face/test_region_escape全部在不可变语义下重跑通过。
说明
mut语法;参数仍默认可赋值,避免把范围扩到调用约定。test_lsp.py的既有 6/10 本地失败与本批无关;pub/LSP 过滤由独立的test_lsp_visibility.py覆盖并已挂 CI。