Skip to content
This repository has been archived by the owner on Jan 27, 2021. It is now read-only.

another code-generation issue with value types #63

Open
nano-o opened this issue Apr 15, 2020 · 1 comment
Open

another code-generation issue with value types #63

nano-o opened this issue Apr 15, 2020 · 1 comment

Comments

@nano-o
Copy link

nano-o commented Apr 15, 2020

Hello, ivyc generates invalid C++ code on the example below. Should it be working?

instance elem : iterable
object obj = {
    type my_set = struct {
        member(N:elem) : bool
    }
    relation empty(S:my_set)
    definition empty(s:my_set) = forall N . ~member(s,N)
    export action emptyset returns (s:my_set) = {
        member(s,N) := false;
    }
    export action add(s:my_set, n:elem) returns (s:my_set) = {
        if ~member(s,n) {
            member(s,N) := member(s,N) | N = n
        }
    }
}
extract code = obj, elem
@kenmcmil
Copy link
Contributor

That's a really painful bug. Structs have to have computable equality. So if a struct has a function member, then the function's domain has to be of a type that is iterable. So far, so good. The problem is that the equality comparator is a static overload in C++. But the size parameter of type elem is a non-static member of the class, so the equality comparator can't access it to iterate over elem. So there are few bad options:

  1. Make equality comparison a non-static member function
  2. Make the size parameter static
  3. Store the size parameter in the struct

Probably the last is the least disruptive option. It might take a while to get this fixed, though.

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

No branches or pull requests

2 participants