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

Using Generic reactors with custom types #2250

Open
erlingrj opened this issue Mar 25, 2024 · 2 comments
Open

Using Generic reactors with custom types #2250

erlingrj opened this issue Mar 25, 2024 · 2 comments
Labels
bug Something isn't working c Related to C target

Comments

@erlingrj
Copy link
Collaborator

I am unable to compile LF programs with generic reactors whose generic type is not included by the generic reactor. Consider this example costing of two source files:

Generic.lf

target CCpp
reactor Generic<T> {
  input in: T
  output out: T
  reaction(in) -> out {=
    out->value = in->value;
  =}
}

UseGeneric.lf

target CCpp
import Generic from "./Generic.lf"
preamble {=
  typedef int my_type_t;
=}
main reactor {
  r = new Generic<my_type_t>()
}

This results in this error:

In file included from /home/erling/dev/lf-ex/src-gen/UseGeneric/UseGeneric.cpp:22:
/home/erling/dev/lf-ex/src-gen/UseGeneric/_genericmy_type_t.h:15:5: error: ‘my_type_t’ does not name a type; did you mean ‘idtype_t’?
   15 |     my_type_t value;
      |     ^~~~~~~~~
      |     idtype_t
/home/erling/dev/lf-ex/src-gen/UseGeneric/_genericmy_type_t.h:29:5: error: ‘my_type_t’ does not name a type; did you mean ‘idtype_t’?
   29 |     my_type_t value;
      |     ^~~~~~~~~
      |     idtype_t
make[2]: *** [CMakeFiles/UseGeneric.dir/build.make:118: CMakeFiles/UseGeneric.dir/UseGeneric.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
In file included from /home/erling/dev/lf-ex/src-gen/UseGeneric/_genericmy_type_t.cpp:5:
/home/erling/dev/lf-ex/src-gen/UseGeneric/include/Generic/Genericmy_type_t.h:29:5: error: ‘my_type_t’ does not name a type; did you mean ‘idtype_t’?
   29 |     my_type_t value;
      |     ^~~~~~~~~
      |     idtype_t
/home/erling/dev/lf-ex/src-gen/UseGeneric/include/Generic/Genericmy_type_t.h:43:5: error: ‘my_type_t’ does not name a type; did you mean ‘idtype_t’?
   43 |     my_type_t value;
      |     ^~~~~~~~~
      |     idtype_t
In file included from /home/erling/dev/lf-ex/src-gen/UseGeneric/_genericmy_type_t.cpp:6:
/home/erling/dev/lf-ex/src-gen/UseGeneric/_genericmy_type_t.h:15:5: error: ‘my_type_t’ does not name a type; did you mean ‘idtype_t’?
   15 |     my_type_t value;
      |     ^~~~~~~~~
      |     idtype_t
/home/erling/dev/lf-ex/src-gen/UseGeneric/_genericmy_type_t.h:29:5: error: ‘my_type_t’ does not name a type; did you mean ‘idtype_t’?
   29 |     my_type_t value;
      |     ^~~~~~~~~
      |     idtype_t
/home/erling/dev/lf-ex/src/Generic.lf: In function ‘void _genericmy_type_treaction_function_0(void*)’:
/home/erling/dev/lf-ex/src/Generic.lf:8:10: error: ‘struct _genericmy_type_t_out_t’ has no member named ‘value’
    8 |     out->value = in->value;
      |          ^~~~~
/home/erling/dev/lf-ex/src/Generic.lf:8:22: error: ‘struct _genericmy_type_t_in_t’ has no member named ‘value’
    8 |     out->value = in->value;
      |                      ^~~~~
/home/erling/dev/lf-ex/src-gen/UseGeneric/_genericmy_type_t.cpp: In function ‘_genericmy_type_t_self_t* new__genericmy_type_t()’:
/home/erling/dev/lf-ex/src-gen/UseGeneric/_genericmy_type_t.cpp:10:11: error: ‘my_type_t’ was not declared in this scope; did you mean ‘idtype_t’?
   10 | #define T my_type_t
      |           ^~~~~~~~~
/home/erling/dev/lf-ex/src-gen/UseGeneric/_genericmy_type_t.cpp:47:52: note: in expansion of macro ‘T’
   47 |     self->_lf__in.tmplt.type.element_size = sizeof(T);
      |                                                    ^
make[2]: *** [CMakeFiles/UseGeneric.dir/build.make:104: CMakeFiles/UseGeneric.dir/_genericmy_type_t.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:100: CMakeFiles/UseGeneric.dir/all] Error 2
make: *** [Makefile:136: all] Error 2
lfc: error: CMake failed with error code 2
lfc: fatal error: Aborting due to 1 previous error.

I think the preamble of the file where the generic reactor is instantiated must also be "added" to the preamble of the generic reactor.

@erlingrj
Copy link
Collaborator Author

Any thoughts on this @petervdonovan ?

@petervdonovan
Copy link
Collaborator

Hmm, yes, I agree that that should be considered to be a problem. I am not sure what to do about it however. Without interpreting the C header files, the only way to prevent this sort of problem would be for the generic child reactor to be compiled with all the headers of its parent reactor, which seems like namespace pollution which could also lead to large code size (since the child reactor is compiled for every place where it is instantiated, even if the type args are the same). It is possible that we already have these problems anyway for other reasons but I would have to investigate this further to know.

@cmnrd cmnrd added bug Something isn't working c Related to C target labels Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working c Related to C target
Projects
None yet
Development

No branches or pull requests

3 participants