zeek/spicy

Inouts & sinks + contexts compile error

Closed this issue · 1 comments

Using inout with sinks and contexts results in this error message:

$spicyz test.spicy -o test.hlto
In file included from /private/var/folders/50/z8y2zkwd4lsdl3qr2l4shn8c0000gn/T/Test_5e7bb92ea7bd7a6c-17aab9b4f987eead.cc:6:
In file included from /Users/johanna/zeek/install/include/hilti/rt/libhilti.h:12:
In file included from /Users/johanna/zeek/install/include/hilti/rt/context.h:12:
In file included from /Users/johanna/zeek/install/include/hilti/rt/fiber.h:19:
/Users/johanna/zeek/install/include/hilti/rt/types/reference.h:720:31: error: no matching conversion for functional-style cast from '__hlt::Test::Share' to '__hlt::Test::Alert'
    return StrongReference<T>(T(std::forward<Args>(args)...));
                              ^~~~~~~~~~~~~~~~~~~~~~~~~~
/private/var/folders/50/z8y2zkwd4lsdl3qr2l4shn8c0000gn/T/Test_5e7bb92ea7bd7a6c-17aab9b4f987eead.cc:573:60: note: in instantiation of function template specialization 'hilti::rt::reference::make_strong<__hlt::Test::Alert, __hlt::Test::Share &>' requested here
    (*(*__self).alertsink).connect(::hilti::rt::reference::make_strong<__hlt::Test::Alert>((*(*__self).__context)));
                                                           ^
/private/var/folders/50/z8y2zkwd4lsdl3qr2l4shn8c0000gn/T/Test_5e7bb92ea7bd7a6c-17aab9b4f987eead.cc:99:9: note: candidate constructor not viable: no known conversion from '__hlt::Test::Share' to 'const Alert' for 1st argument
        Alert(const Alert&) = default;
        ^
/private/var/folders/50/z8y2zkwd4lsdl3qr2l4shn8c0000gn/T/Test_5e7bb92ea7bd7a6c-17aab9b4f987eead.cc:100:9: note: candidate constructor not viable: no known conversion from '__hlt::Test::Share' to 'Alert' for 1st argument
        Alert(Alert&&) = default;
        ^
/private/var/folders/50/z8y2zkwd4lsdl3qr2l4shn8c0000gn/T/Test_5e7bb92ea7bd7a6c-17aab9b4f987eead.cc:176:19: note: candidate constructor not viable: no known conversion from '__hlt::Test::Share' to '::hilti::rt::ValueReference<__hlt::Test::Share> &' for 1st argument
    inline Alert::Alert(::hilti::rt::ValueReference<__hlt::Test::Share>& __p_sh) : __p_sh(std::move(__p_sh)) {
                  ^
/private/var/folders/50/z8y2zkwd4lsdl3qr2l4shn8c0000gn/T/Test_5e7bb92ea7bd7a6c-17aab9b4f987eead.cc:179:19: note: candidate constructor not viable: no known conversion from '__hlt::Test::Share' to 'std::optional<std::optional< ::hilti::rt::Vector<__hlt::Test::Alert_message>>>' for 1st argument
    inline Alert::Alert(std::optional<std::optional<::hilti::rt::Vector<__hlt::Test::Alert_message>>> alerts) : Alert() {
                  ^
/private/var/folders/50/z8y2zkwd4lsdl3qr2l4shn8c0000gn/T/Test_5e7bb92ea7bd7a6c-17aab9b4f987eead.cc:173:19: note: candidate constructor not viable: requires 0 arguments, but 1 was provided
    inline Alert::Alert() {
                  ^
1 error generated.
[error] <Spicy support for Zeek>: JIT compilation failed

Source:

module Test;

type Share = unit {
};

public type Message = unit {
  %context = Share;

	sink alertsink;

	on %init {
		self.alertsink.connect(new Alert(self.context()));
	}
};

# note - this will mostly be garbage because it is encrypted.
public type Alert = unit(inout sh: Share) {
  alerts: Alert_message(sh)[];
};

type Alert_message = unit(sh: Share) {
  level: uint8; # &convert=AlertLevel($$);
  description: uint8; # &convert=AlertDescription($$);
};

(Previously mentioned as comment in #1711)

This looks like a missed validation. Since recently Spicy rejects passing references as inout; instead references provide interior mutability. This validation seems to miss contexts which are also modeled as references.1

Instead you should use the following signature:

public type Alert = unit(sh: Share&) {

Footnotes

  1. Might be that this needs a cleanup similar to what Robin did for sinks which now are modeled as refs all the way through.