Skip to content

[MRE] successive Declare fails if InstantiateFunctionDefinition fails in MakeFunctionCallable #616

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

Conversation

Vipul-Cariappa
Copy link
Collaborator

This is a bug report.

If the instantiation of a templated function fails while CodeGen (MakeFunctionCallable), then successive call to Cpp::Declare fails.
But a second call to Cpp::Declare will pass.

I suspect something similar to

#ifdef CPPINTEROP_USE_CLING
    cling::Interpreter::PushTransactionRAII RAII(&I);
#endif

is required?

Copy link
Contributor

github-actions bot commented Jun 6, 2025

clang-tidy review says "All clean, LGTM! 👍"

@Vipul-Cariappa Vipul-Cariappa marked this pull request as draft June 6, 2025 08:20
@Vipul-Cariappa Vipul-Cariappa changed the title [DO NOT MERGE] [MRE] successive Declare fails if InstantiateFunctionDefinition fails in MakeFunctionCallable [MRE] successive Declare fails if InstantiateFunctionDefinition fails in MakeFunctionCallable Jun 6, 2025
@Vipul-Cariappa
Copy link
Collaborator Author

Summary of conversion had over discord:
Declare does not print out any error.
The return code says it failed.
Stray Declare(" ") also fails.

@Vipul-Cariappa Vipul-Cariappa force-pushed the bug/InstantiateFunctionDefinition branch from c2130c8 to 58d155a Compare June 6, 2025 09:11
Copy link
Contributor

github-actions bot commented Jun 6, 2025

clang-tidy review says "All clean, LGTM! 👍"

Copy link

codecov bot commented Jun 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.18%. Comparing base (28abd17) to head (07e91ab).
Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #616      +/-   ##
==========================================
+ Coverage   78.00%   78.18%   +0.17%     
==========================================
  Files           9        9              
  Lines        3769     3781      +12     
==========================================
+ Hits         2940     2956      +16     
+ Misses        829      825       -4     
Files with missing lines Coverage Δ
include/CppInterOp/CppInterOp.h 100.00% <ø> (ø)
lib/CppInterOp/CXCppInterOp.cpp 48.86% <ø> (ø)
lib/CppInterOp/Compatibility.h 92.37% <100.00%> (+0.40%) ⬆️
lib/CppInterOp/CppInterOp.cpp 85.85% <100.00%> (+0.23%) ⬆️
Files with missing lines Coverage Δ
include/CppInterOp/CppInterOp.h 100.00% <ø> (ø)
lib/CppInterOp/CXCppInterOp.cpp 48.86% <ø> (ø)
lib/CppInterOp/Compatibility.h 92.37% <100.00%> (+0.40%) ⬆️
lib/CppInterOp/CppInterOp.cpp 85.85% <100.00%> (+0.23%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

github-actions bot commented Jun 6, 2025

clang-tidy review says "All clean, LGTM! 👍"

GeneratedPTU.takeError(), llvm::errs(),
"[MakeFunctionCallable -> InstantiateFunctionDefinition] Failed to "
"generate PTU:");
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to move this somewhere in InstantiateTemplate and replace S.InstantiateFunctionDefinition with it?

@Vipul-Cariappa Vipul-Cariappa marked this pull request as ready for review June 10, 2025 07:07
@Vipul-Cariappa Vipul-Cariappa force-pushed the bug/InstantiateFunctionDefinition branch from 58d155a to 65f2092 Compare June 10, 2025 07:42
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

Cpp::GetClassTemplatedMethods("is_equal", Cpp::GetGlobalScope(), fns);
EXPECT_EQ(fns.size(), 1);

Cpp::TemplateArgInfo args[2] = {{o1}, {o2}};
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: do not declare C-style arrays, use std::array<> instead [cppcoreguidelines-avoid-c-arrays]

  Cpp::TemplateArgInfo args[2] = {{o1}, {o2}};
  ^

EXPECT_EQ(fns.size(), 1);

Cpp::TemplateArgInfo args[2] = {{o1}, {o2}};
Cpp::TCppScope_t fn = Cpp::InstantiateTemplate(fns[0], args, 2);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit cast instead [cppcoreguidelines-pro-bounds-array-to-pointer-decay]

  Cpp::TCppScope_t fn = Cpp::InstantiateTemplate(fns[0], args, 2);
                                                         ^

@Vipul-Cariappa Vipul-Cariappa force-pushed the bug/InstantiateFunctionDefinition branch 2 times, most recently from 04cdcd5 to 35b6780 Compare June 13, 2025 08:32
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

@@ -376,6 +380,20 @@ namespace Cpp_utils = Cpp::utils;

namespace compat {
using Interpreter = Cpp::Interpreter;

class PushTransactionRAII {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: class 'PushTransactionRAII' defines a non-default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions]

class PushTransactionRAII {
      ^

Copy link
Contributor

Choose a reason for hiding this comment

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

The name should be something like SynthesizingCodeRAII or similar that tells the reader that we are producing ast nodes and require the codegen and the jit to know about it...

getSema().InstantiateFunctionDefinition(SourceLocation(), FD,
/*Recursive=*/true,
/*DefinitionRequired=*/true);
(void)Cpp::Interpreter::CompilationResult();
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "Cpp::Interpreter" is directly included [misc-include-cleaner]

lib/CppInterOp/CppInterOp.cpp:12:

+ #include "CppInterOpInterpreter.h"

@Vipul-Cariappa Vipul-Cariappa force-pushed the bug/InstantiateFunctionDefinition branch 3 times, most recently from 16ae2e9 to 9f0c48a Compare June 13, 2025 14:31
@Vipul-Cariappa Vipul-Cariappa force-pushed the bug/InstantiateFunctionDefinition branch from 9f0c48a to 688fb53 Compare June 16, 2025 08:11
add `InstantiateFunctionDefinition` function
@Vipul-Cariappa Vipul-Cariappa force-pushed the bug/InstantiateFunctionDefinition branch from 688fb53 to 07e91ab Compare June 16, 2025 13:01
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

@@ -376,6 +381,20 @@ namespace Cpp_utils = Cpp::utils;

namespace compat {
using Interpreter = Cpp::Interpreter;

class SynthesizingCodeRAII {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: class 'SynthesizingCodeRAII' defines a non-default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions]

class SynthesizingCodeRAII {
      ^

Copy link
Contributor

@vgvassilev vgvassilev left a comment

Choose a reason for hiding this comment

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

Should we replace more occurrences of PushTransactionRAII? LGTM!

@Vipul-Cariappa
Copy link
Collaborator Author

I have not replaced it in other places because clang does the necessary cleanup, and we need not explicitly compile code for the cleanup to take place. If I replace it in all the occurrences, it would hit performance.

@Vipul-Cariappa Vipul-Cariappa merged commit 49e6f4c into compiler-research:main Jun 16, 2025
50 checks passed
@Vipul-Cariappa Vipul-Cariappa deleted the bug/InstantiateFunctionDefinition branch June 16, 2025 15:20
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.

2 participants