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

Format most of FSharp.Core #13150

Merged
merged 13 commits into from
May 30, 2022
Merged

Format most of FSharp.Core #13150

merged 13 commits into from
May 30, 2022

Conversation

dsyme
Copy link
Contributor

@dsyme dsyme commented May 18, 2022

From the compiler code cleanup session last night, this applies auto-formatting to most implementation files in FSharp.Core

There are a lot of changes so we might want to do this in smaller chunks we can review carefully, and possibly make some preliminary adjustments to reduce the diff

+8,971 −5,300 - 120 width

+8,641 −5,286 - 140 width

@vzarytovskii
Copy link
Member

Oh boy 😆

@nojaf
Copy link
Contributor

nojaf commented May 18, 2022

To have this in smaller chunks, you could negate some ignored files using !.
For example: !src/FSharp.Core/result.fs, this would format result.fs even though **/*.fs was listed above.

Comment on lines +149 to +147
assert
(match res with
| NewAnonymousObject _ -> true
| _ -> false)
Copy link
Member

@vzarytovskii vzarytovskii May 18, 2022

Choose a reason for hiding this comment

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

This too, looks a bit weird, I thing oneliner looked more readable.

Copy link
Contributor

Choose a reason for hiding this comment

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

Matches are never in one line in Fantomas.

Copy link
Member

Choose a reason for hiding this comment

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

@nojaf Can we keep existing one liner if they are short enough to fit on the line (or use some other metric)?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we could have a setting for this, to control the max-width to print it as a one-liner.
At first glance, using max_line_length won't work for everyone.
Sounds like a reasonable thing to add to the style guide though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TBH I look at cases like this as places where the original code needs improvement

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is a tricky case though. People do certainly use one line matches for this purpose

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The lack of one line formatting for match union with A -> true | B -> false is a general concern for the style guide, as there is no other way to implement an union.IsA property or check, and that is very common - one of the reasons we don't expose the IsA properties has always been that implementing them is just a trivial match, but now there is a larger penalty for that

So I do wonder whether this shouls be a special case for fantomas, at least until the IsA properties are exposed to F#

@dsyme
Copy link
Contributor Author

dsyme commented May 18, 2022

Looks like a fantomas bug here:

-type hertz = / second / second
+type hertz = / second / second / second / second

https://github.com/dotnet/fsharp/pull/13150/files#diff-dcae2bcdbe279a9e446b192c415ade297e6a324e9bb1b6de75e1f4b347e9df68R42

src/FSharp.Core/SI.fs Outdated Show resolved Hide resolved
Comment on lines 41 to 54
let inline NonStructural<'T when 'T: (static member (<): 'T * 'T -> bool) and 'T: (static member (>):
'T * 'T -> bool)> : IComparer<'T> =
Copy link
Member

Choose a reason for hiding this comment

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

Should line breaks instead be aligned with and and only then :?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes this looks a little dodgy. @nojaf similar question to above - will constraint formatting affect this? thanks

Copy link
Contributor

Choose a reason for hiding this comment

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

No, reported fsprojects/fantomas#2267.

Comment on lines 81 to 83
type Event<'Delegate, 'Args when 'Delegate: delegate<'Args, unit> and 'Delegate :> System.Delegate and 'Delegate: not struct>
() =
Copy link
Member

Choose a reason for hiding this comment

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

Is it expected to have constructor moved to new line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess so. I mean it's at column 133 and it needs a break :)

@nojaf will the adjusted constraint formatting change this? e.g.

type Event<'Delegate, 'Args
                        when 'Delegate: delegate<'Args, unit>
                        and 'Delegate :> System.Delegate
                        and 'Delegate: not struct> () =

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I guess that's what I meant, is if it's possible, to have line breaks at the ands.

Copy link
Contributor

Choose a reason for hiding this comment

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

No, probably not. I created fsprojects/fantomas#2266.

.Append("; ")
.Append(txt2)
.Append("]")
.ToString()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

src/FSharp.Core/map.fs Outdated Show resolved Hide resolved
@dsyme
Copy link
Contributor Author

dsyme commented May 19, 2022

I have to say, looking through the files I'm finding it hard to spot additional problems - and there are many improvements.

@dsyme
Copy link
Contributor Author

dsyme commented May 19, 2022

@vzarytovskii @nojaf It feels like the only outstanding issue here is the constrained type parameter declarations.

We could

  1. suppress the use of formatting for those specific files, or
  2. accept them as they are
  3. wait for the fix

I guess (1) ? I'd sort of be OK for (2) but probably better to do (1)

@nojaf
Copy link
Contributor

nojaf commented May 19, 2022

wait for the fix

I might be able to take a look tomorrow.
Maybe it will be something quite similar to the previous fix.

@dsyme
Copy link
Contributor Author

dsyme commented May 19, 2022

@nojaf thanks! Yes I expect will be very similar

@dsyme dsyme changed the title WIP - format most of FSharp.Core Format most of FSharp.Core May 27, 2022
@dsyme dsyme enabled auto-merge (squash) May 30, 2022 13:11
@dsyme dsyme merged commit 05b560d into dotnet:main May 30, 2022
KevinRansom pushed a commit that referenced this pull request May 31, 2022
* update fantomas (#13206)

* Format most of FSharp.Core (#13150)

* modify fantomasignore

* fix setting

* no single line functions in FSHarp.Core

* update fantomas

* apply formatting

* Format src/Compiler/Driver (#13195)

* adjust settings

* adjust code

* adjust settings

* adjust code

* fix code before formatting

* remove unnecessary yield

* manual pre-formatting

* preadjust code

* preadjust code

* preadjust code

* preadjust code

* adjust settings"

* adjust settings"

* adjust settings

* adjust settings

* fix build

* adjust settings

* adjust code

* adjust code

* adjust code

* update fantomas

* apply formatting

* apply formatting (fix build) (#13209)

* preformat

* apply formatting

Co-authored-by: Don Syme <[email protected]>
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