Skip to content

Declaration introspection: shapes, overload counts, template parameters and TU enumeration - #1102

Open
conrade-ctc wants to merge 5 commits into
compiler-research:mainfrom
chicagotrading:pr-g-decl-introspection
Open

Declaration introspection: shapes, overload counts, template parameters and TU enumeration#1102
conrade-ctc wants to merge 5 commits into
compiler-research:mainfrom
chicagotrading:pr-g-decl-introspection

Conversation

@conrade-ctc

Copy link
Copy Markdown
Collaborator

A consumer that mirrors C++ declarations meets five gaps in the API today. It reads a specialisation's template arguments, but cannot read the parameters a template declares. It cannot tell a scoped enum from an unscoped one, a union from a class, or an alias template from a class template. It cannot tell a definition from a forward declaration, nor see that a template parameter is a pack. It cannot count overloads, because GetFunctionsUsingName drops function templates. It cannot list what the interpreter has parsed, nor say which file and line a declaration comes from.

These five commits close the gaps and add tests to ScopeReflectionTest. Enumeration also replaces a separate parse: measured against a libclang parse of the same closure, the same declarations, 0.04s against 8.49s. The additions follow the API-extension style of #810, #1090, #1087 and #1093. The last commit is a small fix for llvm's virtual-FileEntry change; take it on its own if that merges faster.

@codecov

codecov Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.06%. Comparing base (9bbdbb2) to head (905b63e).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1102      +/-   ##
==========================================
+ Coverage   87.74%   88.06%   +0.31%     
==========================================
  Files          23       23              
  Lines        6429     6601     +172     
==========================================
+ Hits         5641     5813     +172     
  Misses        788      788              
Files with missing lines Coverage Δ
include/CppInterOp/CppInterOpTypes.h 96.93% <ø> (ø)
lib/CppInterOp/CppInterOp.cpp 90.99% <100.00%> (+0.44%) ⬆️
Files with missing lines Coverage Δ
include/CppInterOp/CppInterOpTypes.h 96.93% <ø> (ø)
lib/CppInterOp/CppInterOp.cpp 90.99% <100.00%> (+0.44%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@conrade-ctc
conrade-ctc force-pushed the pr-g-decl-introspection branch from 048e263 to 9131998 Compare September 1, 2026 18:27

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 10 out of 16. Check the log or trigger a new build to see more.

Comment thread lib/CppInterOp/CppInterOp.cpp Outdated
Comment thread lib/CppInterOp/CppInterOp.cpp Outdated
Comment thread lib/CppInterOp/CppInterOp.cpp
Comment thread lib/CppInterOp/CppInterOp.cpp
Comment thread lib/CppInterOp/CppInterOp.cpp
Comment thread unittests/CppInterOp/ScopeReflectionTest.cpp Outdated
Comment thread unittests/CppInterOp/ScopeReflectionTest.cpp Outdated
Comment thread unittests/CppInterOp/ScopeReflectionTest.cpp Outdated
Comment thread unittests/CppInterOp/ScopeReflectionTest.cpp Outdated
Comment thread unittests/CppInterOp/ScopeReflectionTest.cpp Outdated
@conrade-ctc
conrade-ctc force-pushed the pr-g-decl-introspection branch from 9131998 to 0060fd4 Compare September 1, 2026 21:11

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 10 out of 13. Check the log or trigger a new build to see more.

Comment thread unittests/CppInterOp/ScopeReflectionTest.cpp Outdated
Comment thread unittests/CppInterOp/ScopeReflectionTest.cpp Outdated
Comment thread unittests/CppInterOp/ScopeReflectionTest.cpp Outdated
Comment thread unittests/CppInterOp/ScopeReflectionTest.cpp Outdated
Comment thread unittests/CppInterOp/ScopeReflectionTest.cpp Outdated
Comment thread unittests/CppInterOp/ScopeReflectionTest.cpp Outdated
Comment thread unittests/CppInterOp/ScopeReflectionTest.cpp Outdated
Comment thread unittests/CppInterOp/ScopeReflectionTest.cpp Outdated
Comment thread unittests/CppInterOp/ScopeReflectionTest.cpp Outdated
Comment thread unittests/CppInterOp/ScopeReflectionTest.cpp
Emery Conrad added 2 commits September 2, 2026 08:14
The API could report a specialisation's template arguments but not the
parameters a template declares, which a caller mirroring a declaration needs:
the parameter's name, whether it stands for a type, a value or a template, and
its default if it has one.

GetNumTemplateParameters and GetTemplateParameter accept either the template or
the class or function it describes, so a caller that walked to a CXXRecordDecl
does not have to find the ClassTemplateDecl first. Parameters come back as
declarations, so the ordinary name accessors apply to them.
Five shapes a consumer mirroring declarations has to distinguish had no
accessor: scoped vs unscoped enum, union vs class, alias template vs class
template, parameter packs, and a definition vs a forward declaration.

GetOverloadCount counts function templates too, which GetFunctionsUsingName
drops.
@conrade-ctc
conrade-ctc force-pushed the pr-g-decl-introspection branch from 0060fd4 to 352b51f Compare September 2, 2026 13:31

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

Comment thread lib/CppInterOp/CppInterOp.cpp
Comment thread unittests/CppInterOp/ScopeReflectionTest.cpp Outdated
Comment thread unittests/CppInterOp/ScopeReflectionTest.cpp Outdated
Comment thread unittests/CppInterOp/ScopeReflectionTest.cpp Outdated
Emery Conrad added 3 commits September 3, 2026 11:58
EnumerateTranslationUnitDecls walks every partial translation unit the
interpreter has parsed, descending through namespaces, classes and language
linkage blocks. A linkage block is unnamed, so filtering to named declarations
at the top level alone drops extern "C" declarations entirely.

GetDeclFile, GetDeclLine and IsInSystemHeader attribute a declaration to its
source. They screen the location first. An interpreter accumulates declarations
whose offset lands in the loaded half of the SLoc space with no external source
behind it. Expanding one of those reads unallocated memory instead of reporting
a bad location.

Measured against a libclang parse of the same closure: the same declarations,
0.04s against 8.49s. Naming follows clang's qualified names, which differ from a
namespace-path walk in two ways -- inline namespaces are not spelled, and an
out-of-line member template definition is named for its class rather than its
lexical namespace.
Enumeration now descends class-template bodies and reports the PTU chain
in declaration order; GetNumTemplateParameters answers for partial
specializations; new predicates IsClassTemplate, IsImplicitDecl and
IsFriendDeclared.

Co-developed-with-the-help-of: Claude Code (Fable 5, human in the loop)
LLVM now registers each interpreter input buffer as a virtual FileEntry
with overridden contents. The no-FileEntry check no longer identifies
interpreter inputs, so also return "" for content-overridden entries.

Co-developed-with-the-help-of: Claude Code (Fable 5, human in the loop)
@conrade-ctc
conrade-ctc force-pushed the pr-g-decl-introspection branch from 352b51f to 905b63e Compare September 3, 2026 16:59
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.

1 participant