Skip to content
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

[WIP] Converters not created for templated method arguments #211

Closed
aaronj0 opened this issue Mar 19, 2024 · 1 comment
Closed

[WIP] Converters not created for templated method arguments #211

aaronj0 opened this issue Mar 19, 2024 · 1 comment

Comments

@aaronj0
Copy link
Collaborator

aaronj0 commented Mar 19, 2024

Fails the vectorcall from TemplateProxies when calling the corresponding Executor (in CPyCppyy/Executors.cxx).
Reproducible example:

cppyy.cppdef('''class MyTemplatedMethodClass {
public:
template<class A>
long get_size(A) {
    return sizeof(A)+1;
}
''')

m = cppyy.gbl.MyTemplatedMethodClass()
m.get_size(1)

there are two issues here:
1 is not a priority which is the GetSmartPtrInfo interface which is missing but when we create converters for normal C++ classes it returns false anyway so most tests/usecases it will still work.

the second is the interesting bug. The converter creation for args relies on a loop over args that sets up the dispatch cache.
where we do fullType = GetMethodArgType(fMethod, iarg)
The cling implementation does

TFunction* f = m2f(method);
TMethodArg* arg = (TMethodArg*)f->GetListOfMethodArgs()->At((int)iarg);
std::string ft = arg->GetFullTypeName();

which will always return the C++ type of the arg with which we call the function.

For example if we do

m = cppyy.gbl.MyTemplatedMethodClass()
m.get_size(1)

it will be

arg->GetTypeNormalizedName()
$22 = "int"

but with m.get_size('A')

p fullType
$2 = "std::string"

But with clang this returns theParmVarDeclwhich for a templated parameter is ‘A’ in the case of

template<class A>
long get_size(A) {
	
    return sizeof(A)+1;
}

And we cannot create a converter passing a string type 'A'
I did think of one way to approach this. We look for the Clang::DeclStmt that should be created when the python side cppyy.obj.function(arg) is called.
Then we traverse the AST which should contain the CXXMemberCallExpr for the MemberExpr which is our bound member function get_size and the nodes would contain the types of the literals passed.
We get the normalised type and go from there. This should even work for multiple template parameters:

template<class A, class B>
long get_size(A, B) {
    return sizeof(A)+sizeof(B);
}|
long res = a.get_size(1.5, 'A');

CallExpr node will contain:

|-FloatingLiteral <col:27> 'double' 1.500000e+00
`-CharacterLiteral <col:32> 'char' 65 (edited) 
@aaronj0
Copy link
Collaborator Author

aaronj0 commented Apr 28, 2024

Closing as this is fixed with:

@aaronj0 aaronj0 closed this as completed Apr 28, 2024
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

No branches or pull requests

1 participant