From 1e5bc18553795ba740a4c60092069899ef9f7589 Mon Sep 17 00:00:00 2001 From: Chet Husk Date: Tue, 27 Jul 2021 09:01:31 -0500 Subject: [PATCH 1/2] update to FCS 40, blocked due to fantomas having fcs39 dependency --- paket.dependencies | 5 +++- paket.lock | 12 ++++---- sample/CreateAst.fs | 4 +-- sample/FormatFs.fs | 3 +- sample/PrintAstInfo.fs | 10 +++---- src/AstCreate.fs | 67 +++++++++++++++++++++++------------------- src/AstRcd.fs | 46 +++++++++++++++-------------- 7 files changed, 80 insertions(+), 67 deletions(-) diff --git a/paket.dependencies b/paket.dependencies index 382a5a5..8213c44 100644 --- a/paket.dependencies +++ b/paket.dependencies @@ -6,4 +6,7 @@ framework: netstandard2.0, netcoreapp3.1 nuget FSharp.Compiler.Service ~> 39 nuget Fantomas -nuget Microsoft.SourceLink.GitHub copy_local: true \ No newline at end of file +nuget Microsoft.SourceLink.GitHub copy_local: true +nuget FSharp.Compiler.Service ~> 40 +nuget Microsoft.SourceLink.GitHub copy_local: true +nuget Fantomas \ No newline at end of file diff --git a/paket.lock b/paket.lock index 5aa8865..3fdc48c 100644 --- a/paket.lock +++ b/paket.lock @@ -5,11 +5,11 @@ NUGET Fantomas (4.5.1) FSharp.Compiler.Service (>= 39.0) FSharp.Core (>= 5.0.1) - FSharp.Compiler.Service (39.0) - FSharp.Core (5.0.1) - Microsoft.Build.Framework (>= 16.6) - Microsoft.Build.Tasks.Core (>= 16.6) - Microsoft.Build.Utilities.Core (>= 16.6) + FSharp.Compiler.Service (40.0) + FSharp.Core (5.0.2) + Microsoft.Build.Framework (>= 16.9) + Microsoft.Build.Tasks.Core (>= 16.9) + Microsoft.Build.Utilities.Core (>= 16.9) System.Buffers (>= 4.5.1) System.Collections.Immutable (>= 5.0) System.Diagnostics.Process (>= 4.3) @@ -31,7 +31,7 @@ NUGET System.Threading.Tasks.Parallel (>= 4.3) System.Threading.Thread (>= 4.3) System.Threading.ThreadPool (>= 4.3) - FSharp.Core (5.0.1) + FSharp.Core (5.0.2) Microsoft.Build.Framework (16.10) System.Security.Permissions (>= 4.7) Microsoft.Build.Tasks.Core (16.10) diff --git a/sample/CreateAst.fs b/sample/CreateAst.fs index 0270117..5b4d0de 100644 --- a/sample/CreateAst.fs +++ b/sample/CreateAst.fs @@ -3,10 +3,10 @@ module FsAst.CreateAst open System open Fantomas -open FSharp.Compiler.SyntaxTree +open FSharp.Compiler.Syntax open FSharp.Compiler.Text open Microsoft.FSharp.Quotations -open FSharp.Compiler.XmlDoc +open FSharp.Compiler.Xml let createBasicClass() = async { diff --git a/sample/FormatFs.fs b/sample/FormatFs.fs index 47b831b..73b2afc 100644 --- a/sample/FormatFs.fs +++ b/sample/FormatFs.fs @@ -3,7 +3,8 @@ module FsAst.FormatFs open System.IO open Fantomas -open FSharp.Compiler.SourceCodeServices +open FSharp.Compiler.CodeAnalysis + let formatAst ast = let cfg = { FormatConfig.FormatConfig.Default with StrictMode = true } // do not format comments diff --git a/sample/PrintAstInfo.fs b/sample/PrintAstInfo.fs index ea9af50..a98ab4e 100644 --- a/sample/PrintAstInfo.fs +++ b/sample/PrintAstInfo.fs @@ -3,8 +3,8 @@ module FsAst.PrintAstInfo open System.IO open Fantomas -open FSharp.Compiler.SyntaxTree -open FSharp.Compiler.SourceCodeServices +open FSharp.Compiler.Syntax +open FSharp.Compiler.CodeAnalysis let rec printType indent typ = match typ with @@ -22,7 +22,7 @@ let rec printExpr indent expr = | SynExpr.Const(c,_) -> match c with | SynConst.Int32 i -> printfn "%*sConst Int32: %d" indent "" i - | SynConst.String (s,_) -> printfn "%*sConst String: %s" indent "" s + | SynConst.String (s, _, _) -> printfn "%*sConst String: %s" indent "" s | cnst -> printfn "%*scnst not matched: %A" indent "" cnst | SynExpr.Paren(innerExpr, _, _, _) -> printfn "%*sParen expr" indent "" @@ -78,7 +78,7 @@ let rec printPattern indent pat = let printAstInfo filename checker = async { let s = File.ReadAllText filename - let parsOpt = {FSharpParsingOptions.Default with SourceFiles = [|filename|]} + let parsOpt = { FSharpParsingOptions.Default with SourceFiles = [|filename|]} let! res = CodeFormatter.ParseAsync(filename, SourceOrigin.SourceString s, parsOpt, checker) for (ast,_) in res do match ast with @@ -114,7 +114,7 @@ let printAstInfo filename checker = | SynTypeDefnSimpleReprRcd.Record record -> for field in record.Fields do match field with - | SynField.Field(attribs, isstatic, ident, typ, e, prexmldoc, access, range) -> + | SynField(attribs, isstatic, ident, typ, e, prexmldoc, access, range) -> printfn "%s:" (match ident with | Some i -> i.idText diff --git a/src/AstCreate.fs b/src/AstCreate.fs index b74ec37..372b458 100644 --- a/src/AstCreate.fs +++ b/src/AstCreate.fs @@ -1,11 +1,11 @@ [] module FsAst.AstCreate open System -open FSharp.Compiler.SyntaxTree +open FSharp.Compiler.Syntax open FSharp.Compiler.Text open FSharp.Compiler.Text.Range -open FSharp.Compiler.Text.Pos -open FSharp.Compiler.XmlDoc +open FSharp.Compiler.Text.Position +open FSharp.Compiler.Xml type Ident with static member Create text = @@ -57,15 +57,19 @@ type QualifiedNameOfFile with static member Create name = QualifiedNameOfFile(Ident.Create name) -type MemberFlags with - static member InstanceMember = - { IsInstance = true; MemberKind = MemberKind.Member; IsDispatchSlot = false; IsOverrideOrExplicitImpl = false; IsFinal = false } - static member StaticMember = - { MemberFlags.InstanceMember with IsInstance = false } +type SynMemberFlags with + static member InstanceMember: SynMemberFlags = + { IsInstance = true; MemberKind = SynMemberKind.Member; IsDispatchSlot = false; IsOverrideOrExplicitImpl = false; IsFinal = false } + static member StaticMember: SynMemberFlags = + { SynMemberFlags.InstanceMember with IsInstance = false } type SynConst with static member CreateString s = - SynConst.String(s, range.Zero) + SynConst.String(s, SynStringKind.Regular, range.Zero) + static member CreateVerbatimString s = + SynConst.String(s, SynStringKind.Verbatim, range.Zero) + static member CreateTripleQuoteString s = + SynConst.String(s, SynStringKind.TripleQuote, range.Zero) type SynExpr with static member CreateConst cnst = @@ -114,7 +118,7 @@ type SynExpr with /// | clauseN /// ``` static member CreateMatch(matchExpr, clauses) = - SynExpr.Match(DebugPointForBinding.DebugPointAtBinding range0, matchExpr, clauses, range0) + SynExpr.Match(DebugPointAtBinding.Yes range0, matchExpr, clauses, range0) /// Creates : `instanceAndMethod(args)` static member CreateInstanceMethodCall(instanceAndMethod : LongIdentWithDots, args) = let valueExpr = SynExpr.CreateLongIdent instanceAndMethod @@ -358,17 +362,17 @@ type SynBindingReturnInfoRcd with type SynBindingRcd with static member Null = { Access = None - Kind = SynBindingKind.NormalBinding + Kind = SynBindingKind.Normal IsInline = false IsMutable = false Attributes = SynAttributes.Empty XmlDoc = PreXmlDoc.Empty - ValData = SynValData(Some MemberFlags.InstanceMember, SynValInfo.Empty, None) + ValData = SynValData(Some SynMemberFlags.InstanceMember, SynValInfo.Empty, None) Pattern = SynPatRcd.CreateNull ReturnInfo = None Expr = SynExpr.Null range.Zero Range = range.Zero - Bind = DebugPointForBinding.NoDebugPointAtInvisibleBinding + Bind = DebugPointAtBinding.NoneAtInvisible } static member Let = { SynBindingRcd.Null with @@ -407,13 +411,13 @@ type SynMemberDefn with /// static member CreateStaticMember(binding:SynBindingRcd) = let (SynValData(usedMemberFlags, valInfo, identifier)) = binding.ValData - let staticMemberFlags = Some { + let staticMemberFlags: SynMemberFlags option = Some { // this means the member is static IsInstance = false; IsOverrideOrExplicitImpl = false IsDispatchSlot = false; IsFinal = false - MemberKind = MemberKind.Member + MemberKind = SynMemberKind.Member } let staticBinding = { binding with ValData = SynValData.SynValData(staticMemberFlags, valInfo, identifier) } SynMemberDefn.Member(staticBinding.FromRcd, range.Zero) @@ -424,12 +428,12 @@ type SynMemberDefn with /// static member CreateOverrideMember(binding:SynBindingRcd) = let (SynValData(usedMemberFlags, valInfo, identifier)) = binding.ValData - let overrideMemberFlags = Some { + let overrideMemberFlags: SynMemberFlags option = Some { IsInstance = true; IsOverrideOrExplicitImpl = true IsDispatchSlot = false; IsFinal = false - MemberKind = MemberKind.Member + MemberKind = SynMemberKind.Member } let overrideBinding = { binding with ValData = SynValData.SynValData(overrideMemberFlags, valInfo, identifier) } SynMemberDefn.Member(overrideBinding.FromRcd, range.Zero) @@ -439,23 +443,25 @@ type SynMemberDefn with type SynTypeDefnReprObjectModelRcd with static member Create members = - { //Kind = SynTypeDefnKind.TyconClass - Kind = SynTypeDefnKind.TyconUnspecified + { + Kind = SynTypeDefnKind.Unspecified Members = members Range = range.Zero } type SynTypeDefnRcd with - static member Create (info: SynComponentInfoRcd, members) = + static member Create (info: SynComponentInfoRcd, members, ?implicitCtor) = { Info = info Repr = SynTypeDefnReprObjectModelRcd.Create(members).FromRcd Members = [] + ImplicitConstructor = implicitCtor Range = range.Zero } - static member CreateSimple (info: SynComponentInfoRcd, simple: SynTypeDefnSimpleRepr, ?members) = + static member CreateSimple (info: SynComponentInfoRcd, simple: SynTypeDefnSimpleRepr, ?members, ?implicitCtor) = { Info = info Repr = SynTypeDefnRepr.Simple(simple, range.Zero) Members = Option.defaultValue [] members + ImplicitConstructor = implicitCtor Range = range.Zero } @@ -549,25 +555,26 @@ type SynTypeDefnSimpleReprUnionRcd with Range = range.Zero } type SynUnionCaseRcd with - static member Create(id, typ) : SynUnionCaseRcd = + static member Create(id, kind) : SynUnionCaseRcd = { Attributes = SynAttributes.Empty Id = id - Type = typ + Kind = kind XmlDoc = PreXmlDoc.Empty Access = None Range = range.Zero } -type SynUnionCaseType with +type SynUnionCaseKind with static member Create(synFieldList : SynFieldRcd list) = - SynUnionCaseType.UnionCaseFields(synFieldList |> List.map (fun sf -> sf.FromRcd )) + SynUnionCaseKind.Fields (synFieldList |> List.map (fun sf -> sf.FromRcd )) type SynEnumCaseRcd with static member Create (id, cnst) = { Attributes = SynAttributes.Empty Id = id Constant = cnst + ConstantRange = range0 XmlDoc = PreXmlDoc.Empty - Range = range.Zero + Range = range0 } type SynFieldRcd with @@ -610,19 +617,19 @@ type SynFieldRcd with SynFieldRcd.Create(Ident.Create id, SynType.CreateApp(SynType.CreateLongIdent typ, args |> List.map (SynType.CreateLongIdent))) type SynAttributeList with - static member Create(attrs) = + static member Create(attrs): SynAttributeList = { Attributes = attrs Range = range0 } - static member Create(attr) = + static member Create(attr): SynAttributeList = { Attributes = [ attr ] Range = range0 } - static member Create([] attrs) = + static member Create([] attrs): SynAttributeList = { Attributes = List.ofArray attrs Range = range0 @@ -641,7 +648,7 @@ type SynAttribute with static member Create(name: string, argument: string) : SynAttribute = { AppliesToGetterAndSetter = false - ArgExpr = SynExpr.Const (SynConst.String(argument, range0), range0) + ArgExpr = SynExpr.Const (SynConst.CreateString argument, range0) Range = range0 Target = None TypeName = LongIdentWithDots([ Ident.Create name ], [ ]) diff --git a/src/AstRcd.fs b/src/AstRcd.fs index dd4dc2f..9e03ffc 100644 --- a/src/AstRcd.fs +++ b/src/AstRcd.fs @@ -3,8 +3,8 @@ module FsAst.AstRcd open System open FSharp.Compiler.Text -open FSharp.Compiler.SyntaxTree -open FSharp.Compiler.XmlDoc +open FSharp.Compiler.Syntax +open FSharp.Compiler.Xml type ParsedImplFileInputRcd = { File: string @@ -53,26 +53,27 @@ type SynComponentInfoRcd = { Range: range } with member x.FromRcd = - ComponentInfo(x.Attributes, x.Parameters, x.Constraints, x.Id, x.XmlDoc, x.PreferPostfix, x.Access, x.Range) + SynComponentInfo(x.Attributes, x.Parameters, x.Constraints, x.Id, x.XmlDoc, x.PreferPostfix, x.Access, x.Range) type SynComponentInfo with member x.ToRcd = - let (ComponentInfo(attributes, parameters, constraints, id, xmldoc, preferPostfix, access, range)) = x + let (SynComponentInfo(attributes, parameters, constraints, id, xmldoc, preferPostfix, access, range)) = x { Attributes = attributes; Parameters = parameters; Constraints = constraints; Id = id; XmlDoc = xmldoc; PreferPostfix = preferPostfix; Access = access; Range = range } type SynTypeDefnRcd = { Info: SynComponentInfoRcd Repr: SynTypeDefnRepr Members: SynMemberDefns + ImplicitConstructor: SynMemberDefn option Range: range } with member x.FromRcd = - TypeDefn(x.Info.FromRcd, x.Repr, x.Members, x.Range) + SynTypeDefn(x.Info.FromRcd, x.Repr, x.Members, x.ImplicitConstructor, x.Range) type SynTypeDefn with member x.ToRcd = - let (TypeDefn(info, repr, members, range)) = x - { Info = info.ToRcd; Repr = repr; Members = members; Range = range } + let (SynTypeDefn(info, repr, members, implicitCtor, range)) = x + { Info = info.ToRcd; Repr = repr; Members = members; ImplicitConstructor = implicitCtor; Range = range } type SynTypeDefnReprObjectModelRcd = { Kind: SynTypeDefnKind @@ -397,14 +398,14 @@ type SynBindingRcd = { ReturnInfo: SynBindingReturnInfoRcd option Expr: SynExpr Range: range - Bind: DebugPointForBinding } + Bind: DebugPointAtBinding } with member x.FromRcd = - Binding(x.Access, x.Kind, x.IsInline, x.IsMutable, x.Attributes, x.XmlDoc, x.ValData, x.Pattern.FromRcd, x.ReturnInfo |> Option.map (fun ri -> ri.FromRcd), x.Expr, x.Range, x.Bind) + SynBinding(x.Access, x.Kind, x.IsInline, x.IsMutable, x.Attributes, x.XmlDoc, x.ValData, x.Pattern.FromRcd, x.ReturnInfo |> Option.map (fun ri -> ri.FromRcd), x.Expr, x.Range, x.Bind) type SynBinding with member x.ToRcd = - let (Binding(access, kind, isInline, isMutable, attrs, xmlDoc, info, pattern, returnInfo, rhsExpr, mBind, spBind)) = x + let (SynBinding(access, kind, isInline, isMutable, attrs, xmlDoc, info, pattern, returnInfo, rhsExpr, mBind, spBind)) = x { Access = access; Kind = kind; IsInline = isInline; IsMutable = isMutable; Attributes = attrs; XmlDoc = xmlDoc; ValData = info; Pattern = pattern.ToRcd; ReturnInfo = returnInfo |> Option.map (fun ri -> ri.ToRcd); Expr = rhsExpr; Range = mBind; Bind = spBind } [] @@ -447,7 +448,7 @@ and SynTypeDefnSimpleReprLibraryOnlyILAssemblyRcd = { Range: range } and SynTypeDefnSimpleReprTypeAbbrevRcd = { - ParseDetail: FSharp.Compiler.SyntaxTree.ParserDetail + ParseDetail: FSharp.Compiler.Syntax.ParserDetail Type: SynType Range: range } @@ -502,17 +503,18 @@ type SynEnumCaseRcd = { Attributes: SynAttributes Id: Ident Constant: SynConst + ConstantRange: range XmlDoc: PreXmlDoc Range: range } with member x.FromRcd = - SynEnumCase.EnumCase(x.Attributes, x.Id, x.Constant, x.XmlDoc, x.Range) + SynEnumCase(x.Attributes, x.Id, x.Constant, x.ConstantRange, x.XmlDoc, x.Range) type SynEnumCase with member x.ToRcd = match x with - | EnumCase(attributes, id, constant, xmlDoc, range) -> - { Attributes = attributes; Id = id; Constant = constant; XmlDoc = xmlDoc; Range = range } + | SynEnumCase(attributes, id, constant, constantRange, xmlDoc, range) -> + { Attributes = attributes; Id = id; Constant = constant; ConstantRange = constantRange; XmlDoc = xmlDoc; Range = range } type XmlDoc with member x.Lines = @@ -525,23 +527,23 @@ type PreXmlDoc with type SynUnionCaseRcd = { Attributes: SynAttributes Id: Ident - Type: SynUnionCaseType + Kind: SynUnionCaseKind XmlDoc: PreXmlDoc Access: SynAccess option Range: range } with member x.FromRcd = - SynUnionCase.UnionCase(x.Attributes, x.Id, x.Type, x.XmlDoc, x.Access, x.Range) + SynUnionCase(x.Attributes, x.Id, x.Kind, x.XmlDoc, x.Access, x.Range) member x.HasFields = - match x.Type with - | UnionCaseFields cases -> not cases.IsEmpty + match x.Kind with + | SynUnionCaseKind.Fields cases -> not cases.IsEmpty | _ -> false type SynUnionCase with member x.ToRcd : SynUnionCaseRcd = match x with - | SynUnionCase.UnionCase(attributes, id, typ, xmlDoc, access, range) -> - { Attributes = attributes; Id = id; Type = typ; XmlDoc = xmlDoc; Access = access; Range = range } + | SynUnionCase(attributes, id, kind, xmlDoc, access, range) -> + { Attributes = attributes; Id = id; Kind = kind; XmlDoc = xmlDoc; Access = access; Range = range } type SynFieldRcd = { Attributes: SynAttributes @@ -554,12 +556,12 @@ type SynFieldRcd = { Range: range } with member x.FromRcd = - SynField.Field(x.Attributes, x.IsStatic, x.Id, x.Type, x.IsMutable, x.XmlDoc, x.Access, x.Range) + SynField(x.Attributes, x.IsStatic, x.Id, x.Type, x.IsMutable, x.XmlDoc, x.Access, x.Range) type SynField with member x.ToRcd: SynFieldRcd = match x with - | SynField.Field(attributes, isstatic, id, typ, ismutable, xmlDoc, access, range) -> + | SynField(attributes, isstatic, id, typ, ismutable, xmlDoc, access, range) -> { Attributes = attributes IsStatic = isstatic Id = id From 825c1ff89a38cc5c17fa5bfb3064bc812e6f6363 Mon Sep 17 00:00:00 2001 From: Chet Husk Date: Wed, 4 Aug 2021 09:28:15 -0500 Subject: [PATCH 2/2] Fix paket.dependencies --- paket.dependencies | 4 ---- 1 file changed, 4 deletions(-) diff --git a/paket.dependencies b/paket.dependencies index 8213c44..6b2d043 100644 --- a/paket.dependencies +++ b/paket.dependencies @@ -3,10 +3,6 @@ source https://api.nuget.org/v3/index.json storage: none framework: netstandard2.0, netcoreapp3.1 -nuget FSharp.Compiler.Service ~> 39 -nuget Fantomas - nuget Microsoft.SourceLink.GitHub copy_local: true nuget FSharp.Compiler.Service ~> 40 -nuget Microsoft.SourceLink.GitHub copy_local: true nuget Fantomas \ No newline at end of file