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

FStar.Char: move type into smaller FStar.Char.Type module #3408

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

mtzguido
Copy link
Member

This reduces the dependencies that clients take on just for mentioning the char type or a character literal. Currently this brings in a lot to just check a module with let x = 'a':

Now lax-checking implementation of FStar.Pervasives.Native
Now lax-checking interface of FStar.Pervasives
Now lax-checking implementation of FStar.Mul
Now lax-checking interface of FStar.Classical
Now lax-checking implementation of FStar.StrongExcludedMiddle
Now lax-checking interface of FStar.Classical.Sugar
Now lax-checking implementation of FStar.List.Tot.Base
Now lax-checking implementation of FStar.List.Tot
Now lax-checking interface of FStar.Seq.Base
Now lax-checking interface of FStar.Seq.Properties
Now lax-checking implementation of FStar.Seq
Now lax-checking interface of FStar.Math.Lemmas
Now lax-checking implementation of FStar.BitVector
Now lax-checking interface of FStar.UInt32
Now lax-checking interface of FStar.Char

With this PR:

Now lax-checking implementation of FStar.Pervasives.Native
Now lax-checking interface of FStar.Pervasives
Now lax-checking interface of FStar.Char.Type

@mtzguido
Copy link
Member Author

This requires the following krml patch:

diff --git a/include/krml/internal/types.h b/include/krml/internal/types.h
index e41b39be..71e8733f 100644
--- a/include/krml/internal/types.h
+++ b/include/krml/internal/types.h
@@ -28,7 +28,7 @@ typedef uint64_t FStar_UInt63_t, FStar_UInt63_t_;
 typedef int64_t FStar_Int63_t, FStar_Int63_t_;
 
 typedef double FStar_Float_float;
-typedef uint32_t FStar_Char_char;
+typedef uint32_t FStar_Char_Type_char;
 typedef FILE *FStar_IO_fd_read, *FStar_IO_fd_write;
 
 typedef void *FStar_Dyn_dyn;
diff --git a/krmllib/c/fstar_char.c b/krmllib/c/fstar_char.c
index f6931522..669220cc 100644
--- a/krmllib/c/fstar_char.c
+++ b/krmllib/c/fstar_char.c
@@ -3,6 +3,6 @@
 
 #include "FStar_Char.h"
 
-FStar_Char_char FStar_Char_char_of_u32(uint32_t x) {
+FStar_Char_Type_char FStar_Char_Type_char_of_u32(uint32_t x) {
   return x;
 }
diff --git a/krmllib/c/fstar_string.c b/krmllib/c/fstar_string.c
index 1117bfa2..7e920134 100644
--- a/krmllib/c/fstar_string.c
+++ b/krmllib/c/fstar_string.c
@@ -28,7 +28,7 @@ Prims_string FStar_String_strcat(Prims_string s0, Prims_string s1) {
 }
 
 
-krml_checked_int_t FStar_String_index_of(Prims_string s1, FStar_Char_char fc) {
+krml_checked_int_t FStar_String_index_of(Prims_string s1, FStar_Char_Type_char fc) {
   if (fc > 127) {
     KRML_HOST_PRINTF("FStar.Char.char overflow at %s:%d\n", __FILE__, __LINE__);
     KRML_HOST_EXIT(252);
diff --git a/krmllib/c/lowstar_printf.c b/krmllib/c/lowstar_printf.c
index 409dfbf1..91a8a4ab 100644
--- a/krmllib/c/lowstar_printf.c
+++ b/krmllib/c/lowstar_printf.c
@@ -17,7 +17,7 @@
   PRINTB(N, T, M2)
 
 PRINT2 (string, Prims_string, "s", "s")
-PRINT2 (char, FStar_Char_char, PRIu32, PRIx32)
+PRINT2 (char, FStar_Char_Type_char, PRIu32, PRIx32)
 PRINT2 (u8, uint8_t, PRIu8, PRIx8)
 PRINT2 (u16, uint16_t, PRIu16, PRIx16)
 PRINT2 (u32, uint32_t, PRIu32, PRIx32)

@gebner
Copy link
Contributor

gebner commented Aug 26, 2024

This reduces the dependencies that clients take on just for mentioning the char type or a character literal. Currently this brings in a lot to just check a module with let x = 'a':

Now lax-checking implementation of FStar.Pervasives.Native
Now lax-checking interface of FStar.Pervasives
Now lax-checking implementation of FStar.Mul
Now lax-checking interface of FStar.Classical
Now lax-checking implementation of FStar.StrongExcludedMiddle
Now lax-checking interface of FStar.Classical.Sugar
Now lax-checking implementation of FStar.List.Tot.Base
Now lax-checking implementation of FStar.List.Tot
Now lax-checking interface of FStar.Seq.Base
Now lax-checking interface of FStar.Seq.Properties
Now lax-checking implementation of FStar.Seq
Now lax-checking interface of FStar.Math.Lemmas
Now lax-checking implementation of FStar.BitVector
Now lax-checking interface of FStar.UInt32
Now lax-checking interface of FStar.Char

FWIW, we could eliminate the Classical.Sugar dependency by adding an interface to FStar.List.Tot.Base.fst (which includes proofs right now!).

@mtzguido
Copy link
Member Author

Good point! I did this for List.Tot.Properties yesterday but didn't do Base yet. It was a bit of pain, wondering if we can do something more systematic to, say, find proofs in fstis and/or infer an interface for a module.

@gebner
Copy link
Contributor

gebner commented Aug 26, 2024

I'm not sure if it's worth it to automate the interface-generation step, but I think a reasonable policy would be that interfaces shouldn't depend on "proof modules":

❯ fstar.exe --dep make {,experimental/}*.fsti 2>/dev/null | grep -v 'Tactics.*:' | rg '\.fsti:.*(Classical|Lemmas)'
FStar.GSet.fsti: FStar.Classical.fsti FStar.Set.fsti FStar.Pervasives.fsti prims.fst
FStar.GhostSet.fsti: FStar.Classical.fsti FStar.Set.fsti FStar.Pervasives.fsti prims.fst
LowStar.Literal.fsti: FStar.Pervasives.Native.fst FStar.Map.fsti FStar.Set.fsti FStar.Seq.fst FStar.Int.Cast.Full.fst FStar.Math.Lemmas.fsti FStar.UInt8.fsti FStar.String.fsti FStar.List.Tot.fst FStar.UInt32.fsti FStar.Char.fsti FStar.Mul.fst FStar.HyperStack.ST.fsti FStar.HyperStack.fst LowStar.ImmutableBuffer.fst LowStar.Buffer.fst FStar.Pervasives.fsti prims.fst
FStar.Modifies.fsti: FStar.ModifiesGen.fsti FStar.Map.fsti FStar.Heap.fst FStar.Pervasives.Native.fst FStar.Classical.fsti FStar.UInt32.fsti FStar.Preorder.fst FStar.Set.fsti /home/gebner/FStar/ulib/legacy/FStar.Buffer.fst FStar.HyperStack.ST.fsti FStar.HyperStack.fst FStar.Pervasives.fsti prims.fst
FStar.Endianness.fsti: FStar.Mul.fst FStar.Seq.fst FStar.Math.Lemmas.fsti FStar.UInt64.fsti FStar.UInt32.fsti FStar.UInt8.fsti FStar.Pervasives.fsti prims.fst
FStar.UInt.fsti: FStar.Seq.Base.fsti FStar.Math.Lemmas.fsti FStar.BitVector.fsti FStar.Mul.fst FStar.Pervasives.fsti prims.fst
FStar.Matrix.fsti: FStar.Classical.fsti FStar.Mul.fst FStar.IntegerIntervals.fst FStar.Math.Lemmas.fsti FStar.Seq.Base.fsti FStar.Seq.Permutation.fsti FStar.Algebra.CommMonoid.Fold.fsti FStar.Algebra.CommMonoid.Equiv.fst FStar.Pervasives.fsti prims.fst
FStar.Int.fsti: FStar.Seq.fst FStar.UInt.fsti FStar.Math.Lemmas.fsti FStar.BitVector.fsti FStar.Mul.fst FStar.Pervasives.fsti prims.fst

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.

2 participants