Repository navigation
fix(npa,npm): keep a typed C++ macro call inside parentheses a method - #1931
Merged
Merged
Conversation
A class-scope macro call inside a declarator's parentheses expands to
the name and parameter list of a method that returns a pointer to
function:
#define DECL(P) method(int P)
struct A { void (*DECL(S::*p))(int); };
// void (*method(int S::*p))(int);
// truth 0 attributes / 1 method; before this commit 1 / 0;
// before #1885 0 / 1
The call is a `function_declarator` named `DECL` whose parameter list
is a recovered member pointer, under a `pointer_declarator` inside a
`parenthesized_declarator`. Outside parentheses the same node is a
method when the declaration writes a type or opens with `[[noreturn]]`
(`void *DECL(S::*p);`, #1928). Inside them the first word was asked as
unsettled, so the call read as the data member its recovery would be
alone. `cpp_parenthesized_child_verdict` now carries the declaration's
first word through the parentheses, to a pointer, a reference, a member
pointer and a nested pair alike.
The cost is one family of data members. An annotation macro inside the
parentheses of a pointer to function or to member function, before a
parenthesised member pointer, is the tree of the call:
`int (* MOZ_X (S::*pd))(int);` and `int (S::* MOZ_X (S::*pd))(int);`
read as methods, as they did before #1885. Pinned FIXME(#1829). A call
after a type written as a lone identifier stays an attribute inside
parentheses as outside them (`T (*DECL(S::*p))(int);`, pinned).
Behind a member pointer inside parentheses the two grammars part on
three typedef names, as they did before #1885 and did not at 12f312a.
tree-sitter-cpp reads `intmax_t` and `uintmax_t` as identifiers and
the Mozcpp fork reads `nullptr_t` as one. Such a grammar recovers
`intmax_t (S::*DECL(S::*p))(int);` as a declaration with no type, where
no first word is settled, and reads the call and the annotated data
member `intmax_t (S::* MOZ_X (S::*pd))(int);` as data; the other
grammar reads both as methods. Pinned per grammar.
On generated spellings that g++ and clang++ accept, against 12f312a:
of 781 macro calls, 50 more read right (629 to 679) and none fewer; of
1,737 data members, 13 fewer read right (1,207 to 1,194), each of them
`TYPE (* MOZ_X (S::*pd))(int)` with or without `= nullptr`, and each
read as a method at e689d65 too.
Tests: `PARENTHESISED_MACRO_CALLS_WITH_MEMBER_POINTERS` (na 6 / nm 11;
without the change na 17 / nm 0). The pin
`PARENTHESISED_TYPED_MACRO_CALL_WITH_MEMBER_POINTER` is gone with the
misreading it recorded; `ANNOTATION_INSIDE_PARENTHESES_BEFORE_MEMBER_POINTER`
pins the cost, and `INTMAX_T_…` and
`NULLPTR_T_BEFORE_PARENTHESISED_MEMBER_POINTERS` the two grammars'
readings.
Refs #1829 #1885
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1931 +/- ##
=======================================
Coverage 98.57% 98.57%
=======================================
Files 407 407
Lines 127233 127276 +43
Branches 126798 126841 +43
=======================================
+ Hits 125420 125463 +43
Misses 1088 1088
Partials 725 725
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This branch was successfully deployed
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.
Refs #1829, #1885. Follow-up to #1928.
The bug
A class-scope macro call inside a declarator's parentheses expands to the name and parameter list of a method that returns a pointer to function.
npaandnpmread it as an attribute on both grammars (cppandmozcpp):Areads 1 attribute / 0 methods onmain12f312aa. The truth, and the reading before #1885, is 0 / 1.Since #1928 the same call outside parentheses (
void *DECL(S::*p);) is a method when the declaration writes a type or opens with[[noreturn]]. Inside parentheses the reader asked the first word as unsettled, so the call read as the data member its recovered member pointer would be alone.Fix
cpp_parenthesized_child_verdict(src/metrics/npa/cpp_declarators.rs) carries the declaration's first word through the parentheses: to a pointer, a reference, a member pointer and a nested pair of parentheses. No other reader changes.What moves
npaandnpmfor a typed macro call with a member-pointer argument inside a declarator's parentheses:class_methodsrises andclass_attributesfalls by one, with the values derived from them. No corpus snapshot moves.Cost and limits, pinned in the tests
FIXME(#1829)): an annotation macro inside the parentheses of a pointer to function or to member function, before a parenthesised member pointer, is the tree of the call.int (* MOZ_X (S::*pd))(int);andint (S::* MOZ_X (S::*pd))(int);read as methods, as they did before fix(npa,npm): a parenthesised pointer-to-data-member is counted as a method in C++ #1885.T (*DECL(S::*p))(int);, inside parentheses as outside them.intmax_tanduintmax_tas identifiers and the Mozcpp fork readsnullptr_tas one. Behind a member pointer inside parentheses, such a grammar recoversintmax_t (S::*DECL(S::*p))(int);as a declaration with no type and reads the call and the annotated data member as data; the other grammar reads both as methods. Each grammar reads these as it did before fix(npa,npm): a parenthesised pointer-to-data-member is counted as a method in C++ #1885; only12f312aahad the two agree (both read data).Review
No person has reviewed this pull request. The
reviewskill checklist, astra-review and argon-review read the first version (b5de0a93). argon-review found one untested path (a templated member pointer inside parentheses); astra-review found the grammar difference above and that the CHANGELOG claimed more than holds for those three names. Rows and pins were added; no production code changed. Both reviewers then read the amended commit390bcbc4and report no finding.Evidence
390bcbc4:make pre-commitgivesBCA_GATE: pass (gate=pre-commit);make check-test-lang-gates-compare COMPARE_REF=12f312aapasses;make bench-scaling: all 139 probes within their complexity bound. Two earlier runs failed at a host load average of 50 to 58, on different probes each time (2, then 10), none of them C++npaornpm; the run that passed was at a load average of about 4.12f312aa, same on both grammars: of 781 macro calls, 50 more read right (629 to 679) and none fewer; of 1,737 data members, 13 fewer read right (1,207 to 1,194), eachTYPE (* MOZ_X (S::*pd))(int)with or without= nullptr, and each read as a method ate689d658too.::*; 2,687 C++ files ofmozilla/gecko-devat5836a062; 8,244 classes): no class differs between12f312aaand390bcbc4.12f312aaand390bcbc4over the local fixture tree: 6,649 files (12,414 runs, both grammars), 97 runs differ and none changes status. All 3,333 class readings that moved go from attribute to method. 3,329 equal the reading ofe689d658; the other 4 are in two token-mutated files that are not C++.