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

"compilation of seq<TRAIT> is not supported"; consider introducing a ghost #406

Open
robin-aws opened this issue Oct 28, 2019 · 1 comment
Assignees
Labels
kind: enhancement Enhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafny

Comments

@robin-aws
Copy link
Member

To trigger (as long as the /compile flag is 1 or higher):

trait MyTrait {}

class MyClass extends MyTrait {}

class MyOtherClass {
    var mySeqOfClass : seq<MyClass>; 
}

From looking at the compiler source it looks like this is just a "not implemented yet" case rather than a fundamental limitation, but I'd love to hear confirmation of this.

In my case the state needs to be reified at runtime so I can't make it a ghost var. Is there a better workaround than using an array instead?

@robin-aws
Copy link
Member Author

robin-aws commented Nov 4, 2019

It seems like this is due to the fact that the translations of seq<T> in most of the target runtimes do not support co-variance:

// The code in this file demonstrates complications in compiling to C# if a
// trait (like "object") is allowed as a type parameter to something compiled.
// The problem is that an assignment like a "set<MyClass>" to a "set<object>", which
// is allowed in Dafny, would require a deep copy in C#. Another example is an
// assignment of a "MyDatatype<MyClass>" to a "MyDatatype<object>".
// Currently, the Dafny compiler enforces restrictions that rule out the expensive
// cases. A possibly more friendly approach would be to emit code that performs
// the deep copies.
// Note that this is not a problem in JavaScript, which lacks type parameters.

robin-aws added a commit to aws/aws-encryption-sdk-dafny that referenced this issue Nov 5, 2019
@robin-aws robin-aws self-assigned this Mar 4, 2020
robin-aws added a commit that referenced this issue Mar 9, 2020
Addresses #406 for C# only.

See comments in Test/dafny0/RuntimeTypeTests0.dfy for details.

BREAKING CHANGE: Sequences are now represented by a Dafny.ISequence<T> interface, which will break external code.
@robin-aws robin-aws added the kind: enhancement Enhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafny label Jun 23, 2020
@acioc acioc assigned RustanLeino and unassigned robin-aws Aug 12, 2020
@acioc acioc added this to the Dafny 3.0 milestone Aug 12, 2020
@davidcok davidcok modified the milestones: Dafny 3.0, Dafny 3.1 Dec 23, 2020
@atomb atomb removed this from the Dafny 3.1 milestone Apr 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: enhancement Enhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafny
Projects
None yet
Development

No branches or pull requests

5 participants