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

[minor] January 31st Update #224

Merged
merged 81 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
f288337
fix: sem ver up; push action is from another repo
tnelson Jan 18, 2023
4cc335c
fix: remove old forge/forge/forge/check-ex-spec
tnelson Jan 18, 2023
779651b
Merge branch 'main' into dev
tnelson Jan 18, 2023
bc864ef
Replacing where blocks with test-suite construct (#171)
sidprasad Jan 19, 2023
a252465
Typed Froglet (#154)
bennn Jan 19, 2023
33966bf
don't export unnamed tests / runs (#172)
bennn Jan 19, 2023
8a8f1b3
Property Where Syntax update (#174)
sidprasad Jan 20, 2023
bdfff3d
froglet / bsl: allow +, -> in examples (#173)
bennn Jan 20, 2023
63d8b65
bump version
bennn Jan 21, 2023
634488c
restore the syntax-local-context of example blocks (#178)
bennn Jan 24, 2023
8c1b1d2
ci: revert froglet install, forge works for both (#176)
bennn Jan 26, 2023
27ceebb
ci: use LOCAL forge, not pkg forge
bennn Jan 26, 2023
e305b90
feat: universal dylibs for minisat, minisatp, glucose
tnelson Jan 27, 2023
a3d3d86
froglet: fix internal arity error
bennn Jan 30, 2023
76b52f1
no examples in temporal mode (#179)
bennn Jan 30, 2023
9d88af7
flush logs at toplevel (#177)
bennn Jan 30, 2023
af6714e
Merge branch 'main' into dev
tnelson Jan 31, 2023
99d7453
froglet checkpoint (#185)
bennn Feb 1, 2023
41af3f8
example: quick fix for multi-line bounds
bennn Feb 6, 2023
da6b6c3
examples: use one syntax-parameterize, not N, flatten bounds later (#…
bennn Feb 6, 2023
93b6277
typed froglet checkpoint (#188)
bennn Feb 6, 2023
f57b3b4
forge/bsl: don't use 'froglet' in runtime error messages
bennn Feb 6, 2023
7142945
uncomment error tests
bennn Feb 6, 2023
e6040f6
Merge branch 'main' into dev
bennn Feb 6, 2023
cc262e3
ci: use local froglet
bennn Feb 6, 2023
a9759e5
Merge branch 'main' of github.com:tnelson/Forge into dev
bennn Feb 6, 2023
5ca6198
server: relax regexp for java version
bennn Feb 6, 2023
2dc077e
add flag to hide preds (#181)
bennn Feb 7, 2023
64d47b4
Unset _JAVA__OPTIONS in `java>=1.9?' (#193)
TsarFox Feb 10, 2023
6192e69
One pardinus (#187)
tnelson Feb 11, 2023
b7c440c
Logging: anonymize paths in error outputs, print boring string on fai…
bennn Feb 20, 2023
99d1a73
detect use of temporal operators without temporal mode
tnelson Feb 20, 2023
8d6f79a
parser: change ~literal to ~datum (#201)
bennn Feb 24, 2023
3c96f51
feat: test case for PR 201
tnelson Feb 24, 2023
96b0631
forge/bsl: allow + -> in inst blocks (#202)
bennn Mar 5, 2023
80c5248
fix: metadata transmission to sterling
tnelson Mar 8, 2023
c508424
print git branch, commit, timestamp info (#195)
bennn Mar 8, 2023
884af8a
Merge branch 'main' into dev
tnelson Mar 8, 2023
e6ae351
housekeeping: relocate OLD, consolidate
tnelson Apr 26, 2023
59e12ab
feat: updated Sterling for dev testing
tnelson Apr 26, 2023
4227997
add binary-tree vis example
tnelson Apr 26, 2023
20aaeee
static example
tnelson Apr 26, 2023
096181c
fix: faster Edge object rendering
tnelson Apr 27, 2023
d8ffaa1
add tree3 viz example
tnelson Apr 28, 2023
f2554eb
minor change to tree3
tnelson Apr 28, 2023
bbbe044
fix: CI badge
tnelson Apr 28, 2023
7ecf40b
CI badge
tnelson Apr 28, 2023
d86d588
improved tree3
tnelson Apr 28, 2023
41bbd2b
update Sterling: events, arcs, images, pictures
tnelson May 13, 2023
7b0557d
fix: sterling update
tnelson May 15, 2023
50dbec0
add do-time macro, time a few spots (#210)
bennn Jul 16, 2023
4f93c60
semanticVersion: canonize major/minor numbers (#205)
bennn Jul 16, 2023
78c6e58
Merge branch 'main' into dev
tnelson Jul 16, 2023
80d15b8
Merge branch 'main' into dev
tnelson Jul 16, 2023
6417283
Crypto DSL for Guttmanfest (#209)
tnelson Jul 16, 2023
6cc349d
minor cleanup, enable run_sterling option to carry a filename
tnelson Jul 25, 2023
f8d0f19
sending script text if provided, fix relative paths (#216)
tnelson Aug 8, 2023
4da80ae
Basic updates to AST, parsing to prep for 2024 (#217)
tnelson Jan 4, 2024
63aec6b
add: #lang forge/temporal
tnelson Jan 4, 2024
3845296
add: 5 simple examples
tnelson Jan 4, 2024
3222771
fix: f4_counter
tnelson Jan 4, 2024
11744e6
Merge branch 'main' into dev
tnelson Jan 5, 2024
005d696
Merge branch 'main' into dev
tnelson Jan 5, 2024
94dc22b
add: Mia's viz for crypto
tnelson Jan 5, 2024
14f65cd
add: GCW puzzle example, original vis script
tnelson Jan 5, 2024
0d8986b
add: network lab adaptation to Forge
tnelson Jan 5, 2024
b9937d6
fix: join on helper functions, crypto example
tnelson Jan 5, 2024
78ec163
add: reflect crypto example
tnelson Jan 6, 2024
e0a8a76
update: add note on narrowing, minimal example
tnelson Jan 9, 2024
2cff004
ABAC DSL, some fixes (#220)
tnelson Jan 15, 2024
e60501f
fix: stopgap to show an actual message if out of instances
tnelson Jan 17, 2024
3b4d827
fix: readable errors, although Sterling displays poorly
tnelson Jan 17, 2024
ec3a5b1
update: sterling
tnelson Jan 21, 2024
9654edd
fix: stop trying to reload a run_sterling file if it doesn't exist
tnelson Jan 21, 2024
1def57f
update Sterling: pre-load script
tnelson Jan 22, 2024
4c350a2
fix: consistent update outside of strict dev mode
tnelson Jan 22, 2024
1b65e03
fix: improve error in case set comprehension is used improperly
Jan 25, 2024
cc46287
Retain sytnax loc (#221)
tnelson Jan 26, 2024
d612cdf
fix: preserve stx loc when desugaring test, example
tnelson Jan 26, 2024
8af5305
Roll in better handling of some errors, propagate stxloc; beginnings …
tnelson Jan 31, 2024
5e58760
Merge branch 'main' into dev
tnelson Jan 31, 2024
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
112 changes: 91 additions & 21 deletions forge/lang/ast.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,19 @@
(struct node/int node () #:transparent)

; Should never be directly instantiated
(struct node/formula node () #:transparent)
(struct node/formula node () #:transparent
; Give a friendlier error if Racket thinks we are asking it to treat a formula as a function
#:property prop:procedure
(λ (f . x)
(cond [(node/fmla/pred-spacer? f)
(raise-forge-error
#:msg (format "Tried to give arguments to a predicate, but it takes none: ~a." (node/fmla/pred-spacer-name f))
#:context f)]
[else
(raise-forge-error
#:msg (format "Could not use formula as a function: ~a." (deparse f))
#:context f)])))


;; ARGUMENT CHECKS -------------------------------------------------------------

Expand Down Expand Up @@ -451,15 +463,21 @@
; Helper to construct a set comprehension (and give useful errors, in case
; these are shown to an end-user)
(define (raise-set-comp-quantifier-error e)
(raise-user-error "Set-comprehension variable domain expected a singleton or relational expression" (deparse e)))
(raise-forge-error
#:msg (format "Set-comprehension variable domain expected a singleton or relational expression: ~a" (deparse e))
#:context e))
(define (comprehension info decls formula)
(for ([e (map cdr decls)])
(unless (node/expr? e)
(raise-set-comp-quantifier-error e))
(unless (equal? (node/expr-arity e) 1)
(raise-user-error "Set-comprehension variable domain needs arity = 1" (deparse e)))
(raise-forge-error
#:msg (format "Set-comprehension variable domain needs arity = 1: ~a" (deparse e))
#:context e))
(unless (node/formula? formula)
(raise-user-error "Set-comprehension condition expected a formula." (deparse formula))))
(raise-forge-error
#:msg (format "Set-comprehension condition expected a formula: ~a" (deparse formula))
#:context formula)))
(node/expr/comprehension info (length decls) decls formula))
(define (set/func decls formula #:info [node-info empty-nodeinfo])
(comprehension node-info decls formula))
Expand Down Expand Up @@ -806,14 +824,16 @@
(datum->syntax #f (deparse expr) (build-source-location-syntax loc))))
(node/formula/multiplicity info mult expr))

(define (no-pairwise-intersect vars)
(apply &&/func (no-pairwise-intersect-recursive-helper vars)))
(define (no-pairwise-intersect vars #:context [context #f])
(apply &&/func (no-pairwise-intersect-recursive-helper vars #:context context)))

(define (no-pairwise-intersect-recursive-helper vars)
(cond [(empty? vars) (raise-user-error "Cannot take pairwise intersection of empty list")]
(define (no-pairwise-intersect-recursive-helper vars #:context [context #f])
(cond [(empty? vars) (raise-forge-error
#:msg "Cannot take pairwise intersection of empty list"
#:context context)]
[(empty? (rest vars)) (list true)]
[else (append (map (lambda (elt) (no (& (first vars) elt))) (rest vars))
(no-pairwise-intersect-recursive-helper (rest vars)))]))
(no-pairwise-intersect-recursive-helper (rest vars) #:context context))]))

;;; ALL ;;;

Expand All @@ -830,7 +850,10 @@
; quantifier case with disjointness flag; embed and repeat
; TODO: currently discarding the multiplicity info, unchecked
[(_ info #:disj ([v0 e0 m0:opt-mult-class] ...) pred)
#'(all/info info ([v0 e0 m0] ...) (=> (no-pairwise-intersect (list v0 ...)) pred))]
(quasisyntax/loc stx
(all/info info ([v0 e0 m0] ...)
#,(quasisyntax/loc stx
(=> (no-pairwise-intersect (list v0 ...) #:context #,(build-source-location stx)) pred))))]
[(_ info ([v0 e0 m0:opt-mult-class] ...) pred)
(quasisyntax/loc stx
(let* ([v0 (node/expr/quantifier-var info (node/expr-arity e0) (gensym (format "~a_all" 'v0)) 'v0)] ...)
Expand Down Expand Up @@ -863,7 +886,11 @@
(quantified-formula info 'some (list (cons v0 e0) ...) pred)))]
; quantifier case with disjointness flag; embed and repeat
[(_ info #:disj ([v0 e0 m0:opt-mult-class] ...) pred)
#'(some/info info ([v0 e0 m0] ...) (&& (no-pairwise-intersect (list v0 ...)) pred))]
(quasisyntax/loc stx
(some/info info ([v0 e0 m0] ...)
#,(quasisyntax/loc stx
(&& (no-pairwise-intersect (list v0 ...)
#:context #,(build-source-location stx)) pred))))]
; multiplicity case
[(_ info expr)
(quasisyntax/loc stx
Expand Down Expand Up @@ -923,7 +950,10 @@
(quasisyntax/loc stx
; Kodkod doesn't have a "one" quantifier natively.
; Instead, desugar as a multiplicity of a set comprehension
(multiplicity-formula info 'one (set ([x1 r1] ...) (&& (no-pairwise-intersect (list x1 ...)) pred))))]
(multiplicity-formula info 'one
(set ([x1 r1] ...)
#,(quasisyntax/loc stx (&& (no-pairwise-intersect (list x1 ...)
#:context #,(build-source-location stx)) pred)))))]
[(_ info ([x1 r1 m0:opt-mult-class] ...) pred)
(quasisyntax/loc stx
; Kodkod doesn't have a "one" quantifier natively.
Expand Down Expand Up @@ -955,7 +985,10 @@
(quasisyntax/loc stx
; Kodkod doesn't have a lone quantifier natively.
; Instead, desugar as a multiplicity of a set comprehension
(multiplicity-formula info 'lone (set ([x1 r1] ...) (&& (no-pairwise-intersect (list x1 ...)) pred))))]
(multiplicity-formula info 'lone (set ([x1 r1] ...)
#,(quasisyntax/loc stx
(&& (no-pairwise-intersect (list x1 ...)
#:context #,(build-source-location stx)) pred)))))]
[(_ info ([x1 r1 m0:opt-mult-class] ...) pred)
(quasisyntax/loc stx
; Kodkod doesn't have a lone quantifier natively.
Expand Down Expand Up @@ -1045,8 +1078,8 @@
(equal? (procedure-arity vala) 0)
(equal? (procedure-arity valb) 0))
(equal-proc (vala) (valb))]
[(and (or (node/expr? vala) (not (procedure? vala)))
(or (node/expr? valb) (not (procedure? valb))))
[(and (or (node/expr? vala) (node/formula? vala) (not (procedure? vala)))
(or (node/expr? valb) (node/formula? vala) (not (procedure? valb))))
(equal-proc vala valb)]
[else (raise (format "Mismatched procedure fields when checking equality for ~a. Got: ~a and ~a"
structname vala valb))]))
Expand All @@ -1061,15 +1094,32 @@
[multiplier (drop multipliers offset)])
; Some AST fields may be thunkified
; Also, any node/expr is a procedure? since that's how we impl. box join
; Also, in order to add better error messages for mis-used node/formulas,
; any node/formula is also a procedure?
; ASSUME: node/expr will never be an exactly-arity-0 procedure.
(define vala (access a))
(cond
(cond
; zero-arity procedure (a "thunk"): invoke it and then hash the result
[(and (procedure? vala)
(equal? (procedure-arity vala) 0))
(@* multiplier (hash-proc (vala)))]
[(or (node/expr? vala)
(not (procedure? vala)))
(@* multiplier (hash-proc vala))]
;(printf "field was zero arity procedure: ~a~n" vala)
(@* multiplier (hash-proc (vala)))]

; node/expr? (but not a zero-arity procedure): just hash it
[(node/expr? vala)
;(printf "field was expr: ~a~n" vala)
(@* multiplier (hash-proc vala))]

; node/formula? (but not a zero-arity procedure): just hash it
[(node/formula? vala)
;(printf "field was formula: ~a~n" vala)
(@* multiplier (hash-proc vala))]

; not a procedure at all: just hash it
[(not (procedure? vala))
;(printf "field was other non-procedure: ~a~n" vala)
(@* multiplier (hash-proc vala))]

[else (raise (format "Non-thunk procedure field when hashing for ~a. Got: ~a"
structname vala))])))
;(printf "in mrnhs for ~a/~a: ~a, multiplied: ~a~n" structname offset a multiplied)
Expand Down Expand Up @@ -1106,4 +1156,24 @@
(make-breaker bij 'bij)
(make-breaker pbij 'pbij)

(make-breaker default 'default)
(make-breaker default 'default)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; *** raise-forge-error ***
;
; Use this error-throwing function whenever possible in Forge.
;
; Racket "user errors" avoid the (possibly confusing) stack trace that a Racket
; "syntax error" produces, but only DrRacket will highlight source location from
; a user error. For the VSCode extension (and use from the terminal), produce a
; custom user error that contains the row and column information of the offending
; AST node.
(define (pretty-loc loc)
(format "~a:~a:~a" (srcloc-source loc) (srcloc-line loc) (srcloc-column loc)))
(define (raise-forge-error #:msg [msg "error"] #:context [context #f])
(define loc (cond [(nodeinfo? context) (pretty-loc (nodeinfo-loc context))]
[(node? context) (pretty-loc (nodeinfo-loc (node-info context)))]
[(srcloc? context) (pretty-loc context)]
[else "unknown:?:?"]))
(raise-user-error (format "[~a] ~a" loc msg)))

18 changes: 12 additions & 6 deletions forge/lang/expander.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
(for-syntax racket/base syntax/parse racket/syntax syntax/parse/define racket/function
syntax/srcloc racket/match racket/list
(only-in racket/path file-name-from-path))
syntax/srcloc
; Needed because the abstract-tok definition below requires phase 2
(for-syntax (for-syntax racket/base)))

(require (only-in racket empty? first))
(require forge/sigs)
(require forge/choose-lang-specific)
(require (only-in forge/lang/ast raise-forge-error))

(provide isSeqOf seqFirst seqLast indsOf idxOf lastIdxOf elems inds isEmpty hasDups reachable)
(provide #%module-begin)
Expand Down Expand Up @@ -1025,7 +1027,7 @@
(syntax-parameterize ([current-forge-context 'inst])
(list #,@(syntax/loc stx bounds.translate))))))]))

(define (disambiguate-block xs)
(define (disambiguate-block xs #:stx [stx #f])
(cond [(empty? xs)
; {} always means the formula true
true]
Expand All @@ -1034,20 +1036,24 @@
(first xs)]
; Body of a predicate: any number of formulas
[(andmap node/formula? xs)
(&& xs)]
(define info (nodeinfo (build-source-location stx) 'checklangplaceholder))
(&&/info info xs)]
; body of a helper function that produces an int-expression: one int-expression
[(and (equal? 1 (length xs)) (node/int? (first xs)))
(first xs)]
[else
(raise-user-error (format "~a" xs)
(format "Ill-formed block: expected either one expression or any number of formulas"))]))
[else
(raise-forge-error
#:msg (format "Ill-formed block: expected either one expression or any number of formulas")
#:context stx)]))

; Block : /LEFT-CURLY-TOK Expr* /RIGHT-CURLY-TOK
(define-syntax (Block stx)
(syntax-parse stx
[((~datum Block) exprs:ExprClass ...)
(with-syntax ([(exprs ...) (syntax->list #'(exprs ...))])
(syntax/loc stx (disambiguate-block (list exprs ...))))]))
(quasisyntax/loc stx
(disambiguate-block (list exprs ...)
#:stx #,(build-source-location stx))))]))

(define-syntax (Expr stx)
;(printf "Debug: Expr: ~a~n" stx)
Expand Down
2 changes: 1 addition & 1 deletion forge/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ raco setup forge

# Get test files
testDir=$1
doNotTestPattern="error/[^/]*\\.frg"
doNotTestPattern="[error|srcloc]/[^/]*\\.frg"
# ^ these tests get checked by tests/error/main.rkt
testFiles="$( find $testDir -type f \( -name "*.rkt" -o -name "*.frg" \) | grep --invert-match ${doNotTestPattern} )"
numTestFiles="$(echo "$testFiles" | wc -l)"
Expand Down
1 change: 0 additions & 1 deletion forge/shared.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,3 @@
(set!-gc-time gc)
(format "~a at ~a\tlast step: ~a\tgc: ~a\ttotal: ~a"
new-msg t diff gc-diff (- t initial-time)))))))

2 changes: 1 addition & 1 deletion forge/sigs-structs.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ Returns whether the given run resulted in sat or unsat, respectively.
(if (node/formula? b)
(&&/info info
(=>/info info a b)
(=>/info info (! a) c))
(=>/info info (!/info info a) c))
(ite/info info a b c)))
(define-syntax (ifte stx)
(syntax-parse stx
Expand Down
16 changes: 8 additions & 8 deletions forge/sigs.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -840,16 +840,16 @@

(define-builtin (isSeqOf info r1 d)
(&&/info info
(in/info info r1 (-> Int univ))
(in/info info r1 (->/info info Int univ))
(in/info info (join/info info Int r1) d)
(all ([i1 (join/info info r1 univ)])
(all/info info ([i1 (join/info info r1 univ)])
(&&/info info (int>= (sum/info info i1) (int 0))
(lone (join/info info i1 r1))))
(all ([e (join/info info Int r1)])
(some (join/info info r1 e)))
(all ([i1 (join/info info r1 univ)])
(implies (!= i1 (sing/info info (int 0)))
(some (join/info info
(lone/info info (join/info info i1 r1))))
(all/info info ([e (join/info info Int r1)])
(some/info info (join/info info r1 e)))
(all/info info ([i1 (join/info info r1 univ)])
(=>/info info (!= i1 (sing/info info (int 0)))
(some/info info (join/info info
(sing/info info
(subtract/info info
(sum/info info i1) (int 1))) r1))))))
Expand Down
14 changes: 14 additions & 0 deletions forge/tests/error/expect-predicate-args.frg
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#lang forge/bsl
option verbose 0
option run_sterling off
abstract sig Player {}
one sig X, O extends Player {}
sig Board {board: pfunc Int -> Int -> Player}

pred wellformed[b: Board] {
all row, col: Int | {
(row < 0 or row > 2 or col < 0 or col > 2)
implies no b.board[row][col] }}

test expect { should_error: { wellformed } is sat }

14 changes: 14 additions & 0 deletions forge/tests/error/expect-predicate-no-args.frg
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#lang forge/bsl
option verbose 0
option run_sterling off
abstract sig Player {}
one sig X, O extends Player {}
sig Board {board: pfunc Int -> Int -> Player}

pred wellformed {
all b: Board | all row, col: Int | {
(row < 0 or row > 2 or col < 0 or col > 2)
implies no b.board[row][col] }}

test expect { should_error: { all b: Board | wellformed[b] } is sat }

2 changes: 2 additions & 0 deletions forge/tests/error/main.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@
(list "expr-in-comprehension-condition.frg" #rx"expected a formula")
(list "non-expr-in-comprehension-domain.frg" #rx"expected a singleton or relational expression")
(list "arity-in-comprehension-domain.frg" #rx"variable domain needs arity = 1")
(list "expect-predicate-args.frg" #rx"Ill-formed block")
(list "expect-predicate-no-args.frg" #rx"Tried to give arguments to a predicate, but it takes none")
))


Expand Down
1 change: 0 additions & 1 deletion forge/tests/forge-core/formulas/disj-one-core.rkt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#lang forge/core

(set-option! 'verbose 0)
;(set-option! 'verbose 10)

(sig onede)
(relation edges (onede onede))
Expand Down
Loading
Loading