Skip to content

Commit

Permalink
Various changes
Browse files Browse the repository at this point in the history
Don't need to delay/force the root trie node. Just use #f/set!
pattern to create on-demand.

Ditto for the module-doc-path-index hash table.

Add some logging about time and size building both.

Fix libs-exporting-documented to use the newer index structs. But also
add a comment about how this should be revised more thoroughly.
  • Loading branch information
greghendershott committed Nov 14, 2024
1 parent bd25b83 commit 58113b6
Showing 1 changed file with 45 additions and 28 deletions.
73 changes: 45 additions & 28 deletions racket/scribble.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,6 @@

;;; Documentation search

(define root (delay
(with-memory-use/log "build-doc-search-trie"
(with-time/log "build-doc-search-trie"
(build-doc-search-trie)))))

(define (doc-search prefix)
(trie-find (force root) prefix 256))

;; A trie where a node's children are represented as a hash-table from
;; char to node. Each node also has a set of zero or more values
;; (multiple, since we have so many duplicate keys e.g. various
Expand All @@ -114,6 +106,16 @@
(struct node (kids values))
(define (empty-node) (node (make-hasheq) (set)))

(define root #f)

(define (doc-search prefix)
(unless root
(set! root
(with-memory-use/log "build-doc-search-trie"
(with-time/log "build-doc-search-trie"
(build-doc-search-trie)))))
(trie-find root prefix 256))

(define (trie-add! root str value)
(let add! ([n root]
[chs (string->list str)])
Expand Down Expand Up @@ -270,17 +272,21 @@

;;; This is for the requires/find command

;; TODO: Rewrite front end racket-add-require-for-identifier to use
;; same UX as doc-search, but instead of viewing docs we insert their
;; choice of from-libs. Also, that front end command already is wrong
;; wrt non-sexp langs and needs a re-think.

;; Given some symbol as a string, return the modules providing it,
;; sorted by most likely to be desired.
(define (libs-exporting-documented sym-as-str)
(define results
(for*/set ([entry (in-list (xref-index xref))]
[desc (in-value (entry-desc entry))]
#:when (exported-index-desc? desc)
[name (in-value (symbol->string
(exported-index-desc-name desc)))]
[name (in-value (~a (exported-index-desc-name desc)))]
#:when (equal? name sym-as-str)
[libs (in-value (map symbol->string
[libs (in-value (map ~a
(exported-index-desc-from-libs desc)))]
#:when (not (null? libs)))
;; Take just the first lib. This usually seems to be the
Expand All @@ -301,27 +307,38 @@
;; This is for package-details

(define (build-module-doc-path-index)
(delay/idle
#:wait-for xref-ready-evt
(for*/hash ([entry (in-list (xref-index xref))]
[desc (in-value (entry-desc entry))]
[module? (in-value (module-path-index-desc? desc))]
[lang? (in-value (language-index-desc? desc))]
#:when (or module? lang?))
(define k (cons (car (entry-words entry))
lang?))
(define v (let-values ([(p a) (xref-tag->path+anchor xref (entry-tag entry))])
(let ([p (path->string p)]
[a a])
(cons p a))))
(values k v))))
(define (is-module? desc)
(or (module-path-index-desc? desc)
(and (index-desc? desc)
(eq? 'lib (hash-ref (index-desc-extras desc) 'module-kind #f)))))
(define (is-lang? desc)
(or (language-index-desc? desc)
(and (index-desc? desc)
(eq? 'lang (hash-ref (index-desc-extras desc) 'module-kind #f)))))
(for*/hash ([entry (in-list (xref-index xref))]
[desc (in-value (entry-desc entry))]
[module? (in-value (is-module? desc))]
[lang? (in-value (is-lang? desc))]
#:when (or module? lang?))
(define k (cons (car (entry-words entry))
lang?))
(define v (let-values ([(p a) (xref-tag->path+anchor xref (entry-tag entry))])
(let ([p (path->string p)]
[a a])
(cons p a))))
(values k v)))

(define module-doc-path-index (build-module-doc-path-index))
(define module-doc-path-index #f)

(define (refresh-module-doc-path-index!)
(set! module-doc-path-index (build-module-doc-path-index)))
(set! module-doc-path-index
(with-memory-use/log "build-module-doc-path-index"
(with-time/log "build-module-doc-path-index"
(build-module-doc-path-index)))))

(define (module-doc-path mod-path-str lang?)
(hash-ref (force module-doc-path-index)
(unless module-doc-path-index
(refresh-module-doc-path-index!))
(hash-ref module-doc-path-index
(cons mod-path-str lang?)
#f))

0 comments on commit 58113b6

Please sign in to comment.