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

Cpp Examples in the Playground #99

Open
edwardalee opened this issue Jan 31, 2024 · 3 comments
Open

Cpp Examples in the Playground #99

edwardalee opened this issue Jan 31, 2024 · 3 comments
Assignees
Labels

Comments

@edwardalee
Copy link
Contributor

I made a pass on the Cpp examples in the Playground (see PR #98), but they still need a bit of work:

  • All of the examples give lots of warnings when compiled. See examples below.

  • I didn't try the ROS2 example. Probably its README file should explain what you need to run this and how to install.

  • With this directory layout, which is quite different from the C examples, we need lots of .gitignore files and/or a make clean action, otherwise you get lots of "untracked files" from git after running a few examples.

  • AlarmClock.lf does not compile for me (and gives lots of warnings):

<command line>:2:18: warning: ISO C99 requires whitespace after the macro name [-Wc99-extensions]
#define _CROW_ICD-NOTFOUND 1
                 ^
/Users/edwardlee/git/playground-lingua-franca/examples/Cpp/AlarmClock/src-gen/AlarmClock/Network/Network.cc:148:69: error: no viable conversion from 'const time_point<Clock>' to 'const time_point<system_clock>'
        std::time_t end_time = std::chrono::system_clock::to_time_t(chrono_time_point);
                                                                    ^~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/__chrono/time_point.h:33:28: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'const TimePoint' (aka 'const time_point<std::chrono::steady_clock>') to 'const std::chrono::time_point<std::chrono::system_clock> &' for 1st argument
class _LIBCPP_TEMPLATE_VIS time_point
                           ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/__chrono/time_point.h:33:28: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'const TimePoint' (aka 'const time_point<std::chrono::steady_clock>') to 'std::chrono::time_point<std::chrono::system_clock> &&' for 1st argument
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/__chrono/time_point.h:52:5: note: candidate template ignored: could not match 'std::chrono::system_clock' against 'std::chrono::steady_clock'
    time_point(const time_point<clock, _Duration2>& __t,
    ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/__chrono/time_point.h:47:70: note: explicit constructor is not a candidate
    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit time_point(const duration& __d) : __d_(__d) {}
                                                                     ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/__chrono/system_clock.h:37:53: note: passing argument to parameter '__t' here
    static time_t     to_time_t  (const time_point& __t) _NOEXCEPT;
                                                    ^
In file included from /Users/edwardlee/git/playground-lingua-franca/examples/Cpp/AlarmClock/src-gen/AlarmClock/Network/Network.cc:7:
/Users/edwardlee/git/playground-lingua-franca/examples/Cpp/AlarmClock/src-gen/AlarmClock/Network/Network.hh:31:18: warning: private field '__lf_inner' is not used [-Wunused-private-field]
    const Inner& __lf_inner = *this;
                 ^
/Users/edwardlee/git/playground-lingua-franca/examples/Cpp/AlarmClock/src-gen/AlarmClock/Network/Network.hh:32:22: warning: private field '__lf_parameters' is not used [-Wunused-private-field]
    const Parameters __lf_parameters;
                     ^
3 warnings and 1 error generated.
  • All of the programs in the Pattern directory give a lot of warnings when compiled. For example:
$ lfc-dev Patterns/src/FullyConnected_00_Broadcast.lf 
lfc: info: Generating code for: file:/Users/edwardlee/git/playground-lingua-franca/examples/Cpp/Patterns/src/FullyConnected_00_Broadcast.lf
lfc: info: Generation mode: STANDALONE
lfc: info: Generating sources into: /Users/edwardlee/git/playground-lingua-franca/examples/Cpp/Patterns/src-gen/FullyConnected_00_Broadcast
lfc: info: Target Configuration:
Path: /Users/edwardlee/git/playground-lingua-franca/examples/Cpp/Patterns/src-gen/FullyConnected_00_Broadcast /Users/edwardlee/git/playground-lingua-franca/examples/Cpp/Patterns/src-gen/FullyConnected_00_Broadcast
--- Current working directory: /Users/edwardlee/git/playground-lingua-franca/examples/Cpp/Patterns/build
--- Executing command: cmake --version
cmake version 3.27.6

CMake suite maintained and supported by Kitware (kitware.com/cmake).
--- Current working directory: /Users/edwardlee/git/playground-lingua-franca/examples/Cpp/Patterns/build
--- Executing command: cmake -DCMAKE_BUILD_TYPE=Debug -DREACTOR_CPP_VALIDATE=ON -DREACTOR_CPP_PRINT_STATISTICS=OFF -DREACTOR_CPP_TRACE=OFF -DREACTOR_CPP_LOG_LEVEL=3 -DLF_SRC_PKG_PATH=/Users/edwardlee/git/playground-lingua-franca/examples/Cpp/Patterns -DCMAKE_INSTALL_PREFIX=/Users/edwardlee/git/playground-lingua-franca/examples/Cpp/Patterns -DCMAKE_INSTALL_BINDIR=bin /Users/edwardlee/git/playground-lingua-franca/examples/Cpp/Patterns/src-gen
-- Could NOT find reactor-cpp (missing: reactor-cpp_DIR)
-- Could NOT find reactor-cpp (missing: reactor-cpp_DIR)
-- Configuring done (0.1s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/edwardlee/git/playground-lingua-franca/examples/Cpp/Patterns/build
--- Current working directory: /Users/edwardlee/git/playground-lingua-franca/examples/Cpp/Patterns/build
--- Executing command: cmake --build . --target FullyConnected_00_Broadcast --parallel 12 --config Debug
[ 70%] Built target reactor-cpp-default
[ 88%] Building CXX object FullyConnected_00_Broadcast/CMakeFiles/FullyConnected_00_Broadcast.dir/FullyConnected_00_Broadcast/Node.cc.o
[ 88%] Building CXX object FullyConnected_00_Broadcast/CMakeFiles/FullyConnected_00_Broadcast.dir/FullyConnected_00_Broadcast/FullyConnected_00_Broadcast.cc.o
[ 88%] Building CXX object FullyConnected_00_Broadcast/CMakeFiles/FullyConnected_00_Broadcast.dir/FullyConnected_00_Broadcast/_lf_preamble.cc.o
[ 94%] Building CXX object FullyConnected_00_Broadcast/CMakeFiles/FullyConnected_00_Broadcast.dir/main.cc.o
/Users/edwardlee/git/playground-lingua-franca/examples/Cpp/Patterns/src-gen/FullyConnected_00_Broadcast/FullyConnected_00_Broadcast/FullyConnected_00_Broadcast.cc:77:4: warning: lambda capture 'this' is not used [-Wunused-lambda-capture]
  [this](reactor::Port<typename std::remove_reference<decltype(nodes[0]->out)>::type::value_type>* left, reactor::Port<typename std::remove_reference<decltype(nodes[0]->out)>::type::value_type>* right) {
   ^~~~
In file included from /Users/edwardlee/git/playground-lingua-franca/examples/Cpp/Patterns/src-gen/FullyConnected_00_Broadcast/FullyConnected_00_Broadcast/Node.cc:7:
/Users/edwardlee/git/playground-lingua-franca/examples/Cpp/Patterns/src-gen/FullyConnected_00_Broadcast/FullyConnected_00_Broadcast/Node.hh:34:18: warning: private field '__lf_inner' is not used [-Wunused-private-field]
    const Inner& __lf_inner = *this;
                 ^
/Users/edwardlee/git/playground-lingua-franca/examples/Cpp/Patterns/src-gen/FullyConnected_00_Broadcast/FullyConnected_00_Broadcast/Node.hh:57:49: warning: private field 'bank_index' is not used [-Wunused-private-field]
  const typename Parameters::__lf_bank_index_t& bank_index = __lf_inner.bank_index;
                                                ^
/Users/edwardlee/git/playground-lingua-franca/examples/Cpp/Patterns/src-gen/FullyConnected_00_Broadcast/FullyConnected_00_Broadcast/Node.hh:58:48: warning: private field 'num_nodes' is not used [-Wunused-private-field]
  const typename Parameters::__lf_num_nodes_t& num_nodes = __lf_inner.num_nodes;
                                               ^
In file included from /Users/edwardlee/git/playground-lingua-franca/examples/Cpp/Patterns/src-gen/FullyConnected_00_Broadcast/FullyConnected_00_Broadcast/FullyConnected_00_Broadcast.cc:7:
/Users/edwardlee/git/playground-lingua-franca/examples/Cpp/Patterns/src-gen/FullyConnected_00_Broadcast/FullyConnected_00_Broadcast/FullyConnected_00_Broadcast.hh:32:18: warning: private field '__lf_inner' is not used [-Wunused-private-field]
    const Inner& __lf_inner = *this;
                 ^
/Users/edwardlee/git/playground-lingua-franca/examples/Cpp/Patterns/src-gen/FullyConnected_00_Broadcast/FullyConnected_00_Broadcast/FullyConnected_00_Broadcast.hh:51:48: warning: private field 'num_nodes' is not used [-Wunused-private-field]
  const typename Parameters::__lf_num_nodes_t& num_nodes = __lf_inner.num_nodes;
                                               ^
3 warnings generated.
3 warnings generated.
[100%] Linking CXX executable FullyConnected_00_Broadcast
[100%] Built target FullyConnected_00_Broadcast
--- Current working directory: /Users/edwardlee/git/playground-lingua-franca/examples/Cpp/Patterns/build
--- Executing command: cmake --build . --target install --parallel 12 --config Debug
Install the project...
-- Install configuration: "Debug"
SUCCESS (compiling generated C++ code)
  • ReflexGame also gives lots of warnings:
In file included from /Users/edwardlee/git/playground-lingua-franca/examples/Cpp/ReflexGame/src-gen/ReflexGame/ReflexGame/RandomSource.cc:7:
/Users/edwardlee/git/playground-lingua-franca/examples/Cpp/ReflexGame/src-gen/ReflexGame/ReflexGame/RandomSource.hh:61:47: warning: private field 'min_time' is not used [-Wunused-private-field]
  const typename Parameters::__lf_min_time_t& min_time = __lf_inner.min_time;
                                              ^
/Users/edwardlee/git/playground-lingua-franca/examples/Cpp/ReflexGame/src-gen/ReflexGame/ReflexGame/RandomSource.hh:62:47: warning: private field 'max_time' is not used [-Wunused-private-field]
  const typename Parameters::__lf_max_time_t& max_time = __lf_inner.max_time;
                                              ^
In file included from /Users/edwardlee/git/playground-lingua-franca/examples/Cpp/ReflexGame/src-gen/ReflexGame/ReflexGame/GetUserInput.cc:7:
/Users/edwardlee/git/playground-lingua-franca/examples/Cpp/ReflexGame/src-gen/ReflexGame/ReflexGame/GetUserInput.hh:32:22: warning: private field '__lf_parameters' is not used [-Wunused-private-field]
    const Parameters __lf_parameters;
                     ^
In file included from /Users/edwardlee/git/playground-lingua-franca/examples/Cpp/ReflexGame/src-gen/ReflexGame/ReflexGame/ReflexGame.cc:7:
/Users/edwardlee/git/playground-lingua-franca/examples/Cpp/ReflexGame/src-gen/ReflexGame/ReflexGame/ReflexGame.hh:32:22: warning: private field '__lf_parameters' is not used [-Wunused-private-field]
    const Parameters __lf_parameters;
                     ^
2 warnings generated.
@cmnrd
Copy link
Contributor

cmnrd commented Feb 9, 2024

Thanks for this summary of problems!

I fixed the .gitignore issue in #98. @tanneberger Could you have a look at the alarm clock?

All other issues appear to be warnings generated by clang. These only appear when using the latest release of clang. Older versions and gcc compile warning free. It should be easy enough to avoid the warnings with some updates to the code generator. I will try to address this soon.

Tracking this in lf-lang/lingua-franca#2189

@tanneberger
Copy link
Member

I fixed the .gitignore issue in #98. @tanneberger Could you have a look at the alarm clock?

On it but first exams ;D

cmnrd added a commit to lf-lang/lingua-franca that referenced this issue Feb 16, 2024
@cmnrd
Copy link
Contributor

cmnrd commented Feb 16, 2024

lf-lang/lingua-franca#2201 fixes the warnings in the generated C++ code.

This means three issues remain:

  • The ROS2 examples could use a better explanation
  • The alarm clock seems to be broken on Edward's system (it compiles on mine, also with clang)
  • The alarm clock produces many warnings (these come from the example code itself)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants