From f66fff1ca92722365649859833c8fce3273e866c Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Sun, 24 May 2020 11:05:53 -0600 Subject: [PATCH] setup/xref: fix `load-collections-xref` for multple uses When the result of `load-collections-xref` is used in multiple document renderings (e.g., multiple calls to `render`), then an intenal cache behaved the wrong way. Fixing the problem required an extension to `scribble/xref`. --- pkgs/racket-doc/info.rkt | 2 +- pkgs/racket-doc/scribblings/raco/setup.scrbl | 13 ++++---- pkgs/racket-index/setup/xref.rkt | 32 ++++++++++++-------- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/pkgs/racket-doc/info.rkt b/pkgs/racket-doc/info.rkt index 8a9b51e731..ba36f0e1bd 100644 --- a/pkgs/racket-doc/info.rkt +++ b/pkgs/racket-doc/info.rkt @@ -6,7 +6,7 @@ ["base" #:version "6.5.0.2"] "net-lib" "sandbox-lib" - ["scribble-lib" #:version "1.14"] + ["scribble-lib" #:version "1.34"] "racket-index")) (define build-deps '("rackunit-doc" "compatibility" diff --git a/pkgs/racket-doc/scribblings/raco/setup.scrbl b/pkgs/racket-doc/scribblings/raco/setup.scrbl index 6222d9fd11..aabf3b3a74 100644 --- a/pkgs/racket-doc/scribblings/raco/setup.scrbl +++ b/pkgs/racket-doc/scribblings/raco/setup.scrbl @@ -2157,11 +2157,10 @@ Returns @racket[#t] if cross-installation mode has been detected, @defproc[(load-collections-xref [on-load (-> any/c) (lambda () (void))]) xref?]{ -Like @racket[load-xref], but automatically find all cross-reference files for -manuals that have been installed with @exec{raco setup}. - -A cached copy of cross-reference information can be used, in which -case @racket[on-load] is @emph{not} called.} +Either creates and caches or returns a cached cross-reference record +created with @racket[make-collections-xref]. The @racket[on-load] +function is called only when a previously cached record is not +returned.} @defproc[(make-collections-xref [#:no-user? no-user? any/c #f] @@ -2171,7 +2170,9 @@ case @racket[on-load] is @emph{not} called.} [#:register-shutdown! register-shutdown! ((-> any) . -> . any) void]) xref?]{ -Like @racket[load-collections-xref], but takes advantage of a +Like @racket[load-xref], but automatically finds all cross-reference +files for manuals that have been installed with @exec{raco setup}. +The resulting cross-reference record takes advantage of a cross-reference database @racket[db-path], when support is available, to delay the loading of cross-reference details until needed. diff --git a/pkgs/racket-index/setup/xref.rkt b/pkgs/racket-index/setup/xref.rkt index d2a8fe9f04..e30501432a 100644 --- a/pkgs/racket-index/setup/xref.rkt +++ b/pkgs/racket-index/setup/xref.rkt @@ -103,20 +103,25 @@ (close p)))) (when main-db (close main-db)) (when user-db (close user-db)))) - (define done-ht (make-hash)) ; tracks already-loaded documents - (define forced-all? #f) - (define (force-all) + (define done-hts (make-hasheq)) ; tracks already-loaded documents per ci + (define (get-done-ht use-id) + (or (hash-ref done-hts use-id #f) + (let ([ht (make-hash)]) + (hash-set! done-hts use-id ht) + ht))) + (define forced-all?s (make-hasheq)) ; per ci: whether forced all + (define (force-all use-id) ;; force all documents - (define thunks (get-reader-thunks no-user? no-main? quiet-fail? done-ht)) - (set! forced-all? #t) + (define thunks (get-reader-thunks no-user? no-main? quiet-fail? (get-done-ht use-id))) + (hash-set! forced-all?s use-id #t) (lambda () ;; return a procedure so we can produce a list of results: (lambda () (for/list ([thunk (in-list thunks)]) (thunk))))) - (lambda (key) + (lambda (key use-id) (cond - [forced-all? #f] + [(hash-ref forced-all?s use-id #f) #f] [key (define (try p) (and p @@ -140,11 +145,11 @@ (define dest (or (try main-db) (try user-db))) (and dest (if (eq? dest #t) - (force-all) - ((dest->source done-ht quiet-fail?) dest)))] + (force-all use-id) + ((dest->source (get-done-ht use-id) quiet-fail?) dest)))] [else - (unless forced-all? - (force-all))]))) + (unless (hash-ref forced-all?s use-id #f) + (force-all use-id))]))) (define (get-reader-thunks no-user? no-main? quiet-fail? done-ht) (map (dest->source done-ht quiet-fail?) @@ -165,8 +170,9 @@ #:register-shutdown! [register-shutdown! void]) (if (doc-db-available?) (load-xref null - #:demand-source (make-key->source db-path no-user? no-main? quiet-fail? - register-shutdown!)) + #:demand-source-for-use + (make-key->source db-path no-user? no-main? quiet-fail? + register-shutdown!)) (load-xref (get-reader-thunks no-user? no-main? quiet-fail? (make-hash)))))