Skip to content

Commit

Permalink
Merge pull request #239 from LPCIC/fix-linear
Browse files Browse the repository at this point in the history
fix regexp for linear variable silencing
  • Loading branch information
gares authored Jun 25, 2024
2 parents 40b1bc5 + 2cff654 commit c272d5f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/elpi-checker.elpi
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,14 @@ infix >>> 141.
type (>>>) term -> int -> entry.
type variable term -> prop.

pred silence-linear-warning i:string.
silence-linear-warning VN :- rex_match "^_.*" VN ; rex_match ".*_$" VN.

mode (report-linear i).
report-linear [].
report-linear [(V >>> 1 + uvar) |NS] :- !,
pp V VN,
if (not(rex_match "_" VN), not(rex_match ".*_" VN))
if (not(silence-linear-warning VN))
(checking LOC,
MSG is VN ^" is linear: name it _" ^ VN ^
" (discard) or " ^ VN ^ "_ (fresh variable)",
Expand All @@ -288,7 +291,7 @@ report-linear [(V >>> 1 + uvar) |NS] :- !,
report-linear NS.
report-linear [(V >>> uvar) |NS] :-
pp V VN,
if (not(rex_match "_" VN), not(rex_match ".*_" VN))
if (not(silence-linear-warning VN))
(checking LOC, MSG is VN ^" is unused", warning LOC MSG)
true,
report-linear NS.
Expand Down
2 changes: 2 additions & 0 deletions tests/sources/linear.elpi
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
main :-
X = Foo_Bar.
8 changes: 8 additions & 0 deletions tests/suite/elpi_specific.ml
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,14 @@ X0 || X2 && X3 ==> X4
|})))
()

let () = declare "linear"
~source_elpi:"linear.elpi"
~description:"linear variable check"
~typecheck:true
~expectation:Test.(SuccessOutput (Str.regexp_string "Foo_Bar is linear"))
()


let () = declare "IO_COLON"
~source_elpi:"io_colon.elpi"
~description:"IO_COLON token"
Expand Down

0 comments on commit c272d5f

Please sign in to comment.