-
Notifications
You must be signed in to change notification settings - Fork 36
[wip] [feature] timeit xmagic enabled for native and lite case #289
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
base: main
Are you sure you want to change the base?
Changes from all commits
ee97b3f
a5c5393
d2703cd
c3a0565
4771adb
6d08824
08621ec
989a66e
aebc3e7
265fba8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -17,6 +17,7 @@ | |||||
|
||||||
#include "xinput.hpp" | ||||||
#include "xinspect.hpp" | ||||||
#include "xmagics/execution.hpp" | ||||||
#include "xmagics/os.hpp" | ||||||
#ifndef EMSCRIPTEN | ||||||
#include "xmagics/xassist.hpp" | ||||||
|
@@ -26,47 +27,66 @@ | |||||
|
||||||
using Args = std::vector<const char*>; | ||||||
|
||||||
void* createInterpreter(const Args &ExtraArgs = {}) { | ||||||
Args ClangArgs = {/*"-xc++"*/"-v"}; // ? {"-Xclang", "-emit-llvm-only", "-Xclang", "-diagnostic-log-file", "-Xclang", "-", "-xc++"}; | ||||||
void* createInterpreter(const Args& ExtraArgs = {}) | ||||||
{ | ||||||
Args ClangArgs = {/*"-xc++"*/ "-v"}; // ? {"-Xclang", "-emit-llvm-only", "-Xclang", | ||||||
// "-diagnostic-log-file", "-Xclang", "-", "-xc++"}; | ||||||
#ifdef EMSCRIPTEN | ||||||
ClangArgs.push_back("-std=c++20"); | ||||||
ClangArgs.push_back("-std=c++20"); | ||||||
#else | ||||||
if (std::find_if(ExtraArgs.begin(), ExtraArgs.end(), [](const std::string& s) { | ||||||
return s == "-resource-dir";}) == ExtraArgs.end()) { | ||||||
std::string resource_dir = Cpp::DetectResourceDir(); | ||||||
if (resource_dir.empty()) | ||||||
std::cerr << "Failed to detect the resource-dir\n"; | ||||||
ClangArgs.push_back("-resource-dir"); | ||||||
ClangArgs.push_back(resource_dir.c_str()); | ||||||
} | ||||||
std::vector<std::string> CxxSystemIncludes; | ||||||
Cpp::DetectSystemCompilerIncludePaths(CxxSystemIncludes); | ||||||
for (const std::string& CxxInclude : CxxSystemIncludes) { | ||||||
ClangArgs.push_back("-isystem"); | ||||||
ClangArgs.push_back(CxxInclude.c_str()); | ||||||
} | ||||||
if (std::find_if( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: no header providing "std::find_if" is directly included [misc-include-cleaner] src/xinterpreter.cpp:21: - #ifndef EMSCRIPTEN
+ #include <algorithm>
+ #ifndef EMSCRIPTEN |
||||||
ExtraArgs.begin(), | ||||||
ExtraArgs.end(), | ||||||
[](const std::string& s) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: no header providing "std::string" is directly included [misc-include-cleaner] src/xinterpreter.cpp:21: - #ifndef EMSCRIPTEN
+ #include <string>
+ #ifndef EMSCRIPTEN |
||||||
{ | ||||||
return s == "-resource-dir"; | ||||||
} | ||||||
) | ||||||
== ExtraArgs.end()) | ||||||
{ | ||||||
std::string resource_dir = Cpp::DetectResourceDir(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: no header providing "Cpp::DetectResourceDir" is directly included [misc-include-cleaner] src/xinterpreter.cpp:21: - #ifndef EMSCRIPTEN
+ #include <clang/Interpreter/CppInterOp.h>
+ #ifndef EMSCRIPTEN |
||||||
if (resource_dir.empty()) | ||||||
{ | ||||||
std::cerr << "Failed to detect the resource-dir\n"; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: no header providing "std::cerr" is directly included [misc-include-cleaner] src/xinterpreter.cpp:21: - #ifndef EMSCRIPTEN
+ #include <iostream>
+ #ifndef EMSCRIPTEN |
||||||
} | ||||||
ClangArgs.push_back("-resource-dir"); | ||||||
ClangArgs.push_back(resource_dir.c_str()); | ||||||
} | ||||||
std::vector<std::string> CxxSystemIncludes; | ||||||
Cpp::DetectSystemCompilerIncludePaths(CxxSystemIncludes); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: no header providing "Cpp::DetectSystemCompilerIncludePaths" is directly included [misc-include-cleaner] Cpp::DetectSystemCompilerIncludePaths(CxxSystemIncludes);
^ |
||||||
for (const std::string& CxxInclude : CxxSystemIncludes) | ||||||
{ | ||||||
ClangArgs.push_back("-isystem"); | ||||||
ClangArgs.push_back(CxxInclude.c_str()); | ||||||
} | ||||||
#endif | ||||||
ClangArgs.insert(ClangArgs.end(), ExtraArgs.begin(), ExtraArgs.end()); | ||||||
// FIXME: We should process the kernel input options and conditionally pass | ||||||
// the gpu args here. | ||||||
return Cpp::CreateInterpreter(ClangArgs/*, {"-cuda"}*/); | ||||||
ClangArgs.insert(ClangArgs.end(), ExtraArgs.begin(), ExtraArgs.end()); | ||||||
// FIXME: We should process the kernel input options and conditionally pass | ||||||
// the gpu args here. | ||||||
return Cpp::CreateInterpreter(ClangArgs /*, {"-cuda"}*/); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: no header providing "Cpp::CreateInterpreter" is directly included [misc-include-cleaner] return Cpp::CreateInterpreter(ClangArgs /*, {"-cuda"}*/);
^ |
||||||
} | ||||||
|
||||||
using namespace std::placeholders; | ||||||
|
||||||
namespace xcpp | ||||||
{ | ||||||
struct StreamRedirectRAII { | ||||||
std::string &err; | ||||||
StreamRedirectRAII(std::string &e) : err(e) { | ||||||
Cpp::BeginStdStreamCapture(Cpp::kStdErr); | ||||||
Cpp::BeginStdStreamCapture(Cpp::kStdOut); | ||||||
} | ||||||
~StreamRedirectRAII() { | ||||||
std::string out = Cpp::EndStdStreamCapture(); | ||||||
err = Cpp::EndStdStreamCapture(); | ||||||
std::cout << out; | ||||||
} | ||||||
struct StreamRedirectRAII | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: class 'StreamRedirectRAII' 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] struct StreamRedirectRAII
^ |
||||||
{ | ||||||
std::string& err; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: member 'err' of type 'std::string &' (aka 'basic_string &') is a reference [cppcoreguidelines-avoid-const-or-ref-data-members] std::string& err;
^ |
||||||
|
||||||
StreamRedirectRAII(std::string& e) | ||||||
: err(e) | ||||||
{ | ||||||
Cpp::BeginStdStreamCapture(Cpp::kStdErr); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: no header providing "Cpp::BeginStdStreamCapture" is directly included [misc-include-cleaner] Cpp::BeginStdStreamCapture(Cpp::kStdErr);
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: no header providing "Cpp::kStdErr" is directly included [misc-include-cleaner] Cpp::BeginStdStreamCapture(Cpp::kStdErr);
^ |
||||||
Cpp::BeginStdStreamCapture(Cpp::kStdOut); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: no header providing "Cpp::kStdOut" is directly included [misc-include-cleaner] Cpp::BeginStdStreamCapture(Cpp::kStdOut);
^ |
||||||
} | ||||||
|
||||||
~StreamRedirectRAII() | ||||||
{ | ||||||
std::string out = Cpp::EndStdStreamCapture(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: no header providing "Cpp::EndStdStreamCapture" is directly included [misc-include-cleaner] std::string out = Cpp::EndStdStreamCapture();
^ |
||||||
err = Cpp::EndStdStreamCapture(); | ||||||
std::cout << out; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: no header providing "std::cout" is directly included [misc-include-cleaner] std::cout << out;
^ |
||||||
} | ||||||
}; | ||||||
|
||||||
void interpreter::configure_impl() | ||||||
|
@@ -101,14 +121,14 @@ __get_cxx_version () | |||||
return std::to_string(cxx_version); | ||||||
} | ||||||
|
||||||
interpreter::interpreter(int argc, const char* const* argv) : | ||||||
xmagics() | ||||||
interpreter::interpreter(int argc, const char* const* argv) | ||||||
: xmagics() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: initializer for member 'xmagics' is redundant [readability-redundant-member-init]
Suggested change
|
||||||
, p_cout_strbuf(nullptr) | ||||||
, p_cerr_strbuf(nullptr) | ||||||
, m_cout_buffer(std::bind(&interpreter::publish_stdout, this, _1)) | ||||||
, m_cerr_buffer(std::bind(&interpreter::publish_stderr, this, _1)) | ||||||
{ | ||||||
//NOLINTNEXTLINE (cppcoreguidelines-pro-bounds-pointer-arithmetic) | ||||||
// NOLINTNEXTLINE (cppcoreguidelines-pro-bounds-pointer-arithmetic) | ||||||
createInterpreter(Args(argv ? argv + 1 : argv, argv + argc)); | ||||||
m_version = get_stdopt(); | ||||||
redirect_output(); | ||||||
|
@@ -211,10 +231,11 @@ __get_cxx_version () | |||||
// | ||||||
// JupyterLab displays the "{ename}: {evalue}" if the traceback is | ||||||
// empty. | ||||||
if (evalue.size() < 4) { | ||||||
if (evalue.size() < 4) | ||||||
{ | ||||||
ename = " "; | ||||||
} | ||||||
std::vector<std::string> traceback({ename + evalue}); | ||||||
std::vector<std::string> traceback({ename + evalue}); | ||||||
if (!config.silent) | ||||||
{ | ||||||
publish_execution_error(ename, evalue, traceback); | ||||||
|
@@ -257,7 +278,8 @@ __get_cxx_version () | |||||
|
||||||
Cpp::CodeComplete(results, code.c_str(), 1, _cursor_pos + 1); | ||||||
|
||||||
return xeus::create_complete_reply(results /*matches*/, | ||||||
return xeus::create_complete_reply( | ||||||
results /*matches*/, | ||||||
cursor_pos - to_complete.length() /*cursor_start*/, | ||||||
cursor_pos /*cursor_end*/ | ||||||
); | ||||||
|
@@ -278,13 +300,17 @@ __get_cxx_version () | |||||
|
||||||
nl::json interpreter::is_complete_request_impl(const std::string& code) | ||||||
{ | ||||||
if (!code.empty() && code[code.size() - 1] == '\\') { | ||||||
if (!code.empty() && code[code.size() - 1] == '\\') | ||||||
{ | ||||||
auto found = code.rfind('\n'); | ||||||
if (found == std::string::npos) | ||||||
{ | ||||||
found = -1; | ||||||
} | ||||||
auto found1 = found++; | ||||||
while (isspace(code[++found1])) ; | ||||||
return xeus::create_is_complete_reply("incomplete", code.substr(found, found1-found)); | ||||||
while (isspace(code[++found1])) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: no header providing "isspace" is directly included [misc-include-cleaner] src/xinterpreter.cpp:21: - #ifndef EMSCRIPTEN
+ #include <cctype>
+ #ifndef EMSCRIPTEN |
||||||
; | ||||||
return xeus::create_is_complete_reply("incomplete", code.substr(found, found1 - found)); | ||||||
} | ||||||
|
||||||
return xeus::create_is_complete_reply("complete"); | ||||||
|
@@ -358,11 +384,11 @@ __get_cxx_version () | |||||
|
||||||
void interpreter::init_preamble() | ||||||
{ | ||||||
//NOLINTBEGIN(cppcoreguidelines-owning-memory) | ||||||
// NOLINTBEGIN(cppcoreguidelines-owning-memory) | ||||||
preamble_manager.register_preamble("introspection", std::make_unique<xintrospection>()); | ||||||
preamble_manager.register_preamble("magics", std::make_unique<xmagics_manager>()); | ||||||
preamble_manager.register_preamble("shell", std::make_unique<xsystem>()); | ||||||
//NOLINTEND(cppcoreguidelines-owning-memory) | ||||||
// NOLINTEND(cppcoreguidelines-owning-memory) | ||||||
} | ||||||
|
||||||
void interpreter::init_magic() | ||||||
|
@@ -373,6 +399,7 @@ __get_cxx_version () | |||||
// timeit(&m_interpreter)); | ||||||
// preamble_manager["magics"].get_cast<xmagics_manager>().register_magic("python", pythonexec()); | ||||||
preamble_manager["magics"].get_cast<xmagics_manager>().register_magic("file", writefile()); | ||||||
preamble_manager["magics"].get_cast<xmagics_manager>().register_magic("timeit", timeit()); | ||||||
#ifndef EMSCRIPTEN | ||||||
preamble_manager["magics"].get_cast<xmagics_manager>().register_magic("xassist", xassist()); | ||||||
#endif | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: function 'createInterpreter' can be made static or moved into an anonymous namespace to enforce internal linkage [misc-use-internal-linkage]