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 #1400

Merged
merged 2 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 7 additions & 4 deletions typed-racket-lib/typed-racket/optimizer/apply.rkt
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#lang racket/base
(require syntax/parse racket/syntax
(for-template racket/unsafe/ops racket/base (prefix-in k- '#%kernel))
(require (for-template racket/base
racket/unsafe/ops
(prefix-in k- '#%kernel))
racket/syntax
syntax/parse
"../utils/utils.rkt"
"utils.rkt"
"logging.rkt")
"logging.rkt"
"utils.rkt")

(provide apply-opt-expr)

Expand Down
9 changes: 5 additions & 4 deletions typed-racket-lib/typed-racket/optimizer/box.rkt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#lang racket/base

(require syntax/parse
(require (for-template racket/base
racket/unsafe/ops)
syntax/parse
"../utils/utils.rkt"
(for-template racket/base racket/unsafe/ops)
"utils.rkt"
"logging.rkt")
"logging.rkt"
"utils.rkt")

(provide box-opt-expr)

Expand Down
12 changes: 7 additions & 5 deletions typed-racket-lib/typed-racket/optimizer/dead-code.rkt
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#lang racket/base

(require syntax/parse syntax/stx racket/sequence
(require (for-template racket/base)
racket/sequence
racket/syntax
(for-template racket/base)
"../utils/utils.rkt"
syntax/parse
syntax/stx
(only-in "../utils/tc-utils.rkt" current-type-enforcement-mode deep)
"../types/type-table.rkt"
"utils.rkt"
"logging.rkt")
"../utils/utils.rkt"
"logging.rkt"
"utils.rkt")

(provide dead-code-opt-expr)

Expand Down
13 changes: 8 additions & 5 deletions typed-racket-lib/typed-racket/optimizer/extflonum.rkt
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#lang racket/base

(require syntax/parse racket/extflonum
(require (for-template racket/base
racket/extflonum
racket/unsafe/ops)
racket/extflonum
syntax/parse
syntax/parse/experimental/specialize
(for-template racket/base racket/extflonum racket/unsafe/ops)
"../utils/utils.rkt"
"utils.rkt"
"logging.rkt"
"fixnum.rkt"
"float.rkt"
"fixnum.rkt")
"logging.rkt"
"utils.rkt")

(provide extflonum-opt-expr)

Expand Down
24 changes: 14 additions & 10 deletions typed-racket-lib/typed-racket/optimizer/fixnum.rkt
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
#lang racket/base

(require syntax/parse
(require (for-syntax racket/base
racket/syntax
syntax/parse)
(for-template racket/base
racket/fixnum
racket/unsafe/ops)
syntax/parse
syntax/parse/experimental/specialize
"../utils/utils.rkt"
(for-template racket/base racket/fixnum racket/unsafe/ops)
(for-syntax racket/base syntax/parse racket/syntax)
"../rep/type-rep.rkt"
"../types/numeric-tower.rkt"
"utils.rkt"
"logging.rkt")
"../utils/utils.rkt"
"logging.rkt"
"utils.rkt")

(provide fixnum-expr fixnum-opt-expr)

Expand Down Expand Up @@ -124,10 +128,10 @@
;; if we make it this far, an optimization is likely to be expected by the
;; user, so we report a missed opt if the check fails
(define (check-if-safe stx)
(let ([safe-to-opt? (subtypeof? stx -Fixnum)])
(unless safe-to-opt?
(log-fixnum-missed-opt stx))
safe-to-opt?))
(define safe-to-opt? (subtypeof? stx -Fixnum))
(unless safe-to-opt?
(log-fixnum-missed-opt stx))
safe-to-opt?)

(define-syntax-class fixnum-opt-expr
#:literal-sets (kernel-literals)
Expand Down
48 changes: 28 additions & 20 deletions typed-racket-lib/typed-racket/optimizer/float-complex.rkt
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
#lang racket/base

(require syntax/parse syntax/stx syntax/id-table racket/promise
racket/syntax racket/match syntax/parse/experimental/specialize
"../utils/utils.rkt" racket/unsafe/ops racket/sequence
(for-template racket/base racket/math racket/flonum racket/unsafe/ops)
(require (for-template racket/base
racket/flonum
racket/math
racket/unsafe/ops)
racket/match
racket/promise
racket/sequence
racket/syntax
racket/unsafe/ops
syntax/id-table
syntax/parse
syntax/parse/experimental/specialize
syntax/stx
"../types/numeric-tower.rkt"
"../types/subtype.rkt"
"../types/type-table.rkt"
"../types/utils.rkt"
"utils.rkt"
"numeric-utils.rkt"
"logging.rkt"
"../utils/tc-utils.rkt"
"../utils/utils.rkt"
"float.rkt"
"logging.rkt"
"numeric-utils.rkt"
"unboxed-tables.rkt"
"../utils/tc-utils.rkt")
"utils.rkt")

(provide float-complex-opt-expr
float-complex-expr
Expand Down Expand Up @@ -82,18 +92,16 @@
(define c1 (stx-car cs))
(define o-nf (as-non-float o))
(define c1-nf (as-non-float c1))
(if (or o-nf c1-nf)
;; can't convert those to floats just yet, or may change
;; the result
(let ([new-o (mark-as-non-float
(quasisyntax/loc this-syntax
(#,op #,(or o-nf o) #,(or c1-nf c1))))])
(if (stx-null? (stx-cdr cs))
new-o
(loop new-o
(stx-cdr cs))))
;; we've hit floats, can start coercing
(n-ary->binary this-syntax unsafe (cons #`(real->double-flonum #,(or o-nf o)) cs)))))
(cond
[(or o-nf c1-nf)
;; can't convert those to floats just yet, or may change
;; the result
(define new-o
(mark-as-non-float (quasisyntax/loc this-syntax
(#,op #,(or o-nf o) #,(or c1-nf c1)))))
(if (stx-null? (stx-cdr cs)) new-o (loop new-o (stx-cdr cs)))]
Copy link
Contributor

@sorawee sorawee Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be collapsed to one line with the fmt PR that @9999years is proposing.

;; we've hit floats, can start coercing
[else (n-ary->binary this-syntax unsafe (cons #`(real->double-flonum #,(or o-nf o)) cs))])))



Expand Down
30 changes: 18 additions & 12 deletions typed-racket-lib/typed-racket/optimizer/float.rkt
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
#lang racket/base

(require syntax/parse racket/sequence racket/flonum racket/promise
syntax/parse/experimental/specialize
(require (for-template racket/base
racket/flonum
racket/math
racket/unsafe/ops)
racket/flonum
racket/promise
racket/sequence
syntax/id-table
(for-template racket/base racket/flonum racket/unsafe/ops racket/math)
"../utils/utils.rkt"
"../utils/tc-utils.rkt"
"../types/numeric-tower.rkt"
syntax/parse
syntax/parse/experimental/specialize
"../types/abbrev.rkt"
"utils.rkt"
"numeric-utils.rkt"
"../types/numeric-tower.rkt"
"../utils/tc-utils.rkt"
"../utils/utils.rkt"
"fixnum.rkt"
"logging.rkt"
"fixnum.rkt")
"numeric-utils.rkt"
"utils.rkt")

(provide float-opt-expr float-arg-expr int-expr float-op)

Expand Down Expand Up @@ -136,10 +142,10 @@
;; (Note: could allow for more args, if not next to each other, but
;; probably not worth the trouble (most ops have 2 args anyway))
(and (subtypeof? this-syntax -Flonum)
(for/and ([a (in-syntax #'(fs ...))])
(for/and ([a (in-syntax #'(fs ...))]
#:unless (subtypeof? a -Flonum))
jackfirth marked this conversation as resolved.
Show resolved Hide resolved
;; flonum or provably non-zero
(or (subtypeof? a -Flonum)
(subtypeof? a (Un -PosReal -NegReal))))
(subtypeof? a (Un -PosReal -NegReal)))
(>= 1
(for/sum ([a (in-syntax #'(fs ...))]
#:when (not (subtypeof? a -Flonum)))
Expand Down
13 changes: 7 additions & 6 deletions typed-racket-lib/typed-racket/optimizer/hidden-costs.rkt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#lang racket/base

(require syntax/parse racket/sequence
(for-template racket/base)
"../utils/utils.rkt"
"utils.rkt"
"logging.rkt"
(require (for-template racket/base)
racket/sequence
syntax/parse
"../types/abbrev.rkt"
"../types/numeric-tower.rkt"
"../types/struct-table.rkt")
"../types/struct-table.rkt"
"../utils/utils.rkt"
"logging.rkt"
"utils.rkt")

(provide hidden-cost-log-expr)

Expand Down
12 changes: 7 additions & 5 deletions typed-racket-lib/typed-racket/optimizer/list.rkt
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#lang racket/base

(require syntax/parse racket/match
"../utils/utils.rkt"
(require (for-template racket/base
racket/unsafe/ops)
racket/match
syntax/parse
"../types/abbrev.rkt"
"../types/utils.rkt"
"../types/type-table.rkt"
"utils.rkt"
"../types/utils.rkt"
"../utils/utils.rkt"
"logging.rkt"
(for-template racket/base racket/unsafe/ops))
"utils.rkt")

(provide list-opt-expr)

Expand Down
29 changes: 13 additions & 16 deletions typed-racket-lib/typed-racket/optimizer/logging.rkt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#lang racket/base

(require racket/string
syntax/location racket/logging syntax/parse
data/queue
(require data/queue
racket/logging
racket/string
syntax/location
syntax/parse
"../utils/tc-utils.rkt")

(provide log-optimization log-missed-optimization log-optimization-info
Expand Down Expand Up @@ -90,25 +92,20 @@
;;--------------------------------------------------------------------

(define (line+col->string stx)
(let ([line (syntax-line stx)]
[col (syntax-column stx)])
(if (and line col)
(format "~a:~a" line col)
"(no location)")))
(define line (syntax-line stx))
(define col (syntax-column stx))
(if (and line col) (format "~a:~a" line col) "(no location)"))

(define (format-irritants irritants)
(if (null? irritants)
""
(format " -- caused by: ~a"
(string-join
(map (lambda (irritant)
(let ([irritant (locate-stx irritant)])
(format "~a ~s"
(line+col->string irritant)
(syntax->datum irritant))))
(sort irritants <
#:key (lambda (x)
(or (syntax-position x) 0))))
(for/list ([irritant (in-list (sort irritants
<
#:key (lambda (x) (or (syntax-position x) 0))))])
(let ([irritant (locate-stx irritant)])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this become a define?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's shadowing the irritant loop variable.

(format "~a ~s" (line+col->string irritant) (syntax->datum irritant))))
", "))))

;; For command-line printing purposes.
Expand Down
10 changes: 5 additions & 5 deletions typed-racket-lib/typed-racket/optimizer/number.rkt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#lang racket/base

(require syntax/parse
(require (for-template racket/base)
syntax/parse
syntax/parse/experimental/specialize
(for-template racket/base)
"../utils/utils.rkt"
"../types/abbrev.rkt"
"../types/numeric-tower.rkt"
"utils.rkt"
"logging.rkt")
"../utils/utils.rkt"
"logging.rkt"
"utils.rkt")

(provide number-opt-expr)

Expand Down
10 changes: 7 additions & 3 deletions typed-racket-lib/typed-racket/optimizer/numeric-utils.rkt
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#lang racket/base

(require syntax/parse syntax/id-table
(for-template racket/base racket/flonum racket/fixnum racket/unsafe/ops)
"../utils/utils.rkt"
(require (for-template racket/base
racket/fixnum
racket/flonum
racket/unsafe/ops)
syntax/id-table
syntax/parse
"../types/numeric-tower.rkt"
"../utils/utils.rkt"
"utils.rkt")

(provide (all-defined-out))
Expand Down
Loading