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

Aligning changes from libraries-without-variance #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/Unicode/Utf16EncodingForm.dfy
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@ module Utf16EncodingForm refines UnicodeEncodingForm {
&& prefix == s[..|prefix|]
&& IsMinimalWellFormedCodeUnitSubsequence(prefix)
{
if |s| >= 1 && IsWellFormedSingleCodeUnitSequence(s[..1]) then Some(s[..1])
else if |s| >= 2 && IsWellFormedDoubleCodeUnitSequence(s[..2]) then Some(s[..2])
// Attaching the subset types explicitly to work around
// type inference not picking them (unless Option<T> is declared as Option<+T>).
// BUG(https://github.com/dafny-lang/dafny/issues/2551)
if |s| >= 1 && IsWellFormedSingleCodeUnitSequence(s[..1]) then
var r: MinimalWellFormedCodeUnitSeq := s[..1]; Some(r)
else if |s| >= 2 && IsWellFormedDoubleCodeUnitSequence(s[..2]) then
var r: MinimalWellFormedCodeUnitSeq := s[..2]; Some(r)
else None
}

Expand Down
15 changes: 11 additions & 4 deletions src/Unicode/Utf8EncodingForm.dfy
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,17 @@ module Utf8EncodingForm refines UnicodeEncodingForm {
function method SplitPrefixMinimalWellFormedCodeUnitSubsequence(s: CodeUnitSeq):
(maybePrefix: Option<MinimalWellFormedCodeUnitSeq>)
{
if |s| >= 1 && IsWellFormedSingleCodeUnitSequence(s[..1]) then Some(s[..1])
else if |s| >= 2 && IsWellFormedDoubleCodeUnitSequence(s[..2]) then Some(s[..2])
else if |s| >= 3 && IsWellFormedTripleCodeUnitSequence(s[..3]) then Some(s[..3])
else if |s| >= 4 && IsWellFormedQuadrupleCodeUnitSequence(s[..4]) then Some(s[..4])
// Attaching the subset types explicitly to work around
// type inference not picking it (unless Option<T> is declared as Option<+T>).
// BUG(https://github.com/dafny-lang/dafny/issues/2551)
if |s| >= 1 && IsWellFormedSingleCodeUnitSequence(s[..1]) then
var r: MinimalWellFormedCodeUnitSeq := s[..1]; Some(r)
else if |s| >= 2 && IsWellFormedDoubleCodeUnitSequence(s[..2]) then
var r: MinimalWellFormedCodeUnitSeq := s[..2]; Some(r)
else if |s| >= 3 && IsWellFormedTripleCodeUnitSequence(s[..3]) then
var r: MinimalWellFormedCodeUnitSeq := s[..3]; Some(r)
else if |s| >= 4 && IsWellFormedQuadrupleCodeUnitSequence(s[..4]) then
var r: MinimalWellFormedCodeUnitSeq := s[..4]; Some(r)
else None
}

Expand Down
14 changes: 14 additions & 0 deletions src/Wrappers.dfy
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ module Wrappers {
{
value
}

function method Map<NewT>(reWrap: T -> NewT): Option<NewT>
{
match this
case Some(v) => Some(reWrap(v))
case None => None
}
}

datatype Result<+T, +R> = | Success(value: T) | Failure(error: R) {
Expand Down Expand Up @@ -62,6 +69,13 @@ module Wrappers {
Failure(this.error)
}

function method MapSuccess<NewT>(reWrap: T -> NewT): Result<NewT, R>
{
match this
case Success(s) => Success(reWrap(s))
case Failure(e) => Failure(e)
}

function method MapFailure<NewR>(reWrap: R -> NewR): Result<T, NewR>
{
match this
Expand Down