未验证 提交 d31eae10 编写于 作者: D Don Syme 提交者: GitHub

fix 13043 (#13065)

* Fix https://github.com/dotnet/fsharp/issues/13043

* with debug

* remove labels

* rename

* Remove extra line

* fix 13043

* baselines

* temp

* Disable il test for now

* opt/non-opt

* proper no_opt

* proper optimize+

* merge main

* strip lambdas correctly during codegen

* proper treatment of typed expressions

* update baselines

* baseline

* simplify
Co-authored-by: NKevin Ransom <codecutter@hotmail.com>
上级 2de40458
......@@ -5850,7 +5850,7 @@ and TcNonControlFlowExpr (env: TcEnv) f =
| NotedSourceConstruct.Combine
| NotedSourceConstruct.With
| NotedSourceConstruct.While
| NotedSourceConstruct.DelayOrQuoteOrRun ->
| NotedSourceConstruct.DelayOrQuoteOrRun ->
res, tpenv
| NotedSourceConstruct.None ->
// Skip outer debug point for "e1 && e2" and "e1 || e2"
......@@ -5929,7 +5929,6 @@ and TcExprUndelayed cenv (overallTy: OverallTy) env tpenv (synExpr: SynExpr) =
// e: ty
| SynExpr.Typed (synBodyExpr, synType, m) ->
TcNonControlFlowExpr env <| fun env ->
TcExprTypeAnnotated cenv overallTy env tpenv (synBodyExpr, synType, m)
// e :? ty
......
......@@ -7,14 +7,23 @@ open FSharp.Test.Compiler
module TestFunctions =
let verifyCompilation compilation =
let verifyCore compilation =
compilation
|> withOptions [ "--test:EmitFeeFeeAs100001" ]
|> withOptions [ "--test:EmitFeeFeeAs100001"; "--nowarn:988"; "--nowarn:3370"]
|> asExe
|> withNoOptimize
|> withEmbeddedPdb
|> withEmbedAllSource
|> ignoreWarnings
let verifyCompileAndRun compilation =
compilation
|> verifyCore
|> compileAndRun
let verifyCompilation compilation =
compilation
|> verifyCore
|> verifyILBaseline
//SOURCE=TestFunction01.fs SCFLAGS="-g --test:EmitFeeFeeAs100001 --optimize-" COMPILE_ONLY=1 POSTCMD="..\\CompareIL.cmd TestFunction01.exe" # TestFunction01.fs
......@@ -245,3 +254,28 @@ module TestFunctions =
compilation
|> verifyCompilation
// Verify IL 13043
[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"Verify13043.fs"|])>]
let ``Verify13043_il`` compilation =
compilation
|> withDebug
|> verifyCompilation
// Verify Execution 13043 run it built not optimized with debug
[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"Verify13043.fs"|])>]
let ``Verify13043_execution_noopt`` compilation =
compilation
|> withDebug
|> verifyCompileAndRun
|> shouldSucceed
// Verify Execution 13043 --- run it built optimized no debug
[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"Verify13043.fs"|])>]
let ``Verify13043_execution_opt`` compilation =
compilation
|> asExe
|> withOptions [ "--test:EmitFeeFeeAs100001"; "--nowarn:988"; "--nowarn:3370"]
|> withOptimize
|> withNoDebug
|> compileAndRun
|> shouldSucceed
module Verify13043
let list = [1; 2; 3]
let condition n = n < 3
let dropWhileWithMatch condition list =
let rec f (l : List<int>) : List<int> =
match l with
| [] -> []
| head :: tail ->
match condition head with
| true -> f tail
| false -> head :: tail
f list
(*
This function caused an Unhandled exception at execution time:
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
at Program.f@14-1.Invoke(FSharpList`1 _arg1) in /workspaces/function-rec-fsharp-dotnet7-bug-demo/Program.fs:line 18
at Program.dropWhileWithFunction(FSharpFunc`2 condition, FSharpList`1 list) in /workspaces/function-rec-fsharp-dotnet7-bug-demo/Program.fs:line 21
at <StartupCode$function-rec-fsharp-dotnet7-bug-demo>.$Program.main@() in /workspaces/function-rec-fsharp-dotnet7-bug-demo/Program.fs:line 29
*)
let dropWhileWithFunction condition list =
let rec f : List<int> -> List<int> =
function
| [] -> []
| head :: tail ->
match condition head with
| true -> f tail
| false -> head :: tail
f list
// this runs fine:
let matchResult = dropWhileWithMatch condition list
printfn "Match: %A" matchResult
// and this results in a null reference exception
let functionResult = dropWhileWithFunction condition list
printfn "Function: %A" functionResult
......@@ -193,6 +193,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(FSharpSourcesRoot)\fsharp\FSharp.Compiler.Service\FSharp.Compiler.Service.fsproj" />
<ProjectReference Include="$(FSharpSourcesRoot)\fsharp\FSharp.Compiler.Interactive.Settings\FSharp.Compiler.Interactive.Settings.fsproj" />
<ProjectReference Include="$(FSharpSourcesRoot)\fsharp\FSharp.Core\FSharp.Core.fsproj" />
<ProjectReference Include="$(FSharpTestsRoot)\FSharp.Test.Utilities\FSharp.Test.Utilities.fsproj" />
</ItemGroup>
......
......@@ -342,6 +342,12 @@ module rec Compiler =
| FS fs -> FS { fs with Options = fs.Options @ options }
| _ -> failwith message
let withDebug (cUnit: CompilationUnit) : CompilationUnit =
withOptionsHelper [ "--debug+" ] "debug+ is only supported on F#" cUnit
let withNoDebug (cUnit: CompilationUnit) : CompilationUnit =
withOptionsHelper [ "--debug-" ] "debug- is only supported on F#" cUnit
let withOcamlCompat (cUnit: CompilationUnit) : CompilationUnit =
withOptionsHelper [ "--mlcompatibility" ] "withOcamlCompat is only supported on F#" cUnit
......@@ -845,8 +851,8 @@ module rec Compiler =
// if the environment variable TEST_UPDATE_BSL has been set
if snd (Int32.TryParse(Environment.GetEnvironmentVariable("TEST_UPDATE_BSL"))) <> 0 then
match baseline with
| Some baseline -> System.IO.File.Copy(baseline.ILBaseline.FilePath, baseline.ILBaseline.BslSource, true)
| None -> ()
| Some baseline -> System.IO.File.Copy(baseline.ILBaseline.FilePath, baseline.ILBaseline.BslSource, true)
| None -> ()
createBaselineErrors bsl.ILBaseline actualIL
Assert.Fail(errorMsg)
......
......@@ -66,8 +66,8 @@ type DirectoryAttribute(dir: string) =
let readFileOrDefault (path: string) : string option =
match FileSystem.FileExistsShim(path) with
| true -> Some <| File.ReadAllText path
| _ -> None
| true -> Some (File.ReadAllText path)
| _ -> None
let createCompilationUnit path fs name =
let outputDirectory = outputDirectory name
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册