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

Better record and value formatting in tools #7021

Merged
merged 25 commits into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from 11 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
22 changes: 14 additions & 8 deletions src/fsharp/NicePrint.fs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ module internal PrintUtilities =
let bracketIfL x lyt = if x then bracketL lyt else lyt
let squareAngleL x = LeftL.leftBracketAngle ^^ x ^^ RightL.rightBracketAngle
let angleL x = sepL Literals.leftAngle ^^ x ^^ rightL Literals.rightAngle
let braceL x = leftL Literals.leftBrace ^^ x ^^ rightL Literals.rightBrace
let braceBarL x = leftL Literals.leftBraceBar ^^ x ^^ rightL Literals.rightBraceBar
let braceL x = wordL Literals.leftBrace ^^ x ^^ wordL Literals.rightBrace
let braceBarL x = wordL Literals.leftBraceBar ^^ x ^^ wordL Literals.rightBraceBar

let comment str = wordL (tagText (sprintf "(* %s *)" str))

Expand Down Expand Up @@ -942,7 +942,7 @@ module private PrintTypes =

// Layout a tuple type
| TType_anon (anonInfo, tys) ->
let core = sepListL (wordL (tagPunctuation ";")) (List.map2 (fun nm ty -> wordL (tagField nm) ^^ wordL (tagPunctuation ":") ^^ layoutTypeWithInfoAndPrec denv env prec ty) (Array.toList anonInfo.SortedNames) tys)
let core = sepListL (rightL (tagPunctuation ";")) (List.map2 (fun nm ty -> wordL (tagField nm) ^^ rightL (tagPunctuation ":") ^^ layoutTypeWithInfoAndPrec denv env prec ty) (Array.toList anonInfo.SortedNames) tys)
if evalAnonInfoIsStruct anonInfo then
WordL.keywordStruct --- braceBarL core
else
Expand Down Expand Up @@ -1445,7 +1445,7 @@ module private TastDefinitionPrinting =
let lhs =
tagRecordField fld.Name
|> mkNav fld.DefinitionRange
|> wordL
|> wordL
let lhs = (if addAccess then layoutAccessibility denv fld.Accessibility lhs else lhs)
let lhs = if fld.IsMutable then wordL (tagKeyword "mutable") --- lhs else lhs
(lhs ^^ RightL.colon) --- layoutType denv fld.FormalType
Expand Down Expand Up @@ -1726,8 +1726,15 @@ module private TastDefinitionPrinting =
let denv = denv.AddAccessibility tycon.TypeReprAccessibility
match repr with
| TRecdRepr _ ->
let recdFieldRefL fld = layoutRecdField false denv fld ^^ rightL (tagPunctuation ";")
let recdL = tycon.TrueFieldsAsList |> List.map recdFieldRefL |> applyMaxMembers denv.maxMembers |> aboveListL |> braceL
let recdFieldRefL fld = layoutRecdField false denv fld

let recdL =
tycon.TrueFieldsAsList
|> List.map recdFieldRefL
|> applyMaxMembers denv.maxMembers
|> aboveListL
|> braceL

Some (addMembersAsWithEnd (addReprAccessL recdL))

| TFSharpObjectRepr r ->
Expand Down Expand Up @@ -1759,8 +1766,7 @@ module private TastDefinitionPrinting =
| _ -> []
let vsprs =
tycon.MembersOfFSharpTyconSorted
|> List.filter (fun v -> isNil (Option.get v.MemberInfo).ImplementedSlotSigs)
|> List.filter (fun v -> v.IsDispatchSlot)
|> List.filter (fun v -> isNil (Option.get v.MemberInfo).ImplementedSlotSigs && v.IsDispatchSlot)
|> List.map (fun vref -> PrintTastMemberOrVals.prettyLayoutOfValOrMemberNoInst denv vref.Deref)
let staticValsLs =
tycon.TrueFieldsAsList
Expand Down
4 changes: 2 additions & 2 deletions tests/fsharp/Compiler/Language/AnonRecordTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ let rAnon = RefClass<struct {| R: int |}>()
"""
1
(3, 12, 3, 41)
"A generic construct requires that the type 'struct {|R : int|}' have reference semantics, but it does not, i.e. it is a struct"
"A generic construct requires that the type 'struct {| R: int |}' have reference semantics, but it does not, i.e. it is a struct"

[<Test>]
let StructConstraintFail() =
Expand All @@ -43,4 +43,4 @@ let sAnon = StructClass<{| S: int |}>()
"""
1
(3, 12, 3, 37)
"A generic construct requires that the type '{|S : int|}' is a CLI or F# struct type"
"A generic construct requires that the type '{| S: int |}' is a CLI or F# struct type"
54 changes: 27 additions & 27 deletions tests/fsharp/core/printing/z.output.test.1000.stdout.bsl
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,7 @@ end
| B

> type internal T2 =
{x: int;}
{ x: int }

> type internal T3

Expand All @@ -1148,28 +1148,28 @@ end
| B

> type T2 =
internal {x: int;}
internal { x: int }

> type private T1 =
| A
| B

> type private T2 =
{x: int;}
{ x: int }

> type T1 =
private | A
| B

> type T2 =
private {x: int;}
private { x: int }

> type internal T1 =
private | A
| B

> type internal T2 =
private {x: int;}
private { x: int }

> type private T3

Expand Down Expand Up @@ -1233,16 +1233,16 @@ type 'a T1Pre with
member E : IEvent<obj>

> type r =
{f0: int;
f1: int;
f2: int;
f3: int;
f4: int;
f5: int;
f6: int;
f7: int;
f8: int;
f9: int;}
{ f0: int
f1: int
f2: int
f3: int
f4: int
f5: int
f6: int
f7: int
f8: int
f9: int }
val r10 : r = {f0 = 0;
f1 = 1;
f2 = 2;
Expand Down Expand Up @@ -1398,7 +1398,7 @@ val x1564_A3 : int = 3
| A
| B
type T2 =
{x: int;}
{ x: int }
type T3
type T4 =
class
Expand All @@ -1408,22 +1408,22 @@ val x1564_A3 : int = 3
| A
| B
type T6 =
{x: int;}
{ x: int }
type private T7 =
| A
| B
type private T8 =
{x: int;}
{ x: int }
type T9 =
private | A
| B
type T10 =
private {x: int;}
private { x: int }
type T11 =
private | A
| B
type T12 =
private {x: int;}
private { x: int }
type private T13
type private T14 =
class
Expand All @@ -1446,7 +1446,7 @@ module internal PrivateM = begin
| A
| B
type T2 =
{x: int;}
{ x: int }
type T3
type T4 =
class
Expand All @@ -1456,22 +1456,22 @@ module internal PrivateM = begin
| A
| B
type T6 =
{x: int;}
{ x: int }
type private T7 =
| A
| B
type private T8 =
{x: int;}
{ x: int }
type T9 =
private | A
| B
type T10 =
private {x: int;}
private { x: int }
type T11 =
private | A
| B
type T12 =
private {x: int;}
private { x: int }
type private T13
type private T14 =
class
Expand Down Expand Up @@ -2732,11 +2732,11 @@ val namedEx1 : exn = MyNamedException1 (5,"")
val namedEx2 : exn = MyNamedException7 25

> type optionRecord =
{x: int option;}
{ x: int option }
val x : optionRecord = {x = None;}

> type optionRecord =
{x: obj;}
{ x: obj }
val x : optionRecord = {x = null;}

> > >
54 changes: 27 additions & 27 deletions tests/fsharp/core/printing/z.output.test.200.stdout.bsl
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ end
| B

> type internal T2 =
{x: int;}
{ x: int }

> type internal T3

Expand All @@ -472,28 +472,28 @@ end
| B

> type T2 =
internal {x: int;}
internal { x: int }

> type private T1 =
| A
| B

> type private T2 =
{x: int;}
{ x: int }

> type T1 =
private | A
| B

> type T2 =
private {x: int;}
private { x: int }

> type internal T1 =
private | A
| B

> type internal T2 =
private {x: int;}
private { x: int }

> type private T3

Expand Down Expand Up @@ -557,16 +557,16 @@ type 'a T1Pre with
member E : IEvent<obj>

> type r =
{f0: int;
f1: int;
f2: int;
f3: int;
f4: int;
f5: int;
f6: int;
f7: int;
f8: int;
f9: int;}
{ f0: int
f1: int
f2: int
f3: int
f4: int
f5: int
f6: int
f7: int
f8: int
f9: int }
val r10 : r = {f0 = 0;
f1 = 1;
f2 = 2;
Expand Down Expand Up @@ -647,7 +647,7 @@ val x1564_A3 : int = 3
| A
| B
type T2 =
{x: int;}
{ x: int }
type T3
type T4 =
class
Expand All @@ -657,22 +657,22 @@ val x1564_A3 : int = 3
| A
| B
type T6 =
{x: int;}
{ x: int }
type private T7 =
| A
| B
type private T8 =
{x: int;}
{ x: int }
type T9 =
private | A
| B
type T10 =
private {x: int;}
private { x: int }
type T11 =
private | A
| B
type T12 =
private {x: int;}
private { x: int }
type private T13
type private T14 =
class
Expand All @@ -695,7 +695,7 @@ module internal PrivateM = begin
| A
| B
type T2 =
{x: int;}
{ x: int }
type T3
type T4 =
class
Expand All @@ -705,22 +705,22 @@ module internal PrivateM = begin
| A
| B
type T6 =
{x: int;}
{ x: int }
type private T7 =
| A
| B
type private T8 =
{x: int;}
{ x: int }
type T9 =
private | A
| B
type T10 =
private {x: int;}
private { x: int }
type T11 =
private | A
| B
type T12 =
private {x: int;}
private { x: int }
type private T13
type private T14 =
class
Expand Down Expand Up @@ -1981,11 +1981,11 @@ val namedEx1 : exn = MyNamedException1 (5,"")
val namedEx2 : exn = MyNamedException7 25

> type optionRecord =
{x: int option;}
{ x: int option }
val x : optionRecord = {x = None;}

> type optionRecord =
{x: obj;}
{ x: obj }
val x : optionRecord = {x = null;}

> > >
Loading