Skip to content

Commit b2aee70

Browse files
authored
Merge pull request #3167 from Martin521/WarnScopes
Adaptation to breaking FCS changes in sdk 9.0 and 10.0
2 parents 57a1ad7 + 451e001 commit b2aee70

Some content is hidden

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

44 files changed

+645
-811
lines changed

.devcontainer/Dockerfile

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM mcr.microsoft.com/dotnet/sdk:8.0.400
1+
FROM mcr.microsoft.com/dotnet/sdk:10.0.100
22

33
# Avoid warnings by switching to noninteractive
44
ENV DEBIAN_FRONTEND=noninteractive
@@ -19,8 +19,16 @@ RUN apt-get update \
1919
&& apt-get -y install git iproute2 procps lsb-release \
2020
#
2121
# Create a non-root user to use if preferred - see https://aka.ms/vscode-remote/containers/non-root-user.
22-
&& groupadd --gid $USER_GID $USERNAME \
23-
&& useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \
22+
# Create group if it doesn't exist (handle case where GID already exists)
23+
&& if ! getent group $USERNAME > /dev/null 2>&1; then \
24+
groupadd --gid $USER_GID $USERNAME 2>/dev/null || \
25+
(EXISTING_GROUP=$(getent group $USER_GID | cut -d: -f1) && groupmod -n $USERNAME $EXISTING_GROUP); \
26+
fi \
27+
# Create user if it doesn't exist (handle case where UID already exists)
28+
&& if ! getent passwd $USERNAME > /dev/null 2>&1; then \
29+
useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME 2>/dev/null || \
30+
(EXISTING_USER=$(getent passwd $USER_UID | cut -d: -f1) && usermod -l $USERNAME -d /home/$USERNAME -m $EXISTING_USER); \
31+
fi \
2432
# [Optional] Add sudo support for the non-root user
2533
&& apt-get install -y sudo \
2634
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME\

.devcontainer/devcontainer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@
3030
// Use 'postCreateCommand' to run commands after the container is created.
3131
"postCreateCommand": "dotnet tool restore && dotnet restore",
3232

33-
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
34-
"remoteUser": "root"
33+
// Use the non-root user created in the Dockerfile. More info: https://aka.ms/dev-containers-non-root.
34+
"remoteUser": "vscode"
3535
}

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Some common use cases include:
4545

4646
<!-- Versions -->
4747
<PropertyGroup>
48-
<FCSCommitHash>e668b90e3c087e5fba8a855e502af60bf35be45e</FCSCommitHash>
48+
<FCSCommitHash>43932b4c7984d6562e91e5f1484868cd4f5befcf</FCSCommitHash>
4949
</PropertyGroup>
5050

5151
<PropertyGroup>

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
55
</PropertyGroup>
66
<ItemGroup>
7-
<PackageVersion Include="FSharp.Core" Version="8.0.100"/>
7+
<PackageVersion Include="FSharp.Core" Version="9.0.300"/>
88
<PackageVersion Include="System.Collections.Immutable" Version="8.0.0" />
99
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="8.0.1" />
1010
<PackageVersion Include="System.Memory" Version="4.6.0" />

build.fsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ pipeline "Init" {
233233
"src/Compiler/Utilities/NullnessShims.fs"
234234
"src/Compiler/Utilities/Activity.fsi"
235235
"src/Compiler/Utilities/Activity.fs"
236+
"src/Compiler/Utilities/Caches.fsi"
237+
"src/Compiler/Utilities/Caches.fs"
236238
"src/Compiler/Utilities/sformat.fsi"
237239
"src/Compiler/Utilities/sformat.fs"
238240
"src/Compiler/Utilities/sr.fsi"
@@ -301,6 +303,10 @@ pipeline "Init" {
301303
"src/Compiler/SyntaxTree/SyntaxTree.fs"
302304
"src/Compiler/SyntaxTree/SyntaxTreeOps.fsi"
303305
"src/Compiler/SyntaxTree/SyntaxTreeOps.fs"
306+
"src/Compiler/SyntaxTree/WarnScopes.fsi"
307+
"src/Compiler/SyntaxTree/WarnScopes.fs"
308+
"src/Compiler/SyntaxTree/LexerStore.fsi"
309+
"src/Compiler/SyntaxTree/LexerStore.fs"
304310
"src/Compiler/SyntaxTree/ParseHelpers.fsi"
305311
"src/Compiler/SyntaxTree/ParseHelpers.fs"
306312
"src/Compiler/SyntaxTree/LexHelpers.fsi"

docs/docs/contributors/Transforming.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ let a =
7474
Depending on the defines `[]` or `["DEBUG"]`, the AST will be different.
7575
The tree will also be created based on a single code path.
7676

77+
You can use your locally installed F# compiler to parse a file and view the AST via:
78+
79+
```shell
80+
# Tip: figure out the location of your installed sdk
81+
whereis dotnet
82+
# Invoke the parser
83+
dotnet '/Users/nojaf/Library/Application Support/dnvm/dn/sdk/10.0.100/FSharp/fsc.dll' --parseonly --ast foo.fs
84+
```
85+
7786
### Transform untyped AST to Oak
7887

7988
The untyped syntax tree from the F# compiler is used as an intermediate representation of source code in the process of transforming a text file to binary.

docs/docs/end-users/GeneratingCode.fsx

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,25 @@ let implementationSyntaxTree =
5656
[ BindingNode(
5757
None,
5858
None,
59-
MultipleTextsNode([ SingleTextNode("let", Range.Zero) ], Range.Zero),
59+
MultipleTextsNode([ SingleTextNode("let", Range.range0) ], Range.range0),
6060
false,
6161
None,
6262
None,
63-
Choice1Of2(IdentListNode([ IdentifierOrDot.Ident(SingleTextNode("a", Range.Zero)) ], Range.Zero)),
63+
Choice1Of2(
64+
IdentListNode([ IdentifierOrDot.Ident(SingleTextNode("a", Range.range0)) ], Range.range0)
65+
),
6466
None,
6567
[],
6668
None,
67-
SingleTextNode("=", Range.Zero),
68-
Expr.Constant(Constant.FromText(SingleTextNode("0", Range.Zero))),
69-
Range.Zero
69+
SingleTextNode("=", Range.range0),
70+
Expr.Constant(Constant.FromText(SingleTextNode("0", Range.range0))),
71+
None,
72+
Range.range0
7073
)
7174
|> ModuleDecl.TopLevelBinding ],
72-
Range.Zero
75+
Range.range0
7376
) ],
74-
Range.Zero
77+
Range.range0
7578
)
7679

7780
open Fantomas.Core
@@ -92,7 +95,7 @@ Let's deconstruct a couple of things:
9295
9396
- The `functionName ` of binding contains the name or is a pattern.
9497
- The `expr` ([Expr](../../reference/fantomas-core-syntaxoak-expr.html)) represents the F# syntax expression.
95-
- Because there is no actual source code, all ranges will be `Range.Zero`.
98+
- Because there is no actual source code, all ranges will be `Range.range0`.
9699
97100
The more you interact with AST/Oak, the easier you pick up which node represents what.
98101
@@ -141,18 +144,18 @@ Please make sure you construct the same Oak as Fantomas would.
141144
*)
142145

143146
// You typically make some helper functions along the way
144-
let text v = SingleTextNode(v, Range.Zero)
147+
let text v = SingleTextNode(v, Range.range0)
145148

146149
let mkCodeFromExpression (e: Expr) =
147-
Oak([], [ ModuleOrNamespaceNode(None, [ ModuleDecl.DeclExpr e ], Range.Zero) ], Range.Zero)
150+
Oak([], [ ModuleOrNamespaceNode(None, [ ModuleDecl.DeclExpr e ], Range.range0) ], Range.range0)
148151
|> CodeFormatter.FormatOakAsync
149152
|> Async.RunSynchronously
150153
|> printfn "%s"
151154

152155
let numberExpr = Expr.Constant(Constant.FromText(text "7"))
153156

154157
let wrappedNumber =
155-
Expr.Paren(ExprParenNode(text "(", numberExpr, text ")", Range.Zero))
158+
Expr.Paren(ExprParenNode(text "(", numberExpr, text ")", Range.range0))
156159

157160
mkCodeFromExpression wrappedNumber
158161
(*** include-output ***)
@@ -187,16 +190,16 @@ Oak (1,0-1,16)
187190

188191
let lambdaExpr =
189192
let body: Expr =
190-
ExprInfixAppNode(Expr.Ident(text "a"), text "+", Expr.Ident(text "b"), Range.Zero)
193+
ExprInfixAppNode(Expr.Ident(text "a"), text "+", Expr.Ident(text "b"), Range.range0)
191194
|> Expr.InfixApp
192195

193196
ExprLambdaNode(
194197
text "fun",
195-
[ Pattern.Named(PatNamedNode(None, text "a", Range.Zero))
196-
Pattern.Named(PatNamedNode(None, text "b", Range.Zero)) ],
198+
[ Pattern.Named(PatNamedNode(None, text "a", Range.range0))
199+
Pattern.Named(PatNamedNode(None, text "b", Range.range0)) ],
197200
text "->",
198201
body,
199-
Range.Zero
202+
Range.range0
200203
)
201204
|> Expr.Lambda
202205

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "8.0.400",
3+
"version": "10.0.100",
44
"rollForward": "latestPatch"
55
}
66
}

scripts/ast.fsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#r "../artifacts/bin/Fantomas.FCS/debug/Fantomas.FCS.dll"
2+
3+
open System.IO
4+
5+
match Array.tryHead fsi.CommandLineArgs with
6+
| Some scriptPath ->
7+
let scriptFile = FileInfo(scriptPath)
8+
let sourceFile = FileInfo(Path.Combine(__SOURCE_DIRECTORY__, __SOURCE_FILE__))
9+
10+
if scriptFile.FullName = sourceFile.FullName then
11+
let inputPath = fsi.CommandLineArgs.[fsi.CommandLineArgs.Length - 1]
12+
let sample = File.ReadAllText(inputPath)
13+
let isSignature = inputPath.EndsWith(".fsi")
14+
15+
let ast =
16+
Fantomas.FCS.Parse.parseFile isSignature (Fantomas.FCS.Text.SourceText.ofString sample) []
17+
|> fst
18+
19+
ast |> printfn "%A"
20+
| _ -> printfn "Usage: dotnet fsi ast.fsx <input file>"

scripts/oak.fsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#r "../artifacts/bin/Fantomas.FCS/debug/Fantomas.FCS.dll"
2+
#r "../artifacts/bin/Fantomas.Core/debug/Fantomas.Core.dll"
3+
4+
open System.Threading.Tasks
5+
open Fantomas.Core
6+
7+
let parseOak (input: string) (isSignature: bool) : Task<string> =
8+
task {
9+
try
10+
let! oaks = CodeFormatter.ParseOakAsync(isSignature, input)
11+
12+
match Array.tryHead oaks with
13+
| None -> return "No Oak found in input"
14+
| Some(oak, _) -> return (string oak)
15+
16+
with ex ->
17+
return $"Error while parsing to Oak: %A{ex}"
18+
}
19+
20+
open System.IO
21+
22+
match Array.tryHead fsi.CommandLineArgs with
23+
| Some scriptPath ->
24+
let scriptFile = FileInfo(scriptPath)
25+
let sourceFile = FileInfo(Path.Combine(__SOURCE_DIRECTORY__, __SOURCE_FILE__))
26+
27+
if scriptFile.FullName = sourceFile.FullName then
28+
let inputPath = fsi.CommandLineArgs.[fsi.CommandLineArgs.Length - 1]
29+
let sample = File.ReadAllText(inputPath)
30+
let isSignature = inputPath.EndsWith(".fsi")
31+
32+
parseOak sample isSignature
33+
|> Async.AwaitTask
34+
|> Async.RunSynchronously
35+
|> printfn "%s"
36+
| _ -> printfn "Usage: dotnet fsi oak.fsx <input file>"

0 commit comments

Comments
 (0)