Skip to content

fix: resolve namespace while instantiating templates in a namespace #151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Vipul-Cariappa
Copy link
Collaborator

Enables instantiating templates f with type t without explicitly specifying the namespace in type t, if f and t belong to the same namespace.


Has a cyclic dependency with compiler-research/CPyCppyy#104

@@ -593,6 +593,17 @@ bool Cppyy::AppendTypesSlow(const std::string& name,
if (is_integral(i))
integral_value = strdup(i.c_str());
types.emplace_back(type, integral_value);
} else if (parent && (Cpp::IsNamespace(parent) || Cpp::IsClass(parent))) {
std::string qualified_name = Cpp::GetQualifiedCompleteName(parent) + "::" + name;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we replace that with a simple lookup without qualification.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nope, the lookup does not work without the qualification.

Copy link
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 what api we need to create to avoid string concatenation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I believe this is acceptable. We are only concatenating the parent scope with the child. There is nothing else going on here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why GetNamed(name, parent) does not work?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

GetNamed worked. I initially tried GetScope and it failed. I have pushed the changes.

@Vipul-Cariappa Vipul-Cariappa force-pushed the dev/instantiate-namespace branch from 2164192 to 7acfe70 Compare June 23, 2025 07:06
Copy link
Collaborator

@aaronj0 aaronj0 left a comment

Choose a reason for hiding this comment

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

LGTM! I would wait for Vassil's review to merge

@@ -607,22 +617,16 @@ Cppyy::TCppType_t Cppyy::GetType(const std::string &name, bool enable_slow_looku
if (auto type = Cpp::GetType(name))
return type;

if (!enable_slow_lookup) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that diagnostic is important to expose interfaces that still do parsing of qualified names.

Enables instantiating templates `f` with type `t` without explicitly specifying the namespace in type `t`, if `f` and `t` belong to the same namespace.
@Vipul-Cariappa Vipul-Cariappa force-pushed the dev/instantiate-namespace branch from 7acfe70 to fc231c5 Compare June 23, 2025 13:51
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.

3 participants