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

Error in generated c++ source code when passing sinks to functions #1447

Closed
0xxon opened this issue Jun 2, 2023 · 1 comment · Fixed by #1450
Closed

Error in generated c++ source code when passing sinks to functions #1447

0xxon opened this issue Jun 2, 2023 · 1 comment · Fixed by #1450
Assignees
Labels
Bug Something isn't working Codegen

Comments

@0xxon
Copy link
Member

0xxon commented Jun 2, 2023

# file: foo.spicy

module foo;

function fun(s: sink): bool {
    s.close();
    return True;
}

type Y = unit {
    sink s;
    x: X(self.s);
};


type X = unit (s: sink){
    data: uint8;
    var a: bool;

    on data {
      self.a = fun(s);
    }
};

Causes the following error:

$ spicyc -j ./foo.spicy
/private/var/folders/xg/y2l9jptj6bq6gm7rz1mm2lc80000gn/T/foo_93d27a28ebfe11ba-92d90ada2067c1b3.cc:354:5: error: 'this' argument to member function 'close' has type 'const spicy::rt::Sink', but function is not marked const
    (*s).close();
    ^~~~
/Users/johanna/zeek/install/include/spicy/rt/sink.h:170:10: note: 'close' declared here
    void close() { _close(true); }
         ^
1 error generated.
[error] spicyc: JIT compilation failed

It can be resolved by either calling s.close() in on data, or by changing the function signature to use inout for the sink. However, this still seems like a bug/inconsistency since one does not need inout when passing sinks to other units.

@bbannier bbannier added Bug Something isn't working Codegen labels Jun 5, 2023
@bbannier
Copy link
Member

bbannier commented Jun 5, 2023

The issue here is that we generate a C++ function which passes the sink parameter as a const, i.e., a pure in parameter. One way to work around this until a fix is available would be to declare the parameter as inout,

...
function fun(inout s: sink): bool {
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Codegen
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants