Resolve templated type names as a whole in GetScope - #213
Conversation
a9fcc5b to
b4c6cd0
Compare
|
Failures are pre-existing failures also in other PRs like #212 |
|
|
||
| std::vector<Cpp::TemplateArgInfo> types; | ||
| InterOpMutex.unlock(); // unlock to allow AppendTypesSlow | ||
| bool no_new_type = Cppyy::AppendTypesSlow(name, types); |
There was a problem hiding this comment.
| 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.
| // 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); |
There was a problem hiding this comment.
We need to figure out how to avoid concatenating strings here.
There was a problem hiding this comment.
Good point! I moved the string concatenation to AppendTypesSlow, so that we're sure the string concatenation is localized to that function.
| // 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); |
There was a problem hiding this comment.
| 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?
There was a problem hiding this comment.
Only that this doesn't work with the current implementation of AppendTypesSlow (see other comment)
b0198e3 to
62c042c
Compare
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.
62c042c to
a2f913c
Compare
vgvassilev
left a comment
There was a problem hiding this comment.
Lgtm! Let’s wait for @Vipul-Cariappa for the lock/unlock part.
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
3in 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: