Skip to content

Commit c662043

Browse files
committed
Revert accidentally-pushed changes with HISTORY update.
Revert "Merge pull request #1263 from capfredf/fix-contract" This reverts commit dbe5a6b, reversing changes made to 460916a.
1 parent 18dd1bc commit c662043

File tree

12 files changed

+48
-148
lines changed

12 files changed

+48
-148
lines changed

typed-racket-lib/typed-racket/env/type-alias-helper.rkt

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,10 @@
5757
(map vertex-data component)))
5858

5959

60-
;; register-all-type-aliases : Listof<Syntax> IDTable<ID, Listof<ID>> -> Void
60+
;; register-all-type-aliases : Listof<Syntax> -> Void
6161
;;
6262
;; register all type alias definitions carried by the input syntaxes
63-
;; dependency-map accounts for the dependencies of struct declarations
64-
(define (register-all-type-aliases type-aliases [dependency-map (make-immutable-free-id-table)])
63+
(define (register-all-type-aliases type-aliases)
6564
(parameterize ([incomplete-name-alias-map (make-free-id-table)])
6665
(define-values (type-alias-names type-alias-map)
6766
(for/lists (_1 _2 #:result (values _1 (make-free-id-table
@@ -75,7 +74,7 @@
7574
(values id (list id type-stx args))))
7675

7776
(begin0
78-
(register-all-type-alias-info type-alias-names type-alias-map dependency-map)
77+
(register-all-type-alias-info type-alias-names type-alias-map)
7978
(unless (zero? (free-id-table-count (incomplete-name-alias-map)))
8079
(define names (free-id-table-keys (incomplete-name-alias-map)))
8180
(int-err "not all type alias names are fully registered: ~n ~a"
@@ -92,7 +91,7 @@
9291
;; of actually registering the type aliases. If struct names or
9392
;; other definitions need to be registered, do that before calling
9493
;; this function.
95-
(define (register-all-type-alias-info type-alias-names type-alias-map dependency-map)
94+
(define (register-all-type-alias-info type-alias-names type-alias-map)
9695
;; Find type alias dependencies
9796
;; The two maps defined here contains the dependency structure
9897
;; of type aliases in two senses:
@@ -103,19 +102,8 @@
103102
;; The second is necessary in order to prevent recursive
104103
;; #:implements clauses and to determine the order in which
105104
;; recursive type aliases should be initialized.
106-
107-
(define (free-id-table-union! a b)
108-
(define struct-names (list->set (free-id-table-keys b)))
109-
(for ([(id deps) (in-free-id-table b)])
110-
(free-id-table-set! a id (filter (lambda (v)
111-
(or (free-id-table-ref type-alias-map v #f)
112-
(set-member? struct-names v)))
113-
deps))))
114-
115105
(define-values (type-alias-dependency-map type-alias-class-map type-alias-productivity-map)
116-
(for/lists (_1 _2 _3 #:result (values (let ([tbl1 (make-free-id-table _1)])
117-
(free-id-table-union! tbl1 dependency-map)
118-
tbl1)
106+
(for/lists (_1 _2 _3 #:result (values (make-free-id-table _1)
119107
(make-free-id-table _2)
120108
(make-free-id-table _3)))
121109
([(name alias-info) (in-free-id-table type-alias-map)])
@@ -179,7 +167,6 @@
179167
recursive-aliases
180168
free-identifier=?))
181169
(car component)))
182-
183170
(define other-recursive-aliases
184171
(for/list ([alias (in-list recursive-aliases)]
185172
#:unless (member alias
@@ -217,9 +204,8 @@
217204
;; reverse order of that to avoid unbound type aliases.
218205
(define acyclic-constr-names
219206
(for/fold ([acc '()])
220-
([id (in-list acyclic-singletons)]
221-
#:when (free-id-table-ref type-alias-map id #f))
222-
(match-define (list _ type-stx args) (free-id-table-ref type-alias-map id #f))
207+
([id (in-list acyclic-singletons)])
208+
(match-define (list _ type-stx args) (free-id-table-ref type-alias-map id))
223209
(define acc^
224210
(cond
225211
[(not (null? args))
@@ -265,8 +251,7 @@
265251
#:result
266252
(values (reverse type-records)
267253
(reverse type-op-records)))
268-
([id (in-list (append other-recursive-aliases class-aliases))]
269-
#:when (free-id-table-ref type-alias-map id #f))
254+
([id (in-list (append other-recursive-aliases class-aliases))])
270255
(define record (free-id-table-ref type-alias-map id))
271256
(match-define (list _ type-stx args) record)
272257
(if (null? args)
@@ -307,8 +292,7 @@
307292
(define res (in-same-component? id x))
308293
res)
309294
type-alias-productivity-map
310-
#:delay-variances? #t
311-
#:recursive? #t))
295+
#:delay-variances? #t))
312296
(register-type-constructor! id ty-op)
313297
(complete-type-alias-registration! id)
314298
(reset-resolver-cache!)

typed-racket-lib/typed-racket/env/type-constr-env.rkt

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
(require "../rep/type-constr.rkt"
33
syntax/id-table
44
"../env/env-utils.rkt"
5-
"../private/user-defined-type-constr.rkt"
65
"../typecheck/renamer.rkt")
76

87
(provide register-type-constructor!
98
lookup-type-constructor
10-
simple-type-constructor?
119
kind-env-map)
1210

1311
(define kind-env (make-free-id-table))
@@ -23,14 +21,3 @@
2321

2422
(define (register-type-constructor! name type-constr)
2523
(free-id-table-set! kind-env name type-constr))
26-
27-
28-
;; returns true if id refers to a built-in or non-recursive type constructor
29-
(define (simple-type-constructor? id)
30-
(cond
31-
[(lookup-type-constructor id)
32-
=>
33-
(lambda (constr)
34-
(not (and (user-defined-type-constr? constr)
35-
(recursive-type-constr? constr))))]
36-
[else #f]))

typed-racket-lib/typed-racket/private/parse-type.rkt

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@
6666
[parse-type-operator-abstraction (c:->* (identifier? (c:listof identifier?) syntax?)
6767
((c:or/c (c:-> identifier? boolean?) #f)
6868
(free-id-table/c identifier? boolean?)
69-
#:delay-variances? boolean?
70-
#:recursive? boolean?)
69+
#:delay-variances? boolean?)
7170
TypeConstructor?)]
7271
[parse-for-effects (c:-> identifier? (c:cons/c (c:listof identifier?) syntax?)
7372
(values (c:listof identifier?)
@@ -652,8 +651,7 @@
652651
(define (parse-type-operator-abstraction name arg-names stx [opt-in-same-component? #f]
653652
[type-op-productivity-map (make-immutable-free-id-table)]
654653
#:delay-variances?
655-
[delay-variances? #f]
656-
#:recursive? [recursive? #f])
654+
[delay-variances? #f])
657655
(define syms (map syntax-e arg-names))
658656
(define mode (synth-mode name syms opt-in-same-component?))
659657
(define var-kind-level-env
@@ -672,10 +670,7 @@
672670
var-kind-level-env
673671
#:mode mode)))
674672

675-
(make-type-constr (user-defined-type-op syms res (if (equal? (symbol->string (syntax-e name))
676-
"Formula")
677-
#t
678-
recursive?))
673+
(make-type-constr (user-defined-type-op syms res)
679674
(length syms)
680675
(free-id-table-ref type-op-productivity-map name #f)
681676
#:variances
@@ -1304,8 +1299,7 @@
13041299
(add-disappeared-use (syntax-local-introduce #'id)))
13051300
t)]
13061301
[else
1307-
(unless (side-effect-mode? mode)
1308-
(parse-error #:delayed? #t (~a "type name `" v "' is unbound")))
1302+
(parse-error #:delayed? #t (~a "type name `" v "' is unbound"))
13091303
Err])]
13101304
[(:Opaque^ . rest)
13111305
(parse-error "bad syntax in Opaque")]

typed-racket-lib/typed-racket/private/type-contract.rkt

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"../env/type-name-env.rkt"
1818
"../env/row-constraint-env.rkt"
1919
"../env/lexical-env.rkt"
20-
"../env/type-constr-env.rkt"
2120

2221
"../rep/core-rep.rkt"
2322
"../rep/rep-utils.rkt"
@@ -413,23 +412,17 @@
413412
;; Key with (cons name 'app) instead of just name because the
414413
;; application of the Name is not necessarily the same as the
415414
;; Name type alone
416-
(cond
417-
;; when constr is a built-in or non-recursive user-defined type
418-
;; constructor, don't generate a recursive static contract
419-
;; for the resulting type.
420-
[(simple-type-constructor? name)
421-
(t->sc (resolve-once type))]
422-
[(hash-ref recursive-values (cons name 'app) #f)]
423-
[else
424-
(define name* (generate-temporary name))
425-
(recursive-sc (list name*)
426-
(list
427-
(t->sc (resolve-once type)
428-
#:recursive-values
429-
(hash-set recursive-values
430-
(cons name 'app)
431-
(recursive-sc-use name*))))
432-
(recursive-sc-use name*))])]
415+
(cond [(hash-ref recursive-values (cons name 'app) #f)]
416+
[else
417+
(define name* (generate-temporary name))
418+
(recursive-sc (list name*)
419+
(list
420+
(t->sc (resolve-once type)
421+
#:recursive-values
422+
(hash-set recursive-values
423+
(cons name 'app)
424+
(recursive-sc-use name*))))
425+
(recursive-sc-use name*))])]
433426
;; Implicit recursive aliases
434427
[(Name: name-id args #f)
435428
(cond [;; recursive references are looked up in a special table

typed-racket-lib/typed-racket/private/user-defined-type-constr.rkt

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,22 @@
77
(subst-all make-simple-substitution)])
88

99
(provide (struct-out user-defined-type-op)
10-
user-defined-type-constr?
11-
recursive-type-constr?)
10+
user-defined-type-constr?)
1211

13-
(struct user-defined-type-op (vars type recursive?) #:transparent
12+
(struct user-defined-type-op (vars type) #:transparent
1413
#:methods gen:type-rep-maker
1514
[(define (gen-create-type-rep me args)
16-
(match-define (user-defined-type-op vars type recursive?) me)
15+
(match-define (user-defined-type-op vars type) me)
1716
(subst-all (make-simple-substitution vars args)
1817
type))
1918
(define (gen-serialize-type-rep me t->s)
20-
(match-define (user-defined-type-op vars type recursive?) me)
19+
(match-define (user-defined-type-op vars type) me)
2120
`(user-defined-type-op (list ,@(for/list ([i (in-list vars)])
2221
`(quote ,i)))
23-
,(t->s type)
24-
,recursive?))])
22+
,(t->s type)))])
2523

2624
(define (user-defined-type-constr? constr-rep)
2725
(match constr-rep
2826
[(struct* TypeConstructor ([real-trep-constr (? user-defined-type-op?)]))
2927
#t]
3028
[_ #f]))
31-
32-
(define (recursive-type-constr? constr)
33-
(match constr
34-
[(struct* TypeConstructor
35-
([real-trep-constr (struct* user-defined-type-op ([recursive? recursive?]))]))
36-
recursive?]))

typed-racket-lib/typed-racket/rep/free-variance.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@
210210
(match-define (struct* TypeConstructor ([real-trep-constr maker]
211211
[variances old-variances]))
212212
constr)
213-
(match-define (struct user-defined-type-op [tvars type _]) maker)
213+
(match-define (struct user-defined-type-op [tvars type]) maker)
214214
(cond
215215
[(or (not tvars) (null? tvars)) #t]
216216
[else

typed-racket-lib/typed-racket/rep/type-rep.rkt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,13 @@
185185
#:with fld-frees #'(make-invariant (frees name))))
186186
(syntax-parse stx
187187
[(_ name:var-name ((~var flds (structural-flds #'frees)) ...) . rst)
188-
(with-syntax ([constructor-name (format-id #'name "make-~a-rep" (syntax-e #'name))]
188+
(with-syntax ([contructor-name (format-id #'name "make-~a-rep" (syntax-e #'name))]
189189
[type-constructor-name (format-id #'name "make-~a" (syntax-e #'name))])
190190
(define arity (length (syntax->list #'(flds ...))))
191191
(quasisyntax/loc stx
192192
(begin
193193
(def-rep (name #:constructor-name constructor-name) ([flds.name Type?] ...)
194+
#:no-provide (constructor-name)
194195
[#:parent Type]
195196
[#:frees (frees) . #,(if (= 1 (length (syntax->list #'(flds.name ...))))
196197
#'(flds.fld-frees ...)

typed-racket-lib/typed-racket/typecheck/tc-app/tc-app-lambda.rkt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"../find-annotation.rkt"
1111
"../tc-metafunctions.rkt"
1212
"../../types/abbrev.rkt"
13-
"../../types/resolve.rkt"
1413
"../../types/utils.rkt"
1514
"../../types/generalize.rkt"
1615
"../../types/type-table.rkt"
@@ -109,8 +108,8 @@
109108
(generalize (tc-expr/t ac)))))]
110109
[acc-ty (or
111110
(type-annotation #'val #:infer #t)
112-
(match (resolve expected)
113-
[(tc-result1: (app resolve (and t (Listof: _)))) t]
111+
(match expected
112+
[(tc-result1: (and t (Listof: _))) t]
114113
[_ #f])
115114
(generalize -Null))])
116115
;; this check is needed because the type annotation may come

typed-racket-lib/typed-racket/typecheck/tc-structs.rkt

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@
4444
(provide tc/struct
4545
tc/struct-prop-values
4646
tc/make-struct-type-property
47-
name-of-struct
48-
names-referred-in-struct
49-
d-s
47+
name-of-struct d-s
5048
register-parsed-struct-sty!
5149
register-parsed-struct-bindings!)
5250

@@ -92,21 +90,6 @@
9290
(syntax-parse stx
9391
[t:typed-struct #'t.type-name]))
9492

95-
(define (names-referred-in-struct stx)
96-
(define-values (tvars field-types)
97-
(syntax-parse stx
98-
[t:typed-struct (values (attribute t.tvars)
99-
(attribute t.types))]))
100-
(define name (name-of-struct stx))
101-
102-
(cond
103-
[(null? tvars) null]
104-
[else
105-
(append-map (lambda (t)
106-
(define-values (r _ __) (parse-for-effects name (cons tvars t)))
107-
r)
108-
field-types)]))
109-
11093
;; a simple wrapper to get proc from a polymorphic or monomorhpic structure
11194
(define/cond-contract (get-struct-proc sty)
11295
(c:-> (c:or/c Struct? Poly?) (c:or/c #f Fun?))
@@ -250,7 +233,7 @@
250233
(make-Poly (struct-desc-tvars desc) sty))
251234
(unless (empty? (struct-desc-tvars desc))
252235
(define variances (map (lambda _ variance:const) (struct-desc-tvars desc)))
253-
(define ty-op (make-type-constr (user-defined-type-op (struct-desc-tvars desc) sty #f)
236+
(define ty-op (make-type-constr (user-defined-type-op (struct-desc-tvars desc) sty)
254237
(length (struct-desc-tvars desc))
255238
#:variances
256239
variances))

typed-racket-lib/typed-racket/typecheck/tc-toplevel.rkt

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -428,23 +428,17 @@
428428
(~datum expand)))))
429429

430430
;; finish registering struct definitions in two steps with the second one being
431-
;; the return thunk, which can be invoked on demand. The function also returns a
432-
;; dependency mappping from struct type names to the type names used in their
433-
;; definitions.
434-
435-
;; Listof[Expr] -> Values[Promise[Listof[binding]], FreeIDTable[Identifer, Identifer]]
431+
;; the return thunk, which can be invoked on demand.
432+
;; Listof[Expr] -> Promise[Listof[binding]]
436433
(define (register-struct-type-info! form-li)
437434
;; register type name and alias first
438-
(define-values (poly-names binding-reg dependency-map)
435+
(define-values (poly-names binding-reg)
439436
(for/fold ([poly-names '()]
440437
[binding-reg '()]
441-
[dependency-map (make-immutable-free-id-table)]
442438
#:result (values (reverse poly-names)
443-
(reverse binding-reg)
444-
dependency-map))
439+
(reverse binding-reg)))
445440
([form (in-list form-li)])
446441
(define name (name-of-struct form))
447-
(define other-names (names-referred-in-struct form))
448442
(define tvars (type-vars-of-struct form))
449443
(register-resolved-type-alias name (make-Name name (length tvars) #t))
450444
(register-type-name name)
@@ -454,14 +448,11 @@
454448
name))
455449
poly-names)
456450
(cons (delay (register-parsed-struct-bindings! (force parsed)))
457-
binding-reg)
458-
(free-id-table-set dependency-map name other-names))))
459-
(values
460-
(delay (lambda (names)
461-
(refine-user-defined-constructor-variances!
462-
(append names (filter-map force poly-names)))
463-
(map force binding-reg)))
464-
dependency-map))
451+
binding-reg))))
452+
(delay (lambda (names)
453+
(refine-user-defined-constructor-variances!
454+
(append names (filter-map force poly-names)))
455+
(map force binding-reg))))
465456

466457

467458
;; the resulting thunk finishes the rest work)
@@ -490,11 +481,11 @@
490481
(parse-and-register-signature! sig-form))
491482

492483
;; Add the struct names to the type table, but not with a type
493-
(define-values (promise-reg-sty-info dependency-map) (register-struct-type-info! struct-defs))
484+
(define promise-reg-sty-info (register-struct-type-info! struct-defs))
494485

495486
(do-time "after adding type names")
496487

497-
(define names (register-all-type-aliases type-aliases dependency-map))
488+
(define names (register-all-type-aliases type-aliases))
498489

499490
(finalize-signatures!)
500491

@@ -727,8 +718,7 @@
727718
'no-type)]
728719
[else
729720
(when (typed-struct? form)
730-
(define-values (after-reg _) (register-struct-type-info! (list form)))
731-
((force after-reg) null))
721+
((force (register-struct-type-info! (list form))) null))
732722
(define all-forms (cond
733723
[(typed-struct? form)
734724
;; after a struct type is registered, check the pending forms is in receiving order

0 commit comments

Comments
 (0)