Skip to content

fix: exact return counts and scope-aware math-spec eligibility - #22

Merged
esrrhs merged 2 commits into
masterfrom
fix/return-count-scope-spec
Oct 2, 2026
Merged

esrrhs merged 2 commits into
masterfrom
fix/return-count-scope-spec

Conversation

@esrrhs

@esrrhs esrrhs commented Oct 2, 2026

Copy link
Copy Markdown
Owner

Summary

  • 尾返回按「前缀表达式个数 + 被调返回数」计算;return ... / return x, ... 记为未知。只有所有路径返回数一致时才保留精确值,否则调用点按多返回值展开。
  • return f() 按词法作用域解析被调。形参、局部变量,以及与文件级函数同名的嵌套 local function,不再套用文件级函数的返回数或数学特化。没有同名文件级函数、且嵌套函数精确返回 1 个值时,外层仍然可以特化。
  • 同名嵌套函数不再生成把 FlMakeMulti 放进 int64_t 特化函数的非法 C。C 代码生成和解释器都会调用局部绑定,而不是同名的文件级函数。

Test plan

  • infer.test_jitbug_vararg_passthrough:纯 return ... 在调用点展开
  • infer.test_jitbug_return_exact:return a, f() 精确计数,路径不一致时不特化
  • infer.test_jitbug_return_scope:同名嵌套函数 / 形参不特化,无同名嵌套函数仍可特化,运行结果为 62
  • 相关既有 infer 测试(test_spec_fib、test_spec_nested_call、test_count_loop 等)通过

Made with Cursor

esrrhs and others added 2 commits October 2, 2026 15:43
Tail returns use prefix plus callee count, vararg tails stay unknown, and a local or nested callee is not specialized or called as its file-level homonym.

Co-authored-by: Cursor <cursoragent@cursor.com>
var_to_def_map_.find(var_ptr) matches chunk-scoped file-level local functions as well, falsely treating them as local value bindings. This bypassed argument count validation and direct local function call compilation.
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 97.52650% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.86%. Comparing base (4e396e8) to head (0374b12).

Files with missing lines Patch % Lines
src/compile/semantic_analysis.cpp 97.59% 6 Missing ⚠️
src/compile/c_gen.cpp 96.77% 1 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #22      +/-   ##
==========================================
- Coverage   87.95%   87.86%   -0.09%     
==========================================
  Files         122      122              
  Lines       24482    24657     +175     
==========================================
+ Hits        21533    21666     +133     
- Misses       2949     2991      +42     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@esrrhs
esrrhs merged commit 598632f into master Oct 2, 2026
9 checks passed
@esrrhs
esrrhs deleted the fix/return-count-scope-spec branch October 2, 2026 09:31
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.

2 participants