Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/Interpreter/CppInterOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1004,8 +1004,9 @@
continue;
#endif

// FIXME : first score based on the type similarity before forcing
// TODO(aaronj0) : first score based on the type similarity before forcing
// instantiation.

TCppFunction_t instantiated =
InstantiateTemplate(candidate, arg_types.data(), arg_types.size());
if (instantiated)
Expand All @@ -1018,6 +1019,19 @@
explicit_types.size());
if (instantiated)
return instantiated;

// join explicit and arg_types
std::vector<TemplateArgInfo> total_arg_set;
total_arg_set.reserve(explicit_types.size() + arg_types.size());
total_arg_set.insert(total_arg_set.end(), explicit_types.begin(),
explicit_types.end());
total_arg_set.insert(total_arg_set.end(), arg_types.begin(),
arg_types.end());

instantiated = InstantiateTemplate(candidate, total_arg_set.data(),
total_arg_set.size());
if (instantiated)
return instantiated;

Check warning on line 1034 in lib/Interpreter/CppInterOp.cpp

View check run for this annotation

Codecov / codecov/patch

lib/Interpreter/CppInterOp.cpp#L1034

Added line #L1034 was not covered by tests
}
return nullptr;
}
Expand Down
11 changes: 10 additions & 1 deletion unittests/CppInterOp/FunctionReflectionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ TEST(FunctionReflectionTest, BestTemplateFunctionMatch) {
template<class A> long get_size(A&);
template<class A> long get_size();
template<class A, class B> long get_size(A a, B b);
template<class A> long add_size(float a);
};

template<class A>
Expand All @@ -609,6 +610,11 @@ TEST(FunctionReflectionTest, BestTemplateFunctionMatch) {
return sizeof(A) + 1;
}

template<class A>
long MyTemplatedMethodClass::add_size(float a) {
return sizeof(A) + long(a);
}

template<class A, class B>
long MyTemplatedMethodClass::get_size(A a, B b) {
return sizeof(A) + sizeof(B);
Expand All @@ -626,21 +632,24 @@ TEST(FunctionReflectionTest, BestTemplateFunctionMatch) {
std::vector<Cpp::TemplateArgInfo> args0;
std::vector<Cpp::TemplateArgInfo> args1 = {C.IntTy.getAsOpaquePtr()};
std::vector<Cpp::TemplateArgInfo> args2 = {C.CharTy.getAsOpaquePtr(), C.FloatTy.getAsOpaquePtr()};
std::vector<Cpp::TemplateArgInfo> args3 = {C.FloatTy.getAsOpaquePtr()};

std::vector<Cpp::TemplateArgInfo> explicit_args0;
std::vector<Cpp::TemplateArgInfo> explicit_args1 = {C.IntTy.getAsOpaquePtr()};


Cpp::TCppFunction_t func1 = Cpp::BestTemplateFunctionMatch(candidates, explicit_args0, args1);
Cpp::TCppFunction_t func2 = Cpp::BestTemplateFunctionMatch(candidates, explicit_args1, args0);
Cpp::TCppFunction_t func3 = Cpp::BestTemplateFunctionMatch(candidates, explicit_args0, args2);
Cpp::TCppFunction_t func4 = Cpp::BestTemplateFunctionMatch(candidates, explicit_args1, args3);

EXPECT_EQ(Cpp::GetFunctionSignature(func1),
"template<> long MyTemplatedMethodClass::get_size<int>(int &)");
EXPECT_EQ(Cpp::GetFunctionSignature(func2),
"template<> long MyTemplatedMethodClass::get_size<int>()");
EXPECT_EQ(Cpp::GetFunctionSignature(func3),
"template<> long MyTemplatedMethodClass::get_size<char, float>(char a, float b)");
EXPECT_EQ(Cpp::GetFunctionSignature(func4),
"template<> long MyTemplatedMethodClass::get_size<float>(float &)");
}

TEST(FunctionReflectionTest, IsPublicMethod) {
Expand Down
Loading