Skip to content

Commit 4e39dc0

Browse files
authored
Merge pull request #3982 from mtzguido/#check
Introduce #check pragma
2 parents 6433df9 + e271a5b commit 4e39dc0

18 files changed

+92
-33
lines changed

bare-tests/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
_cache
2+
_output

bare-tests/Check.fst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module Check
2+
3+
open Prims
4+
5+
#check 1
6+
#check 1+1
7+
8+
let foo x = x
9+
10+
#push-options "--print_implicits"
11+
#check foo
12+
#pop-options

bare-tests/Check.fst.output.expected

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
* Info at Check.fst(5,0-5,8):
2+
- Term 1 has type Prims.int
3+
4+
* Info at Check.fst(6,0-6,10):
5+
- Term 1 + 1 has type Prims.int
6+
7+
* Info at Check.fst(11,0-11,10):
8+
- Term Check.foo has type Prims.Tot (#_: Type -> x: _ -> Prims.Tot _)
9+

bare-tests/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
FSTAR_ARGS += --no_prelude
1010
OTHERFLAGS += --already_cached '-Prims,-FStar,-LowStar' # remove this which test.mk adds by default
1111

12+
OTHERFLAGS += --warn_error -241
13+
# ^ When running the output rules, we may not have checked files. This
14+
# is since the rule in ../mk/test.mk only depends on the fst and not on
15+
# the computed dependencies. That should be fixed. For now, just ignore
16+
# warnings about missing checked files since it will mess up the output.
17+
1218
FSTAR_ROOT ?= ..
1319
FSTAR_EXE ?= $(abspath $(FSTAR_ROOT)/stage1/dune/_build/default/fstarc-bare/fstarc1_bare.exe)
1420
export FSTAR_LIB ?= $(abspath $(FSTAR_ROOT)/ulib)

mk/diff.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ else
2020
# We're gonna fail. If we're running in CI, emit a Github
2121
# error message.
2222
if [ -v GITHUB_ENV ]; then
23-
DIFFTEXT=$($DIFF "$ACTUAL" "$EXPECTED" | sed 's/$/%0A/' | tr -d '\n')
23+
DIFFTEXT=$($DIFF "$EXPECTED" "$ACTUAL" | sed 's/$/%0A/' | tr -d '\n')
2424
ACTUAL=$(realpath "$ACTUAL")
2525
ACTUAL="${ACTUAL#$FSTAR_ROOT}"
2626
EXPECTED=$(realpath "$EXPECTED")

src/ml/FStarC_Parser_LexFStar.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ match%sedlex lexbuf with
471471
| "#pop-options" -> PRAGMA_POP_OPTIONS
472472
| "#restart-solver" -> PRAGMA_RESTART_SOLVER
473473
| "#print-effects-graph" -> PRAGMA_PRINT_EFFECTS_GRAPH
474+
| "#check" -> PRAGMA_CHECK
474475
| "__SOURCE_FILE__" -> STRING (Filepath.basename (L.source_file lexbuf))
475476
| "__LINE__" -> INT (string_of_int (L.current_line lexbuf))
476477
| "__FILELINE__" -> STRING (Filepath.basename (L.source_file lexbuf) ^ "(" ^ (string_of_int (L.current_line lexbuf)) ^ ")")

src/ml/FStarC_Parser_Parse.mly

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ type tc_constraint = {
112112
%token IRREDUCIBLE UNFOLDABLE INLINE OPAQUE UNFOLD INLINE_FOR_EXTRACTION
113113
%token NOEXTRACT
114114
%token NOEQUALITY UNOPTEQUALITY
115-
%token PRAGMA_SHOW_OPTIONS PRAGMA_SET_OPTIONS PRAGMA_RESET_OPTIONS PRAGMA_PUSH_OPTIONS PRAGMA_POP_OPTIONS PRAGMA_RESTART_SOLVER PRAGMA_PRINT_EFFECTS_GRAPH
115+
%token PRAGMA_SHOW_OPTIONS PRAGMA_SET_OPTIONS PRAGMA_RESET_OPTIONS PRAGMA_PUSH_OPTIONS PRAGMA_POP_OPTIONS PRAGMA_RESTART_SOLVER PRAGMA_PRINT_EFFECTS_GRAPH PRAGMA_CHECK
116116
%token TYP_APP_LESS TYP_APP_GREATER SUBTYPE EQUALTYPE SUBKIND BY
117117
%token AND ASSERT SYNTH BEGIN ELSE END
118118
%token EXCEPTION FALSE FUN FUNCTION IF IN MODULE DEFAULT
@@ -224,18 +224,13 @@ startOfNextDeclToken:
224224

225225
pragmaStartToken:
226226
| PRAGMA_SHOW_OPTIONS
227-
{ () }
228227
| PRAGMA_SET_OPTIONS
229-
{ () }
230228
| PRAGMA_RESET_OPTIONS
231-
{ () }
232229
| PRAGMA_PUSH_OPTIONS
233-
{ () }
234230
| PRAGMA_POP_OPTIONS
235-
{ () }
236231
| PRAGMA_RESTART_SOLVER
237-
{ () }
238232
| PRAGMA_PRINT_EFFECTS_GRAPH
233+
| PRAGMA_CHECK
239234
{ () }
240235

241236
/******************************************************************************/
@@ -257,6 +252,8 @@ pragma:
257252
{ RestartSolver }
258253
| PRAGMA_PRINT_EFFECTS_GRAPH
259254
{ PrintEffectsGraph }
255+
| PRAGMA_CHECK t=term
256+
{ Check t }
260257

261258
attribute:
262259
| LBRACK_AT x = list(atomicTerm) RBRACK

src/parser/FStarC.Parser.AST.Diff.fst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ let eq_pragma (t1 t2: pragma) =
455455
| PopOptions, PopOptions -> true
456456
| RestartSolver, RestartSolver -> true
457457
| PrintEffectsGraph, PrintEffectsGraph -> true
458+
| Check t1, Check t2 -> eq_term t1 t2
458459
| _ -> false
459460

460461

src/parser/FStarC.Parser.AST.fst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,7 @@ let string_of_pragma = function
858858
| PopOptions -> "pop-options"
859859
| RestartSolver -> "restart-solver"
860860
| PrintEffectsGraph -> "print-effects-graph"
861+
| Check t -> "check " ^ term_to_string t
861862
862863
let restriction_to_string: FStarC.Syntax.Syntax.restriction -> string =
863864
let open FStarC.Syntax.Syntax in

src/parser/FStarC.Parser.AST.fsti

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ type pragma =
234234
| PopOptions
235235
| RestartSolver
236236
| PrintEffectsGraph
237+
| Check of term
237238

238239
type dep_scan_callbacks = {
239240
scan_term: term -> unit;

0 commit comments

Comments
 (0)