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

Mutable maps via Java extern #87

Merged
merged 47 commits into from
Feb 24, 2023
Merged

Mutable maps via Java extern #87

merged 47 commits into from
Feb 24, 2023

Conversation

stefan-aws
Copy link
Contributor

@stefan-aws stefan-aws commented Feb 15, 2023

Per request, adds support for mutable maps by interfacing with Java. Partly follows https://github.com/dafny-lang/dafny/wiki/Modeling-External-State-Correctly and https://github.com/dafny-lang/libraries/tree/master/src/FileIO.

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

@stefan-aws stefan-aws marked this pull request as ready for review February 16, 2023 17:05
@stefan-aws stefan-aws requested a review from robin-aws February 16, 2023 17:06
@stefan-aws stefan-aws changed the title DRAFT: Mutable map Mutable maps via Java extern Feb 16, 2023
Copy link
Member

@robin-aws robin-aws left a comment

Choose a reason for hiding this comment

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

Looks great! Lots of suggestions for polish but nothing serious.

src/MutableMap/MutableMap.dfy Outdated Show resolved Hide resolved
examples/MutableMap/MutableMapExamples.dfy Outdated Show resolved Hide resolved
reads this
ensures keys == this.content().Keys

function {:extern "values"} Values(): (values: set<V>)
Copy link
Member

Choose a reason for hiding this comment

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

Could we leave off Values() and Items() for now, so that we don't force V to be equality-supporting unnecessarily?

Alternatively, you could make those methods instead of functions and have them return non-deterministically ordered sequences instead of sets.

Copy link
Member

Choose a reason for hiding this comment

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

I'm especially inclined to leave these out given dafny-lang/dafny#1373

Copy link
Collaborator

Choose a reason for hiding this comment

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

Keep them functions if they are there. But perhaps then we need two types, because equality supporting types for the parameters are going to be by far the most common.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From what I've seen, at least Values() is used frequently by our customers. It would be good if we could find a way to support it.

src/MutableMap/MutableMap.dfy Outdated Show resolved Hide resolved
src/MutableMap/MutableMap.dfy Outdated Show resolved Hide resolved
src/MutableMap/MutableMap.dfy Outdated Show resolved Hide resolved
src/MutableMap/MutableMap.dfy Show resolved Hide resolved
src/MutableMap/MutableMapFeasability.dfy Outdated Show resolved Hide resolved
src/MutableMap/MutableMap.java Outdated Show resolved Hide resolved
src/MutableMap/MutableMap.dfy Outdated Show resolved Hide resolved
examples/MutableMap/MutableMapExamples.dfy Show resolved Hide resolved
src/MutableMap/MutableMap.java Show resolved Hide resolved
src/MutableMap/MutableMapDafny.dfy Outdated Show resolved Hide resolved
src/MutableMap/MutableMapTrait.dfy Outdated Show resolved Hide resolved
examples/MutableMap/MutableMapExamples.dfy Outdated Show resolved Hide resolved
Copy link
Member

@robin-aws robin-aws left a comment

Choose a reason for hiding this comment

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

Looks great, just a couple of bookkeeping changes to do

src/MutableMap/MutableMap.dfy Outdated Show resolved Hide resolved
examples/MutableMap/MutableMapTrait.dfy Show resolved Hide resolved
@robin-aws
Copy link
Member

Oh one other thing for later: users might expect more to find this under "Collections". We may want to consider that when we make a copy for this under DafnyCore as well.

@stefan-aws stefan-aws requested a review from robin-aws February 24, 2023 19:21
Comment on lines +18 to +19
* NOTE: Only here because of #2500; once resolved import "../../examples/MutableMap/
* MutableMapTrait.dfy".
Copy link
Member

Choose a reason for hiding this comment

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

nit for later: it seems useful to have the trait for consumers too, so my preference would be to remove the example copy instead. But this is fine for now.

Copy link
Member

@robin-aws robin-aws left a comment

Choose a reason for hiding this comment

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

Hooray for 🔇 🅰️ 🔔 🗺️s!

@stefan-aws stefan-aws requested a review from alex-chew February 24, 2023 19:29
@robin-aws robin-aws dismissed davidcok’s stale review February 24, 2023 19:52

Feedback addressed and reviewer is not available for a while

@robin-aws robin-aws merged commit dc95fdd into master Feb 24, 2023
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.

5 participants