Repository navigation
fix(resolve): follow C++ member chains through four more declaration shapes - #514
Merged
Merged
Conversation
…shapes
A call on a member reached through another member now links to the
member's class when the class or the object is declared in one of the
ways google/leveldb writes them:
- a nested class defined out of line, `struct DBImpl::CompactionState {`,
whose qualified name the field lookup did not match;
- a global struct whose member's type comes in through
`using leveldb::WriteBatch;`;
- a local built with call syntax, `SharedState shared(n);`, which
tree-sitter reads as a function declaration; it now counts as an object
when every "parameter" is a name a declaration in scope binds as a
variable, replacing the smart-pointer-only special case;
- a class written with an attribute macro, `class SCOPED_LOCKABLE
MutexLock`, `struct LEVELDB_EXPORT Options`; the resolver's re-parse now
blanks class-head macros as extraction's pre-parse does.
…no project method
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.
On google/leveldb (bb74ef7), this change adds 141 correct C++ call links and removes or moves none. It covers calls on a member reached through another member, like
compact->compaction->level()andshared.mu.Lock(), in four places leveldb declares the class or the object. The fork linked none of the 109 such calls before. It now links 104 of them the way upstream (e8ec7fd) does, and 5 more correctly where upstream is wrong or has no link.What each fix does
struct DBImpl::CompactionState { … };, the member lookup compared the class's name with a qualified name,DBImpl::CompactionState, so it never matched. It now reads the last part of that name.struct leveldb_writebatch_t { WriteBatch rep; };afterusing leveldb::WriteBatch;. A written member type that isn't visible as-is is now looked up through theusingdeclarations above it, the same lookup local variables already use.SharedState shared(n);as a function declaration. It now counts as an object of that type when every "parameter" is a bare name that a declaration in scope binds as a variable. C++ itself cannot read a name it finds as a variable as a type. This replaces the narrowerstd::unique_ptr/std::shared_ptrspecial case.Shared shared(Config);, withConfiga type, still counts as a function declaration, and a name the resolver can't place still blocks the reading.class SCOPED_LOCKABLE MutexLock {orstruct LEVELDB_EXPORT Options {, extraction blanks the macro before parsing, but the resolver's own re-parse did not, so tree-sitter took the macro for the class's name. The resolver's re-parse now blanks class-head macros with the same rules extraction uses (a port ofblankCppExportMacros): a body or base list must follow, it handlesfinaland template arguments, and it leaves preprocessor lines and forward declarations alone.The 5 calls where the fork and upstream differ:
rep_->index_block->NewIterator(…)attable.cclines 210, 218 and 246 now reachesBlock::NewIterator, where upstream reachesTable::NewIteratorbecauseindex_blockis aBlock*.table.cc:102,rep_->options.filter_policy->Name(), reachesFilterPolicy::Name, anddb_impl.cc:892reachesVersionEdit::AddFile. Upstream links neither.Verification
__tests__/cpp-member-chain-declarations.test.tshas one test per shape, each against aDecoyclass with methods of the same names: "reads a member of a struct defined out of line as a nested class", "reads a member of a global struct whose type a using-declaration brings in", "reads a local constructed with call syntax when its arguments are variables" and "reads a member of a class written with an attribute macro". All 4 fail on the unfixed kernel and pass with the fix. The Rust unit testblanks_class_head_macros_before_a_body_or_base_listcovers the macro blanking, with 6 cases that blank and 5 that stay as written.Iteratormethods reached throughclass LEVELDB_EXPORT Iterator,EnvWrapper'starget_->…calls andtable_test.cc'sBlock block(contents);.c.cc),BlockBasedTableBuilder::Repand the cache'sALIGN_AS(…)handles. Twelve sampled sites I read in the source were all correct, for examplestd::vector<VersionEdit> edits(n),WriteThread write_thread(db_options),FaissIVFIndex::KNNContextand gtest'sTestInfo.eval:precision, which checks a fixed set of links that must exist and must not): jq stays at 5,307 call edges, unchanged. json goes from 12,722 to 12,741 call edges (+19, 0 removed). The checked links held both times: all 11 that must not exist and all 7 that must. Of the 19, 16 arecit.key()/cit.value()inunit-iterators1.cppthroughjson j_const(j);, and 3 are doctest'sString::c_strthroughclass DOCTEST_INTERFACE String. I deleted the result files the runs wrote.__tests__/cpp-member-chain-outside-calls-fork.test.ts, next to upstream's outside-calls file:void RawPointer(std::string* out) { out->clear(); }with a projectBuffer::clear()has no calls edge toBuffer::clear, and a control,b->clear()on aBuffer*, still links to it. It passes with and without this fix, so the fork already handles it.UPDATE_GOLDEN=1, no.dumpchanged.Native stack traceorWorker exited unexpectedlyin its output.npx tsc,npm run check:agent-docsandcargo clippy --release --lib -- -D warningspass.README rows checked: the "About this fork" C++ rows on aliases,
->on smart pointers, the types ofautolocals, chained calls and data members, namespace lookup, and object creation. This change makes none of them wrong and moves no number the README quotes, so the README is unchanged.Not covered
compact->current_output()->smallest.DecodeFrom(key)atdb_impl.cclines 1004 and 1006. The fork still guessesVersionEdit::DecodeFromby name; upstream reachesInternalKey::DecodeFrom.(*flist_)[index_]->largest.Encode()atversion_set.cc:191.state.cvar.Wait()onenv_test.cc's localRunState.Foo x(member_);. A member is not a proven variable, so this stays unread, as before.Summary by CodeRabbit
using, local objects initialized with call syntax, and classes with attribute macros.Shared shared(Config);continue to be treated as function declarations whenConfigis a type.