Repository navigation
fix(cpp): a call on an element read by subscript, statuses[i].IsNotFound(), calls the element's method - #2602
Merged
Merged
Conversation
…ound()`, calls the element's method The extractor records a call on a subscripted receiver, like `statuses[i].IsNotFound()`, `buffers[key].Flush()` or `iters[i]->Valid()`, by its bare name, which went to whichever class had a method of that name, and a local an element initializes (`auto& s = statuses[i]`) had no type. - C++ expression typing reads a subscript: an array's element, what a pointer points at, a library map's mapped value, a sequence's element, or what a class's `operator[]` returns. - Declarations record their array dimensions (locals, parameters and data members, also through an alias), so a subscript, `*arr`, `arr->` and a range-for over an array read the type the array is declared with. - The bare-name receiver reader takes subscripts after a name or `(*name)`, reading the line with its literals blanked. - Overload arguments use the same subscript typing: a map's `values[key]` is its value type, no longer a `std::pair`. A/B vs main, every changed site triaged: leveldb 12 removed, 14 added, 1 retargeted, 11 metadata-only; fmt 6/4/10/2; redis identical; rocksdb 513/292/843/807; protobuf 58/5/34/66. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary
This is the follow-up left after #2601: calls on an element read by subscript.
The extractor can't spell a subscripted receiver, so it records
statuses[i].IsNotFound(),buffers[key].Flush()anditers[i]->Valid()by their bare names. The name strategies then gave those calls to whichever class had a method of that name. Examples:values[i].c_str()andcolumn_family_names_[i].c_str()onstd::strings went to googletest'sFilePath::c_strat 0.9;first_key_result[0].columns()onPinnableAttributeGroups went toArenaWrappedDBIter::columns;message_generators_[i]->GenerateInterface(printer)went toImmutableMessageGeneratorrather than theMessageGeneratorthe vector holds.Separately, a local an element initializes (
auto& s = statuses[i],const auto& key = keys_[ki]) had no type.What changed:
Subscript typing: C++ expression typing (
cppSubscriptElement) now reads the element a subscript gives:RepeatedField/RepeatedPtrField/autovector);operator[]returns.It gives nothing for a
std::string'schar, or for a class whoseoperator[]the index doesn't hold.Arrays: declarations now record their array dimensions, which the type text doesn't show:
LRUCache shard_[kNumShards],std::vector<FileMetaData*> files_[kNumLevels],Status grid[2][3].*arr,arr->and a range-for over an array read the type the array is declared with.More receivers read from the source: fix(cpp): a call on the member of the pair a map's iterator points at,
it->second.Flush(), calls the value's method #2601's bare-name receiver reader (cppUnspelledReceiver) now takes any number of subscripts after a name or(*name).table[0][1].Flush(),(*m)[key].Flush(),cfs[i].first.Flush().buffers["a]b"]doesn't end the subscript.Overload arguments:
cppArgumentTypedrops its own one-levelname[i]reader for the shared subscript typing. A map'svalues[key]passed to an overloaded method is now its value type rather than astd::pair, and arrays, nested subscripts andoperator[]work there too.Validation
New test
__tests__/cpp-element-access-calls.test.ts(5 tests): all 5 fail on main and pass here.Mutations: switching off each part fails its test:
keys[i];operator[]: 1;*arr: 1;A/B (full index, main vs fix) on google/leveldb, fmtlib/fmt, redis (C control), facebook/rocksdb and protocolbuffers/protobuf.
size191,push_back60,c_str45,reset25,empty21, …std::string,std::vector,std::set,std::map,std::dequeandstd::unique_ptr.key.size()onconst auto& key = keys_[ki]over astd::vector<std::string>reachedSlice::sizeat 0.9.values[i].size()over astd::vector<TValue>.Slice256,WideColumn124,PinnableAttributeGroup102,IteratorBase88,PinnableWideColumns75,ColumnFamilyHandle61,Status53,DB47,WalFile31,TruncatedRangeDelIterator26,autovector25, …autovectoris reached formems_list[k]->size()over anautovectorofautovectorpointers.InternalKeyoverload ofInternalKeyComparator::Compare, forbottom_files[i]->largestarguments.fields[i]->number()andextensions[0]->full_name().FieldDescriptordeclares them in its class and defines them withPROTOBUF_DEFINE_ACCESSORmacros, so no node exists for them. Every removed edge pointed at another class's namesake, like C#'sFieldGeneratorBase::number. The rest are library calls.ZeroCopyInputStream,DescriptorDatabaseandEnumValueDescriptor; 66 metadata-only.files_[level].size()overstd::vector<FileMetaData*> files_[kNumLevels], which had been guessed asSlice::size.shard_[s].Insert(…)overLRUCache shard_[kNumShards],IteratorWrapper,files[i]->Read(…).MatcherBase,MatcherDescriberInterfaceandTestEventListener;Arrays: the first version read a class without an indexed
operator[]as an array of itself. The A/B showed where that misfires:std::vector<FileMetaData*> files_[kNumLevels]read one level too deep;PinnableSlice values[2]read aschars throughSlice::operator[].So arrays now come from the declarator instead. Between the two versions, 35 sites in leveldb and rocksdb changed, each toward the declared type.
Full suite: 7,160 passed, 0 failed (82 skipped).
Remaining, out of scope:
m.at(k).Foo()andv.front().Foo()chains, which need library containers' element-returning members;this->arr_[i].Foo(), which doesn't occur in the five repos.🤖 Generated with Claude Code