Skip to content

Commit 9b3d3dc

Browse files
committed
Update synthcl to use new synthesis constructs.
1 parent 59079bb commit 9b3d3dc

File tree

5 files changed

+35
-55
lines changed

5 files changed

+35
-55
lines changed

sdsl/synthcl/examples/fastWalshTransform/synth/kernel.rkt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
(: int tid group pair match)
66
(: float t1 t2)
77
(= tid (get_global_id 0))
8-
(= group (idx tid step 1)) ; (% tid step)
9-
(= pair (+ (* (<< step 1) (idx tid step 1)) group)) ; (/ tid step)
8+
(= group (idx tid step)) ; (% tid step)
9+
(= pair (+ (* (<< step 1) (idx tid step)) group)) ; (/ tid step)
1010
(= match (+ pair step))
1111
(= t1 [tArray pair])
1212
(= t2 [tArray match])
@@ -33,10 +33,9 @@
3333
(* left right)
3434
(% left right)])
3535

36-
(grammar* int (idx [int tid] [int step] [int depth])
37-
[choose tid step (?? int)
38-
(op (idx tid step (- depth 1))
39-
(idx tid step (- depth 1)))])
36+
(grammar int (idx [int tid] [int step])
37+
(op (choose tid step (?? int))
38+
(choose tid step (?? int))))
4039

4140
(kernel void (fwtKernel [float* tArray] [int step])
4241
(: int tid group pair match)

sdsl/synthcl/lang/forms.rkt

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
(for-syntax "types.rkt" "errors.rkt" (only-in racket make-list) (only-in syntax/stx stx-null?))
55
"types.rkt" "util.rkt"
66
(prefix-in rosette/ (only-in rosette if assert void))
7-
(only-in rosette/lib/synthax define-synthax [?? @??] choose)
7+
(only-in rosette/lib/synthax define-simple-grammar [?? @??] choose)
88
(only-in "../model/runtime.rkt" address-of malloc)
99
(only-in "builtins.rkt" NULL clCreateProgramWithSource))
1010

1111
(provide assert
12-
print procedure kernel grammar grammar* ?? choose
12+
print procedure kernel grammar ?? choose
1313
sizeof @ : =
1414
app-or-ref locally-scoped if-statement for-statement range)
1515

@@ -156,35 +156,14 @@
156156
(set! param ((type) param)) ...
157157
expr ...))]))
158158

159-
; Grammar syntax. We assume (but don't enforce) that
160-
; grammar bodies are free of side effects, and that
161-
; grammars are invoked on side-effect free expressions.
162-
; This assumption is needed only for simplified code generation,
163-
; where we treat each grammar application as a substition
164-
; in the codegen phase. Synthesis works fine without this
165-
; assumption, and a better code generator could get rid of it
166-
; by lifting all the lets/lambda to the top level.
167-
(define-syntax (grammar* stx)
168-
(syntax-case stx ()
169-
[(_ out (id [type param] ... [int depth]) expr)
170-
(quasisyntax/loc stx
171-
(define-synthax id
172-
[(param ... depth)
173-
(assert (>= depth 0))
174-
expr]
175-
(lambda (e sol)
176-
(define vars (syntax->list #'(param ... depth)))
177-
(define vals (cdr (syntax->list e)))
178-
#`(let (#,@(map list vars vals)) expr))))]))
179-
180159
(define-syntax (grammar stx)
181160
(syntax-case stx ()
182161
[(grammar out (id [type param] ...) expr)
183162
(quasisyntax/loc stx
184-
(define-synthax (id param ...) expr))]))
163+
(define-simple-grammar (id param ...) expr))]))
185164

186165
; Constant syntax.
187-
(define-synthax (?? t) (@?? (type-base t)))
166+
(define-simple-grammar (?? t) (@?? (type-base t)))
188167

189168
; Syntax for creating a local scope for a sequence of statements.
190169
(define-syntax (locally-scoped stx)

sdsl/synthcl/lang/main.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
locally-scoped range @ sizeof
3131

3232
; Solver-aided statements and forms
33-
assert verify synth choose ?? grammar grammar*
33+
assert verify synth choose ?? grammar
3434

3535
; Real operators
3636
= += -= *= /= %= &= $= ^= <<= >>=

sdsl/synthcl/lang/queries.rkt

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
(only-in rackunit test-pred)
55
(for-syntax (only-in racket/syntax with-syntax*))
66
(only-in "forms.rkt" range :)
7-
(only-in rosette/lib/synthax generate-forms)
7+
(only-in rosette/lib/synthax current-grammar-depth print-forms)
88
(prefix-in @ (only-in rosette verify synthesize)))
99

1010
(provide verify synth expected? query-output-port)
@@ -39,25 +39,10 @@
3939
(printf "No counterexample found.\n")
4040
(unsat))))))))))]))
4141

42-
(define (inline-let f [env (hash)])
43-
(syntax-case f (let)
44-
[(let ([x e] ...) body)
45-
(let ([vars (syntax->datum #'(x ...))]
46-
[exps (map (curryr inline-let env) (syntax->list #'(e ...)))])
47-
(inline-let #'body (apply hash-set* env (flatten (map cons vars exps)))))]
48-
[(_ ...)
49-
#`(#,@(map (curryr inline-let env) (syntax->list f)))]
50-
[_ (hash-ref env (syntax->datum f) f)]))
51-
52-
(define (print-forms sol)
53-
(for ([f (generate-forms sol)])
54-
(printf "~a:~a:~a\n" (syntax-source f) (syntax-line f) (syntax-column f))
55-
(printf "~a\n" (pretty-format (syntax->datum (inline-let f))))))
56-
5742
; The synthesize form.
5843
(define-syntax (synth stx)
5944
(syntax-case stx ()
60-
[(synthesize #:forall [decl ...] #:bitwidth bw #:ensure expr)
45+
[(synthesize #:forall [decl ...] #:bitwidth bw #:grammar-depth depth #:ensure expr)
6146
(with-syntax* ([([id seq] ...) (map id&range (syntax->list #'(decl ...)))]
6247
[(tmp ...) (generate-temporaries #'(id ...))])
6348
(quasisyntax/loc stx
@@ -68,6 +53,7 @@
6853
(expected?)
6954
(with-terms
7055
(parameterize ([current-bitwidth bw]
56+
[current-grammar-depth depth]
7157
[current-output-port (query-output-port)])
7258
(printf "Synthesizing ~a\n" (source-of #'synthesize))
7359
(define-values (id ...)
@@ -79,9 +65,11 @@
7965
(if (sat? m)
8066
(print-forms m)
8167
(printf "No solution found.\n"))
82-
m))))))))]
68+
m))))))))]
69+
[(synthesize #:forall ds #:bitwidth bw #:ensure e)
70+
(syntax/loc stx (synthesize #:forall ds #:bitwidth bw #:grammar-depth 3 #:ensure e))]
8371
[(synthesize #:forall ds #:ensure e)
84-
(syntax/loc stx (synthesize #:forall ds #:bitwidth 8 #:ensure e))]))
72+
(syntax/loc stx (synthesize #:forall ds #:bitwidth 8 #:grammar-depth 3 #:ensure e))]))
8573

8674

8775
; Returns the declared id and the Racket sequence

sdsl/synthcl/lang/typecheck.rkt

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535
(and (identifier? #'proc)
3636
(or (free-label-identifier=? #'proc #'procedure)
3737
(free-label-identifier=? #'proc #'kernel)
38-
(free-label-identifier=? #'proc #'grammar)
39-
(free-label-identifier=? #'proc #'grammar*)))
38+
(free-label-identifier=? #'proc #'grammar)))
4039
(let ([out-type (identifier->type #'out stx)]
4140
[arg-types (map (curryr identifier->type stx) (syntax->list #'(type ...)))])
4241
(when (free-label-identifier=? #'proc #'kernel)
@@ -202,13 +201,29 @@
202201
; Typechecks the verify or synthesis query statement.
203202
(define (typecheck-query stx)
204203
(syntax-case stx ()
204+
[(query #:forall [decl ...] #:bitwidth bw #:grammar-depth depth #:ensure form)
205+
(parameterize ([current-env (env)])
206+
(with-syntax ([(typed-decl ...) (map typecheck-query-declaration (syntax->list #'(decl ...)))]
207+
[typed-form (typecheck #'form)]
208+
[typed-bw (typecheck #'bw)]
209+
[typed-depth (typecheck #'depth)])
210+
(check-no-conversion (type-ref #'typed-bw) int #'typed-bw stx)
211+
(check-no-conversion (type-ref #'typed-depth) int #'typed-depth stx)
212+
(type-set (syntax/loc stx (query #:forall [typed-decl ...]
213+
#:bitwidth typed-bw
214+
#:grammar-depth typed-depth
215+
#:ensure typed-form))
216+
void)))]
205217
[(query #:forall [decl ...] #:bitwidth bw #:ensure form)
206218
(parameterize ([current-env (env)])
207219
(with-syntax ([(typed-decl ...) (map typecheck-query-declaration (syntax->list #'(decl ...)))]
208220
[typed-form (typecheck #'form)]
209221
[typed-bw (typecheck #'bw)])
210222
(check-no-conversion (type-ref #'typed-bw) int #'typed-bw stx)
211-
(type-set (syntax/loc stx (query #:forall [typed-decl ...] #:bitwidth typed-bw #:ensure typed-form)) void)))]
223+
(type-set (syntax/loc stx (query #:forall [typed-decl ...]
224+
#:bitwidth typed-bw
225+
#:ensure typed-form))
226+
void)))]
212227
[(query #:forall [decl ...] #:ensure form)
213228
(parameterize ([current-env (env)])
214229
(with-syntax ([(typed-decl ...) (map typecheck-query-declaration (syntax->list #'(decl ...)))]
@@ -435,7 +450,6 @@
435450
(dict-set! procs #'choose typecheck-choose)
436451
(dict-set! procs #'?? typecheck-??)
437452
(dict-set! procs #'grammar typecheck-grammar)
438-
(dict-set! procs #'grammar* typecheck-grammar)
439453

440454
(dict-set! procs #'procedure typecheck-procedure)
441455
(dict-set! procs #'kernel typecheck-procedure)

0 commit comments

Comments
 (0)