-
-
Notifications
You must be signed in to change notification settings - Fork 105
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 #1404
base: master
Are you sure you want to change the base?
Automated Resyntax fixes #1404
Conversation
This is an automated change generated by Resyntax. #### Pass 1 Applied 1 fix to [`typed-racket-lib/typed-racket/typecheck/possible-domains.rkt`](../blob/HEAD/typed-racket-lib/typed-racket/typecheck/possible-domains.rkt) * Line 58, `and-match-to-match`: This `and` expression can be turned into a clause of the inner `match` expression, reducing nesting. Applied 2 fixes to [`typed-racket-lib/typed-racket/typecheck/integer-refinements.rkt`](../blob/HEAD/typed-racket-lib/typed-racket/typecheck/integer-refinements.rkt) * Line 3, `tidy-require`: Keep imports in `require` sorted and grouped by phase, with collections before files. * Line 74, `define-lambda-to-define`: The `define` form supports a shorthand for defining functions. Applied 3 fixes to [`typed-racket-lib/typed-racket/typecheck/toplevel-trampoline.rkt`](../blob/HEAD/typed-racket-lib/typed-racket/typecheck/toplevel-trampoline.rkt) * Line 11, `tidy-require`: Keep imports in `require` sorted and grouped by phase, with collections before files. * Line 34, `tidy-require`: Keep imports in `require` sorted and grouped by phase, with collections before files. * Line 64, `if-begin-to-cond`: Using `cond` instead of `if` here makes `begin` unnecessary Applied 1 fix to [`typed-racket-lib/typed-racket/private/type-annotation.rkt`](../blob/HEAD/typed-racket-lib/typed-racket/private/type-annotation.rkt) * Line 92, `let-to-define`: Internal definitions are recommended instead of `let` expressions, to reduce nesting. Applied 2 fixes to [`typed-racket-lib/typed-racket/private/user-defined-type-constr.rkt`](../blob/HEAD/typed-racket-lib/typed-racket/private/user-defined-type-constr.rkt) * Line 2, `tidy-require`: Keep imports in `require` sorted and grouped by phase, with collections before files. * Line 32, `single-clause-match-to-match-define`: This `match` expression can be simplified using `match-define`. Applied 1 fix to [`typed-racket-lib/typed-racket/typecheck/check-unit-unit.rkt`](../blob/HEAD/typed-racket-lib/typed-racket/typecheck/check-unit-unit.rkt) * Line 178, `define-lambda-to-define`: The `define` form supports a shorthand for defining functions. Applied 15 fixes to [`typed-racket-lib/typed-racket/private/type-contract.rkt`](../blob/HEAD/typed-racket-lib/typed-racket/private/type-contract.rkt) * Line 242, `if-begin-to-cond`: Using `cond` instead of `if` here makes `begin` unnecessary * Line 389, `unused-definition`: This definition is not used. * Line 557, `let-to-define`: Internal definitions are recommended instead of `let` expressions, to reduce nesting. * Line 838, `always-throwing-cond-to-when`: Using `when` and `unless` is simpler than a conditional with an always-throwing branch. * Line 1139, `unused-definition`: This definition is not used. * Line 1167, `single-clause-match-to-match-define`: This `match` expression can be simplified using `match-define`. * Line 1270, `zero-comparison-lambda-to-positive?`: This lambda function is equivalent to the built-in `positive?` predicate. * Line 1290, `map-to-for`: This `map` operation can be replaced with a `for/list` loop. * Line 1295, `single-clause-match-to-match-define`: This `match` expression can be simplified using `match-define`. * Line 1324, `unused-definition`: This definition is not used. * Line 1549, `define-lambda-to-define`: The `define` form supports a shorthand for defining functions. * Line 1550, `define-lambda-to-define`: The `define` form supports a shorthand for defining functions. * Line 1551, `define-lambda-to-define`: The `define` form supports a shorthand for defining functions. * Line 1552, `define-lambda-to-define`: The `define` form supports a shorthand for defining functions. * Line 1553, `define-lambda-to-define`: The `define` form supports a shorthand for defining functions. Applied 8 fixes to [`typed-racket-lib/typed-racket/private/shallow-rewrite.rkt`](../blob/HEAD/typed-racket-lib/typed-racket/private/shallow-rewrite.rkt) * Line 225, `if-let-to-cond`: `cond` with internal definitions is preferred over `if` with `let`, to reduce nesting * Line 275, `define-let-to-double-define`: This `let` expression can be pulled up into a `define` expression. * Line 287, `if-let-to-cond`: `cond` with internal definitions is preferred over `if` with `let`, to reduce nesting * Line 418, `let-to-define`: Internal definitions are recommended instead of `let` expressions, to reduce nesting. * Line 428, `let-to-define`: Internal definitions are recommended instead of `let` expressions, to reduce nesting. * Line 452, `if-let-to-cond`: `cond` with internal definitions is preferred over `if` with `let`, to reduce nesting * Line 632, `let-to-define`: Internal definitions are recommended instead of `let` expressions, to reduce nesting. * Line 717, `unused-definition`: This definition is not used. Applied 2 fixes to [`typed-racket-lib/typed-racket/private/with-types.rkt`](../blob/HEAD/typed-racket-lib/typed-racket/private/with-types.rkt) * Line 3, `tidy-require`: Keep imports in `require` sorted and grouped by phase, with collections before files. * Line 53, `inverted-unless`: This negated `unless` expression can be replaced by a `when` expression. Applied 2 fixes to [`typed-racket-lib/typed-racket/typecheck/check-below.rkt`](../blob/HEAD/typed-racket-lib/typed-racket/typecheck/check-below.rkt) * Line 3, `tidy-require`: Keep imports in `require` sorted and grouped by phase, with collections before files. * Line 86, `unused-definition`: This definition is not used. Applied 3 fixes to [`typed-racket-lib/typed-racket/typecheck/tc-expr-unit.rkt`](../blob/HEAD/typed-racket-lib/typed-racket/typecheck/tc-expr-unit.rkt) * Line 96, `single-clause-match-to-match-define`: This `match` expression can be simplified using `match-define`. * Line 146, `let-to-define`: Internal definitions are recommended instead of `let` expressions, to reduce nesting. * Line 197, `format-identity`: This use of `format` does nothing. Applied 1 fix to [`typed-racket-lib/typed-racket/private/syntax-properties.rkt`](../blob/HEAD/typed-racket-lib/typed-racket/private/syntax-properties.rkt) * Line 2, `tidy-require`: Keep imports in `require` sorted and grouped by phase, with collections before files. Applied 1 fix to [`typed-racket-lib/typed-racket/private/parse-classes.rkt`](../blob/HEAD/typed-racket-lib/typed-racket/private/parse-classes.rkt) * Line 3, `tidy-require`: Keep imports in `require` sorted and grouped by phase, with collections before files. Applied 3 fixes to [`typed-racket-lib/typed-racket/private/parse-type.rkt`](../blob/HEAD/typed-racket-lib/typed-racket/private/parse-type.rkt) * Line 186, `let-to-define`: Internal definitions are recommended instead of `let` expressions, to reduce nesting. * Line 1509, `for/fold-with-conditional-body-to-unless-keyword`: This `for/fold` loop can be simplified by using the `#:unless` keyword. * Line 1658, `inline-unnecessary-define`: This variable is returned immediately and can be inlined. ## Summary Fixed 45 issues in 14 files. * Fixed 8 occurrences of `tidy-require` * Fixed 7 occurrences of `let-to-define` * Fixed 7 occurrences of `define-lambda-to-define` * Fixed 5 occurrences of `unused-definition` * Fixed 4 occurrences of `single-clause-match-to-match-define` * Fixed 3 occurrences of `if-let-to-cond` * Fixed 2 occurrences of `if-begin-to-cond` * Fixed 1 occurrence of `and-match-to-match` * Fixed 1 occurrence of `format-identity` * Fixed 1 occurrence of `for/fold-with-conditional-body-to-unless-keyword` * Fixed 1 occurrence of `inline-unnecessary-define` * Fixed 1 occurrence of `always-throwing-cond-to-when` * Fixed 1 occurrence of `zero-comparison-lambda-to-positive?` * Fixed 1 occurrence of `map-to-for` * Fixed 1 occurrence of `define-let-to-double-define` * Fixed 1 occurrence of `inverted-unless`
@@ -1507,10 +1507,9 @@ | |||
;; Merge all the non-duplicate entries from the parent types | |||
(define (merge-clause parent-clause clause) | |||
(for/fold ([clause clause]) | |||
([(k v) (in-dict parent-clause)]) | |||
(if (dict-has-key? clause k) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, this is really impressive! I guess it only works if one branch is the accumulator identifier?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. I added the rule for this one in jackfirth/resyntax#343.
(cond | ||
[(pair? args) (values (car args) (cdr args))] | ||
[(syntax? args) | ||
(let ([e (syntax-e args)]) (values (car e) (cdr e)))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This let
formatting is not ideal, I guess.
(let ([dom+ (for/fold ([acc '()]) ([dom (in-list dom*)]) | ||
(if (pair? dom) | ||
(cons (cdr dom) acc) | ||
acc))]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why couldn't Resyntax turns this into #:when
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like Resyntax only ran a single pass over all this code for some reason. I'm not sure why it didn't run more passes. I notice that the CI checks are failing, so perhaps Resyntax introduced a compile failure in this file that prevented it from refactoring it further?
racket/format | ||
(require racket/format | ||
racket/match | ||
(prefix-in - (contract-req)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems this line is busted now because contract-req
is a require transformer that came from "../utils/utils.rkt"
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way this is handled in most formatters / linters is via annotation. E.g., users could add #;#[[resyntax ignore-next]]
right before the (require ...)
, and the whole (require ...)
should not be refactored.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory Resyntax has the whole binding structure available, so it could see that contract-req
is imported from one of the modules in this require form. That could be a cue to avoid tidying this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that check syntax doesn't add this arrow so maybe there is an improvement there that resyntax could then use?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately I think check syntax's treatment of require
and provide
forms has been missing for a long time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There were some improvements in march but I think there's more that can be done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also one way to fix this specific code is to move the "../utils/utils.rkt"
import into a separate require
form, which I generally think is a good idea when requiring modules that provide require or provide transformers.
This is an automated change generated by Resyntax.
Pass 1
Applied 1 fix to
typed-racket-lib/typed-racket/typecheck/possible-domains.rkt
and-match-to-match
: Thisand
expression can be turned into a clause of the innermatch
expression, reducing nesting.Applied 2 fixes to
typed-racket-lib/typed-racket/typecheck/integer-refinements.rkt
tidy-require
: Keep imports inrequire
sorted and grouped by phase, with collections before files.define-lambda-to-define
: Thedefine
form supports a shorthand for defining functions.Applied 3 fixes to
typed-racket-lib/typed-racket/typecheck/toplevel-trampoline.rkt
tidy-require
: Keep imports inrequire
sorted and grouped by phase, with collections before files.tidy-require
: Keep imports inrequire
sorted and grouped by phase, with collections before files.if-begin-to-cond
: Usingcond
instead ofif
here makesbegin
unnecessaryApplied 1 fix to
typed-racket-lib/typed-racket/private/type-annotation.rkt
let-to-define
: Internal definitions are recommended instead oflet
expressions, to reduce nesting.Applied 2 fixes to
typed-racket-lib/typed-racket/private/user-defined-type-constr.rkt
tidy-require
: Keep imports inrequire
sorted and grouped by phase, with collections before files.single-clause-match-to-match-define
: Thismatch
expression can be simplified usingmatch-define
.Applied 1 fix to
typed-racket-lib/typed-racket/typecheck/check-unit-unit.rkt
define-lambda-to-define
: Thedefine
form supports a shorthand for defining functions.Applied 15 fixes to
typed-racket-lib/typed-racket/private/type-contract.rkt
if-begin-to-cond
: Usingcond
instead ofif
here makesbegin
unnecessaryunused-definition
: This definition is not used.let-to-define
: Internal definitions are recommended instead oflet
expressions, to reduce nesting.always-throwing-cond-to-when
: Usingwhen
andunless
is simpler than a conditional with an always-throwing branch.unused-definition
: This definition is not used.single-clause-match-to-match-define
: Thismatch
expression can be simplified usingmatch-define
.zero-comparison-lambda-to-positive?
: This lambda function is equivalent to the built-inpositive?
predicate.map-to-for
: Thismap
operation can be replaced with afor/list
loop.single-clause-match-to-match-define
: Thismatch
expression can be simplified usingmatch-define
.unused-definition
: This definition is not used.define-lambda-to-define
: Thedefine
form supports a shorthand for defining functions.define-lambda-to-define
: Thedefine
form supports a shorthand for defining functions.define-lambda-to-define
: Thedefine
form supports a shorthand for defining functions.define-lambda-to-define
: Thedefine
form supports a shorthand for defining functions.define-lambda-to-define
: Thedefine
form supports a shorthand for defining functions.Applied 8 fixes to
typed-racket-lib/typed-racket/private/shallow-rewrite.rkt
if-let-to-cond
:cond
with internal definitions is preferred overif
withlet
, to reduce nestingdefine-let-to-double-define
: Thislet
expression can be pulled up into adefine
expression.if-let-to-cond
:cond
with internal definitions is preferred overif
withlet
, to reduce nestinglet-to-define
: Internal definitions are recommended instead oflet
expressions, to reduce nesting.let-to-define
: Internal definitions are recommended instead oflet
expressions, to reduce nesting.if-let-to-cond
:cond
with internal definitions is preferred overif
withlet
, to reduce nestinglet-to-define
: Internal definitions are recommended instead oflet
expressions, to reduce nesting.unused-definition
: This definition is not used.Applied 2 fixes to
typed-racket-lib/typed-racket/private/with-types.rkt
tidy-require
: Keep imports inrequire
sorted and grouped by phase, with collections before files.inverted-unless
: This negatedunless
expression can be replaced by awhen
expression.Applied 2 fixes to
typed-racket-lib/typed-racket/typecheck/check-below.rkt
tidy-require
: Keep imports inrequire
sorted and grouped by phase, with collections before files.unused-definition
: This definition is not used.Applied 3 fixes to
typed-racket-lib/typed-racket/typecheck/tc-expr-unit.rkt
single-clause-match-to-match-define
: Thismatch
expression can be simplified usingmatch-define
.let-to-define
: Internal definitions are recommended instead oflet
expressions, to reduce nesting.format-identity
: This use offormat
does nothing.Applied 1 fix to
typed-racket-lib/typed-racket/private/syntax-properties.rkt
tidy-require
: Keep imports inrequire
sorted and grouped by phase, with collections before files.Applied 1 fix to
typed-racket-lib/typed-racket/private/parse-classes.rkt
tidy-require
: Keep imports inrequire
sorted and grouped by phase, with collections before files.Applied 3 fixes to
typed-racket-lib/typed-racket/private/parse-type.rkt
let-to-define
: Internal definitions are recommended instead oflet
expressions, to reduce nesting.for/fold-with-conditional-body-to-unless-keyword
: Thisfor/fold
loop can be simplified by using the#:unless
keyword.inline-unnecessary-define
: This variable is returned immediately and can be inlined.Summary
Fixed 45 issues in 14 files.
tidy-require
let-to-define
define-lambda-to-define
unused-definition
single-clause-match-to-match-define
if-let-to-cond
if-begin-to-cond
and-match-to-match
format-identity
for/fold-with-conditional-body-to-unless-keyword
inline-unnecessary-define
always-throwing-cond-to-when
zero-comparison-lambda-to-positive?
map-to-for
define-let-to-double-define
inverted-unless