Skip to content
This repository was archived by the owner on Aug 5, 2026. It is now read-only.

Resolve templated type names as a whole in GetScope - #213

Merged
aaronj0 merged 1 commit into
compiler-research:masterfrom
guitargeek:tmva_test_issue
Jun 29, 2026
Merged

Resolve templated type names as a whole in GetScope#213
aaronj0 merged 1 commit into
compiler-research:masterfrom
guitargeek:tmva_test_issue

Conversation

@guitargeek

Copy link
Copy Markdown

GetScope used to split a templated name like "std::array<float, 3>" into the template "std::array" plus the argument list "float, 3", then feed that list to the all-types __Cppyy_AppendTypesSlow trampoline and instantiate the template from the result. That cannot represent non-type template arguments: the trampoline takes only types, so an argument such as the 3 in std::array<float, 3> forces a guaranteed compile failure. The failure is normally swallowed, but for arguments the string-parsing fallback can't recover (e.g. an enum constant printed as "(EOp)0"), the type fails to resolve and the resulting interpreter error state breaks the next, unrelated JIT call wrapper.

Resolve the full type expression through the trampoline instead and read its scope back with GetScopeFromType, so non-type arguments are handled and no failing instantiation is emitted.

Enables the test added in this PR:

@guitargeek

Copy link
Copy Markdown
Author

Failures are pre-existing failures also in other PRs like #212

Comment thread clingwrapper/src/clingwrapper.cxx Outdated

std::vector<Cpp::TemplateArgInfo> types;
InterOpMutex.unlock(); // unlock to allow AppendTypesSlow
bool no_new_type = Cppyy::AppendTypesSlow(name, types);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
bool no_new_type = Cppyy::AppendTypesSlow(name, types);
bool added_new_type = !Cppyy::AppendTypesSlow(name, types);

maybe that makes the reading slightly more straight-forward.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Changed.

Comment thread clingwrapper/src/clingwrapper.cxx Outdated
// std), retry with the parent's qualification prepended.
if (no_new_type && !parent_name.empty()) {
types.clear();
no_new_type = Cppyy::AppendTypesSlow(parent_name + "::" + name, types);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We need to figure out how to avoid concatenating strings here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good point! I moved the string concatenation to AppendTypesSlow, so that we're sure the string concatenation is localized to that function.

Comment thread clingwrapper/src/clingwrapper.cxx Outdated
// std), retry with the parent's qualification prepended.
if (no_new_type && !parent_name.empty()) {
types.clear();
no_new_type = Cppyy::AppendTypesSlow(parent_name + "::" + name, types);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
no_new_type = Cppyy::AppendTypesSlow(parent_name + "::" + name, types);
no_new_type = Cppyy::AppendTypesSlow(name, types, /*parent=*/parent_scope);

I believe this is what you meant?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Only that this doesn't work with the current implementation of AppendTypesSlow (see other comment)

@guitargeek
guitargeek force-pushed the tmva_test_issue branch 2 times, most recently from b0198e3 to 62c042c Compare June 28, 2026 08:50
GetScope used to split a templated name like "std::array<float, 3>"
into the template "std::array" plus the argument list "float, 3", then
feed that list to the all-types __Cppyy_AppendTypesSlow trampoline and
instantiate the template from the result. That cannot represent non-type
template arguments: the trampoline takes only types, so an argument such
as the `3` in std::array<float, 3> forces a guaranteed compile failure.
The failure is normally swallowed, but for arguments the string-parsing
fallback can't recover (e.g. an enum constant printed as "(EOp)0"), the
type fails to resolve and the resulting interpreter error state breaks
the next, unrelated JIT call wrapper.

Resolve the full type expression through the trampoline instead and read
its scope back with GetScopeFromType, so non-type arguments are handled
and no failing instantiation is emitted.

The trampoline declares its variable in the global scope, so a name
written relative to a parent scope (e.g. "vector<int>" looked up in std)
would no longer be found. Honor the parent that AppendTypesSlow already
accepts: when the name doesn't resolve as given, retry the trampoline
declaration with the parent's qualification prepended.

Naming a type as a template argument does not instantiate it, so the
resolved specialization may be declared but undefined. Earlier the
InstantiateTemplate call completed it; restore that guarantee with an
explicit IsComplete, since callers expect a complete scope (e.g. to walk
its base classes) and would otherwise hit an assertion on an incomplete
class.

@vgvassilev vgvassilev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Lgtm! Let’s wait for @Vipul-Cariappa for the lock/unlock part.

@Vipul-Cariappa Vipul-Cariappa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants