-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore: No extra newtype test (#5506)
### Description Let's consider the following code: ```dafny newtype UX = x: int | 129 <= x < 256 method Main() { var u8toInt := map[1 as u8 := 1, 2 as u8 := 2]; var IntToU8 := map k <- u8toInt :: u8toInt[k] := k; } ``` in every backend, for `IntToU8 `it is generating code lilke ``` c = MapCollectionBuilder() for k in u8toInt if k is u8 { if u8toInt contains k { col.Add(u8toInt[k], k) } } } k.build() ``` I already filed an issue that the ["contains" test is redundant](#5465) when we are already iterating over the collection. But here there is another test that is redundant: The membership test to the newtype. Indeed, contrary to subset types which can be erased, newtype conversions must be explicit. So we cannot iterate over a newtype different than the newtype obtain like we do for subset types. Moreover, the test of being a newtype involves a conversion from a U8 (how the newtype is encoded) to a DafnyInt because otherwise we would not be able to compare it with the number "256" which is out of the range. So this test is not only redundant, it actually adds computation that is not necessary. ### How has this been tested? All existing tests should pass. <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>
- Loading branch information
1 parent
9f0cda2
commit f0b25e0
Showing
3 changed files
with
35 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters