Skip to content

Commit 2fdcc9e

Browse files
The Terminal's compiler service is checked rather than warned about (#1132)
NU1608 has said on every Terminal publish since 2.3.0 that FSharp.Compiler.Service 43.9.300 wants FSharp.Core 9.0.300 and got 10.1, sixteen times per run, and nobody had checked which of the two readings was right. #1100 asked for an hour of running the Terminal against something non-trivial. **It is benign.** A kernel built on the shipped pair compiles generic functions and inference, records, discriminated unions, classes with members, units of measure, async, sequence expressions, list comprehensions, active patterns, tuple destructuring, recursion, `sprintf`, string interpolation, `inline` generic constraints and an object expression over an interface: sixteen of sixteen. It also still refuses a type error and a syntax error, each with the position the Terminal shows to whoever typed it -- a compiler that accepted everything would pass the first sixteen and be useless. So the warning is suppressed, and the claim it was making is carried by `CompilerServiceWorksTest` instead. That is the point of the change rather than a side effect: a warning nobody reads is not a check, and this one had been passing through CI unread for two releases. If FSharp.Core or FSharp.Compiler.Service moves and the pair really does come apart, a test fails where before a sixteen-line warning would have scrolled past again. The constraint cannot be met, which is why suppressing is the option rather than pinning: the 10.1 is the FSharp.Core the F# SDK references implicitly for every F# project, and satisfying FSharp.Compiler.Service would mean pinning two majors back, against the SDK, across the graph. Measured: 16 NU1608 on `dotnet pack` before, 0 after, and 0 NuGet warnings of any kind on the publish path. The tests use a bare kernel deliberately. The Terminal opens `AggressiveOperators` over the top, which rebinds the comparison operators to build expressions, and that is the tool's whole point -- but it means `if a < b then` does not typecheck in the Terminal, which is a separate question and is filed as one rather than smuggled in here. Part of #1100.
1 parent 5e54202 commit 2fdcc9e

4 files changed

Lines changed: 112 additions & 0 deletions

File tree

‎Sources/Terminal/AngouriMath.Terminal.Lib/AngouriMath.Terminal.Lib.fsproj‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,26 @@
2222
https://github.com/asc-community/AngouriMath/issues/542
2323
-->
2424
<IsPackable>false</IsPackable>
25+
26+
<!--
27+
NU1608: FSharp.Compiler.Service 43.9.300 requires FSharp.Core (= 9.0.300), and what is
28+
resolved is the 10.1 that the F# SDK references implicitly for every F# project. Sixteen
29+
occurrences in the publish run for 2.3.0 and sixteen in the one for 2.4.0, so it is neither
30+
new nor going away on its own: the constraint can only be met by pinning FSharp.Core two
31+
majors back, against the SDK, for every project in the graph.
32+
33+
Suppressed because it was measured rather than because it was noisy. A kernel built on this
34+
pair runs generic inference, records, unions, sequences, async, units of measure, object
35+
expressions, inline constraints, active patterns, classes and string interpolation, and
36+
reports a type error and a syntax error with the right positions — sixteen of sixteen, in
37+
CompilerServiceWorksTest, which is what now carries the claim. A warning nobody reads is not
38+
a check; a test that runs the compiler is.
39+
40+
If FSharp.Core or FSharp.Compiler.Service moves, that test is what should be believed, and
41+
this comment is what should be rewritten.
42+
https://github.com/asc-community/AngouriMath/issues/1100
43+
-->
44+
<NoWarn>$(NoWarn);NU1608</NoWarn>
2545
</PropertyGroup>
2646

2747
<ItemGroup>

‎Sources/Terminal/AngouriMath.Terminal/AngouriMath.Terminal.fsproj‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
<Description>F#-based command line interface for symbolic algebra library AngouriMath</Description>
1515

1616
<PackageTags>$(PackageTags), cli, terminal</PackageTags>
17+
18+
<!--
19+
The same NU1608 as AngouriMath.Terminal.Lib's, reaching here through the project reference,
20+
and suppressed on the same measurement. Its comment is the one to read.
21+
https://github.com/asc-community/AngouriMath/issues/1100
22+
-->
23+
<NoWarn>$(NoWarn);NU1608</NoWarn>
1724
</PropertyGroup>
1825

1926
<ItemGroup>
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/// The Terminal bundles FSharp.Compiler.Service beside an FSharp.Core two majors above the one
2+
/// it declares it needs, and NU1608 has said so on every publish since 2.3.0. This is what
3+
/// settles whether that matters: the pair is asked to compile F#, and told to.
4+
/// https://github.com/asc-community/AngouriMath/issues/1100
5+
module AngouriMath.Terminal.CompilerServiceWorksTest
6+
7+
open Xunit
8+
open AngouriMath.Terminal.Lib.FSharpInteractive
9+
open AngouriMath.Terminal.Lib.PreRunCode
10+
open AngouriMath.Terminal.Lib.Consts
11+
12+
/// A kernel with nothing loaded into it, so what is under test is the compiler rather than
13+
/// AngouriMath's own bindings. The Terminal opens AggressiveOperators over the top, which
14+
/// deliberately rebinds the comparison operators to build expressions — that is the tool's whole
15+
/// point and it is not what this asks about.
16+
let private bareKernel () =
17+
match createKernel () with
18+
| Result.Error _ ->
19+
Assert.True(false, "the kernel did not load at all")
20+
raise (System.Exception())
21+
| Result.Ok kernel -> kernel
22+
23+
let private evaluates (code: string) (expected: string) =
24+
match execute (bareKernel ()) code with
25+
| ExecutionResult.PlainTextSuccess actual -> Assert.Equal(expected, actual)
26+
| other ->
27+
Assert.True(false, $"expected {expected}, and the kernel answered {other}")
28+
29+
/// Each of these is a language feature the compiler service has to implement rather than a
30+
/// value the parser can fold, so a mismatched FSharp.Core would show here rather than in
31+
/// arithmetic. Sixteen of sixteen pass on the shipped pair.
32+
[<Theory>]
33+
// Inference and generics.
34+
[<InlineData("let twice f x = f (f x)\ntwice (fun n -> n * 2) 5", "20")>]
35+
[<InlineData("let inline add a b = a + b\nadd 2 3", "5")>]
36+
// Type definitions of every shape.
37+
[<InlineData("type P = { X: int; Y: int }\nlet p = { X = 1; Y = 2 }\np.X + p.Y", "3")>]
38+
[<InlineData("type T = A of int | B\nmatch A 7 with A n -> n | B -> 0", "7")>]
39+
[<InlineData("type C(x: int) =\n member _.Doubled = x * 2\nC(21).Doubled", "42")>]
40+
[<InlineData("[<Measure>] type m\nlet d = 5.0<m>\nfloat d", "5")>]
41+
// Computation expressions and the library that backs them.
42+
[<InlineData("async { return 1 + 1 } |> Async.RunSynchronously", "2")>]
43+
[<InlineData("seq { 1..100 } |> Seq.filter (fun x -> x % 7 = 0) |> Seq.length", "14")>]
44+
[<InlineData("[ for i in 1..10 -> i * i ] |> List.sum", "385")>]
45+
// Pattern matching, including one the compiler generates code for.
46+
[<InlineData("let (|Even|Odd|) n = if n % 2 = 0 then Even else Odd\nmatch 4 with Even -> \"e\" | Odd -> \"o\"", "e")>]
47+
[<InlineData("[(1,2);(3,4)] |> List.map (fun (a,b) -> a + b)", "[3; 7]")>]
48+
[<InlineData("let f x = if x > 0 then Some x else None\nOption.defaultValue 0 (f 5)", "5")>]
49+
// Recursion, formatting, interpolation, and an object expression over an interface.
50+
[<InlineData("let rec fib n = if n < 2 then n else fib (n-1) + fib (n-2)\nfib 20", "6765")>]
51+
[<InlineData("sprintf \"%d %s %.2f\" 42 \"x\" 3.14159", "42 x 3.14")>]
52+
[<InlineData("let n = 6\n$\"n is {n}\"", "n is 6")>]
53+
[<InlineData("let c = { new System.IComparable<int> with member _.CompareTo o = 0 }\nc.CompareTo 1", "0")>]
54+
let ``The compiler service compiles F#`` (code: string) (expected: string) =
55+
evaluates code expected
56+
57+
/// And it still refuses what it should, with a position — a compiler that accepted everything
58+
/// would pass the theory above and be useless.
59+
[<Theory>]
60+
[<InlineData("let x: int = \"not an int\"", "typecheck error")>]
61+
[<InlineData("let =", "parse error")>]
62+
let ``The compiler service reports errors`` (code: string) (expected: string) =
63+
match execute (bareKernel ()) code with
64+
| ExecutionResult.Error message ->
65+
Assert.Contains(expected, message)
66+
// A position, not just a complaint: the Terminal shows these to whoever typed them.
67+
Assert.Contains("input.fsx (1,", message)
68+
| other ->
69+
Assert.True(false, $"expected an error and the kernel answered {other}")
70+
71+
/// The pairing the warning is about, doing the work the Terminal exists for.
72+
[<Theory>]
73+
[<InlineData("solutions \"x\" \"x2 - 5x + 6 = 0\"", "{ 2, 3 }")>]
74+
[<InlineData("derivative \"x\" \"x3 + sin(x)\"", "3 * x ^ 2 + cos(x)")>]
75+
[<InlineData("integral \"x\" \"x2\"", "x ^ 3 / 3 + C")>]
76+
let ``AngouriMath works through the compiler service`` (code: string) (expected: string) =
77+
let kernel = bareKernel ()
78+
match enableAngouriMath kernel with
79+
| ExecutionResult.Error reason -> Assert.True(false, $"AngouriMath did not load: {reason}")
80+
| _ -> ()
81+
match execute kernel code with
82+
| ExecutionResult.LatexSuccess (_, actual) -> Assert.Equal(expected, actual)
83+
| ExecutionResult.PlainTextSuccess actual -> Assert.Equal(expected, actual)
84+
| other -> Assert.True(false, $"expected {expected}, and the kernel answered {other}")

‎Sources/Tests/TerminalUnitTests/TerminalUnitTests.fsproj‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
<ItemGroup>
1111
<Compile Include="Tests.fs" />
12+
<Compile Include="CompilerServiceWorksTest.fs" />
1213
<Compile Include="Program.fs" />
1314
</ItemGroup>
1415

0 commit comments

Comments
 (0)