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

Refining a module method with linear parameters causes linearity errors #39

Open
rtjohnso opened this issue Aug 17, 2021 · 5 comments
Open
Assignees

Comments

@rtjohnso
Copy link
Collaborator

If a module A implements a method with linear or linear inout parameters, and a module B refines A and overrides the method implementation, then dafny generates linearity errors. shared parameters seem to be ok.

module A {
  // Error: linear variable <<old_data>> is unavailable here
  // Error: variable must be unavailable before assignment
  method Foo(linear inout data: seq<int>)
  {
  }
  method Bar(linear data: seq<int>) returns (linear result: seq<int>)
  {
    // Error: linear variable <<data>> is unavailable here
    // Error: variable must be unavailable before assignment
    result := data;
  }
  method Baz(shared data: seq<int>)
  {
  }
}

module B refines A {
  method Foo(linear inout data: seq<int>)
  {
  }
  method Bar(linear data: seq<int>) returns (linear result: seq<int>)
  {
    result := data;
  }
  method Baz(shared data: seq<int>)
  {
  }
}
@parno
Copy link

parno commented Aug 17, 2021

@rtjohnso mentioned that this works in 3748f6c but breaks in 183116c. Is that right?

If so, that's quite odd, since the changes in 183116c (a) skip compiling Functors (which aren't present here), and (b) change how ApplyFunctor works, which also isn't relevant here.

@rtjohnso
Copy link
Collaborator Author

rtjohnso commented Aug 17, 2021 via email

@parno
Copy link

parno commented Aug 18, 2021

@Chris-Hawblitzel points out that Dafny objects to this more generally:

module A {
  method Bar(data: int) returns (result: int)
  {
    result := data;
  }
}

module B refines A {
  method Bar(data: int) returns (result: int)
  {
    result := data;
  }
}

results in

Error: refinement method cannot assign to variable defined in parent module ('result')

I'm not sure that Dafny actually lets you provide a method body in a refining module (B) if it already had a body in the parent module (A), or at least not as a general feature. Do you need this ability for the parser?

@rtjohnso
Copy link
Collaborator Author

rtjohnso commented Aug 18, 2021 via email

@parno
Copy link

parno commented Aug 18, 2021

Weird! What's the use case you want to use it for? Judging from commit density, the Amazon folks have been using Dafny's classes and traits a fair bit, so if that would better fit your use case, they might be usable by this point. Of course, we'd need to update the C++ backend to accommodate them, so it won't compile right away.

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

No branches or pull requests

3 participants