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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Automated Resyntax fixes #1404

wants to merge 1 commit into from

Conversation

resyntax-ci[bot]
Copy link
Contributor

@resyntax-ci resyntax-ci bot commented Oct 18, 2024

This is an automated change generated by Resyntax.

Pass 1

Applied 1 fix to 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

  • 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

  • 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

  • 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

  • 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

  • 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

  • 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

  • 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

  • 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

  • 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

  • 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

  • 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

  • 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

  • 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

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)
Copy link
Contributor

@sorawee sorawee Oct 18, 2024

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?

Copy link
Contributor

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)))]
Copy link
Contributor

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))])
Copy link
Contributor

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?

Copy link
Contributor

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))
Copy link
Contributor

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".

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Member

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?

Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants