Skip to content

Commit 3cc4644

Browse files
committed
change scribble/blueboxes to untyped
This turns out to be the only dependency from "racket-index" on Typed Racket.
1 parent fa17444 commit 3cc4644

File tree

2 files changed

+32
-69
lines changed

2 files changed

+32
-69
lines changed

scribble-lib/info.rkt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
"at-exp-lib"
1313
"draw-lib"
1414
"syntax-color-lib"
15-
"sandbox-lib"
16-
"typed-racket-lib"
17-
))
15+
"sandbox-lib"))
1816
(define build-deps '("rackunit-lib")) ; for embedded module+ test
1917

2018
(define implies '("scribble-html-lib"))
Lines changed: 31 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,47 @@
1-
#lang typed/racket/base
2-
(require racket/match)
3-
(require/typed setup/dirs [get-doc-search-dirs (-> (Listof Path))])
4-
(require/typed racket/serialize [deserialize (Any -> Any)])
5-
(require/typed scribble/core [#:opaque Tag tag?])
6-
(require/typed scribble/tag
7-
[#:opaque Method-Tag method-tag?]
8-
[#:opaque Definition-Tag definition-tag?]
9-
[#:opaque Class/Interface-Tag class/interface-tag?]
10-
[class/interface-tag->constructor-tag (Class/Interface-Tag -> Tag)]
11-
[definition-tag->class/interface-tag (Definition-Tag -> Class/Interface-Tag)]
12-
[get-class/interface-and-method (Method-Tag -> (values Symbol Symbol))]
13-
)
14-
(require/typed "valid-blueboxes-info.rkt" [valid-blueboxes-info? (Any -> Boolean)])
1+
#lang racket/base
2+
(require racket/match
3+
racket/contract/base
4+
setup/dirs
5+
racket/serialize
6+
scribble/core
7+
scribble/tag
8+
"valid-blueboxes-info.rkt")
159

16-
(provide fetch-blueboxes-strs
17-
make-blueboxes-cache
18-
blueboxes-cache?
19-
fetch-blueboxes-method-tags
20-
)
10+
(provide
11+
blueboxes-cache?
12+
(contract-out
13+
[fetch-blueboxes-strs (->* (tag?)
14+
(#:blueboxes-cache blueboxes-cache?)
15+
(or/c #f (non-empty-listof string?)))]
16+
[make-blueboxes-cache (->* (boolean?)
17+
(#:blueboxes-dirs (listof path?))
18+
blueboxes-cache?)]
19+
[fetch-blueboxes-method-tags (->* (symbol?)
20+
(#:blueboxes-cache blueboxes-cache?)
21+
(listof method-tag?))]))
2122

22-
(define-type Bluebox-Info bluebox-info)
23-
(struct bluebox-info
24-
([blueboxes.rktd : Path-String]
25-
[offset : (U Natural #f)]
26-
[tag-ht : (U Blueboxes-Info-Hash #f)] ; (or/c valid-blueboxes-info? #f)
27-
[mod-time : (U Natural #f)])
23+
(struct bluebox-info (blueboxes.rktd
24+
offset
25+
tag-ht
26+
mod-time)
2827
#:mutable)
2928

30-
(define-type Blueboxes-Cache blueboxes-cache)
31-
(struct blueboxes-cache
32-
([info-or-paths : (U (Listof Path) (Listof Bluebox-Info))]
33-
[method->tags : (U (HashTable Symbol (Listof Method-Tag)) #f)])
29+
(struct blueboxes-cache (info-or-paths
30+
method->tags)
3431
#:mutable)
3532

36-
(: make-blueboxes-cache :
37-
Boolean
38-
[#:blueboxes-dirs (Listof Path)]
39-
->
40-
Blueboxes-Cache)
4133
(define (make-blueboxes-cache
4234
populate?
4335
#:blueboxes-dirs
4436
[blueboxes-dirs (for*/list ([d (in-list (get-doc-search-dirs))]
4537
[c (in-list (if (directory-exists? d)
4638
(directory-list d)
4739
'()))])
48-
: (Listof Path)
4940
(build-path d c))])
5041
(define cache (blueboxes-cache blueboxes-dirs #f))
5142
(when populate? (populate-cache! cache))
5243
cache)
5344

54-
(: fetch-blueboxes-strs :
55-
Tag
56-
[#:blueboxes-cache Blueboxes-Cache]
57-
->
58-
(U #f (List* String (Listof String))))
5945
(define (fetch-blueboxes-strs tag #:blueboxes-cache [cache (make-blueboxes-cache #f)])
6046
(define plain-strs (fetch-strs-for-single-tag tag cache))
6147
(cond
@@ -70,11 +56,9 @@
7056
(if constructor-strs (cdr constructor-strs) '()))]
7157
[else plain-strs]))
7258

73-
(: fetch-strs-for-single-tag : Tag Blueboxes-Cache -> (U #f (List* String (Listof String))))
7459
(define (fetch-strs-for-single-tag tag cache)
7560
(populate-cache! cache)
7661
(for/or ([ent (in-list (blueboxes-cache-info-or-paths cache))])
77-
: (U #f (List* String (Listof String)))
7862
(when (bluebox-info? ent)
7963
(check-and-update-bluebox-info! ent))
8064
(match ent
@@ -86,13 +70,11 @@
8670
(apply
8771
append
8872
(for/list ([offset+len (in-list offset+lens)])
89-
: (Listof (Listof (U String EOF)))
9073
(call-with-input-file blueboxes.rktd
91-
(λ ([port : Input-Port])
74+
(λ (port)
9275
(port-count-lines! port)
9376
(file-position port (+ (car offset+len) (or offset 0)))
9477
(for/list ([i (in-range (cdr offset+len))])
95-
: (Listof (U String EOF))
9678
(read-line port)))))))
9779
(cond
9880
[(not (andmap string? lines)) #f]
@@ -102,26 +84,20 @@
10284
[_ (log-warning "expected bluebox-info?, given: ~v" ent)
10385
#f])))
10486

105-
(: fetch-blueboxes-method-tags : Symbol [#:blueboxes-cache Blueboxes-Cache] -> (Listof Method-Tag))
10687
(define (fetch-blueboxes-method-tags sym #:blueboxes-cache [cache (make-blueboxes-cache #f)])
10788
(populate-cache! cache)
10889
(define ht (blueboxes-cache-method->tags cache))
10990
(or (and ht (hash-ref ht sym (λ () '()))) '()))
11091

111-
(define listof-path? (make-predicate (Listof Path)))
112-
113-
(: populate-cache! : Blueboxes-Cache -> Void)
11492
(define (populate-cache! cache)
11593
(define cache-content (blueboxes-cache-info-or-paths cache))
116-
(when (listof-path? cache-content)
94+
(when (and (list? cache-content) (andmap path? cache-content))
11795
(define the-cache (build-blueboxes-cache cache-content))
11896
(define mtd-table (compute-methods-table the-cache))
11997
(set-blueboxes-cache-method->tags! cache mtd-table)
12098
(set-blueboxes-cache-info-or-paths! cache the-cache)))
12199

122-
(: compute-methods-table : (Listof Bluebox-Info) -> (HashTable Symbol (Listof Method-Tag)))
123100
(define (compute-methods-table lst)
124-
(: meth-ht : (HashTable Symbol (Listof Method-Tag)))
125101
(define meth-ht (make-hash))
126102
(for ([a-bluebox-info (in-list lst)])
127103
(match a-bluebox-info
@@ -133,18 +109,15 @@
133109
(hash-set! meth-ht meth (cons tag (hash-ref meth-ht meth (λ () '())))))))]))
134110
meth-ht)
135111

136-
(: build-blueboxes-cache : (Listof Path) -> (Listof Bluebox-Info))
137112
(define (build-blueboxes-cache blueboxes-dirs)
138113
(filter
139114
values
140115
(for*/list ([doc-dir-name (in-list blueboxes-dirs)])
141-
: (Listof Bluebox-Info)
142116
(define blueboxes.rktd (build-path doc-dir-name "blueboxes.rktd"))
143117
(define a-bluebox-info (bluebox-info blueboxes.rktd #f #f #f))
144118
(populate-bluebox-info! a-bluebox-info)
145119
a-bluebox-info)))
146120

147-
(: check-and-update-bluebox-info! : bluebox-info -> Void)
148121
(define (check-and-update-bluebox-info! a-bluebox-info)
149122
(match a-bluebox-info
150123
[(bluebox-info blueboxes.rktd offset tag-ht mod-time)
@@ -153,18 +126,17 @@
153126
(not (mod-time . = . (file-or-directory-modify-seconds blueboxes.rktd)))))
154127
(populate-bluebox-info! a-bluebox-info))]))
155128

156-
(: populate-bluebox-info! : Bluebox-Info -> Void)
157129
(define (populate-bluebox-info! a-bluebox-info)
158130
(define blueboxes.rktd (bluebox-info-blueboxes.rktd a-bluebox-info))
159131
(cond
160132
[(file-exists? blueboxes.rktd)
161133
(call-with-input-file blueboxes.rktd
162-
(λ ([port : Input-Port])
134+
(λ (port)
163135
(port-count-lines! port)
164136
(define first-line (read-line port))
165137
(define pos (file-position port))
166138
(define desed
167-
(with-handlers ([exn:fail? (λ ([x : exn:fail])
139+
(with-handlers ([exn:fail? (λ (x)
168140
(log-warning "Failed to deserialize ~a: ~a"
169141
x
170142
(exn-message x))
@@ -174,7 +146,7 @@
174146
(error 'build-blueboxes-cache
175147
"blueboxes info didn't have the right shape: ~s"
176148
candidate))
177-
(cast candidate Blueboxes-Info-Hash)))
149+
candidate))
178150
(define first-line-num (and (string? first-line) (string->number first-line)))
179151
(cond
180152
[(exact-nonnegative-integer? first-line-num)
@@ -189,10 +161,3 @@
189161
(set-bluebox-info-offset! a-bluebox-info #f)
190162
(set-bluebox-info-tag-ht! a-bluebox-info #f)
191163
(set-bluebox-info-mod-time! a-bluebox-info #f)]))
192-
193-
(define-type Blueboxes-Info-Hash
194-
(HashTable
195-
Tag
196-
(Listof (Pairof Natural
197-
Natural))))
198-

0 commit comments

Comments
 (0)