btreemap: route map .get/.get_mut to member call + e2e parity fixture - #21
Open
shuaimu wants to merge 1 commit into
Open
btreemap: route map .get/.get_mut to member call + e2e parity fixture#21shuaimu wants to merge 1 commit into
shuaimu wants to merge 1 commit into
Conversation
The transpiler was lowering `m.get(&k)` on `std::collections::BTreeMap` (and `HashMap`) through the slice-style `rusty::get(container, idx)` helper, which returns an `Option<element-by-index>` instead of `Option<&V>`. The consuming match arm then fails to compile (clang suppressed-error: "no viable conversion from `const rusty::BTreeMap<...>` to function return type `int32_t`"), and any callsite that destructures the wrong Option becomes unreachable for the @safe checker. Changes: * transpiler/src/codegen.rs: gate `.get`/`.get_mut` slice-style lowering on `!receiver_is_hashmap_like_expr` so map receivers fall through to regular method-call emission, which routes to `rusty::BTreeMap::get(K) -> Option<V&>` directly. Adds 3 codegen unit tests covering BTreeMap and HashMap `.get`/`.get_mut`. * src/main.rs: when analyzing a file marked `// Auto-generated by rusty-cpp-transpiler`, drop the in-module `rusty::*` runtime functions before analysis — those live in the rusty/* headers, are noise for the checker on transpiler-generated modules, and previously masked any real fixture-side violation behind ~250 lines of header-internal findings. Adds two `is_*` helpers and two unit tests. * src/parser/ast_visitor.rs: replace `SourceRange::tokenize()` with a thin source-slice lexer (`lex_cpp_token_spellings`) that returns `Vec<String>` spellings. libclang's `tokenize()` returns invalid token buffers for some generated module ranges and crashes the checker on the transpiled `.cppm` output; the direct-slice path side-steps that. Call sites are updated to the new return type. * tests/transpile_tests/btreemap: minimal Rust fixture exercising `BTreeMap::new`, `insert(K, V) -> Option<V>`, and `get(&K) -> Option<&V>`. Built as a no-workspace `[lib]` so the parent workspace doesn't try to absorb it. * tests/transpile_tests/run_btreemap_check.sh (mode 0755): end-to-end harness — builds both binaries, transpiles the fixture, injects `// @safe` annotations on the three exported functions, and requires a clean `rusty-cpp-checker` exit on the annotated output. * .gitignore + tests/transpile_tests/.gitignore: track the new fixture assets and ignore the harness work dir (`.rusty-btreemap-check/`). Verified from a clean state of this branch — see the published scratchpad `kind:"diff"` record for the rerun results. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Owner
Author
|
This drags in a hand-written include/btree_port/btreemap.hpp, which does not sound right to me? |
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.
The transpiler was lowering
m.get(&k)onstd::collections::BTreeMap(and
HashMap) through the slice-stylerusty::get(container, idx)helper, which returns an
Option<element-by-index>instead ofOption<&V>. The consuming match arm then fails to compile (clangsuppressed-error: "no viable conversion from
const rusty::BTreeMap<...>to function return type
int32_t"), and any callsite that destructuresthe wrong Option becomes unreachable for the @safe checker.
Changes:
transpiler/src/codegen.rs: gate
.get/.get_mutslice-style loweringon
!receiver_is_hashmap_like_exprso map receivers fall through toregular method-call emission, which routes to
rusty::BTreeMap::get(K) -> Option<V&>directly. Adds 3 codegen unit tests covering BTreeMapand HashMap
.get/.get_mut.src/main.rs: when analyzing a file marked
// Auto-generated by rusty-cpp-transpiler, drop the in-modulerusty::*runtime functions before analysis — those live in therusty/* headers, are noise for the checker on transpiler-generated
modules, and previously masked any real fixture-side violation behind
~250 lines of header-internal findings. Adds two
is_*helpers andtwo unit tests.
src/parser/ast_visitor.rs: replace
SourceRange::tokenize()with athin source-slice lexer (
lex_cpp_token_spellings) that returnsVec<String>spellings. libclang'stokenize()returns invalidtoken buffers for some generated module ranges and crashes the
checker on the transpiled
.cppmoutput; the direct-slice pathside-steps that. Call sites are updated to the new return type.
tests/transpile_tests/btreemap: minimal Rust fixture exercising
BTreeMap::new,insert(K, V) -> Option<V>, andget(&K) -> Option<&V>. Built as a no-workspace[lib]so the parent workspacedoesn't try to absorb it.
tests/transpile_tests/run_btreemap_check.sh (mode 0755): end-to-end
harness — builds both binaries, transpiles the fixture, injects
// @safeannotations on the three exported functions, and requiresa clean
rusty-cpp-checkerexit on the annotated output..gitignore + tests/transpile_tests/.gitignore: track the new fixture
assets and ignore the harness work dir (
.rusty-btreemap-check/).Verified from a clean state of this branch — see the published
scratchpad
kind:"diff"record for the rerun results.Co-Authored-By: Claude Opus 4.7 noreply@anthropic.com