Skip to content

feat: update LK VM, syntax, stdlib, and website - #3

Merged
lollipopkit merged 66 commits into
mainfrom
dev
Jun 8, 2026
Merged

feat: update LK VM, syntax, stdlib, and website#3
lollipopkit merged 66 commits into
mainfrom
dev

Conversation

@lollipopkit

@lollipopkit lollipopkit commented Jun 8, 2026

Copy link
Copy Markdown
Owner

Summary

  • Update LK VM/opcode/runtime work, including opcode-oriented refactors and performance groundwork.
  • Rename the module keyword from import to use across parser, tooling, examples, docs, and website specs.
  • Add global builtins assert, assert_eq, and assert_ne, and remove stdlib assert compatibility modules.
  • Expand benchmark coverage for broader opcode preparation instead of single-opcode-only cases.
  • Sync stdlib, examples, LSP/tree-sitter/VSCode support, docs, and website content with the language changes.

Verification

  • cargo test -p lk-core
  • cargo test -p lk-stdlib
  • cargo test -p lk-cli
  • cargo test -p lk-lsp
  • cd website && bun run build
  • git diff --check
  • Scanned .lk files for obsolete fn assert(cond), assert_ modules, and use assert compatibility remnants

Notes

  • Untracked references/* directories are intentionally not included.

Summary by CodeRabbit

发布说明

  • 新功能

    • 添加覆盖率报告与诊断输出工具(CLI)。
    • 新增包管理命令(pkg)与项目初始化命令。
    • 新增自适应工作负载基准套件与运行器;新增多项业务算法基准脚本。
    • 支持 VM 性能分析与运行时指标输出;引入原生执行缓存机制。
  • 文档

    • 项目文档与示例改为 "LK" 约定;新增 Opcode/状态与基准文档。
    • 移除旧的语言概览文档(LANG.md / LANG_zh.md)。
  • 杂项

    • CLI 与库命名从 LKR 迁移为 LK;更新构建/忽略规则与示例。

- Make RuntimeVal derive Copy: all variants are Copy-safe (Nil, Bool, Int, Float, ShortStr, Obj(HeapRef=u32)).
  No Arc ref-count — GC tracks roots via stack scan.
- Simplify Move opcode: eliminate take/clone branch and move_fact query.
  Now just copies the 16-byte value directly, with batch loop for consecutive Moves.
- Inline BrNil/BrNotNil into dispatch loop body with unchecked relative_pc.
- Inline ForLoopI jump with unchecked relative_pc.
- Inline compare-test branch with unchecked relative_pc for the fallthrough path.
- Add relative_pc_unchecked/relative_pc_from_unchecked that elide bounds checks for
  compiler-generated jump targets.
- Make compare_test_value_slow pub(super) for inline access from dispatch loop.
- Update two move-heap-clone metric tests: Move no longer tracks copy policy since
  RuntimeVal is Copy.

Geomean: 1.247x (6-sample RUNS=6), down from ~1.27x baseline.
binary_search improved to ~1.07x (was ~1.15x).
…ked in ForLoopI

- Move rarely-executed opcode handlers (LoadCapture, LoadCellVal,
  StoreCellVal, LoadFunction, MakeClosure, LoadNative, Not, IsNil,
  IsList, IsMap, ToString, StringStartsWith, StringSplit, ListJoin,
  Contains, SliceFrom, MapRest, Raise, TryBegin, TryEnd, Test,
  BrFalse, BrTrue, NewObject, NewRange, CallNamed, SetGlobal)
  into a separate #[inline(never)] dispatch_cold function to reduce
  I-cache pressure on the hot dispatch loop.
- Replace relative_pc() with relative_pc_unchecked() in ForLoopI
  hot path, eliminating bounds check overhead for the loop-back jump.
- Geomean improvement: 1.274x → 1.256x (VM vs Lua)
@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: aa2ca2f4-ec41-407e-aa6c-decac079e762

📥 Commits

Reviewing files that changed from the base of the PR and between c308d7a and 80892ae.

📒 Files selected for processing (8)
  • README.md
  • bench/run_workload_bench.sh
  • cli/src/main.rs
  • cli/src/main_test.rs
  • core/src/ast/parser/literals.rs
  • core/src/ast/parser/support.rs
  • core/src/expr/expr_impl.rs
  • core/src/expr/expr_test.rs
✅ Files skipped from review due to trivial changes (1)
  • README.md
🚧 Files skipped from review as they are similar to previous changes (7)
  • cli/src/main_test.rs
  • core/src/ast/parser/literals.rs
  • core/src/ast/parser/support.rs
  • core/src/expr/expr_test.rs
  • cli/src/main.rs
  • bench/run_workload_bench.sh
  • core/src/expr/expr_impl.rs
📜 Recent review details
⏰ Context from checks skipped due to timeout of 180000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Cloudflare Pages

📝 Walkthrough

Walkthrough

将仓库从 LKR 重命名为 LK 并重构:工作区与构建配置更新,文档与基准重写,CLI 扩展(coverage/pkg/paths/diagnostic)、Parser/AST 常量体系迁移为 LiteralVal,LLVM 后端改为模块工件路径,示例与测试同步更新。

Changes

LK 项目重构与基础设施升级

Layer / File(s) Summary
项目命名与工作区配置迁移
Cargo.toml, cli/Cargo.toml, core/Cargo.toml, .gitignore, Makefile
工作区与 crate 名称从 lkr -> lk,更新成员(tree-sitter-lk / lk)、依赖(新增 arcstr、调整 toml、移除 criterion)、release profile 优化(opt-level/lto/codegen-units)、扩展 .gitignore,并新增 Makefile。
文档与基准套件全量更新
README.md, README.zh-CN.md, OPCODE.md, STATUS.md, bench/README.md, LANG.md, LANG_zh.md
移除旧 LANG 文档,更新 README(示例、CLI 名称、网站链接),新增 OPCODE 与 STATUS 文档;bench 文档改写并记录多轮基线/验证结果。
基准脚本替换与运行器
bench/*, bench/workloads_business_algorithms.{lk,lua}, bench/run_workload_bench.sh
移除若干旧单项基准脚本,新增 20 个业务工作负载脚本(LK/Lua 对应)与自适应运行器脚本,支持 AOT/VM/Lua 比较、噪声检测与 VM profile 汇总。
CLI 架构重组与功能扩展
cli/src/{main,coverage,diagnostic,paths,pkg,repl}.rs, cli/Cargo.toml, cli/tests/*
重命名 CLI 包(lk),移除 bundler,新增 coverage/diagnostic/paths/pkg 模块,重构 main 以支持 Coverage/Init/Pkg、VM profiling、native 缓存执行;新增/更新大量 CLI 集成与解析测试。
Parser 与 AST 字面量体系迁移
core/src/ast/*, core/src/expr/*, core/src/lib.rs
将字面量从 Val 转为 LiteralVal,新增 Expr::Block,支持位运算、结构体更新语法、列表展开与 map 字面量解析,新增 parser 支撑(错误恢复、闭包/块解析)、并更新相应测试。
Expr 模型、常量折叠与测试改写
core/src/expr/expr_impl.rs, core/src/expr/*_test.rs, core/src/expr/pattern_impl.rs
重写常量折叠为基于 LiteralVal 的折叠,移除 Serialize 派生与 TryInto,新增 Pattern Display,实现多处测试由直接 AST 断言改为脚本执行断言。
Core 库与 LLVM 后端重构
core/Cargo.toml, core/src/lib.rs, core/src/llvm.rs, core/src/llvm/backend.rs
核心 crate 名称/导出调整(lk-core、lk_core),新增 vm-profile 特性;新增 core/src/llvm 聚合模块,并改写 backend 以从 ModuleArtifact 生成 LLVM(compile_module_artifact_to_llvm),不再在此处运行 opt。
示例与工具更新
core/examples/*, cli/src/*
示例改为使用 Compiler::compile_source_module / disassemble_module,新增 lkm dump 示例;CLI repl/use 路径与运行逻辑迁移至新的 VM/execute_with_ctx 接口。

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

🧹 Nitpick comments (5)
README.md (1)

45-49: 💤 Low value

可选:修复 markdown 格式问题。

静态分析工具建议在标题前后添加空行以符合 markdown 最佳实践。

📝 建议的格式调整
 Run any example: `lk examples/syntax/closure.lk`
+
 ### Highlights
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@README.md` around lines 45 - 49, Summary: The "### Highlights" heading and
surrounding list lack blank lines; add a single blank line before the "###
Highlights" heading and a blank line after the list block to conform to Markdown
best practices. Locate the "### Highlights" section in README.md, insert an
empty line immediately before the "### Highlights" line and an empty line after
the last list item ("Project website source lives in `website/`...") so the
header and list are separated from surrounding content and render correctly in
Markdown.

Source: Linters/SAST tools

bench/run_workload_bench.sh (1)

390-392: 💤 Low value

空重定向应使用显式的 no-op 命令。

根据 shellcheck SC2188 警告,这些重定向操作缺少命令。虽然在实际运行中可能不会出错,但显式使用 :true 命令会更符合 shell 最佳实践。

♻️ 可选的改进方案
-  > "$TMPDIR/lk_${name}.dat"
-  > "$TMPDIR/lua_${name}.dat"
-  > "$TMPDIR/aot_${name}.dat"
+  : > "$TMPDIR/lk_${name}.dat"
+  : > "$TMPDIR/lua_${name}.dat"
+  : > "$TMPDIR/aot_${name}.dat"

类似的修改也适用于 472、500-502 行。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@bench/run_workload_bench.sh` around lines 390 - 392, The three bare
redirections writing to "$TMPDIR/lk_${name}.dat", "$TMPDIR/lua_${name}.dat", and
"$TMPDIR/aot_${name}.dat" should use an explicit no-op command to satisfy
shellcheck SC2188; replace each bare redirection with an explicit no-op (e.g.,
":" or "true") followed by the same redirection so the file is created
intentionally. Also apply the same change to the other similar bare redirections
noted around lines 472 and 500-502 to avoid SC2188 warnings.

Source: Linters/SAST tools

cli/src/main_test.rs (1)

67-104: ⚡ Quick win

测试可能无法检测到 vm_profile_line 中的字段重复问题。

该测试仅检查输出字符串中是否包含特定字段名(如 val_clones=9),但由于 lines 237-262 中的 bug,多个字段实际上都使用了 copy_policy_heap_clones 的值。

建议在修复 vm_profile_line 中的字段映射问题后,增强该测试以验证每个字段的实际数值是否符合预期(而不仅仅是检查子串存在)。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cli/src/main_test.rs` around lines 67 - 104, The vm_profile_line output is
incorrectly mapping several heap-clone fields to copy_policy_heap_clones, so
update the vm_profile_line implementation to use the correct VmRuntimeMetrics
fields (use copy_policy_heap_clones only for its own label and map
register_copy_heap_clones, local_copy_heap_clones, local_load_heap_clones,
local_store_heap_clones, const_load_heap_clones, call_arg_heap_clones,
container_copy_heap_clones, val_clones and heap_clones to their respective
output labels) and ensure register_write_sources and index_key_metrics are
formatted from their actual arrays; after fixing vm_profile_line, extend the
test_vm_profile_line_contains_benchmark_fields test to assert exact numeric
substrings for each specific label (e.g., "register_copy_heap_clones=10",
"local_copy_heap_clones=12", "local_load_heap_clones=13",
"local_store_heap_clones=14", "const_load_heap_clones=15",
"call_arg_heap_clones=16", "container_copy_heap_clones=17", "val_clones=9",
"heap_clones=9") instead of only existence checks.
core/src/ast/parser/literals.rs (1)

43-51: ⚡ Quick win

重构错误消息构造方式以消除冗余并提升语义清晰度

当前代码在多处手动格式化 token 到错误消息中,并使用 Token::Nil 作为 EOF 占位符,然后再调用 self.err(&msg)。这导致两个问题:

  1. 语义混淆Token::Nil 在语言中代表 nil 字面量,而非文件结束标记。
  2. 冗余输出err() 函数(在 support.rs:269-276)已经会自动添加 "found {token}""found end of input" 上下文,手动构造的消息会导致重复信息,例如:"Syntax error: Expecting '}', found Token::Nil (found end of input)"

建议将错误消息简化为仅描述期望内容,让 err() 统一处理当前 token 或 EOF 的上下文。

♻️ 建议的重构方式(以 Lines 70-79 为例)
-        if self.eof() || self.tokens[self.pos] != Token::RBrace {
-            let msg = format!(
-                "Expecting '}}', found {:?}",
-                if self.eof() {
-                    &Token::Nil
-                } else {
-                    &self.tokens[self.pos]
-                }
-            );
-            return Err(anyhow!(self.err(&msg)));
+        if self.eof() || self.tokens[self.pos] != Token::RBrace {
+            return Err(anyhow!(self.err("Expecting '}' to close map literal")));
         }

对 Lines 43-51、100-108、116-123 应用类似模式。

Also applies to: 70-79, 100-108, 116-123

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/src/ast/parser/literals.rs` around lines 43 - 51, Replace the manual
format! + Token::Nil sentinel and the constructed msg with a simple expectation
string passed to self.err so err() can append the actual "found ..." or "end of
input" context; e.g. in literals.rs where code builds msg with Token::Nil and
calls self.err(&msg), remove that formatting and instead return
Err(anyhow!(self.err("Invalid map key after comma"))). Apply the same pattern to
the other occurrences mentioned (the blocks around the original lines and at the
other two similar sites) so no code uses Token::Nil as EOF placeholder and all
messages rely on self.err() to provide the found-token context.
core/src/ast/parser/support.rs (1)

146-169: ⚡ Quick win

建议为闭包块解析使用分离的括号深度计数器

当前 parse_closure_block_expr 使用单一 depth 计数器追踪所有括号类型((), [], {})。这种简化方法对格式良好的代码可以正常工作,但无法检测括号类型不匹配,例如 { foo(] } 会被错误地接受为合法的 token 范围。

对比 recover_expression_errors(Lines 316-355)为每种括号类型维护独立计数器(paren/bracket/brace),能够更准确地识别嵌套结构。虽然当前实现依赖下游 StmtParser 捕获错误,但使用分离计数器可以:

  1. 在更早阶段提供更精确的错误定位
  2. 避免传递包含不匹配括号的 token 范围给语句解析器
  3. 提升错误消息的可理解性
♻️ 建议的改进方案
 fn parse_closure_block_expr(&mut self) -> Result<Expr> {
     self.pos += 1;
     let start = self.pos;
-    let mut depth = 0i32;
+    let mut paren_depth = 0i32;
+    let mut bracket_depth = 0i32;
+    let mut brace_depth = 0i32;
     while !self.eof() {
         match self.tokens[self.pos] {
-            Token::LBrace | Token::LParen | Token::LBracket => {
-                depth += 1;
+            Token::LParen => {
+                paren_depth += 1;
                 self.pos += 1;
             }
-            Token::RParen | Token::RBracket => {
-                if depth > 0 {
-                    depth -= 1;
+            Token::RParen => {
+                if paren_depth > 0 {
+                    paren_depth -= 1;
                 }
+                if paren_depth == 0 && bracket_depth == 0 && brace_depth == 0 {
+                    // Unmatched closing paren outside closure block
+                    break;
+                }
                 self.pos += 1;
             }
-            Token::RBrace if depth == 0 => break,
+            Token::LBracket => {
+                bracket_depth += 1;
+                self.pos += 1;
+            }
+            Token::RBracket => {
+                if bracket_depth > 0 {
+                    bracket_depth -= 1;
+                }
+                if paren_depth == 0 && bracket_depth == 0 && brace_depth == 0 {
+                    break;
+                }
+                self.pos += 1;
+            }
+            Token::LBrace => {
+                brace_depth += 1;
+                self.pos += 1;
+            }
+            Token::RBrace if brace_depth == 0 => break,
             Token::RBrace => {
-                depth -= 1;
+                brace_depth -= 1;
                 self.pos += 1;
             }
             _ => self.pos += 1,
         }
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/src/ast/parser/support.rs` around lines 146 - 169,
parse_closure_block_expr currently uses a single depth counter for all bracket
types which lets mismatched brackets (e.g. "{ foo(] }") slip through; update
parse_closure_block_expr to use three separate counters (paren, bracket, brace)
like recover_expression_errors does, increment/decrement the appropriate counter
when encountering Token::LParen/Token::RParen, Token::LBracket/Token::RBracket,
and Token::LBrace/Token::RBrace, and only treat Token::RBrace as the closure
terminator when brace == 0 while ensuring other counters are adjusted and never
go negative so mismatched bracket sequences stop the loop and produce a correct
token range/error.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@bench/run_workload_bench.sh`:
- Line 20: The trap command currently uses double quotes which expands $TMPDIR
at parse time; change the trap invocation in run_workload_bench.sh to use single
quotes so $TMPDIR is expanded when the trap runs (e.g., replace trap "rm -rf
$TMPDIR" EXIT with a single-quoted form) and ensure the variable is quoted
inside the command (use "$TMPDIR") to handle paths with spaces.
- Line 10: 当前脚本把 LK_BIN 硬编码为绝对路径,导致不可移植;请修改 run_workload_bench.sh 以优先使用环境变量
LK_BIN(若已设置且可执行则直接使用),否则在脚本内通过解析脚本目录(例如使用脚本所在目录的相对路径)来推导出相对的 target/release/lk
可执行文件路径并验证可执行性,最后可再尝试用系统路径查找(例如 which lk)作为回退;确保对每种情况做可执行性检查并在失败时打印明确错误并退出。

In `@cli/Cargo.toml`:
- Line 32: 升级 rustyline 到 18 可能改变了 DefaultEditor::new 的签名、ReadlineError 枚举项和引入了
Prompt trait;在 cli/src/repl.rs 中检查并更新对 DefaultEditor::new()
的调用(确保错误处理或返回类型匹配新签名),核对并更新对 ReadlineError 的匹配分支(包括 Interrupted/Eof
名称或模块路径是否变动),并如果你实现或自定义提示/渲染逻辑,改用 rustyline 18 的 Prompt trait 实现或其新的提示 API;修复后运行
REPL 并验证中断/EOF 行为与之前一致。

In `@cli/src/main.rs`:
- Around line 237-262: In vm_profile_line the format string's placeholders for
val_clones, heap_clones and copy_policy_heap_clones are all passed
metrics.copy_policy_heap_clones (a copy-paste bug); open the VmRuntimeMetrics
struct, identify the correct fields (e.g. metrics.val_clones and
metrics.heap_clones if present) and replace the duplicate arguments so the nth
argument matches the nth {} in the format string (keep top_opcode_profile,
top_register_write_source_profile, top_index_key_profile and the other metrics
in the same order). If val_clones should be an aggregate, compute it before the
format call and pass that value instead. Ensure the final argument list length
and order exactly match the placeholders in vm_profile_line.
- Around line 694-701: Fnv64::bytes currently applies two extra operations after
the byte loop (self.0 ^= 0xff; self.0 = self.0.wrapping_mul(0x100000001b3);)
which deviates from the standard FNV-1a algorithm; either remove these two lines
to implement standard FNV-1a behavior in the Fnv64::bytes method or, if this is
an intentional custom finalization, replace them with a clear comment above
Fnv64::bytes explaining the rationale and expected effects of this extra
xor/multiply so future readers know it is deliberate.

In `@core/src/expr/expr_impl.rs`:
- Line 795: The constant-fold for modulo currently invokes fold_literal_numeric
with a raw closure (|a, b| a % b) for BinOp::Mod which will panic on rhs == 0
during compilation; update the implementation so fold_literal_numeric (or the
caller for BinOp::Mod) performs an explicit divide-by-zero check before applying
the modulo: detect rhs == 0 and return a safe failure (e.g., None or propagate
an error) rather than calling the % closure, or change fold_literal_numeric to
accept/handle an operation that returns Option and use a wrapper for Mod that
returns None on zero RHS; reference BinOp::Mod and fold_literal_numeric to
locate and implement this guard.
- Around line 862-874: The constant-folding for division in fold_literal_div
currently converts integer-by-zero cases into float inf/nan; change
fold_literal_div to detect division-by-zero and avoid folding when rhs is zero:
explicitly check when rhs is LiteralVal::Int(b) with *b == 0 and when rhs is
LiteralVal::Float(f) with *f == 0.0 (and for mixed cases ensure
fold_literal_numeric is not invoked when the divisor is zero), and return None
in those cases so the original expression is preserved for runtime
division-by-zero handling.

---

Nitpick comments:
In `@bench/run_workload_bench.sh`:
- Around line 390-392: The three bare redirections writing to
"$TMPDIR/lk_${name}.dat", "$TMPDIR/lua_${name}.dat", and
"$TMPDIR/aot_${name}.dat" should use an explicit no-op command to satisfy
shellcheck SC2188; replace each bare redirection with an explicit no-op (e.g.,
":" or "true") followed by the same redirection so the file is created
intentionally. Also apply the same change to the other similar bare redirections
noted around lines 472 and 500-502 to avoid SC2188 warnings.

In `@cli/src/main_test.rs`:
- Around line 67-104: The vm_profile_line output is incorrectly mapping several
heap-clone fields to copy_policy_heap_clones, so update the vm_profile_line
implementation to use the correct VmRuntimeMetrics fields (use
copy_policy_heap_clones only for its own label and map
register_copy_heap_clones, local_copy_heap_clones, local_load_heap_clones,
local_store_heap_clones, const_load_heap_clones, call_arg_heap_clones,
container_copy_heap_clones, val_clones and heap_clones to their respective
output labels) and ensure register_write_sources and index_key_metrics are
formatted from their actual arrays; after fixing vm_profile_line, extend the
test_vm_profile_line_contains_benchmark_fields test to assert exact numeric
substrings for each specific label (e.g., "register_copy_heap_clones=10",
"local_copy_heap_clones=12", "local_load_heap_clones=13",
"local_store_heap_clones=14", "const_load_heap_clones=15",
"call_arg_heap_clones=16", "container_copy_heap_clones=17", "val_clones=9",
"heap_clones=9") instead of only existence checks.

In `@core/src/ast/parser/literals.rs`:
- Around line 43-51: Replace the manual format! + Token::Nil sentinel and the
constructed msg with a simple expectation string passed to self.err so err() can
append the actual "found ..." or "end of input" context; e.g. in literals.rs
where code builds msg with Token::Nil and calls self.err(&msg), remove that
formatting and instead return Err(anyhow!(self.err("Invalid map key after
comma"))). Apply the same pattern to the other occurrences mentioned (the blocks
around the original lines and at the other two similar sites) so no code uses
Token::Nil as EOF placeholder and all messages rely on self.err() to provide the
found-token context.

In `@core/src/ast/parser/support.rs`:
- Around line 146-169: parse_closure_block_expr currently uses a single depth
counter for all bracket types which lets mismatched brackets (e.g. "{ foo(] }")
slip through; update parse_closure_block_expr to use three separate counters
(paren, bracket, brace) like recover_expression_errors does, increment/decrement
the appropriate counter when encountering Token::LParen/Token::RParen,
Token::LBracket/Token::RBracket, and Token::LBrace/Token::RBrace, and only treat
Token::RBrace as the closure terminator when brace == 0 while ensuring other
counters are adjusted and never go negative so mismatched bracket sequences stop
the loop and produce a correct token range/error.

In `@README.md`:
- Around line 45-49: Summary: The "### Highlights" heading and surrounding list
lack blank lines; add a single blank line before the "### Highlights" heading
and a blank line after the list block to conform to Markdown best practices.
Locate the "### Highlights" section in README.md, insert an empty line
immediately before the "### Highlights" line and an empty line after the last
list item ("Project website source lives in `website/`...") so the header and
list are separated from surrounding content and render correctly in Markdown.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e0720731-23a7-4d0c-9bb7-ccfb7183186a

📥 Commits

Reviewing files that changed from the base of the PR and between 443c9fb and c308d7a.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (299)
  • .github/workflows/perf-dashboard.yml
  • .gitignore
  • Cargo.toml
  • LANG.md
  • LANG_zh.md
  • Makefile
  • OPCODE.md
  • README.md
  • README.zh-CN.md
  • STATUS.md
  • bench/README.md
  • bench/arith.lkr
  • bench/arith.lua
  • bench/calls.lkr
  • bench/calls.lua
  • bench/empty_loop.lkr
  • bench/empty_loop.lua
  • bench/fib.lkr
  • bench/fib.lua
  • bench/list.lkr
  • bench/map.lkr
  • bench/map.lua
  • bench/run_bench.sh
  • bench/run_workload_bench.sh
  • bench/strcat.lkr
  • bench/strcat.lua
  • bench/table.lua
  • bench/workloads_business_algorithms.lk
  • bench/workloads_business_algorithms.lua
  • cli/Cargo.toml
  • cli/src/bundler.rs
  • cli/src/coverage.rs
  • cli/src/diagnostic.rs
  • cli/src/main.rs
  • cli/src/main_test.rs
  • cli/src/paths.rs
  • cli/src/pkg.rs
  • cli/src/repl.rs
  • cli/tests/compile_cli_test.rs
  • cli/tests/lkrb_cli_test.rs
  • cli/tests/type_system_cli_test.rs
  • core/Cargo.toml
  • core/benches/bc32_bench.rs
  • core/benches/bc32_for_range_bench.rs
  • core/benches/bc32_ic_mix_bench.rs
  • core/benches/bc32_while_bench.rs
  • core/benches/bench_main.rs
  • core/benches/call_named_bench.rs
  • core/benches/escape_regions.rs
  • core/benches/index_ic_bench.rs
  • core/benches/scripts_bench.rs
  • core/benches/slots_bench.rs
  • core/benches/vm_micro_bench.rs
  • core/examples/dump_bc.rs
  • core/examples/dump_lkm.rs
  • core/examples/dump_loop.rs
  • core/examples/fib_inner.rs
  • core/examples/test_let.rs
  • core/examples/val_size.rs
  • core/src/ast.rs
  • core/src/ast/ast_test.rs
  • core/src/ast/parser.rs
  • core/src/ast/parser/literals.rs
  • core/src/ast/parser/support.rs
  • core/src/expr.rs
  • core/src/expr/expr_impl.rs
  • core/src/expr/expr_test.rs
  • core/src/expr/match_parsing_test.rs
  • core/src/expr/match_test.rs
  • core/src/expr/pattern_impl.rs
  • core/src/lib.rs
  • core/src/llvm.rs
  • core/src/llvm/backend.rs
  • core/src/llvm/callee_eval.rs
  • core/src/llvm/const_display.rs
  • core/src/llvm/diagnostics.rs
  • core/src/llvm/dynamic_containers.rs
  • core/src/llvm/dynamic_containers/f64_lists.rs
  • core/src/llvm/dynamic_containers/i64_lists.rs
  • core/src/llvm/dynamic_containers/i64_maps.rs
  • core/src/llvm/dynamic_containers/ptr_lists.rs
  • core/src/llvm/dynamic_containers/string_maps.rs
  • core/src/llvm/encoding.rs
  • core/src/llvm/intrinsics.rs
  • core/src/llvm/ir_text.rs
  • core/src/llvm/known_key.rs
  • core/src/llvm/map_mutate.rs
  • core/src/llvm/mod.rs
  • core/src/llvm/options.rs
  • core/src/llvm/output.rs
  • core/src/llvm/output/arg_list_methods.rs
  • core/src/llvm/output/io.rs
  • core/src/llvm/output/iter_methods.rs
  • core/src/llvm/output/list_methods.rs
  • core/src/llvm/output/map_methods.rs
  • core/src/llvm/output/math_methods.rs
  • core/src/llvm/output/object_methods.rs
  • core/src/llvm/output/return_value.rs
  • core/src/llvm/output/string_methods.rs
  • core/src/llvm/passes.rs
  • core/src/llvm/runtime.rs
  • core/src/llvm/scalar.rs
  • core/src/llvm/scalar/block_helpers.rs
  • core/src/llvm/scalar/block_helpers/formatting.rs
  • core/src/llvm/scalar/block_helpers/object_display.rs
  • core/src/llvm/scalar/block_helpers/scalars.rs
  • core/src/llvm/scalar/block_helpers/static_direct.rs
  • core/src/llvm/scalar/block_helpers/symbolic.rs
  • core/src/llvm/scalar/blocks.rs
  • core/src/llvm/scalar/blocks/allocas.rs
  • core/src/llvm/scalar/blocks/arithmetic.rs
  • core/src/llvm/scalar/blocks/asserts.rs
  • core/src/llvm/scalar/blocks/call_args.rs
  • core/src/llvm/scalar/blocks/callees.rs
  • core/src/llvm/scalar/blocks/cells.rs
  • core/src/llvm/scalar/blocks/channel.rs
  • core/src/llvm/scalar/blocks/compare.rs
  • core/src/llvm/scalar/blocks/const_lists.rs
  • core/src/llvm/scalar/blocks/control.rs
  • core/src/llvm/scalar/blocks/direct_print.rs
  • core/src/llvm/scalar/blocks/finalize.rs
  • core/src/llvm/scalar/blocks/get_index.rs
  • core/src/llvm/scalar/blocks/globals.rs
  • core/src/llvm/scalar/blocks/i64_list_methods.rs
  • core/src/llvm/scalar/blocks/iter.rs
  • core/src/llvm/scalar/blocks/len.rs
  • core/src/llvm/scalar/blocks/list_builtin_dispatch.rs
  • core/src/llvm/scalar/blocks/list_direct_calls.rs
  • core/src/llvm/scalar/blocks/list_methods.rs
  • core/src/llvm/scalar/blocks/list_push.rs
  • core/src/llvm/scalar/blocks/map_methods.rs
  • core/src/llvm/scalar/blocks/not.rs
  • core/src/llvm/scalar/blocks/object_methods.rs
  • core/src/llvm/scalar/blocks/returns.rs
  • core/src/llvm/scalar/blocks/runtime_builtins.rs
  • core/src/llvm/scalar/blocks/set_index.rs
  • core/src/llvm/scalar/blocks/string_methods.rs
  • core/src/llvm/scalar/blocks/string_split.rs
  • core/src/llvm/scalar/blocks/values.rs
  • core/src/llvm/scalar/contains.rs
  • core/src/llvm/scalar/contains/int_lists.rs
  • core/src/llvm/scalar/emit.rs
  • core/src/llvm/scalar/facts.rs
  • core/src/llvm/scalar/facts/analysis.rs
  • core/src/llvm/scalar/facts/arg_lists.rs
  • core/src/llvm/scalar/facts/entry.rs
  • core/src/llvm/scalar/facts/list_push.rs
  • core/src/llvm/scalar/facts/list_returns.rs
  • core/src/llvm/scalar/facts/map_methods.rs
  • core/src/llvm/scalar/facts/returns.rs
  • core/src/llvm/scalar/facts/slots.rs
  • core/src/llvm/scalar/facts/string_ops.rs
  • core/src/llvm/scalar/inline.rs
  • core/src/llvm/scalar/kind.rs
  • core/src/llvm/scalar/subfunctions.rs
  • core/src/llvm/straightline_main.rs
  • core/src/llvm/straightline_value.rs
  • core/src/llvm/straightline_value/display.rs
  • core/src/llvm/straightline_value/equality.rs
  • core/src/llvm/straightline_value/maps.rs
  • core/src/llvm/straightline_value/modules.rs
  • core/src/llvm/straightline_value/strings.rs
  • core/src/llvm/subfunction.rs
  • core/src/llvm/subfunction/list.rs
  • core/src/llvm/tests.rs
  • core/src/llvm/tests/basic.rs
  • core/src/llvm/tests/direct_calls.rs
  • core/src/llvm/tests/modules.rs
  • core/src/llvm/tests/objects.rs
  • core/src/llvm/tests/strings.rs
  • core/src/module.rs
  • core/src/op/mod.rs
  • core/src/op/op_test.rs
  • core/src/op/ops.rs
  • core/src/operator.rs
  • core/src/operator/operator_test.rs
  • core/src/operator/syntax.rs
  • core/src/package.rs
  • core/src/perf/mod.rs
  • core/src/perf/scenarios.rs
  • core/src/resolve.rs
  • core/src/resolve/slots.rs
  • core/src/resolve/slots_test.rs
  • core/src/rt.rs
  • core/src/rt/concurrency_test.rs
  • core/src/rt/mod.rs
  • core/src/rt/runtime.rs
  • core/src/stmt.rs
  • core/src/stmt/destructuring_test.rs
  • core/src/stmt/function_test.rs
  • core/src/stmt/if_let_test.rs
  • core/src/stmt/import.rs
  • core/src/stmt/import_parse_test.rs
  • core/src/stmt/rust_function_test.rs
  • core/src/stmt/stmt_impl/ast.rs
  • core/src/stmt/stmt_impl/display.rs
  • core/src/stmt/stmt_impl/type_check.rs
  • core/src/stmt/stmt_parser/bindings.rs
  • core/src/stmt/stmt_parser/control.rs
  • core/src/stmt/stmt_parser/declarations.rs
  • core/src/stmt/stmt_parser/function.rs
  • core/src/stmt/stmt_parser/helpers.rs
  • core/src/stmt/stmt_parser/imports.rs
  • core/src/stmt/stmt_parser/program.rs
  • core/src/stmt/stmt_test.rs
  • core/src/stmt/while_let_test.rs
  • core/src/token.rs
  • core/src/token/error.rs
  • core/src/token/lexer.rs
  • core/src/token/token_test.rs
  • core/src/typ.rs
  • core/src/typ/type_checker.rs
  • core/src/typ/type_checker/expressions.rs
  • core/src/typ/type_checker/expressions/calls.rs
  • core/src/typ/type_checker/tests.rs
  • core/src/typ/type_system.rs
  • core/src/typ/type_system_test.rs
  • core/src/util.rs
  • core/src/util/fast_map.rs
  • core/src/val.rs
  • core/src/val/de.rs
  • core/src/val/de_test.rs
  • core/src/val/meta_method_test.rs
  • core/src/val/methods.rs
  • core/src/val/runtime_model.rs
  • core/src/val/runtime_model/heap.rs
  • core/src/val/val_test.rs
  • core/src/val/values/cache.rs
  • core/src/val/values/convert.rs
  • core/src/val/values/iter.rs
  • core/src/val/values/mod.rs
  • core/src/val/values/ops.rs
  • core/src/val/values/strings.rs
  • core/src/val/values/types.rs
  • core/src/vm.rs
  • core/src/vm/alloc.rs
  • core/src/vm/analysis.rs
  • core/src/vm/analysis_queries.rs
  • core/src/vm/artifact.rs
  • core/src/vm/bc32.rs
  • core/src/vm/bytecode.rs
  • core/src/vm/cache.rs
  • core/src/vm/call_window.rs
  • core/src/vm/compiler.rs
  • core/src/vm/compiler/assign.rs
  • core/src/vm/compiler/builder.rs
  • core/src/vm/compiler/call.rs
  • core/src/vm/compiler/const_eval.rs
  • core/src/vm/compiler/const_maps.rs
  • core/src/vm/compiler/container_lower.rs
  • core/src/vm/compiler/driver.rs
  • core/src/vm/compiler/entry.rs
  • core/src/vm/compiler/expr.rs
  • core/src/vm/compiler/facts.rs
  • core/src/vm/compiler/facts_tests.rs
  • core/src/vm/compiler/for_value_usage.rs
  • core/src/vm/compiler/free_vars.rs
  • core/src/vm/compiler/inline.rs
  • core/src/vm/compiler/loop_consts.rs
  • core/src/vm/compiler/lower_into.rs
  • core/src/vm/compiler/match_expr.rs
  • core/src/vm/compiler/pattern_bind.rs
  • core/src/vm/compiler/pattern_control.rs
  • core/src/vm/compiler/peephole.rs
  • core/src/vm/compiler/range_loop.rs
  • core/src/vm/compiler/ssa/pipeline.rs
  • core/src/vm/compiler/stmt.rs
  • core/src/vm/compiler/support.rs
  • core/src/vm/compiler/tests.rs
  • core/src/vm/compiler/tests/arithmetic.rs
  • core/src/vm/compiler/tests/call_intrinsics.rs
  • core/src/vm/compiler/tests/loops.rs
  • core/src/vm/compiler/tests/patterns.rs
  • core/src/vm/compiler/tests/template.rs
  • core/src/vm/compiler_test.rs
  • core/src/vm/context.rs
  • core/src/vm/context/core_methods.rs
  • core/src/vm/exec.rs
  • core/src/vm/exec/arithmetic.rs
  • core/src/vm/exec/call.rs
  • core/src/vm/exec/callable_ops.rs
  • core/src/vm/exec/cell.rs
  • core/src/vm/exec/const_load.rs
  • core/src/vm/exec/container.rs
  • core/src/vm/exec/container/index.rs
  • core/src/vm/exec/container/set_index.rs
  • core/src/vm/exec/dispatch.rs
  • core/src/vm/exec/exec_tests.rs
  • core/src/vm/exec/exec_tests/basic.rs
  • core/src/vm/exec/exec_tests/calls.rs
  • core/src/vm/exec/exec_tests/container.rs
  • core/src/vm/exec/exec_tests/cross_heap.rs
  • core/src/vm/exec/exec_tests/gc_cell_error.rs
  • core/src/vm/exec/exec_tests/native.rs
  • core/src/vm/exec/gc.rs
  • core/src/vm/exec/globals.rs
  • core/src/vm/exec/handler.rs
  • core/src/vm/exec/imports.rs
  • core/src/vm/exec/named_call.rs
💤 Files with no reviewable changes (33)
  • bench/empty_loop.lua
  • bench/calls.lkr
  • bench/list.lkr
  • bench/map.lkr
  • LANG.md
  • core/benches/bc32_for_range_bench.rs
  • bench/map.lua
  • bench/empty_loop.lkr
  • core/benches/bc32_while_bench.rs
  • .github/workflows/perf-dashboard.yml
  • core/benches/bc32_ic_mix_bench.rs
  • core/benches/slots_bench.rs
  • bench/strcat.lkr
  • core/benches/bench_main.rs
  • core/benches/escape_regions.rs
  • bench/fib.lkr
  • bench/calls.lua
  • bench/arith.lkr
  • LANG_zh.md
  • bench/run_bench.sh
  • core/benches/call_named_bench.rs
  • bench/table.lua
  • cli/tests/lkrb_cli_test.rs
  • bench/arith.lua
  • cli/src/bundler.rs
  • core/examples/test_let.rs
  • bench/fib.lua
  • core/benches/scripts_bench.rs
  • core/benches/vm_micro_bench.rs
  • core/benches/bc32_bench.rs
  • bench/strcat.lua
  • core/benches/index_ic_bench.rs
  • core/examples/val_size.rs
📜 Review details
⏰ Context from checks skipped due to timeout of 180000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Cloudflare Pages
🧰 Additional context used
🪛 checkmake (0.3.2)
Makefile

[warning] 7-7: Required target "all" is missing from the Makefile.

(minphony)


[warning] 7-7: Required target "clean" is missing from the Makefile.

(minphony)


[warning] 7-7: Required target "test" is missing from the Makefile.

(minphony)

🪛 LanguageTool
STATUS.md

[grammar] ~18-~18: Ensure spelling is correct
Context: ... RUNS=3 EXTRA_RUNS=5 复验中达到 <0.5x vs Lua;但当前 full-suite `RUN_AOT=1 RUNS=1 EXTRA_RUNS...

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)


[grammar] ~39-~39: Ensure spelling is correct
Context: ...bash bench/run_workload_bench.sh ``` - suite:20 项 workload,包含 customer/event/config/tem...

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)


[grammar] ~174-~174: Ensure spelling is correct
Context: ...val;对未注解参数派生局部变量的 compound assignment 类型约束缺口。 -examples/syntax/*.lk` 已在 30 秒单文件 alarm 下复验通过,没有发现本轮 loop/opcode ...

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)


[grammar] ~325-~325: Ensure spelling is correct
Context: ...dex/SetIndex增加更直接的 typed map/list helper。 2. 减少RuntimeMapKey构造、heap kind 重复判断和Res...

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)


[grammar] ~326-~326: Ensure spelling is correct
Context: ...timeMapKey构造、heap kind 重复判断和Result` 错误路径污染。 3. 对 string key 和 short-string path 做循环内复用或 ...

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)

OPCODE.md

[uncategorized] ~69-~69: 您的意思是“"不"齐”?
Context: ...sets_top 可在新增 operand-shape opcode 前继续补齐。这样 opcode 空间已变成 128,C 回到 8 bit,并保留 `...

(BU)


[uncategorized] ~84-~84: 您的意思是“"不"走”?
Context: ...atch 也已改成 tight next-op bounds check,避免每步走 code.get(...).map(...)。此前默认 VM 样本 `R...

(BU)


[uncategorized] ~305-~305: 您不可用“是”来表达个形容词。大部分人都平常用“很”来代替“是”。您是不是想表达"很短"?
Context: ...确认 target 是 Map 时,跳过当前 handler 开头“key 是短 List slice 描述”的罕见 probe。该候选不改变 bytecode...

(SHI_ADHECTIVE_ERROR)


[uncategorized] ~358-~358: 您的意思是“"不"齐”?
Context: ...s 和 LLVM scalar lowering。 encoding 稳定后再补齐: - ForPrepI 完整 loop opcode 组合对应 Lu...

(BU)

🪛 markdownlint-cli2 (0.22.1)
README.md

[warning] 45-45: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below

(MD022, blanks-around-headings)

🪛 Shellcheck (0.11.0)
bench/run_workload_bench.sh

[warning] 20-20: Use single quotes, otherwise this expands now rather than when signalled.

(SC2064)


[warning] 390-390: This redirection doesn't have a command. Move to its command (or use 'true' as no-op).

(SC2188)


[warning] 391-391: This redirection doesn't have a command. Move to its command (or use 'true' as no-op).

(SC2188)


[warning] 392-392: This redirection doesn't have a command. Move to its command (or use 'true' as no-op).

(SC2188)


[warning] 472-472: This redirection doesn't have a command. Move to its command (or use 'true' as no-op).

(SC2188)


[warning] 500-500: This redirection doesn't have a command. Move to its command (or use 'true' as no-op).

(SC2188)


[warning] 501-501: This redirection doesn't have a command. Move to its command (or use 'true' as no-op).

(SC2188)


[warning] 502-502: This redirection doesn't have a command. Move to its command (or use 'true' as no-op).

(SC2188)

🔇 Additional comments (59)
.gitignore (1)

5-18: LGTM!

Cargo.toml (2)

39-41: LGTM!


18-18: 评估 toml 从 0 → 1 升级的破坏性影响(现有调用点)

Cargo.toml 已将 toml 升级为 toml = "1"。仓库内对 toml 的使用主要集中在:

  • core/src/val/de.rstoml::from_str::<toml::Value>(...) 解析后按 toml::Value::{String,Integer,Float,Boolean,Datetime,Array,Table} 分支处理
  • core/src/package.rstoml::from_str 解析 manifest/lockfile;toml::to_string_pretty 序列化写回
  • core/src/llvm/output.rs:基于 toml::Value 分支,并使用 value.parse::<toml::Table>()

需要重点确认在 toml 1 下上述解析/序列化路径(尤其是 Datetime/Table/数组)与现有逻辑行为一致,并通过构建与测试覆盖 manifest/lockfile 读写及配置解析流程。

Makefile (2)

20-22: LGTM!


17-18: 确认 debug-lsp-ext 目标依赖脚本已存在:无需补充添加

debug-lsp-ext 目标调用的 ./scripts/debug-vscode-lsp.sh 在仓库中已存在(且为可执行文件),因此该依赖缺失的问题不成立。

core/Cargo.toml (3)

2-10: LGTM!


16-16: LGTM!


33-36: LGTM!

OPCODE.md (1)

1-381: LGTM!

README.md (2)

57-74: LGTM!


78-90: LGTM!

README.zh-CN.md (2)

46-62: LGTM!


66-78: LGTM!

STATUS.md (1)

1-381: LGTM!

bench/README.md (1)

1-652: LGTM!

bench/workloads_business_algorithms.lk (1)

1-630: LGTM!

bench/workloads_business_algorithms.lua (1)

1-612: LGTM!

cli/src/coverage.rs (1)

1-156: LGTM!

cli/src/diagnostic.rs (1)

1-47: LGTM!

cli/src/main.rs (3)

570-617: LGTM!


648-684: LGTM!


713-865: LGTM!

cli/src/paths.rs (3)

15-27: LGTM!


33-50: LGTM!


52-207: LGTM!

cli/src/pkg.rs (3)

61-95: LGTM!


97-131: LGTM!


173-210: LGTM!

cli/src/main_test.rs (1)

156-247: LGTM!

cli/src/repl.rs (5)

4-13: LGTM!


112-124: LGTM!


209-240: LGTM!


219-219: LGTM!

Also applies to: 229-229


245-252: LGTM!

cli/tests/compile_cli_test.rs (5)

7-39: LGTM!


41-107: LGTM!


109-905: LLVM 测试中的工具路径设置是刻意为之。

多个 LLVM 测试(如第 141、252、436 行等)将 RUSTCLK_CLANG 环境变量设置为不存在的路径。这是刻意设计,用于强制特定的代码路径执行,避免依赖外部工具。这种做法在集成测试中是合理的。


163-217: LGTM!


987-1029: LGTM!

cli/tests/type_system_cli_test.rs (1)

11-11: LGTM!

Also applies to: 21-21

core/src/ast/ast_test.rs (1)

1-595: LGTM!

core/src/ast/parser.rs (1)

1-1332: LGTM!

core/src/expr/match_test.rs (1)

1-196: LGTM!

core/src/lib.rs (1)

1-21: LGTM!

core/src/llvm/backend.rs (1)

1-83: LGTM!

core/src/expr.rs (1)

2-2: LGTM!

core/examples/dump_bc.rs (1)

1-66: LGTM!

core/examples/fib_inner.rs (1)

1-19: LGTM!

core/src/llvm.rs (1)

1-30: LGTM!

core/src/expr/expr_impl.rs (4)

603-603: 确认:表达式级块不进行常量折叠

Expr::Block 在常量折叠时直接返回自身,不对内部语句进行折叠。这是正确的设计,因为语句级的折叠需要执行上下文,在表达式折叠阶段无法安全进行。

LGTM!


440-450: 确认:访问表达式的折叠保留策略正确

当字段为字符串字面量时,代码有意保留 Access 结构而不将其折叠为具体值。注释清楚地解释了原因:这样可以让后续的方法调用语法(如 foo.bar())能够正确拦截并进行元方法分发。如果将 foo.bar 折叠为具体值(如 Int),则后续调用会尝试调用非函数值而失败。

这是一个深思熟虑的设计决策。

LGTM!


800-840: 字符串拼接优化实现得当

fold_literal_add 中对字符串拼接的处理使用了 itoa::Bufferryu::Buffer 进行高效的整数/浮点数格式化,避免了 format! 宏的开销。代码覆盖了所有字符串与数值类型的组合,实现完整且高效。

LGTM!


33-49: 序列化移除影响:代码库内未见对相关类型的直接 serde 依赖,但仍需补做类型推断场景排查

core/src/expr/expr_impl.rs(含后续相应区段)对应的 Expr / Pattern / MatchArm / SelectCase / SelectPattern 上,core/src/expr/* 未发现 Serialize/Deserialize 派生或 serde::Serialize/serde::Deserialize trait bound;全仓 core/src 里也未发现 serde_json/bincode/ron/toml 的显式序列化调用与这些类型名相邻的用法。
仍建议人工再扫一遍 serde_json::to_* / bincode::serialize 等调用点,确认实参的静态类型是否为上述类型(类型推断时类型名可能不会出现在调用文本中),并评估对外部 API 的兼容性与迁移说明。

core/src/expr/pattern_impl.rs (1)

1-59: LGTM!

core/examples/dump_lkm.rs (1)

1-17: LGTM!

core/examples/dump_loop.rs (1)

1-25: LGTM!

core/src/expr/expr_test.rs (2)

295-347: 测试基础设施迁移设计合理

新的测试辅助函数将表达式测试从直接求值(eval_with_ctx)迁移到完整脚本执行(execute_source)。这种方式更接近实际使用场景,且辅助函数 expectexpect_envpanic_envpanic 提供了清晰的测试意图表达。

LGTM!


417-431: 常量折叠验证测试覆盖得当

测试用例正确验证了模板字符串的常量折叠行为:纯常量模板被折叠为单一 Expr::Literal,而包含变量插值的模板保持为 Expr::TemplateString。这确保了常量折叠优化不会影响动态插值的语义。

LGTM!

core/src/expr/match_parsing_test.rs (1)

1-254: LGTM!

Comment thread bench/run_workload_bench.sh Outdated
Comment thread bench/run_workload_bench.sh Outdated
Comment thread cli/Cargo.toml
toml = { workspace = true }
clap = { version = "4", features = ["derive"] }
rustyline = "17"
rustyline = "18"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# 搜索 rustyline 的使用
rg -n --type=rust 'use.*rustyline' cli/src/ -A2 -B1

# 查找可能受影响的 Editor/Config API
rg -n --type=rust 'Editor|ReadlineError|Config' cli/src/repl.rs -C2

Repository: lollipopkit/lk

Length of output: 893


🌐 Web query:

What are the breaking changes between rustyline 17 and 18?

💡 Result:

The transition from rustyline 17 to 18 (released March 29, 2026) introduced several significant changes, primarily focused on internal refactoring, dependency updates, and improved terminal handling [1]. While there is no singular dedicated "breaking changes" document, the key areas of impact that likely require user code adjustments include: New Prompt Trait: A major addition is the introduction of the Prompt trait [1]. This trait is used for styling the prompt, which may require updates to existing implementations that manage or display prompts [1]. Dependency Updates: Rustyline 18 significantly updated its underlying dependencies, which may necessitate compatibility checks for projects using these libraries alongside rustyline [1]: - nix updated to 0.31 [1]. - signal-hook updated to 0.4 [1]. - rand updated to 0.10 [1]. - skim updated to 3.3.0 [1]. - radix_trie updated to 0.3 [1]. Windows Terminal Behavior: There were specific changes to how prompts are styled and handled on Windows to avoid conflicts, particularly regarding styled prompts [1]. Internal Refactorings: - Signal Handling: The internal mechanism for signal handling was refactored, and signal handlers are now only installed when the library is actively reading input [1]. - File Locking: The crate moved from the fd-lock dependency to using standard library File::lock functionality [1]. - Partial Repaint: Support for minimal/partial repainting was introduced, which might affect custom UI components if they rely on full-line refreshing behavior [1]. To migrate from 17 to 18, users should review their use of the Prompt trait, verify compatibility with the updated dependency versions listed above, and test signal handling if their application relies on specific low-level terminal behaviors [1]. You can view the full list of changes in the official release notes [1].

Citations:


检查 rustyline 17→18 升级对 REPL 的影响

  • 目前仅在 cli/src/repl.rs 中使用 rustyline::{DefaultEditor, error::ReadlineError},并调用 DefaultEditor::new()?、处理 ReadlineError::Interrupted/ReadlineError::Eof;重点核对 DefaultEditor::new() 的签名与 ReadlineError 相关变更是否与 rustyline 18 匹配(枚举项/错误类型是否有改动)。
  • rustyline 18 引入 Prompt trait:如代码存在自定义提示/渲染逻辑,需要确保已按新机制适配;同时核对中断/EOF 对应的终端/信号行为是否仍符合当前分支逻辑。
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cli/Cargo.toml` at line 32, 升级 rustyline 到 18 可能改变了 DefaultEditor::new
的签名、ReadlineError 枚举项和引入了 Prompt trait;在 cli/src/repl.rs 中检查并更新对
DefaultEditor::new() 的调用(确保错误处理或返回类型匹配新签名),核对并更新对 ReadlineError 的匹配分支(包括
Interrupted/Eof 名称或模块路径是否变动),并如果你实现或自定义提示/渲染逻辑,改用 rustyline 18 的 Prompt trait
实现或其新的提示 API;修复后运行 REPL 并验证中断/EOF 行为与之前一致。

Comment thread cli/src/main.rs
Comment on lines +237 to +262
fn vm_profile_line(metrics: VmRuntimeMetrics) -> String {
format!(
"VM profile: opcode_steps={} top_opcodes={} write_sources={} index_keys={} calls={} branches={} typed_branches={} containers={} list_ops={} map_ops={} string_ops={} val_clones={} heap_clones={} copy_policy_heap_clones={} register_copy_heap_clones={} local_copy_heap_clones={} local_load_heap_clones={} local_store_heap_clones={} const_load_heap_clones={} call_arg_heap_clones={} container_copy_heap_clones={}",
metrics.opcode_steps,
top_opcode_profile(&metrics),
top_register_write_source_profile(&metrics),
top_index_key_profile(&metrics),
metrics.call_ops,
metrics.branch_ops,
metrics.typed_branch_ops,
metrics.container_ops,
metrics.list_ops,
metrics.map_ops,
metrics.string_ops,
metrics.copy_policy_heap_clones,
metrics.copy_policy_heap_clones,
metrics.copy_policy_heap_clones,
metrics.register_copy_heap_clones,
metrics.local_copy_heap_clones,
metrics.local_load_heap_clones,
metrics.local_store_heap_clones,
metrics.const_load_heap_clones,
metrics.call_arg_heap_clones,
metrics.container_copy_heap_clones
)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

格式化字符串中存在重复/不一致的字段赋值。

Lines 251-260 中,多个不同的格式化字段都使用了 metrics.copy_policy_heap_clones

  • val_clones={}metrics.copy_policy_heap_clones
  • heap_clones={}metrics.copy_policy_heap_clones
  • copy_policy_heap_clones={}metrics.copy_policy_heap_clones

这很可能是复制粘贴错误。请检查这些字段应该对应哪些实际的 metrics 字段。例如,val_clones 可能应该聚合多个克隆计数器,或者使用其他独立的 metrics 字段。

🐛 建议核对正确的字段映射

请根据 VmRuntimeMetrics 的实际字段定义,确保每个格式化输出字段都使用了正确的 metric 值。可能需要类似这样的修正:

         metrics.opcode_steps,
         top_opcode_profile(&metrics),
         top_register_write_source_profile(&metrics),
         top_index_key_profile(&metrics),
         metrics.call_ops,
         metrics.branch_ops,
         metrics.typed_branch_ops,
         metrics.container_ops,
         metrics.list_ops,
         metrics.map_ops,
         metrics.string_ops,
-        metrics.copy_policy_heap_clones,
-        metrics.copy_policy_heap_clones,
+        // TODO: 确认 val_clones 应该使用哪个字段
+        // TODO: 确认 heap_clones 应该使用哪个字段
         metrics.copy_policy_heap_clones,
         metrics.register_copy_heap_clones,
         metrics.local_copy_heap_clones,
         metrics.local_load_heap_clones,
         metrics.local_store_heap_clones,
         metrics.const_load_heap_clones,
         metrics.call_arg_heap_clones,
         metrics.container_copy_heap_clones
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cli/src/main.rs` around lines 237 - 262, In vm_profile_line the format
string's placeholders for val_clones, heap_clones and copy_policy_heap_clones
are all passed metrics.copy_policy_heap_clones (a copy-paste bug); open the
VmRuntimeMetrics struct, identify the correct fields (e.g. metrics.val_clones
and metrics.heap_clones if present) and replace the duplicate arguments so the
nth argument matches the nth {} in the format string (keep top_opcode_profile,
top_register_write_source_profile, top_index_key_profile and the other metrics
in the same order). If val_clones should be an aggregate, compute it before the
format call and pass that value instead. Ensure the final argument list length
and order exactly match the placeholders in vm_profile_line.

Comment thread cli/src/main.rs
Comment thread core/src/expr/expr_impl.rs Outdated
Comment thread core/src/expr/expr_impl.rs
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 8, 2026

Copy link
Copy Markdown

Deploying lk-lang with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6218d23
Status: ✅  Deploy successful!
Preview URL: https://75a668b4.lk-d8q.pages.dev
Branch Preview URL: https://dev.lk-d8q.pages.dev

View logs

@lollipopkit
lollipopkit merged commit 551fa29 into main Jun 8, 2026
2 checks passed
@lollipopkit
lollipopkit deleted the dev branch June 8, 2026 09:40
lollipopkit added a commit that referenced this pull request Jul 7, 2026
…trait prescan 契约锁

review PR #17 发现的三项修复:

1. **chan.rs 持锁 raise → 永久死锁**(最重):raise 走 longjmp 跳过
   Rust drop,存活的 MutexGuard 永不解锁。两处:
   - channel() 的 "Channel not found" raise 时 registry 全局锁 guard
     还在 match 临时值里活着(**当前可达**:try{recv(999)}catch 后
     一切 channel 操作死锁)→ 先 cloned() 出 Option 再 raise;
   - select send 臂在持 ChanInner state 锁时调用可 raise 的 own()
     (当前 tag 集下 latent)→ armed send 载荷进循环前预深拷,
     kind 预验证,循环内 fallback 改 unreachable。
   blocking send/recv 本就遵守 drop-before-raise 纪律——正是这纪律
   证明这两处是疏漏。纪律成文进 CLAUDE.md lkrt 段。

2. **trait prescan 形状契约锁**(J1 计划欠账):examples 差分对
   unsupported 静默 skip,compiler 改 impl 注册序列发射形状会静默
   丢 trait 覆盖。新 differential_trait_dispatch_contract 走
   run_differential(硬性要求 lower 成功)——形状漂移即红。

3. **CLAUDE.md**:lkrt 边界规则补 dev-dep lk-core(仅 order-
   conformance 测试)例外条款 + 锁跨 raise 硬规则。

新差分 ×3:trait 契约、chan 未知 id catch 后可用、select 闭 send
catch 后可用(2/3 是死锁回归测试,修前会挂死)。
留档不做(review findings #3/#5/#6):硬编码名单收拢进单表、
fixpoint 快照 clone 优化、select spin-poll 换 Condvar 多路等待。
门禁:50/51 · 差分 12/12 · workspace 0 · fuzz 150 · -D warnings
all-features 0 · clippy/fmt 0 · bench 见下
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