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

feat!: Support seq<trait> in C# #557

Merged
merged 11 commits into from
Mar 9, 2020

Conversation

robin-aws
Copy link
Member

@robin-aws robin-aws commented Mar 4, 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
Copy link
Member Author

AWS CodeBuild CI Report

  • CodeBuild project: Dafny
  • Commit ID: 2ece678
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@robin-aws
Copy link
Member Author

AWS CodeBuild CI Report

  • CodeBuild project: Dafny
  • Commit ID: ec8405e
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Copy link
Collaborator

@RustanLeino RustanLeino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's with DafnyRuntimeTests that makes them difficult to include at this time?

Some more tests of some compile code would be good. Also, it would be good to include that example (which I think sits somewhere in the test suite) that has the comment that says "this would be expensive to support at run time", to make sure it compiles correctly (to efficient code).

Type ty = typeof(G);
// TODO-RS: How to generalize this?
if (ty.Name.Equals("ISequence`1")) {
Type classType = Type.GetType("Dafny.Sequence`1");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the type Dafny.Sequence`1 always in the run time? If so, can its type be looked up with a typeof instead of by name? Also, is the `1 suffix unavoidable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is super-sloppy and needs to be cleaned up. ISequence`1 is shorthand for "The ISequence type that takes one type parameter" (since C# allows overloading by number of type parameters). It's just a little tricky because I need to map from Dafny.ISequence<x> to Dafny.Sequence<x>, where x is a concrete type rather than the generic type parameter T, and I'm still learning the C# reflection model. I know how to do it in Java! :)

@robin-aws
Copy link
Member Author

I hadn't intended this to be ready for review yet, I wanted to check that all tests passed on CodeBuild before I added a lot of new ones. Perhaps I should have put (draft PR don't review yet) in the title. :) Appreciate the eyes on it all the same though!

What's with DafnyRuntimeTests that makes them difficult to include at this time?

Nothing fundamental, it'll just be extra work to have the build process run C# tests as well as the lit tests. I initially created this just to validate my assumptions about the out type parameter qualifier, but plan to achieve adequate coverage through lit tests as usual. I definitely want to start adding C# tests but I didn't feel like this change was the right timing. I'm planning on returning to this in a later PR, but feel free to vote for getting the new project working now instead!

Some more tests of some compile code would be good. Also, it would be good to include that example (which I think sits somewhere in the test suite) that has the comment that says "this would be expensive to support at run time", to make sure it compiles correctly (to efficient code).

Agreed, working on the explicit tests now. You're referring to Test/dafny0/RuntimeTypeTests0.dfy I believe, which still doesn't work because it uses seq<object> which appears to be a special case. I'll check if it's easy to support that too.

@robin-aws
Copy link
Member Author

robin-aws commented Mar 5, 2020

Some more tests of some compile code would be good. Also, it would be good to include that example (which I think sits somewhere in the test suite) that has the comment that says "this would be expensive to support at run time", to make sure it compiles correctly (to efficient code).

Agreed, working on the explicit tests now. You're referring to Test/dafny0/RuntimeTypeTests0.dfy I believe, which still doesn't work because it uses seq<object> which appears to be a special case. I'll check if it's easy to support that too.

My mistake, that test happens to only cover set<trait> and (user-defined datatype)<trait>, which can be addressed with the same technique but requires about the same amount of compiler changes each, so I'm not going to address them in this PR. I will move my additional tests on seq<trait> to that file though.

@robin-aws
Copy link
Member Author

AWS CodeBuild CI Report

  • CodeBuild project: Dafny
  • Commit ID: 8d66c02
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@robin-aws
Copy link
Member Author

AWS CodeBuild CI Report

  • CodeBuild project: Dafny
  • Commit ID: 2a97770
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@robin-aws
Copy link
Member Author

AWS CodeBuild CI Report

  • CodeBuild project: Dafny
  • Commit ID: e55eebc
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@robin-aws
Copy link
Member Author

AWS CodeBuild CI Report

  • CodeBuild project: Dafny
  • Commit ID: a2b3639
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@robin-aws robin-aws changed the title Support seq<trait> in csharp (draft PR) Support seq<trait> in C# Mar 5, 2020
@robin-aws robin-aws changed the title Support seq<trait> in C# Support seq<trait> in C# Mar 5, 2020
@robin-aws
Copy link
Member Author

Ready for review now - interested in feedback on whether existing regression tests and the added case in Test/dafny0/RuntimeTypeTests0.dfy are adequate.

@robin-aws robin-aws marked this pull request as ready for review March 5, 2020 22:16
@RustanLeino
Copy link
Collaborator

Things look good. I think the one test in RuntimeTypeTests0.dfy is fine, since it mostly serves as a comparison with Datatype and set, which don't yet have this support. However, I do think that adding a run-time checked example would be appropriate, since the PR changes the run-time representation of sequences. (Note that, despite the /compile:3 flag and the Main method in this example, nothing gets executed because of the compiler errors.) Such tests would go well in Test/comp, where they could test the seq functionality for all target compilers.

@robin-aws
Copy link
Member Author

AWS CodeBuild CI Report

  • CodeBuild project: Dafny
  • Commit ID: 97319ee
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@robin-aws robin-aws changed the title Support seq<trait> in C# feat!: Support seq<trait> in C# Mar 9, 2020
@robin-aws robin-aws merged commit 9d79b3c into dafny-lang:master Mar 9, 2020
@robin-aws
Copy link
Member Author

AWS CodeBuild CI Report

  • CodeBuild project: Dafny
  • Commit ID: bfea981
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

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

Successfully merging this pull request may close these issues.

None yet

2 participants