From cc8bd4f294fc0d978c8ac3db379ead86c60a82ee Mon Sep 17 00:00:00 2001 From: Vincent St-Amour Date: Thu, 6 Dec 2012 11:59:26 -0500 Subject: [PATCH] Make srclocs serializable. --- collects/racket/private/serialize.rkt | 10 ++++++++-- collects/scribblings/reference/serialization.scrbl | 10 +++++++++- collects/tests/racket/serialize.rktl | 3 +++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/collects/racket/private/serialize.rkt b/collects/racket/private/serialize.rkt index e6a68d1ed1..3052922e2e 100644 --- a/collects/racket/private/serialize.rkt +++ b/collects/racket/private/serialize.rkt @@ -54,7 +54,8 @@ (void? v) (date? v) (arity-at-least? v) - (module-path-index? v))) + (module-path-index? v) + (srcloc? v))) ;; If a module is dynamic-required through a path, ;; then it can cause simplified module paths to be paths; @@ -191,7 +192,8 @@ (char? v) (symbol? v) (null? v) - (void? v)) + (void? v) + (srcloc? v)) (void)] [(hash-ref cycle v #f) ;; We already know that this value is @@ -367,6 +369,9 @@ (cons 'mpi (cons ((serial #t) path) ((serial #t) base))))] + [(srcloc? v) + (cons 'srcloc + (map (serial #t) (take (struct->list v) 5)))] [else (error 'serialize "shouldn't get here")])) ((serial check-share?) v)) @@ -529,6 +534,7 @@ [(arity-at-least) (make-arity-at-least (loop (cdr v)))] [(mpi) (module-path-index-join (loop (cadr v)) (loop (cddr v)))] + [(srcloc) (apply make-srcloc (map loop (cdr v)))] [else (error 'serialize "ill-formed serialization")])]))) (define (deserial-shell v mod-map fixup n) diff --git a/collects/scribblings/reference/serialization.scrbl b/collects/scribblings/reference/serialization.scrbl index ba8e4c006f..1eff521851 100644 --- a/collects/scribblings/reference/serialization.scrbl +++ b/collects/scribblings/reference/serialization.scrbl @@ -48,7 +48,8 @@ The following kinds of values are serializable: @item{@tech{pairs}, @tech{mutable pairs}, @tech{vectors}, @tech{flvectors}, @tech{fxvectors}, @tech{box}es, @tech{hash tables}, and @tech{sets};} - @item{@racket[date], @racket[date*], and @racket[arity-at-least] structures; and} + @item{@racket[date], @racket[date*], @racket[arity-at-least] and @racket[srcloc] + structures; and} @item{@tech{module path index} values.} @@ -178,6 +179,10 @@ elements: this case does not appear in output generated by @racket[serialize]).} + @item{@racket['srcloc] for a @racket[srcloc] structure, which + fails on deserialization (since srclocs are immutable; + this case does not appear in output generated by + @racket[serialize]).} ] The @racket[#f]-filled value will be updated with content specified @@ -309,6 +314,9 @@ elements: @tech{module path index} that joins the paired values.} + @item{a pair whose @racket[car] is @racket['srcloc] and whose + @racket[cdr] is a list of serials; it represents a + @racket[srcloc] structure.} ]} ]} diff --git a/collects/tests/racket/serialize.rktl b/collects/tests/racket/serialize.rktl index a25f322a2e..803c4eed7b 100644 --- a/collects/tests/racket/serialize.rktl +++ b/collects/tests/racket/serialize.rktl @@ -163,6 +163,9 @@ (test-ser (make-c 30)) (test-ser (make-d 100 200 300)) +(test-ser (make-srcloc 1 2 3 4 5)) +(test-ser (make-srcloc (string->path "/tmp/test.rkt") 2 3 4 5)) + ;; Simple sharing (let ([p (cons 1 2)]) (test-ser (cons p p))