Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated Resyntax fixes #1422

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions typed-racket-lib/typed-racket/rep/base-type-rep.rkt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#lang racket/base

(require "rep-utils.rkt"
"core-rep.rkt"
"type-mask.rkt"
racket/match
(for-syntax racket/base
(require (for-syntax racket/base
racket/syntax
syntax/parse))
syntax/parse)
racket/match
"core-rep.rkt"
"rep-utils.rkt"
"type-mask.rkt")

(provide define-base-types
Base-bits:
Expand Down
12 changes: 5 additions & 7 deletions typed-racket-lib/typed-racket/rep/base-union.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@
(app BaseUnion-bases bases)))])))

(define (BaseUnion-bases t)
(match t
[(BaseUnion: bbits nbits)
(cond
[(eqv? bbits 0) (nbits->base-types nbits)]
[(eqv? nbits 0) (bbits->base-types bbits)]
[else (append (bbits->base-types bbits)
(nbits->base-types nbits))])]))
(match-define (BaseUnion: bbits nbits) t)
(cond
[(eqv? bbits 0) (nbits->base-types nbits)]
[(eqv? nbits 0) (bbits->base-types bbits)]
[else (append (bbits->base-types bbits) (nbits->base-types nbits))]))
2 changes: 1 addition & 1 deletion typed-racket-lib/typed-racket/rep/core-rep.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@
(-> Result? Result?)
(match-define (Result: type propset optobject n-existentials) result)
(cond
[(> n-existentials 0)
[(positive? n-existentials)
(define syms (hash-ref type-var-name-table result (build-list n-existentials (lambda _ (gensym)))))
(define vars (map make-F syms))
(make-Result (instantiate-type type vars) (instantiate-propset propset vars) optobject n-existentials)]
Expand Down
8 changes: 3 additions & 5 deletions typed-racket-lib/typed-racket/rep/free-ids.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,9 @@
(cond
[(member x seen free-identifier=?) (cons x seen)]
[else
(begin0
(let ([seen+x (cons x seen)])
(for/or ([neighbor (in-list (cdr (assoc x deps free-identifier=?)))])
(and (not (member neighbor visited free-identifier=?))
(visit neighbor seen+x))))
(define seen+x (cons x seen))
(begin0 (for/or ([neighbor (in-list (cdr (assoc x deps free-identifier=?)))])
(and (not (member neighbor visited free-identifier=?)) (visit neighbor seen+x)))
(set! visited (cons x visited)))]))
(match (for/or ([entry (in-list deps)])
(visit (car entry) '()))
Expand Down
24 changes: 10 additions & 14 deletions typed-racket-lib/typed-racket/rep/free-variance.rkt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#lang racket/base
(require racket/match
racket/set
(require racket/lazy-require
racket/list
"../rep/type-constr.rkt"
"../utils/utils.rkt"
racket/lazy-require
racket/match
racket/set
"../env/type-constr-env.rkt"
"../private/user-defined-type-constr.rkt"
"../env/type-constr-env.rkt")
"../rep/type-constr.rkt"
"../utils/utils.rkt")

(provide
;; Variances
Expand Down Expand Up @@ -123,18 +123,14 @@
(for/fold ([hash (hasheq)]
[computed null])
([frees (in-list freess)])
(match frees
[(combined-frees new-hash new-computed)
(values (combine-hashes (list hash new-hash))
(append new-computed computed))])))
(match-define (combined-frees new-hash new-computed) frees)
(values (combine-hashes (list hash new-hash)) (append new-computed computed))))
(combined-frees hash computed))


(define (free-vars-remove frees name)
(match frees
[(combined-frees hash computed)
(combined-frees (hash-remove hash name)
(map (λ (v) (remove-frees v name)) computed))]))
(match-define (combined-frees hash computed) frees)
(combined-frees (hash-remove hash name) (map (λ (v) (remove-frees v name)) computed)))

;;
(define (free-vars-names vars)
Expand Down
17 changes: 7 additions & 10 deletions typed-racket-lib/typed-racket/rep/object-rep.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,10 @@
[(list (? exact-integer? coeff) (? Path? p))
(values c (terms-set ts p (+ coeff (terms-ref ts p))))]
[(list (? exact-integer? coeff) (? name-ref/c nm))
(let ([p (-id-path nm)])
(if (Empty? nm)
(values c ts)
(values c (terms-set ts p (+ coeff (terms-ref ts p))))))]
(define p (-id-path nm))
(if (Empty? nm)
(values c ts)
(values c (terms-set ts p (+ coeff (terms-ref ts p)))))]
[(? exact-integer? new-const)
(values (+ new-const c) ts)]
[(LExp: c* ts*)
Expand Down Expand Up @@ -313,9 +313,7 @@
(-> OptObject? (or/c #f exact-integer?))
(match l
[(LExp: c terms)
(if (hash-empty? terms)
c
#f)]
(and (hash-empty? terms) c)]
[_ #f]))

(define/cond-contract (in-LExp? obj l)
Expand Down Expand Up @@ -388,6 +386,5 @@
(make-LExp* (+ c1 c2) (terms-add terms1 terms2))]))

(define (add-path-to-lexp p l)
(match l
[(LExp: const terms)
(make-LExp* const (terms-set terms p (add1 (terms-ref terms p))))]))
(match-define (LExp: const terms) l)
(make-LExp* const (terms-set terms p (add1 (terms-ref terms p)))))
3 changes: 1 addition & 2 deletions typed-racket-lib/typed-racket/rep/prop-rep.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@
[#:for-each (f) (for-each f ps)]
[#:custom-constructor/contract
(-> (listof (or/c TypeProp? NotTypeProp? LeqProp?)) OrProp?)
(let ([ps (sort ps (λ (p q) (unsafe-fx<= (eq-hash-code p)
(eq-hash-code q))))])
(let ([ps (sort ps unsafe-fx<= #:key eq-hash-code)])
(intern-single-ref!
orprop-intern-table
ps
Expand Down
12 changes: 6 additions & 6 deletions typed-racket-lib/typed-racket/rep/rep-switch.rkt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#lang racket/base

(require "rep-utils.rkt"
(require (for-syntax racket/base
racket/list
racket/syntax
syntax/parse)
racket/match
racket/unsafe/ops
(for-syntax racket/base
syntax/parse
racket/list
racket/syntax))
"rep-utils.rkt")

(provide define-rep-switch)

Expand Down Expand Up @@ -35,7 +35,7 @@
(~var clause (switch-clause #'(pre-args ...) #'arg #'(post-args ...))) ...
[(~datum else:) . default])
(define name-symbols (map syntax->datum (syntax->list #'(clause.name ...))))
(unless (not (null? name-symbols))
(when (null? name-symbols)
(raise-syntax-error 'define-switch "switch cannot be null" stx))
(define sorted-name-symbols (sort name-symbols symbol<?))
(unless (eq? (first name-symbols) (first sorted-name-symbols))
Expand Down
18 changes: 7 additions & 11 deletions typed-racket-lib/typed-racket/rep/rep-utils.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@
;; NOTE: the #:construct expression is only run if there
;; is no interned copy, so we should avoid unnecessary
;; allocation w/ this approach
(define-simple-macro (intern-single-ref! table-exp:expr
key-exp:expr
#:construct val-exp:expr)
(define-syntax-parse-rule (intern-single-ref! table-exp:expr key-exp:expr #:construct val-exp:expr)
(let ([table table-exp])
(define key key-exp)
(define intern-box (hash-ref table key #f))
Expand All @@ -132,13 +130,11 @@

;; fetches an interned Rep based on the given _two_ keys
;; see 'intern-single-ref!'
(define-simple-macro (intern-double-ref! table:id
key-exp1:expr
key-exp2:expr
#:construct val-exp:expr)
(intern-single-ref! (hash-ref! table key-exp1 make-hash)
key-exp2
#:construct val-exp))
(define-syntax-parse-rule (intern-double-ref! table:id
key-exp1:expr
key-exp2:expr
#:construct val-exp:expr)
(intern-single-ref! (hash-ref! table key-exp1 make-hash) key-exp2 #:construct val-exp))



Expand Down Expand Up @@ -398,7 +394,7 @@
;; singletons cannot have fields or #:no-provide
(when (and (attribute singleton)
(or (attribute no-provide?-kw)
(> (length (syntax->list #'flds)) 0)))
(positive? (length (syntax->list #'flds)))))
(raise-syntax-error 'def-rep "singletons cannot have fields or the #:no-provide option"
#'var))
(when (and (attribute base?)
Expand Down
6 changes: 3 additions & 3 deletions typed-racket-lib/typed-racket/rep/type-constr.rkt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#lang racket/base
(require racket/match
(require racket/generic
racket/lazy-require
racket/list
racket/string
racket/generic)
racket/match
racket/string)

(provide print-kind
make-type-constr
Expand Down
57 changes: 29 additions & 28 deletions typed-racket-lib/typed-racket/rep/type-rep.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,39 @@
;; This module provides type representations and utility functions
;; and pattern matchers on types

(require "../utils/utils.rkt"
(for-syntax "../utils/utils.rkt"))
(require (for-syntax "../utils/utils.rkt")
"../utils/utils.rkt")

;; TODO use contract-req
(require "../utils/tc-utils.rkt"
"../utils/prefab.rkt"
"../utils/identifier.rkt"
(require (for-syntax racket/base
racket/syntax
syntax/parse)
racket/contract
racket/format
racket/lazy-require
racket/list
racket/match
racket/string
racket/unsafe/undefined
syntax/id-set
syntax/id-table
(only-in racket/generic define/generic)
"../env/env-utils.rkt"
"rep-utils.rkt"
"type-constr.rkt"
"../utils/identifier.rkt"
"../utils/prefab.rkt"
"../utils/tc-utils.rkt"
"base-type-rep.rkt"
"base-types.rkt"
"base-union.rkt"
"core-rep.rkt"
"free-variance.rkt"
"numeric-base-types.rkt"
"object-rep.rkt"
"prop-rep.rkt"
"values-rep.rkt"
"rep-utils.rkt"
"type-constr.rkt"
"type-mask.rkt"
"free-variance.rkt"
"base-type-rep.rkt"
"base-types.rkt"
"numeric-base-types.rkt"
"base-union.rkt"
racket/match racket/list
racket/format
syntax/id-table
syntax/id-set
racket/contract
racket/string
(only-in racket/generic define/generic)
racket/lazy-require
racket/unsafe/undefined
(for-syntax racket/base
racket/syntax
syntax/parse))
"values-rep.rkt")

(provide (except-out (all-from-out "core-rep.rkt"
"base-type-rep.rkt"
Expand Down Expand Up @@ -1154,8 +1155,8 @@
(match ts
[(list) (-refine Univ prop)]
[(list t) (-refine t prop)]
[_ (let ([t (make-Intersection ts -tt elems)])
(-refine t prop))])]
[_ (define t (make-Intersection ts -tt elems))
(-refine t prop)])]
[(cons arg args)
(match arg
[(Univ:) (loop ts elems prop args)]
Expand Down Expand Up @@ -1806,7 +1807,7 @@

;; sorts the given field of a Row by the member name
(define (sort-row-clauses clauses)
(sort clauses (λ (x y) (symbol<? (car x) (car y)))))
(sort clauses symbol<? #:key car))

(define-match-expander Class:*
(λ (stx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@
(arr-seq-sc-map f (combinator-args v))
(void))
(define (sc->contract v f)
(match v
[(arr-combinator (arr-seq args rest range))
(with-syntax ([(arg-stx ...) (map f args)]
[(rest-stx ...) (if rest #`(#:rest #,(f rest)) #'())]
[range-stx (if range #`(values #,@(map f range)) #'any)])
#'(arg-stx ... rest-stx ... . -> . range-stx))]))
(match-define (arr-combinator (arr-seq args rest range)) v)
(with-syntax ([(arg-stx ...) (map f args)]
[(rest-stx ...) (if rest
#`(#:rest #,(f rest))
#'())]
[range-stx (if range
#`(values #,@(map f range))
#'any)])
#'(arg-stx ... rest-stx ... . -> . range-stx)))
(define (sc->constraints v f)
(merge-restricts* 'chaperone (map f (arr-seq->list (combinator-args v)))))])

Expand All @@ -66,20 +69,18 @@


(define (arr-seq-sc-map f seq)
(match seq
[(arr-seq args rest range)
(arr-seq
(map (λ (a) (f a 'contravariant)) args)
(and rest (f rest 'contravariant))
(and range (map (λ (a) (f a 'covariant)) range)))]))
(match-define (arr-seq args rest range) seq)
(arr-seq (map (λ (a) (f a 'contravariant)) args)
(and rest (f rest 'contravariant))
(and range (map (λ (a) (f a 'covariant)) range))))

(define (arr-seq->list seq)
(match seq
[(arr-seq args rest range)
(append
args
(if rest (list rest) empty)
(or range empty))]))
(match-define (arr-seq args rest range) seq)
(append args
(if rest
(list rest)
empty)
(or range empty)))


(struct arr-seq (args rest range)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,10 @@
(match-define (function-combinator args indices mand-kws opt-kws typed-side?) v)
(define-values (mand-args opt-args mand-kw-args opt-kw-args rest-arg range-args)
(apply split-function-args args indices))
(if (and (not rest-arg)
(null? (append mand-kw-args mand-args opt-kw-args opt-args))
typed-side?)
;; currently we only handle this trivial case
;; we could probably look at the actual kind of `range-args` as well
(if (not range-args) 'flat #f)
#f))
(and (and (not rest-arg) (null? (append mand-kw-args mand-args opt-kw-args opt-args)) typed-side?)
;; currently we only handle this trivial case
;; we could probably look at the actual kind of `range-args` as well
(and (not range-args) 'flat)))


(define (function-sc-constraints v f)
Expand Down
Loading
Loading