Skip to content

feat: Allow type parameters on newtypes - #5495

Merged
RustanLeino merged 102 commits into
dafny-lang:masterfrom
RustanLeino:newtype-type-params
Aug 28, 2024
Merged

RustanLeino merged 102 commits into
dafny-lang:masterfrom
RustanLeino:newtype-type-params

Conversation

@RustanLeino

@RustanLeino RustanLeino commented May 28, 2024 •

Copy link
Copy Markdown
Collaborator

This PR adds the following language features:

  • type parameters of newtype declarations
  • optional witness clause of constraint-less newtype declarations
  • tool tips show auto-completed type parameters
  • tool tips show inferred (==) characteristics

It also makes a breaking change in what's allowed in refinement modules, namely that a refinement module is no longer allowed to rename type parameters. Since comparisons during these refinement checks are done syntactically, it gets difficult to make sure the types in the refinement module really mean the same thing as in the original module. Having the ability to rename type parameters here does not seem like an important feature, so it was easier to just be more strict about it. (Note, there are some cases where type parameters can be renamed when going from a trait to a type that implements the trait. Those comparisons are done with semantic information, so they can be done reliably.)

Along the way, the PR also fixes two previous soundness issues:

Fixes #5520
Fixes #5521

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

@ssomayyajula ssomayyajula left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved pending resolution of TODO in Combine()

ssomayyajula
ssomayyajula previously approved these changes Aug 26, 2024
Variance does not need to be considered here, because type parameters with non-co variance that should be excluded from these type-refinement flows have already been marked as such (by omitting the bottom wrapper in `PreType2RefinableType`).
@RustanLeino
RustanLeino merged commit 030ce55 into dafny-lang:master Aug 28, 2024
@RustanLeino
RustanLeino deleted the newtype-type-params branch August 28, 2024 21:30
dnezam pushed a commit to dnezam/dafny that referenced this pull request Aug 29, 2024
This PR adds the following language features:

* type parameters of `newtype` declarations
* optional `witness` clause of constraint-less `newtype` declarations
* tool tips show auto-completed type parameters
* tool tips show inferred `(==)` characteristics

Along the way, the PR also fixes two previous soundness issues:

* fix: Check the emptiness status of constraint-less `newtype`
declarations (dafny-lang#5520)
* fix: Don't let `newtype` well-formedness checking affect witness
checking (dafny-lang#5521)

Fixes dafny-lang#5520
Fixes dafny-lang#5521

<small>By submitting this pull request, I confirm that my contribution
is made under the terms of the [MIT
license](https://github.com/dafny-lang/dafny/blob/master/LICENSE.txt).</small>
dnezam pushed a commit to dnezam/dafny that referenced this pull request Sep 21, 2024
This PR adds the following language features:

* type parameters of `newtype` declarations
* optional `witness` clause of constraint-less `newtype` declarations
* tool tips show auto-completed type parameters
* tool tips show inferred `(==)` characteristics

Along the way, the PR also fixes two previous soundness issues:

* fix: Check the emptiness status of constraint-less `newtype`
declarations (dafny-lang#5520)
* fix: Don't let `newtype` well-formedness checking affect witness
checking (dafny-lang#5521)

Fixes dafny-lang#5520
Fixes dafny-lang#5521

<small>By submitting this pull request, I confirm that my contribution
is made under the terms of the [MIT
license](https://github.com/dafny-lang/dafny/blob/master/LICENSE.txt).</small>
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.

Constraint-less newtypes assumed to be nonempty Base type throws off witness checking

2 participants