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

Feature request: ignore {:extern} method in trait #2212

Closed
txiang61 opened this issue Jun 6, 2022 · 2 comments · Fixed by #2446
Closed

Feature request: ignore {:extern} method in trait #2212

txiang61 opened this issue Jun 6, 2022 · 2 comments · Fixed by #2446
Assignees
Labels
has-workaround: no There are no known workarounds kind: enhancement Enhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafny part: language definition Relating to the Dafny language definition itself

Comments

@txiang61
Copy link

txiang61 commented Jun 6, 2022

Currently Dafny forces class C to implement trait method T.m, even though we specified it as implemented externally.

trait T {
  method {:extern} m() returns (res: int)
}

class C extends T {
  method n() returns (res: int)  {
    var v := m();
    return v;
  }
}

One work around is adding method {:extern} m() returns (res: int) to class C as well, but it's a pain if we have massive classes and need to do this over and over.

@cpitclaudel
Copy link
Member

Another work around is to give m an empty body in T, but that only works for (some) methods (not functions), so it's not satisfactory:

trait T {
  method {:extern} m() returns (res: int) {}
}

class C extends T {
  method n() returns (res: int)  {
    var v := m();
    return v;
  }
}

@fabiomadge fabiomadge added kind: enhancement Enhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafny part: language definition Relating to the Dafny language definition itself has-workaround: yes There is a known workaround labels Jun 20, 2022
@cpitclaudel cpitclaudel added has-workaround: no There are no known workarounds and removed has-workaround: yes There is a known workaround labels Jul 15, 2022
@cpitclaudel
Copy link
Member

cpitclaudel commented Jul 15, 2022

After looking at this with @RustanLeino and @fabiomadge , we came up with the following proposal:

Current rule: *When a class is checked to make sure that it overrides the definitions of each trait that it extends, it has to override any definition in the trait that does not have a body.

New rule: When a class is checked to make sure that it overrides the definitions (functions or methods) of each trait that it extends, it has to override any definition in the trait that

  1. Does not have a body,
  2. Does not have an :axiom attribute,
  3. Does not have an :compile false attribute.

In other words, definitions with :axiom or :compile false in the trait are treated the same as definitions with bodies in the trait; in particular, they cannot have a body in the class.

With these rules, if a trait has a bodyless definition without an :axiom or :compile false attribute, then the class must redeclare that definition, and the redeclaration must either have a body or have the :axiom or :compile false attribute.

Note that :extern is not used to make that decision; that is because :extern "name" can be used to indicate the name under which a trait method should be exposed to the world — even for methods that are implemented in Dafny.

@txiang61 , could you check whether this proposal would fulfill your use case? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has-workaround: no There are no known workarounds kind: enhancement Enhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafny part: language definition Relating to the Dafny language definition itself
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants