Upgrade Myriad (#7)

This commit is contained in:
Patrick Stevens
2023-12-24 12:43:01 +00:00
committed by GitHub
parent 487a5f8641
commit 0f42e6fda9
13 changed files with 155 additions and 106 deletions

View File

@@ -1,12 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"fantomas": {
"version": "6.0.1",
"commands": [
"fantomas"
]
}
}
}
{
"version": 1,
"isRoot": true,
"tools": {
"fantomas": {
"version": "6.3.0-alpha-005",
"commands": [
"fantomas"
]
}
}
}

View File

@@ -91,8 +91,21 @@ jobs:
- name: Run link checker
run: nix develop --command markdown-link-check README.md
flake-check:
name: Check flake
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Install Nix
uses: cachix/install-nix-action@v20
with:
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- name: Flake check
run: nix flake check
all-required-checks-complete:
needs: [check-dotnet-format, check-nix-format, build, build-nix, linkcheck]
needs: [check-dotnet-format, check-nix-format, build, build-nix, linkcheck, flake-check]
runs-on: ubuntu-latest
steps:
- run: echo "All required checks complete."

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>

View File

@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Myriad.Core" Version="0.8.2" />
<PackageReference Include="Myriad.Core" Version="0.8.3" />
<PackageReference Update="FSharp.Core" Version="6.0.6" />
</ItemGroup>

View File

@@ -1,9 +1,9 @@
namespace MyriadPlugin
open System
open FSharp.Compiler.Syntax
open FSharp.Compiler.SyntaxTrivia
open FSharp.Compiler.Xml
open Fantomas.FCS.Syntax
open Fantomas.FCS.SyntaxTrivia
open Fantomas.FCS.Xml
open Myriad.Core
/// Attribute indicating a record type to which the "Remove Options" Myriad
@@ -12,9 +12,35 @@ type RemoveOptionsAttribute () =
inherit Attribute ()
module internal Create =
open FSharp.Compiler.Text.Range
open Fantomas.FCS.Text.Range
open Myriad.Core.Ast
let createRecordMyriad fields =
// TODO: this first equals-None requires a range
let fields =
fields
|> List.map (fun (rfn, synExpr) -> SynExprRecordField (rfn, Some range0, synExpr, None))
SynExpr.Record (None, None, fields, range0)
let createFromRepr (name : Ident, repr : SynTypeDefnRepr, members : SynMemberDefns, xmldoc : PreXmlDoc) =
let name = SynComponentInfo.Create ([ name ], xmldoc = xmldoc)
let trivia : SynTypeDefnTrivia =
{
LeadingKeyword = SynTypeDefnLeadingKeyword.Type range0
EqualsRange = Some range0
WithKeyword = Some range0
}
SynTypeDefn (name, repr, members, None, range0, trivia)
let createRecord (name : Ident, fields : SynField seq, members : SynMemberDefns option, xmldoc : PreXmlDoc option) =
let repr =
SynTypeDefnRepr.Simple (SynTypeDefnSimpleRepr.Record (None, Seq.toList fields, range0), range0)
createFromRepr (name, repr, defaultArg members SynMemberDefns.Empty, defaultArg xmldoc PreXmlDoc.Empty)
let isOptionIdent (ident : SynLongIdent) : bool =
match ident.LongIdent with
| [ i ] when String.Equals (i.idText, "option", StringComparison.OrdinalIgnoreCase) -> true
@@ -34,7 +60,8 @@ module internal Create =
isMutable,
preXmlDoc,
synAccessOption,
range)) =
range,
trivia)) =
s
let newType =
@@ -50,7 +77,8 @@ module internal Create =
isMutable,
preXmlDoc,
synAccessOption,
range
range,
trivia
)
// TODO: this option seems a bit odd
@@ -60,8 +88,8 @@ module internal Create =
let typeDecl : SynTypeDefn =
match xmlDoc with
| None -> SynTypeDefn.CreateRecord (name, fields)
| Some xmlDoc -> SynTypeDefn.CreateRecord (name, fields, xmldoc = xmlDoc)
| None -> createRecord (name, fields, None, None)
| Some xmlDoc -> createRecord (name, fields, None, Some xmlDoc)
SynModuleDecl.Types ([ typeDecl ], range0)
@@ -83,19 +111,14 @@ module internal Create =
let body =
fields
|> List.map (fun (SynField (_, _, id, fieldType, _, _, _, _)) ->
|> List.map (fun (SynField (_, _, id, fieldType, _, _, _, _, _)) ->
let id =
match id with
| None -> failwith "Expected record field to have an identifying name"
| Some id -> id
let accessor =
SynExpr.DotGet (
SynExpr.CreateIdent inputArg,
range0,
SynLongIdent.CreateFromLongIdent [ id ],
range0
)
SynExpr.LongIdent (false, SynLongIdent ([ inputArg ; id ], [ range0 ], []), None, range0)
let body =
match fieldType with
@@ -115,15 +138,10 @@ module internal Create =
accessor
),
SynExpr.CreateApp (
SynExpr.CreateLongIdent (SynLongIdent.CreateString "Option.defaultValue"),
SynExpr.CreateParen (
SynExpr.CreateApp (
SynExpr.CreateLongIdent (
SynLongIdent.CreateFromLongIdent (
withoutOptionsType @ [ Ident.Create (sprintf "Default%s" id.idText) ]
)
),
SynExpr.CreateUnit
SynExpr.CreateLongIdent (SynLongIdent.CreateString "Option.defaultWith"),
SynExpr.CreateLongIdent (
SynLongIdent.CreateFromLongIdent (
withoutOptionsType @ [ Ident.Create (sprintf "Default%s" id.idText) ]
)
)
)
@@ -132,7 +150,7 @@ module internal Create =
(SynLongIdent.CreateFromLongIdent [ id ], true), Some body
)
|> SynExpr.CreateRecord
|> createRecordMyriad
let pattern =
SynPat.LongIdent (
@@ -153,6 +171,8 @@ module internal Create =
let binding =
SynBinding.Let (
isInline = false,
isMutable = false,
xmldoc = xmlDoc,
returnInfo = returnInfo,
expr = body,

View File

@@ -22,7 +22,7 @@ module RecordType =
/// Remove the optional members of the input.
let shorten (input : RecordType) : Short =
{
A = input.A |> Option.defaultValue (RecordType.DefaultA ())
A = input.A |> Option.defaultWith RecordType.DefaultA
B = input.B
C = input.C
}

View File

@@ -1,5 +1,11 @@
namespace UsePlugin
open System
type ParseState =
| AwaitingKey
| AwaitingValue of string
/// My whatnot
[<MyriadPlugin.RemoveOptions>]
type RecordType =

View File

@@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
@@ -22,8 +22,8 @@
<ItemGroup>
<ProjectReference Include="..\MyriadPlugin\MyriadPlugin.fsproj" />
<PackageReference Include="Myriad.Sdk" Version="0.8.2" />
<PackageReference Include="Myriad.Core" Version="0.8.2" />
<PackageReference Include="Myriad.Sdk" Version="0.8.3" />
<PackageReference Include="Myriad.Core" Version="0.8.3" />
</ItemGroup>
</Project>

12
flake.lock generated
View File

@@ -5,11 +5,11 @@
"systems": "systems"
},
"locked": {
"lastModified": 1681202837,
"narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=",
"lastModified": 1701680307,
"narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "cfacdce06f30d2b68473a46042957675eebb3401",
"rev": "4022d587cbbfd70fe950c1e2083a02621806a725",
"type": "github"
},
"original": {
@@ -20,11 +20,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1683353485,
"narHash": "sha256-Skp5El3egmoXPiINWjnoW0ktVfB7PR/xc4F4bhD+BJY=",
"lastModified": 1703134684,
"narHash": "sha256-SQmng1EnBFLzS7WSRyPM9HgmZP2kLJcPAz+Ug/nug6o=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "caf436a52b25164b71e0d48b671127ac2e2a5b75",
"rev": "d6863cbcbbb80e71cecfc03356db1cda38919523",
"type": "github"
},
"original": {

View File

@@ -14,9 +14,9 @@
}:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = nixpkgs.legacyPackages.${system};
pname = "dotnet-cipher-suite";
dotnet-sdk = pkgs.dotnet-sdk_7;
dotnet-runtime = pkgs.dotnetCorePackages.runtime_7_0;
pname = "fsharp-arguments";
dotnet-sdk = pkgs.dotnet-sdk_8;
dotnet-runtime = pkgs.dotnetCorePackages.runtime_8_0;
version = "0.1";
dotnetTool = toolName: toolVersion: sha256:
pkgs.stdenvNoCC.mkDerivation rec {
@@ -39,7 +39,7 @@
};
in {
packages = {
fantomas = dotnetTool "fantomas" "6.0.1" "sha256-TNAkurZ0NYI2Tkr99ms9MdAMLLKCQzemx5zHo/hDOTo=";
fantomas = dotnetTool "fantomas" (builtins.fromJSON (builtins.readFile ./.config/dotnet-tools.json)).tools.fantomas.version "sha256-Jmo7s8JMdQ8SxvNvPnryfE7n24mIgKi5cbgNwcQw3yU=";
fetchDeps = let
flags = [];
runtimeIds = ["win-x64"] ++ map (system: pkgs.dotnetCorePackages.systemToDotnetRid system) dotnet-sdk.meta.platforms;
@@ -74,7 +74,7 @@
buildInputs = with pkgs; [
(with dotnetCorePackages;
combinePackages [
dotnet-sdk_7
dotnet-sdk_8
dotnetPackages.Nuget
])
];

View File

@@ -1,6 +1,6 @@
{
"sdk": {
"version": "7.0.200",
"version": "8.0.100",
"rollForward": "latestFeature"
}
}

View File

@@ -1,6 +1,11 @@
# This file was automatically generated by passthru.fetch-deps.
# Please don't edit it manually, your changes might get overwritten!
{fetchNuGet}: [
(fetchNuGet {
pname = "fantomas";
version = "6.3.0-alpha-005";
sha256 = "sha256-Jmo7s8JMdQ8SxvNvPnryfE7n24mIgKi5cbgNwcQw3yU=";
})
(fetchNuGet {
pname = "ApiSurface";
version = "4.0.8";
@@ -13,13 +18,13 @@
})
(fetchNuGet {
pname = "Fantomas.Core";
version = "5.0.6";
sha256 = "10550v04qk4diiv3hfqrxxgqmd9b4awb3vr4ja2wf353ccs5wcla";
version = "6.1.1";
sha256 = "1h2wsiy4fzwsg9vrlpk6w7zsvx6bc4wg4x25zqc48akg04fwpi0m";
})
(fetchNuGet {
pname = "Fantomas.FCS";
version = "5.0.6";
sha256 = "167q4ivfclhcqqbkfllilicx101jri10w3hydk27bbkxdg87vrxc";
version = "6.1.1";
sha256 = "0733dm5zjdp8w5wwalqlv1q52pghfr04863i9wy807f4qfd7rrin";
})
(fetchNuGet {
pname = "FSharp.Core";
@@ -28,38 +33,38 @@
})
(fetchNuGet {
pname = "FSharp.Core";
version = "7.0.200";
sha256 = "1ji816r8idwjmxk8bzyq1z32ybz7xdg3nb0a7pnvqr8vys11bkgb";
version = "8.0.100";
sha256 = "06z3vg8yj7i83x6gmnzl2lka1bp4hzc07h6mrydpilxswnmy2a0l";
})
(fetchNuGet {
pname = "Microsoft.AspNetCore.App.Ref";
version = "7.0.5";
sha256 = "09amylhcl0fgrn08zan5xcsa4wjw5prdnlgypbvsz4z930lm4zf4";
version = "8.0.0";
sha256 = "0k304yhpm92c46a1fscbzlgvdbhrm9vlbpyfgwp3cafz4f7z7a5y";
})
(fetchNuGet {
pname = "Microsoft.AspNetCore.App.Runtime.linux-arm64";
version = "7.0.5";
sha256 = "1f7j3fxfdbin5zh39knsr1icpbdf5zkyjdxds9m8brraw9gj5mlw";
version = "8.0.0";
sha256 = "05y1xb5fw8lzvb4si77a5qwfwfz1855crqbphrwky6x9llivbhkx";
})
(fetchNuGet {
pname = "Microsoft.AspNetCore.App.Runtime.linux-x64";
version = "7.0.5";
sha256 = "01irhwqq80ifrqf87897jlh8v0mr5yls000gryv4v8cagsq648s0";
version = "8.0.0";
sha256 = "18zdbcb2bn7wy1dp14z5jyqiiwr9rkad1lcb158r5ikjfq1rg5iw";
})
(fetchNuGet {
pname = "Microsoft.AspNetCore.App.Runtime.osx-arm64";
version = "7.0.5";
sha256 = "152dlxn5bqvf0nyhmxbcmaqj95bmm4vhvm4y23ajfwwgh373n00a";
version = "8.0.0";
sha256 = "1nbxzmj6cnccylxis67c54c0ik38ma4rwdvgg6sxd6r04219maqm";
})
(fetchNuGet {
pname = "Microsoft.AspNetCore.App.Runtime.osx-x64";
version = "7.0.5";
sha256 = "1nwlyz0sgykx801fg1lj7la2b3vbgyvk51132v0gnz48m8b62n3w";
version = "8.0.0";
sha256 = "1wqkbjd1ywv9w397l7rsb89mijc5n0hv7jq9h09xfz6wn9qsp152";
})
(fetchNuGet {
pname = "Microsoft.AspNetCore.App.Runtime.win-x64";
version = "7.0.5";
sha256 = "0nxyv0bz9c46pmwvvbmpb6c7id8l9ka9lpymi0ljwln01xwhi8fx";
version = "8.0.0";
sha256 = "08vlmswmiyp2nxlr9d77716hk7kz7h9x5bl8wh76xzbj5id1xlb2";
})
(fetchNuGet {
pname = "Microsoft.Build.Tasks.Git";
@@ -78,58 +83,58 @@
})
(fetchNuGet {
pname = "Microsoft.NETCore.App.Host.linux-arm64";
version = "7.0.5";
sha256 = "1fq6bjpsmqdgv5z4ncxnxrfn10aw90n2zh8sqw0whhv2kjsq7v8l";
version = "8.0.0";
sha256 = "0bpg3v9dnalz7yh7lsgriw9rnm9jx37mqhhvf7snznb3sfk7rgwb";
})
(fetchNuGet {
pname = "Microsoft.NETCore.App.Host.linux-x64";
version = "7.0.5";
sha256 = "12p3zq5n8pmpscrgz944rkrjb12q702if8510xyf2b4na85r85qh";
version = "8.0.0";
sha256 = "1c7l68bm05d94x5wk1y33mnd4v8m196vyprgrzqnh94yrqy6fkf7";
})
(fetchNuGet {
pname = "Microsoft.NETCore.App.Host.osx-arm64";
version = "7.0.5";
sha256 = "0b87x1r9103fwg3bg6y42hgv4dk40kgysnvksv3wssd9m40v3kqf";
version = "8.0.0";
sha256 = "1hdv825s964vfcgnk94pzhgxnj948f1vdj423jjxpkppcy30fl0m";
})
(fetchNuGet {
pname = "Microsoft.NETCore.App.Host.osx-x64";
version = "7.0.5";
sha256 = "1lnv3z082ijmyzwa3in98wz7jchaxld2gbc3dk2k804pavaamr8r";
version = "8.0.0";
sha256 = "0jmzf58vv45j0hqlxq8yalpjwi328vp2mjr3h0pdg0qr143iivnr";
})
(fetchNuGet {
pname = "Microsoft.NETCore.App.Host.win-x64";
version = "7.0.5";
sha256 = "08raqcy32yni373c6kdmxvyndxlwrhnxadfjp4fn7rfqyrgqkifn";
version = "8.0.0";
sha256 = "1n8yr13df2f6jhxpfazs6rxahfqm18fhjvfm16g5d60c3za1hwnk";
})
(fetchNuGet {
pname = "Microsoft.NETCore.App.Ref";
version = "7.0.5";
sha256 = "1sam55nhsa0q6npcx2qa2q2rfqss3lk27djyhp4q7yazsnlihq1d";
version = "8.0.0";
sha256 = "0hyvbh86433764qqqhw9i7ga0ax7bbdmzh77jw58pq0ggm41cff9";
})
(fetchNuGet {
pname = "Microsoft.NETCore.App.Runtime.linux-arm64";
version = "7.0.5";
sha256 = "08ak2khqcn9dqinb59c5nlpa7imdhi5j7l4g9p2xm62jm6816qlp";
version = "8.0.0";
sha256 = "0gwqmkmr7jy3sjh9gha82amlry41gp8nwswy2iqfw54f28db63n7";
})
(fetchNuGet {
pname = "Microsoft.NETCore.App.Runtime.linux-x64";
version = "7.0.5";
sha256 = "1cl6g85yaigyzixdqnxqpclf46x32f3ndjl08x9lpypwsv62cd9z";
version = "8.0.0";
sha256 = "042cjvnwrrjs3mw5q8q5kinh0cwkks33i3n1vyifaid2jbr3wlc0";
})
(fetchNuGet {
pname = "Microsoft.NETCore.App.Runtime.osx-arm64";
version = "7.0.5";
sha256 = "1qw07w5qll6y8rdids8bv3717hmhcv69vs7xbgpddh7ag0xxihr7";
version = "8.0.0";
sha256 = "06ndp4wh1cap01dql3nixka4g56bf6ipmqys7xaxvg4xisf79x8d";
})
(fetchNuGet {
pname = "Microsoft.NETCore.App.Runtime.osx-x64";
version = "7.0.5";
sha256 = "1rmim6wrkh9vd0klmlwm5yr6xszrhv2qmw4sh12453khxdsi0xpl";
version = "8.0.0";
sha256 = "1kh5bnaf6h9mr4swcalrp304625frjiw6mlz1052rxwzsdq98a96";
})
(fetchNuGet {
pname = "Microsoft.NETCore.App.Runtime.win-x64";
version = "7.0.5";
sha256 = "1wd6i75alsj2hv8aich5gjc6979s4shmrdmfraqj2qr51k3jdf0r";
version = "8.0.0";
sha256 = "054icf5jjnwnswrnv1r05x3pfjvacbz6g3dj8caar1zp53k49rkk";
})
(fetchNuGet {
pname = "Microsoft.NETCore.Platforms";
@@ -173,13 +178,13 @@
})
(fetchNuGet {
pname = "Myriad.Core";
version = "0.8.2";
sha256 = "11cx1dfhf4lf5abg63l6xlvd8p8s6a5yh9fkdv3ryfp9l63sq6n5";
version = "0.8.3";
sha256 = "0s5pdckjw4x0qrbd4i3cz9iili5cppg5qnjbr7zjbbhhmxzb24xw";
})
(fetchNuGet {
pname = "Myriad.Sdk";
version = "0.8.2";
sha256 = "0xzsy22nn205fcrm2qfk1rhy31fjap5i1gfyv7hjcjvkzhblcfvj";
version = "0.8.3";
sha256 = "0qv78c5s5m04xb8h17nnn2ig26zcyya91k2dpj745cm1cbnzvvgc";
})
(fetchNuGet {
pname = "Nerdbank.GitVersioning";
@@ -261,6 +266,11 @@
version = "4.3.0";
sha256 = "1jx02q6kiwlvfksq1q9qr17fj78y5v6mwsszav4qcz9z25d5g6vk";
})
(fetchNuGet {
pname = "System.Diagnostics.DiagnosticSource";
version = "7.0.0";
sha256 = "1jxhvsh5mzdf0sgb4dfmbys1b12ylyr5pcfyj1map354fiq3qsgm";
})
(fetchNuGet {
pname = "System.Formats.Asn1";
version = "5.0.0";
@@ -278,8 +288,8 @@
})
(fetchNuGet {
pname = "System.Memory";
version = "4.5.4";
sha256 = "14gbbs22mcxwggn0fcfs1b062521azb9fbb7c113x0mq6dzq9h6y";
version = "4.5.5";
sha256 = "08jsfwimcarfzrhlyvjjid61j02irx6xsklf32rv57x2aaikvx0h";
})
(fetchNuGet {
pname = "System.Private.Uri";

View File

@@ -1,9 +1,9 @@
#!/bin/sh
dotnet \
"/Users/patrick/.nuget/packages/myriad.sdk/0.8.2/build/../tools/net6.0/any/Myriad.dll" \
"/Users/patrick/.nuget/packages/myriad.sdk/0.8.3/build/../tools/net6.0/any/Myriad.dll" \
--inputfile "/Users/patrick/Documents/GitHub/MyriadPlugin/UsePlugin/RecordFile.fs" \
--outputfile "/Users/patrick/Documents/GitHub/MyriadPlugin/UsePlugin/Generated.fs" \
--configfile "/Users/patrick/Documents/GitHub/MyriadPlugin/UsePlugin/myriad.toml" \
--contextfile "/Users/patrick/Documents/GitHub/MyriadPlugin/UsePlugin/obj/myriad.context.toml"
--plugin "/Users/patrick/Documents/GitHub/MyriadPlugin/bin/Debug/net7.0/MyriadPlugin.dll"
--contextfile "/Users/patrick/Documents/GitHub/MyriadPlugin/UsePlugin/obj/myriad.context.toml" \
--plugin "/Users/patrick/Documents/GitHub/MyriadPlugin/MyriadPlugin/bin/Debug/net8.0/MyriadPlugin.dll"