-
Notifications
You must be signed in to change notification settings - Fork 237
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
Much cleaner strings with index_extensionality (and for Seq and ImmutableArray) that does not create a new eq. #3598
Open
briangmilnes
wants to merge
6
commits into
FStarLang:master
Choose a base branch
from
briangmilnes:milnes-restring
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
491140a
Much cleaner strings with index_extensionality (and for Seq and Immut…
briangmilnes 66d4992
Merge branch 'master' into milnes-restring
briangmilnes 10d95e9
Nik caught a bogus -1 in an interface, all still proves.
briangmilnes a1a7d0f
Merged milnes-restring
briangmilnes 5c32a0c
Nik caught a bogus -1 and it should have been a <= for a variable pos…
briangmilnes 0a18e5c
Oops, missed some files on the checkin.
briangmilnes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
(* | ||
Copyright 2024 Microsoft Research | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
Author: Brian Milnes <[email protected]> | ||
|
||
*) | ||
|
||
module Test.FStar.String.TestMain | ||
|
||
open FStar.String | ||
open FStar.String.Base | ||
open FStar.String.Properties | ||
open FStar.String.Match | ||
open FStar.IO | ||
open FStar.Class.Printable | ||
|
||
let main () = | ||
print_string "Running TestMain.main() \n"; | ||
print_string("lines \"\" 0 " ^ (to_string (lines "" 0)) ^ "\n"); | ||
assert_norm(strlen "ABCDEF" = 6); | ||
assert_norm(strlen "ABC123" = 6); | ||
print_string("streq_upto' \"ABCDEF\" \"ABC123\" 1 " ^ | ||
(to_string (streq_upto' "ABCDEF" "ABC123" 1)) ^ "\n"); | ||
print_string("streq_upto' \"ABCDEF\" \"ABC123\" 2 " ^ | ||
(to_string (streq_upto' "ABCDEF" "ABC123" 2)) ^ "\n"); | ||
print_string("streq_upto' \"ABCDEF\" \"ABC123\" 3 " ^ | ||
(to_string (streq_upto' "ABCDEF" "ABC123" 3)) ^ "\n"); | ||
print_string("streq_upto' \"ABCDEF\" \"ABC123\" 4 " ^ | ||
(to_string (streq_upto' "ABCDEF" "ABC123" 4)) ^ "\n") | ||
|
||
#push-options "--warn_error -272" | ||
let _ = main () | ||
#pop-options |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
(* | ||
Copyright 2024 Microsoft Research | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
Author: Brian Milnes <[email protected]> | ||
|
||
*) | ||
|
||
/// Some of these tests are marked with expect_failure as they won't run at | ||
/// validation time given an interface file for operations. There is run -time | ||
/// test code for them in another FStar.String.TestMain. Which at this point | ||
/// only prints. | ||
/// | ||
|
||
module Test.FStar.String | ||
|
||
open FStar.String | ||
|
||
open FStar.String | ||
open FStar.String.Base | ||
open FStar.String.Properties | ||
open FStar.String.Match | ||
open FStar.Class.Printable | ||
|
||
/// Is this caused by strlen being UTF8 characters instead of bytes? | ||
/// And there is no byte length. | ||
let _ = assert_norm(strlen "A" = 1) | ||
let _ = assert(streq_upto "A" "AB" 0) | ||
let _ = assert(streq_upto "AB" "AB" 0) | ||
|
||
let _ = assert_norm(streq_upto "AB" "AB" 1) | ||
let _ = assert_norm(streq_upto "AB" "AB" 2) | ||
|
||
[@@expect_failure] | ||
let _ = assert_norm(lines "" 0 = (0,0)) | ||
|
||
[@@expect_failure] | ||
let _ = assert_norm(lines "A" 0 = (0,0)) | ||
let _ = assert_norm(strlen "A" = 1) | ||
|
||
let strlen_A_1 () : Lemma (strlen "A" = 1) = assert_norm(strlen "A" = 1) | ||
|
||
[@@expect_failure] | ||
let _ = assert_norm(strlen_A_1(); lines "A" 1 = (0,1)) | ||
|
||
[@@expect_failure] | ||
let _ = assert_norm(strlen "A\n" = 2); | ||
assert_norm(lines "A\n" 1 = (0,1)) | ||
|
||
[@@expect_failure] | ||
let _ = assert_norm(strlen "AB\nC\nD" = 6); | ||
assert_norm(lines "AB\nC\nD" 0 = (0,0)) | ||
|
||
[@@expect_failure] | ||
let _ = assert_norm(strlen "AB\nC\nD" = 6); | ||
assert_norm(lines "AB\nC\nD" 1 = (0,1)) | ||
|
||
[@@expect_failure] | ||
let _ = assert_norm(strlen "AB\nC\nD" = 6); | ||
assert_norm(lines "AB\nC\nD" 2 = (0,2)) | ||
|
||
[@@expect_failure] | ||
let _ = assert_norm(strlen "AB\nC\nD" = 6); | ||
assert_norm(lines "AB\nC\nD" 3 = (1,0)) | ||
|
||
[@@expect_failure] | ||
let _ = assert_norm(strlen "AB\nC\nD" = 6); | ||
assert_norm(lines "AB\nC\nD" 4 = (1,1)) | ||
|
||
[@@expect_failure] | ||
let _ = assert_norm(strlen "AB\nC\nD" = 6); | ||
assert_norm(lines "AB\nC\nD" 5 = (2,0)) | ||
|
||
[@@expect_failure] | ||
let _ = assert_norm(strlen "AB\nC\nD" = 6); | ||
assert_norm(lines "AB\nC\nD" 6 = (2,1)) | ||
|
||
/// A few streq_uptos | ||
let _ = assert_norm(strlen "ABCDEF" = 6); | ||
assert_norm(streq_upto "ABCDEF" "ABCDEF" 0) | ||
|
||
let _ = assert_norm(strlen "ABCDEF" = 6); | ||
assert_norm(streq_upto "ABCDEF" "ABCDEF" 1) | ||
|
||
let _ = assert_norm(strlen "ABCDEF" = 6); | ||
assert_norm(streq_upto "ABCDEF" "ABCDEF" 6) | ||
|
||
let _ = assert_norm(strlen "ABCDEF" = 6); | ||
assert_norm(streq_upto "ABCDEF" "ABCDEF" 6) | ||
|
||
let _ = assert_norm(strlen "ABCDEF" = 6); | ||
assert_norm(~(streq_upto "ABCDEF" "ABC" 6)) | ||
|
||
/// A few streq_upto' | ||
let _ = assert_norm(strlen "ABCDEF" = 6); | ||
assert_norm(streq_upto' "ABCDEF" "ABCDEF" 0) | ||
|
||
let _ = assert_norm(strlen "ABCDEF" = 6); | ||
assert_norm(streq_upto' "ABCDEF" "ABCDEF" 1) | ||
|
||
let _ = assert_norm(strlen "ABCDEF" = 6); | ||
assert_norm(streq_upto' "ABCDEF" "ABCDEF" 6) | ||
|
||
let _ = assert_norm(strlen "ABCDEF" = 6); | ||
assert_norm(streq_upto' "ABCDEF" "ABCDEF" 6) | ||
|
||
[@@expect_failure] | ||
let _ = assert_norm(strlen "ABCDEF" = 6); | ||
assert_norm(strlen "ABC123" = 6); | ||
assert_norm(streq_upto' "ABCDEF" "ABC123" 1) | ||
|
||
[@@expect_failure] | ||
let _ = assert_norm(strlen "ABCDEF" = 6); | ||
assert_norm(strlen "ABC123" = 6); | ||
assert_norm(streq_upto' "ABCDEF" "ABC123" 2) | ||
[@@expect_failure] | ||
let _ = assert_norm(strlen "ABCDEF" = 6); | ||
assert_norm(strlen "ABC123" = 6); | ||
assert_norm(streq_upto' "ABCDEF" "ABC123" 3) | ||
|
||
[@@expect_failure] | ||
let _ = assert_norm(strlen "ABCDEF" = 6); | ||
assert_norm(strlen "ABC123" = 6); | ||
assert_norm(~(streq_upto' "ABCDEF" "ABC123" 4)) | ||
|
||
[@@expect_failure] | ||
let _ = assert_norm(strlen "ABCDEF" = 6); | ||
assert_norm(strlen "ABC123" = 6); | ||
assert_norm(~(streq_upto' "ABCDEF" "ABC123" 5)) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
(* | ||
Copyright 2024 Microsoft Research | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
Author: Brian Milnes <[email protected]> | ||
|
||
*) | ||
module FStar.String.Base | ||
|
||
let rec streq_upto'' (s1: string) (s2: string{strlen s1 = strlen s2}) | ||
(to: nat{to <= strlen s1}) (from: nat{from <= strlen s1 /\ streq_upto s1 s2 from /\ from <= to}): | ||
Tot (b:bool{b <==> streq_upto s1 s2 to}) | ||
(decreases strlen s1 - from) | ||
= | ||
if from = to | ||
then true | ||
else if from = strlen s1 | ||
then true | ||
else if index s1 from <> index s2 from | ||
then false | ||
else streq_upto'' s1 s2 to (from+1) | ||
|
||
let streq_upto' s1 (s2: string{strlen s1 = strlen s2}) (to: nat{to <= strlen s1}): | ||
Tot (b:bool{b <==> streq_upto s1 s2 to}) | ||
= streq_upto'' s1 s2 to 0 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
(* | ||
Copyright 2024 Microsoft Research | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*) | ||
|
||
module FStar.String.Base | ||
open FStar.String | ||
|
||
/// Partial equivalence properties. | ||
|
||
let streq_upto s1 s2 (pos: nat) = | ||
(pos <= strlen s1 /\ pos <= strlen s2 /\ | ||
(forall (i: nat{i < pos}). index s1 i = index s2 i)) | ||
|
||
let streq_upto_min s1 s2 (pos: int{pos < (min (strlen s1) (strlen s2))}) = | ||
(forall (i: nat{i < (pos - 1)}). index s1 i = index s2 i) | ||
|
||
/// The boolean form of streq. | ||
|
||
val streq_upto' s1 (s2: string{strlen s1 = strlen s2}) (to: nat{to <= strlen s1}): | ||
Tot (b:bool{b <==> streq_upto s1 s2 to}) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The minus 1 here looks suspicious.