Skip to content

Commit 9eed71e

Browse files
iitalicsAlexKnauth
authored andcommitted
Delta introducer to avoid re-expansion; rename val-decl
1 parent 9ba7700 commit 9eed71e

File tree

1 file changed

+36
-39
lines changed

1 file changed

+36
-39
lines changed

hackett-lib/hackett/private/base.rkt

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -326,31 +326,34 @@
326326
;; ---------------------------------------------------------------------------------------------------
327327

328328
(begin-for-syntax
329+
; Instances of this struct are created by `:` when declaring the types of bindings
330+
; seperately from their definitions. When a binding is defined (with `def` or related
331+
; forms), it searches for a `binding-declaration` and fills in `internal-id` with the
332+
; actual definition. The `type` field is used as the expected type of the definition.
329333
; fixity : [Maybe Fixity]
330-
(struct val-decl [internal-id
331-
type
332-
type-unexpanded
333-
exact?
334-
fixity]
334+
(struct binding-declaration [internal-id type delta-syntax residual fixity]
335335
#:property prop:procedure
336336
(λ (this stx)
337-
(match-define (val-decl x- type _ _ _) this)
337+
(match-define (binding-declaration x- type _ _ _) this)
338338
((make-typed-var-transformer x- type) stx))
339339
#:property prop:infix-operator
340-
(λ (this) (val-decl-fixity this)))
341-
342-
(define-syntax-class id/val-decl
343-
#:attributes [internal-id
344-
type-unexpanded
345-
exact?
346-
fixity]
347-
[pattern (~var x (local-value val-decl?))
348-
#:do [(match-define (val-decl x-* _ type* exact?* fixity*)
340+
(λ (this) (binding-declaration-fixity this)))
341+
342+
(define-syntax-class id/binding-declaration
343+
#:attributes [internal-id type scoped-binding-introducer residual fixity]
344+
[pattern (~var x (local-value binding-declaration?))
345+
#:do [(match-define (binding-declaration x-* type* delta* resid* fixity*)
349346
(attribute x.local-value))]
350-
#:attr internal-id (syntax-local-introduce x-*)
351-
#:with type-unexpanded (syntax-local-introduce type*)
352-
#:attr exact? exact?*
353-
#:attr fixity fixity*]))
347+
#:attr internal-id (syntax-local-introduce x-*)
348+
#:with type (syntax-local-introduce type*)
349+
#:attr scoped-binding-introducer (make-syntax-delta-introducer delta* #'_)
350+
#:with residual (syntax-local-introduce resid*)
351+
#:attr fixity fixity*]))
352+
353+
(define-syntax-parser define/binding-declaration
354+
[(_ x:id/binding-declaration rhs)
355+
#:with x- #'x.internal-id
356+
#'(define- x- rhs)])
354357

355358
;; ---------------------------------------------------------------------------------------------------
356359

@@ -412,12 +415,15 @@
412415
#:with t_reduced (if (attribute exact?)
413416
#'t.expansion
414417
(type-reduce-context #'t.expansion))
415-
#'(define-syntax x
416-
(val-decl (quote-syntax x-)
417-
(quote-syntax t_reduced)
418-
(quote-syntax t_unexpanded)
419-
'exct?
420-
'fixity))])])))
418+
#:with delta (syntax-local-introduce
419+
((attribute t.scoped-binding-introducer) #'_))
420+
#`(define-syntax x
421+
(binding-declaration
422+
(quote-syntax x-)
423+
(quote-syntax t_reduced)
424+
(quote-syntax delta)
425+
(quote-syntax t.residual)
426+
'fixity))])])))
421427

422428
(define-syntax-parser λ1
423429
[(_ x:id e:expr)
@@ -444,19 +450,15 @@
444450

445451
(define-syntax-parser def
446452
#:literals [:]
447-
[(_ x:id/val-decl e:expr)
453+
[(_ x:id/binding-declaration e:expr)
448454
#:with x- #'x.internal-id
449-
#:with {~type t:type} #'x.type-unexpanded
450-
#:with t_reduced (if (attribute x.exact?)
451-
#'t.expansion
452-
(type-reduce-context #'t.expansion))
453455
(syntax-property
454456
#`(define- x-
455-
(let-values ([() t.residual])
457+
(let-values ([() x.residual])
456458
(#%expression
457-
(: #,((attribute t.scoped-binding-introducer)
459+
(: #,((attribute x.scoped-binding-introducer)
458460
#'e)
459-
t_reduced
461+
x.type
460462
#:exact))))
461463
'disappeared-use
462464
(syntax-local-introduce #'x))]
@@ -482,16 +484,11 @@
482484
#:with id-/gen (attach-type id- #'t_gen)
483485
#`(begin-
484486
(: id t_gen fixity-stuff ... #:exact)
485-
(define/val-decl id
487+
(define/binding-declaration id
486488
(let-syntax ([id-/gen
487489
(make-rename-transformer (quote-syntax id))])
488490
#,e-)))])
489491

490-
(define-syntax-parser define/val-decl
491-
[(_ x:id/val-decl rhs)
492-
#:with x- #'x.internal-id
493-
#'(define- x- rhs)])
494-
495492

496493
(begin-for-syntax
497494
(struct todo-item (full summary) #:prefab))

0 commit comments

Comments
 (0)