Skip to content

Commit b23b2a0

Browse files
dsymeDon Syme
and
Don Syme
authored
Further work on FCS API (#10772)
* trim API surface area * move Range and Pos types to FSharp.Compiler * undo uppercae range/pos * move Range and Pos types to FSHarp.Compiler.SourceCodeServices since they are part of the FCS API * fix baselines * release notes * FIX BUILD * fix test * fix test * fix test * fix test * fix build * fix build * fix build * PrettyNaming moved to SourceCodeServices * ISourceText moved to SourceCodeServices * update docs * update docs * fix build * fix build * move Range, Pos to FSharp.Compiler.Text * fix test * fix build Co-authored-by: Don Syme <donsyme@fastmail.com>
1 parent a9d719d commit b23b2a0

File tree

344 files changed

+10351
-25857
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

344 files changed

+10351
-25857
lines changed

docs/compiler-guide.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ The following are the key phases and high-level logical operations of the F# com
7272

7373
* _Parsing_. Accepts a token stream and produces an AST per the grammar in the F# Language Specification.
7474

75-
* _Resolving references_. See [ReferenceResolver.fs](https://github.com/dotnet/fsharp/blob/master/src/fsharp/ReferenceResolver.fs) for the abstract definition of compiler reference resolution. See [LegacyMSBuildReferenceResolver.fs](https://github.com/dotnet/fsharp/blob/master/src/fsharp/LegacyMSBuildReferenceResolver.fs) for reference resolution used by the .NET Framework F# compiler when running on .NET Framework. See [SimulatedMSBuildReferenceResolver.fs](https://github.com/dotnet/fsharp/blob/master/src/fsharp/SimulatedMSBuildReferenceResolver.fs) when not using the .NET Framework F# compiler. See [Microsoft.DotNet.DependencyManager](https://github.com/dotnet/fsharp/tree/master/src/fsharp/Microsoft.DotNet.DependencyManager) for reference resolution and package management used in `fsi`.
75+
* _Resolving references_. For .NET SDK generally references are resolved explicitly by external tooling.
76+
There is a legacy aspect to this if references use old .NET Framework references including for
77+
scripting. See [ReferenceResolver.fs](https://github.com/dotnet/fsharp/blob/master/src/fsharp/ReferenceResolver.fs) for the abstract definition of compiler reference resolution. See [LegacyMSBuildReferenceResolver.fs](https://github.com/dotnet/fsharp/blob/master/src/fsharp/LegacyMSBuildReferenceResolver.fs) for reference resolution used by the .NET Framework F# compiler when running on .NET Framework. See [SimulatedMSBuildReferenceResolver.fs](https://github.com/dotnet/fsharp/blob/master/src/fsharp/SimulatedMSBuildReferenceResolver.fs) when not using the .NET Framework F# compiler.
78+
See [Microsoft.DotNet.DependencyManager](https://github.com/dotnet/fsharp/tree/master/src/fsharp/Microsoft.DotNet.DependencyManager) for reference resolution and package management used in `fsi`.
7679

7780
* _Importing referenced .NET binaries_, see [import.fsi](https://github.com/dotnet/fsharp/blob/master/src/fsharp/import.fsi)/[import.fs](https://github.com/dotnet/fsharp/blob/master/src/fsharp/import.fs). Accepts file references and produces a Typed Tree node for each referenced assembly, including information about its type definitions (and type forwarders if any).
7881

@@ -556,6 +559,24 @@ decide not to bother continuing with the computation (it drops it on the floor)
556559

557560
The second can be interrupted via having `isResultObsolete` to the F# Compiler Service API return true.
558561

562+
### The F# Compiler Service Public Surface Area
563+
564+
The "intended" FCS API is the parts under the namespaces
565+
566+
* FSharp.Compiler.SourceCodeServices.* (analysis, compilation, tooling, lexing)
567+
* FSharp.Compiler.Interactive.Shell.* (scripting support)
568+
* FSharp.Compiler.AbstractIL.* (for ILAssemblyReader hook for Rider)
569+
* FSharp.Compiler.SyntaxTree.* (direct access to full untyped tree)
570+
571+
These sections are generally designed with F#/.NET design conventions (e.g. types in namespaces, not modules, no nesting of modules etc.)
572+
and we will continue to iterate to make this so.
573+
574+
In contrast, the public parts of the compiler directly under `FSharp.Compiler.*` and `FSharp.AbstractIL.*` are
575+
"incidental" and not really designed for public use apart from the hook for Jet Brains Rider
576+
(Aside: In theory all these other parts could be renamed to FSharp.Compiler.Internal though there's no need to do that right now).
577+
These internal parts tend to be implemented with the "module containing lots of stuff in one big file" approach for layers of the compiler.
578+
579+
559580
### The F# Compiler Service Operations Queue
560581

561582
See [F# Compiler Service Queue](fsharp-compiler-service-queue.md).

docs/fcs/compiler.fsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ First, we need to reference the libraries that contain F# interactive service:
3030
#r "FSharp.Compiler.Service.dll"
3131
open System.IO
3232
open FSharp.Compiler.SourceCodeServices
33+
open FSharp.Compiler.Text
3334

3435
// Create an interactive checker instance
3536
let checker = FSharpChecker.Create()

docs/fcs/corelib.fsx

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,25 @@
44
Compiler Services: Notes on FSharp.Core.dll
55
=================================================
66
7+
Versions of FSharp.Core involved in the operation of FSharp.Compiler.Service
8+
---------------------------------------------
9+
10+
There are three versions of FSharp.Core relevant to the operation of FSharp.Compiler.Service:
11+
12+
1. **The FSharp.Compiler.Service.dll static reference to FSharp.Core** - The FCS DLL and nuget have a static minbound dependency on FSharp.Core.
13+
14+
This is just a normal .NET dependency like any other, it expresses the minimum surface area of FSharp.Core that the implementation of FSharp.Compiler.Service (and any components that depend on it) needs. It could be a reference to a reference assembly if we supported that. In theory this could be very low and all is cool - if we could implement FCS in terms of FSharp.Core 2.0.0.0 then that could be the minbound (indeed in theory we could implement FCS pretty almost without any use of FSharp.Core functionality at all, though obviously we don't)
15+
16+
In practice this is 0-2 versions behind latest FSharp.Core.
17+
18+
2. **The runtime reference to FSharp.Core in a tool, application or test suite that includes FSharp.Compiler.Service** - This is the actual version of FSharp.Core used when, say, fsc.exe or devenv.exe or fsi.exe or fsdocs.exe runs.
19+
20+
This must be at least as high as (1) and is usually the very latest FSharp.Core available (in or out of repo tree). This is important to the operation of the FCS-based tool because it is used for execution of scripts, and the default compilation reference for scripts. If scripts are going to use a particular language feature then this must be sufficient to support the language feature
21+
22+
3. **The FSharp.Core reference in a compilation or analysis being processed by FSharp.Compiler.Service**.
23+
24+
This can be anything - 2.0.0.0, 4.0.0.0 or 5.0.0 or whatever. For script compilation and execution is is the same as (2). It must be sufficient to support language features used in the compilation.
25+
726
Shipping an FSharp.Core with your application
827
---------------------------------------------
928
@@ -13,32 +32,6 @@ include a copy of FSharp.Core.dll as part of your application.
1332
For example, if you build a ``HostedCompiler.exe``, you will normally place an FSharp.Core.dll (say 4.3.1.0) alongside
1433
your ``HostedCompiler.exe``.
1534
16-
Binding redirects for your application
17-
--------------------------------------
18-
19-
The FSharp.Compiler.Service.dll component depends on FSharp.Core 4.4.0.0. Normally your application will target
20-
a later version of FSharp.Core, and you may need a [binding redirect](https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/redirect-assembly-versions) to ensure
21-
that other versions of FSharp.Core forward to the final version of FSharp.Core.dll your application uses.
22-
Binding redirect files are normally generated automatically by build tools. If not, you can use one like this
23-
(if your tool is called ``HostedCompiler.exe``, the binding redirect file is called ``HostedCompiler.exe.config``)
24-
25-
Some other dependencies may also need to be reconciled and forwarded.
26-
27-
<?xml version="1.0" encoding="utf-8" ?>
28-
<configuration>
29-
<runtime>
30-
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
31-
<dependentAssembly>
32-
<assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
33-
<bindingRedirect oldVersion="2.0.0.0-4.4.0.0" newVersion="4.4.1.0"/>
34-
</dependentAssembly>
35-
<dependentAssembly>
36-
<assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
37-
<bindingRedirect oldVersion="1.0.0.0-1.2.0.0" newVersion="1.2.1.0" />
38-
</dependentAssembly>
39-
</assemblyBinding>
40-
</runtime>
41-
</configuration>
4235
4336
Which FSharp.Core and .NET Framework gets referenced in compilation?
4437
--------------------------------------
@@ -89,6 +82,7 @@ Summary
8982
9083
In this design note we have discussed three things:
9184
85+
- the versions of FSharp.Core relevant to the operation of FSharp.Compiler.Service.dll
9286
- which FSharp.Core.dll is used to run your compilation tools
9387
- how to configure binding redirects for the FSharp.Core.dll used to run your compilation tools
9488
- which FSharp.Core.dll and/or framework assemblies are referenced during the checking and compilations performed by your tools.

docs/fcs/editor.fsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ identifier (the other option lets you get tooltip with full assembly location wh
128128
129129
*)
130130
// Get tag of the IDENT token to be used as the last argument
131-
open FSharp.Compiler
132131
let identToken = FSharpTokenTag.Identifier
133132

134133
// Get tool tip at the specified location

docs/fcs/filesystem.fsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ open System
2121
open System.IO
2222
open System.Collections.Generic
2323
open System.Text
24-
open FSharp.Compiler.AbstractIL.Internal.Library
24+
open FSharp.Compiler.SourceCodeServices
25+
open FSharp.Compiler.Text
2526

26-
let defaultFileSystem = Shim.FileSystem
27+
let defaultFileSystem = FileSystem
2728

2829
let fileName1 = @"c:\mycode\test1.fs" // note, the path doesn't exist
2930
let fileName2 = @"c:\mycode\test2.fs" // note, the path doesn't exist
@@ -91,15 +92,14 @@ let B = File1.A + File1.A"""
9192
defaultFileSystem.AssemblyLoad assemblyName
9293

9394
let myFileSystem = MyFileSystem()
94-
Shim.FileSystem <- MyFileSystem()
95+
FileSystem <- MyFileSystem()
9596

9697
(**
9798
9899
Doing a compilation with the FileSystem
99100
---------------------------------------
100101
101102
*)
102-
open FSharp.Compiler.SourceCodeServices
103103

104104
let checker = FSharpChecker.Create()
105105

docs/fcs/interactive.fsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ First, we need to reference the libraries that contain F# interactive service:
3131
*)
3232

3333
#r "FSharp.Compiler.Service.dll"
34-
open FSharp.Compiler.SourceCodeServices
3534
open FSharp.Compiler.Interactive.Shell
35+
open FSharp.Compiler.SourceCodeServices
36+
open FSharp.Compiler.Text
3637

3738
(**
3839
To communicate with F# interactive, we need to create streams that represent input and
@@ -227,7 +228,6 @@ based on the declarations executed so far.
227228
228229
You can also request declaration list information, tooltip text and symbol resolution:
229230
*)
230-
open FSharp.Compiler
231231

232232
// get a tooltip
233233
checkResults.GetToolTipText(1, 2, "xxx + xx", ["xxx"], FSharpTokenTag.IDENT)

docs/fcs/ja/corelib.fsx

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,6 @@ FSharp.Compiler.Service.dll を利用するアプリケーションまたはプ
1313
1414
動的コンパイルや動的実行を行う場合、FSharp.Core.optdata と FSharp.Core.sigdata も含める必要があるかもしれませんが、これらについては下記の指針をご覧ください。
1515
16-
あなたのアプリケーションにリダイレクトをバインドする
17-
----------------------------------------------------
18-
19-
FSharp.Compiler.Service.dll コンポーネントは FSharp.Core 4.3.0.0 に依存しています。通例、あなたのアプリケーションはこれより後のバージョンの FSharp.Core をターゲットにしており、FSharp.Core 4.3.0.0 をあなたのアプリケーションで用いる FSharp.Core.dll の最終バージョンにちゃんと転送させるように[バインド リダイレクト](https://msdn.microsoft.com/ja-jp/library/7wd6ex19(v=vs.110).aspx)が必要になるでしょう。バインド リダイレクト ファイルは通常ビルドツールによって自動的に生成されます。そうでない場合、下記のようなファイル(あなたのツールが ``HostedCompiler.exe`` という名前で、バインド リダイレクト ファイルが ``HostedCompiler.exe.config`` という名前の場合)を使うことが出来ます。
20-
21-
<?xml version="1.0" encoding="utf-8" ?>
22-
<configuration>
23-
<runtime>
24-
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
25-
<dependentAssembly>
26-
<assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
27-
<bindingRedirect oldVersion="2.0.0.0-4.3.0.0" newVersion="4.3.1.0"/>
28-
</dependentAssembly>
29-
<dependentAssembly>
30-
<assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
31-
<bindingRedirect oldVersion="1.0.0.0-1.2.0.0" newVersion="1.2.1.0" />
32-
</dependentAssembly>
33-
</assemblyBinding>
34-
</runtime>
35-
</configuration>
36-
3716
どの FSharp.Core と .NET フレームワークがコンパイル時に参照される?
3817
--------------------------------------
3918

docs/fcs/ja/editor.fsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ let checkFileResults =
138138
139139
*)
140140
// 最後の引数に指定する、IDENTトークンのタグを取得
141-
open FSharp.Compiler
142141

143142
// 特定の位置におけるツールチップを取得
144143
let tip = checkFileResults.GetToolTipText(4, 7, inputLines.[1], ["foo"], FSharpTokenTag.Identifier)

docs/fcs/ja/filesystem.fsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@ FileSystemの設定
1717
以下の例ではディスクからの読み取りを行うような実装をファイルシステムに設定しています:
1818
*)
1919
#r "FSharp.Compiler.Service.dll"
20-
open System
2120
open System.IO
22-
open System.Collections.Generic
2321
open System.Text
24-
open FSharp.Compiler.AbstractIL.Internal.Library
22+
open FSharp.Compiler.SourceCodeServices
23+
open FSharp.Compiler.Text
2524

26-
let defaultFileSystem = Shim.FileSystem
25+
let defaultFileSystem = FileSystem
2726

2827
let fileName1 = @"c:\mycode\test1.fs" // 注意: 実際には存在しないファイルのパス
2928
let fileName2 = @"c:\mycode\test2.fs" // 注意: 実際には存在しないファイルのパス
@@ -91,7 +90,7 @@ let B = File1.A + File1.A"""
9190
defaultFileSystem.AssemblyLoad assemblyName
9291

9392
let myFileSystem = MyFileSystem()
94-
Shim.FileSystem <- MyFileSystem()
93+
FileSystem <- MyFileSystem()
9594

9695
(**
9796

docs/fcs/ja/interactive.fsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ F# Interactiveの開始
4343

4444
#r "FSharp.Compiler.Service.dll"
4545
open FSharp.Compiler.SourceCodeServices
46+
open FSharp.Compiler.Text
4647
open FSharp.Compiler.Interactive.Shell
4748

4849
(**
@@ -244,7 +245,6 @@ checkResults.Errors.Length // 1
244245
要求することもできます:
245246
246247
*)
247-
open FSharp.Compiler
248248

249249
// ツールチップを取得する
250250
checkResults.GetToolTipText(1, 2, "xxx + xx", ["xxx"], FSharpTokenTag.IDENT)

docs/fcs/ja/tokenizer.fsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ F#のソースコードに対して、トークナイザは
2222
*)
2323
#r "FSharp.Compiler.Service.dll"
2424
open FSharp.Compiler.SourceCodeServices
25+
open FSharp.Compiler.Text
2526
(**
2627
すると `FSharpSourceTokenizer` のインスタンスを作成できるようになります。
2728
このクラスには2つの引数を指定します。
@@ -32,7 +33,7 @@ open FSharp.Compiler.SourceCodeServices
3233
ファイル名はソースコードの位置を特定する場合にのみ指定する必要があります
3334
(存在しないファイル名でも指定できます):
3435
*)
35-
let sourceTok = FSharpSourceTokenizer([], "C:\\test.fsx")
36+
let sourceTok = FSharpSourceTokenizer([], Some "C:\\test.fsx")
3637
(**
3738
`sourceTok` オブジェクトを使用することでF#ソースコードの各行を
3839
(繰り返し)トークン化することができます。

docs/fcs/tokenizer.fsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ To use the tokenizer, reference `FSharp.Compiler.Service.dll` and open the
2121
*)
2222
#r "FSharp.Compiler.Service.dll"
2323
open FSharp.Compiler.SourceCodeServices
24+
open FSharp.Compiler.Text
2425
(**
2526
Now you can create an instance of `FSharpSourceTokenizer`. The class takes two
2627
arguments - the first is the list of defined symbols and the second is the

docs/fcs/untypedtree.fsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ code](https://github.com/fsharp/fsharp/blob/master/src/fsharp/ast.fs#L464).
8484
8585
The relevant parts are in the following namespace:
8686
*)
87-
open FSharp.Compiler.Ast
87+
open FSharp.Compiler.SyntaxTree
8888
(**
8989
9090
When processing the AST, you will typically write a number of mutually recursive functions
@@ -126,7 +126,8 @@ options). In the following, we only show how to handle `if .. then ..` and `let
126126
/// Walk over an expression - if expression contains two or three
127127
/// sub-expressions (two if the 'else' branch is missing), let expression
128128
/// contains pattern and two sub-expressions
129-
let rec visitExpression = function
129+
let rec visitExpression e =
130+
match e with
130131
| SynExpr.IfThenElse(cond, trueBranch, falseBranchOpt, _, _, _, _) ->
131132
// Visit all sub-expressions
132133
printfn "Conditional:"

0 commit comments

Comments
 (0)