Skip to content

Borrow checker reborrows, SMP shadowing fix, split large source files - #2

Merged
JiTianYu391 merged 5 commits into
mainfrom
claude/fervent-darwin-wimez2
Oct 20, 2026
Merged

JiTianYu391 merged 5 commits into
mainfrom
claude/fervent-darwin-wimez2

Conversation

@JiTianYu391

Copy link
Copy Markdown
Contributor

Summary

  • Split borrow.cpp, sema.cpp, codegen.cpp and mir.cpp into 21 focused translation units (largest now ~650 lines), with shared helpers in src/*_internal.hpp. LLVM IR for all 57 examples and tests is byte-identical before and after.
  • Borrow checker:
    • implicit reborrow when a mutref is passed to a mutref parameter (inc(r); inc(r)); reusing it in the same argument list conflicts, and calls whose result may carry a reference keep the move semantics;
    • explicit borrow [mut] deref r reborrows, including nested ones and ones through reference parameters; the parent stays frozen while the reborrow is live;
    • writes through references (deref r = v) are now checked against live loans and moves (previously unchecked).
  • SMP: a local or parameter that shadows a mutable global is no longer reported as a global access (E0363); the call-graph and shared-state checks now share one AST traversal instead of two hand-copied ones (sema_smp.cpp 372 -> 217 lines).
  • Semantic change: consume(first); consume(first) on a mutref is now accepted (a reborrow, as in Rust). tests/safety/borrow-fail/mutable_ref_move.ux now uses a real move (val second = first) and still fails with E0400.
  • 16 new tests (4 pass, 10 borrow-fail, 1 SMP pass, 2 SMP-fail); docs and CHANGELOG updated.

Checklist

  • ctest --preset ci passes locally (GCC 13, -Werror, 20/20)
  • ctest --preset asan passes locally (20/20)
  • clang-format is clean (format-check)
  • New language behavior has tests under tests/
  • User-visible changes recorded in CHANGELOG.md

Not in this PR: lock-guarded data types, init-once globals, and method calls on generic-bounded receivers (design work, noted for follow-up).


Generated by Claude Code

…ter-free

- Add CMakePresets.json, GitHub Actions CI, issue/PR templates, CONTRIBUTING,
  .editorconfig and .gitattributes
- Move ARCHITECTURE.md and BUILD.md to docs/; move test registration into
  tests/CMakeLists.txt
- Add UINX_WARNINGS_AS_ERRORS and UINX_ENABLE_SANITIZERS options
- Remove stale MANIFEST.sha256 (35 of 159 entries no longer matched) and the
  checked-in verification transcripts that contradicted their own README
- Fix heap-use-after-free in Type::operator= when assigning from an owned
  pointee (found by ASan), and a -Wconversion warning in codegen
- Apply clang-format to files that had drifted

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018uUuRXQcBduAQvVUcJYkWz
Pure move, no behavior change. borrow.cpp (1894 lines), sema.cpp (1795) and
codegen.cpp (1881) are split by responsibility; helpers formerly in anonymous
namespaces move to src/*_internal.hpp. LLVM IR and diagnostics for all 56
examples/tests are byte-identical before and after.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018uUuRXQcBduAQvVUcJYkWz
…erences

- Passing a mutref place to a mutref parameter reborrows it for the call
  instead of moving it; reusing it in the same argument list conflicts, and
  calls whose result may carry a reference keep the move semantics.
- 'borrow [mut] deref r' reborrows through r: the new reference inherits r's
  origins without conflicting with r's own loans, and r and every ancestor stay
  frozen while the reborrow is live. Reference parameters are tracked through
  an external origin.
- 'deref r = v' is now checked against loans on r and rejects a moved r.
- mutable_ref_move now uses a real move ('val second = first'); consuming the
  same mutref twice is a reborrow and valid, as in Rust.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018uUuRXQcBduAQvVUcJYkWz
- E0363 no longer fires for a local or parameter that shadows a mutable
  global (name resolution via HIR instead of string lookup).
- The call-graph and shared-state checks used two hand-copied AST traversals;
  both now use for_each_child_expr/walk_stmt_exprs (sema_smp.cpp 372 -> 217
  lines).
- Split mir.cpp into lowering, statement, expression and optimizer units.
- Tests for shadowing and for walker coverage (loop condition, cast).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018uUuRXQcBduAQvVUcJYkWz
# Conflicts:
#	CHANGELOG.md
#	src/codegen.cpp
#	src/mir.cpp
@JiTianYu391
JiTianYu391 merged commit 82dd6dd into main Oct 20, 2026
4 checks passed
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