Skip to content

Commit

Permalink
Merge pull request #6574 from Microsoft/merges/master-to-nullness
Browse files Browse the repository at this point in the history
Merge master to nullness
  • Loading branch information
dotnet-automerge-bot authored Apr 19, 2019
2 parents c8d40a5 + 0842454 commit a2e4c63
Show file tree
Hide file tree
Showing 22 changed files with 224 additions and 111 deletions.
151 changes: 134 additions & 17 deletions benchmarks/CompilerServiceBenchmarks/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ open FSharp.Compiler.Text
open FSharp.Compiler.AbstractIL
open FSharp.Compiler.AbstractIL.IL
open FSharp.Compiler.AbstractIL.ILBinaryReader
open CodeAnalysis.Text
open Microsoft.CodeAnalysis.Text
open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Running

Expand Down Expand Up @@ -80,6 +80,49 @@ type SourceText with
member this.ToFSharpSourceText() =
SourceText.weakTable.GetValue(this, Runtime.CompilerServices.ConditionalWeakTable<_,_>.CreateValueCallback(SourceText.create))

[<AutoOpen>]
module Helpers =

let createProject name referencedProjects =
let tmpPath = Path.GetTempPath()
let file = Path.Combine(tmpPath, Path.ChangeExtension(name, ".fs"))
{
ProjectFileName = Path.Combine(tmpPath, Path.ChangeExtension(name, ".dll"))
ProjectId = None
SourceFiles = [|file|]
OtherOptions =
Array.append [|"--optimize+"; "--target:library" |] (referencedProjects |> Array.ofList |> Array.map (fun x -> "-r:" + x.ProjectFileName))
ReferencedProjects =
referencedProjects
|> List.map (fun x -> (x.ProjectFileName, x))
|> Array.ofList
IsIncompleteTypeCheckEnvironment = false
UseScriptResolutionRules = false
LoadTime = DateTime()
UnresolvedReferences = None
OriginalLoadReferences = []
ExtraProjectInfo = None
Stamp = Some 0L (* set the stamp to 0L on each run so we don't evaluate the whole project again *)
}

let generateSourceCode moduleName =
sprintf """
module Benchmark.%s
type %s =
val X : int
val Y : int
val Z : int
let function%s (x: %s) =
let x = 1
let y = 2
let z = x + y
z""" moduleName moduleName moduleName moduleName

[<MemoryDiagnoser>]
type CompilerService() =

Expand Down Expand Up @@ -112,7 +155,7 @@ type CompilerService() =
[<GlobalSetup>]
member __.Setup() =
match checkerOpt with
| None -> checkerOpt <- Some(FSharpChecker.Create())
| None -> checkerOpt <- Some(FSharpChecker.Create(projectCacheSize = 200))
| _ -> ()

match sourceOpt with
Expand All @@ -127,30 +170,25 @@ type CompilerService() =
|> Array.map (fun x -> (x.Location))
|> Some
| _ -> ()

[<IterationSetup(Target = "Parsing")>]
member __.ParsingSetup() =
match checkerOpt with
| None -> failwith "no checker"
| Some(checker) ->
checker.InvalidateAll()
checker.ClearLanguageServiceRootCachesAndCollectAndFinalizeAllTransients()
checker.ParseFile("dummy.fs", SourceText.ofString "dummy", parsingOptions) |> Async.RunSynchronously |> ignore

[<Benchmark>]
member __.Parsing() =
member __.ParsingTypeCheckerFs() =
match checkerOpt, sourceOpt with
| None, _ -> failwith "no checker"
| _, None -> failwith "no source"
| Some(checker), Some(source) ->
let results = checker.ParseFile("TypeChecker.fs", source.ToFSharpSourceText(), parsingOptions) |> Async.RunSynchronously
if results.ParseHadErrors then failwithf "parse had errors: %A" results.Errors

[<IterationSetup(Target = "ILReading")>]
member __.ILReadingSetup() =
// With caching, performance increases an order of magnitude when re-reading an ILModuleReader.
// Clear it for benchmarking.
ClearAllILModuleReaderCache()
[<IterationCleanup(Target = "ParsingTypeCheckerFs")>]
member __.ParsingTypeCheckerFsSetup() =
match checkerOpt with
| None -> failwith "no checker"
| Some(checker) ->
checker.InvalidateAll()
checker.ClearLanguageServiceRootCachesAndCollectAndFinalizeAllTransients()
checker.ParseFile("dummy.fs", SourceText.ofString "dummy", parsingOptions) |> Async.RunSynchronously |> ignore
ClearAllILModuleReaderCache()

[<Benchmark>]
member __.ILReading() =
Expand Down Expand Up @@ -198,6 +236,85 @@ type CompilerService() =
)
)

[<IterationCleanup(Target = "ILReading")>]
member __.ILReadingSetup() =
// With caching, performance increases an order of magnitude when re-reading an ILModuleReader.
// Clear it for benchmarking.
ClearAllILModuleReaderCache()

member val TypeCheckFileWith100ReferencedProjectsOptions =
createProject "MainProject"
[ for i = 1 to 100 do
yield
createProject ("ReferencedProject" + string i) []
]

member this.TypeCheckFileWith100ReferencedProjectsRun() =
let options = this.TypeCheckFileWith100ReferencedProjectsOptions
let file = options.SourceFiles.[0]

match checkerOpt with
| None -> failwith "no checker"
| Some checker ->
let parseResult, checkResult =
checker.ParseAndCheckFileInProject(file, 0, SourceText.ofString (File.ReadAllText(file)), options)
|> Async.RunSynchronously

if parseResult.Errors.Length > 0 then
failwithf "%A" parseResult.Errors

match checkResult with
| FSharpCheckFileAnswer.Aborted -> failwith "aborted"
| FSharpCheckFileAnswer.Succeeded checkFileResult ->

if checkFileResult.Errors.Length > 0 then
failwithf "%A" checkFileResult.Errors

[<IterationSetup(Target = "TypeCheckFileWith100ReferencedProjects")>]
member this.TypeCheckFileWith100ReferencedProjectsSetup() =
this.TypeCheckFileWith100ReferencedProjectsOptions.SourceFiles
|> Seq.iter (fun file ->
File.WriteAllText(file, generateSourceCode (Path.GetFileNameWithoutExtension(file)))
)

this.TypeCheckFileWith100ReferencedProjectsOptions.ReferencedProjects
|> Seq.iter (fun (_, referencedProjectOptions) ->
referencedProjectOptions.SourceFiles
|> Seq.iter (fun file ->
File.WriteAllText(file, generateSourceCode (Path.GetFileNameWithoutExtension(file)))
)
)

this.TypeCheckFileWith100ReferencedProjectsRun()

[<Benchmark>]
member this.TypeCheckFileWith100ReferencedProjects() =
// Because the checker's projectcachesize is set to 200, this should be fast.
// If set to 3, it will be almost as slow as re-evaluating all project and it's projects references on setup; this could be a bug or not what we want.
this.TypeCheckFileWith100ReferencedProjectsRun()

[<IterationCleanup(Target = "TypeCheckFileWith100ReferencedProjects")>]
member this.TypeCheckFileWith100ReferencedProjectsCleanup() =
this.TypeCheckFileWith100ReferencedProjectsOptions.SourceFiles
|> Seq.iter (fun file ->
try File.Delete(file) with | _ -> ()
)

this.TypeCheckFileWith100ReferencedProjectsOptions.ReferencedProjects
|> Seq.iter (fun (_, referencedProjectOptions) ->
referencedProjectOptions.SourceFiles
|> Seq.iter (fun file ->
try File.Delete(file) with | _ -> ()
)
)

match checkerOpt with
| None -> failwith "no checker"
| Some(checker) ->
checker.InvalidateAll()
checker.ClearLanguageServiceRootCachesAndCollectAndFinalizeAllTransients()
ClearAllILModuleReaderCache()

[<EntryPoint>]
let main argv =
let _ = BenchmarkRunner.Run<CompilerService>()
Expand Down
3 changes: 0 additions & 3 deletions benchmarks/Directory.Build.props

This file was deleted.

3 changes: 0 additions & 3 deletions benchmarks/Directory.Build.targets

This file was deleted.

4 changes: 2 additions & 2 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<ProductDependencies>
</ProductDependencies>
<ToolsetDependencies>
<Dependency Name="Microsoft.DotNet.Arcade.Sdk" Version="1.0.0-beta.19217.1">
<Dependency Name="Microsoft.DotNet.Arcade.Sdk" Version="1.0.0-beta.19218.1">
<Uri>https://github.com/dotnet/arcade</Uri>
<Sha>4e21d52dabbb9f5705a90f097acb1465a0354c0d</Sha>
<Sha>46718d98c0fd03690a6a8c83da692a4a85a17902</Sha>
</Dependency>
</ToolsetDependencies>
</Dependencies>
44 changes: 34 additions & 10 deletions eng/common/CheckSymbols.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Add-Type -AssemblyName System.IO.Compression.FileSystem
function FirstMatchingSymbolDescriptionOrDefault {
param(
[string] $FullPath, # Full path to the module that has to be checked
[string] $TargetServerParam # Parameter to pass to `Symbol Tool` indicating the server to lookup for symbols
[string] $TargetServerParam, # Parameter to pass to `Symbol Tool` indicating the server to lookup for symbols
[string] $SymbolsPath
)

$FileName = [System.IO.Path]::GetFileName($FullPath)
Expand All @@ -33,9 +34,9 @@ function FirstMatchingSymbolDescriptionOrDefault {

# DWARF file for a .dylib
$DylibDwarf = $SymbolPath.Replace($Extension, ".dylib.dwarf")
.\dotnet-symbol.exe --symbols --modules $TargetServerParam $FullPath -o $SymbolsPath -d | Out-Null

.\dotnet-symbol.exe --symbols --modules --windows-pdbs $TargetServerParam $FullPath -o $SymbolsPath | Out-Null

if (Test-Path $PdbPath) {
return "PDB"
}
Expand Down Expand Up @@ -73,8 +74,9 @@ function CountMissingSymbols {
$MissingSymbols = 0

$PackageId = [System.IO.Path]::GetFileNameWithoutExtension($PackagePath)
$ExtractPath = $ExtractPath + $PackageId;
$SymbolsPath = $ExtractPath + $PackageId + ".Symbols";
$PackageGuid = New-Guid
$ExtractPath = Join-Path -Path $ExtractPath -ChildPath $PackageGuid
$SymbolsPath = Join-Path -Path $ExtractPath -ChildPath "Symbols"

[System.IO.Compression.ZipFile]::ExtractToDirectory($PackagePath, $ExtractPath)

Expand All @@ -84,10 +86,15 @@ function CountMissingSymbols {
Get-ChildItem -Recurse $ExtractPath |
Where-Object {$RelevantExtensions -contains $_.Extension} |
ForEach-Object {
Write-Host -NoNewLine "`t Checking file" $_.FullName "... "
if ($_.FullName -Match "\\ref\\") {
Write-Host "`t Ignoring reference assembly file" $_.FullName
return
}

$SymbolsOnMSDL = FirstMatchingSymbolDescriptionOrDefault $_.FullName "--microsoft-symbol-server"
$SymbolsOnSymWeb = FirstMatchingSymbolDescriptionOrDefault $_.FullName "--internal-server"
$SymbolsOnMSDL = FirstMatchingSymbolDescriptionOrDefault $_.FullName "--microsoft-symbol-server" $SymbolsPath
$SymbolsOnSymWeb = FirstMatchingSymbolDescriptionOrDefault $_.FullName "--internal-server" $SymbolsPath

Write-Host -NoNewLine "`t Checking file" $_.FullName "... "

if ($SymbolsOnMSDL -ne $null -and $SymbolsOnSymWeb -ne $null) {
Write-Host "Symbols found on MSDL (" $SymbolsOnMSDL ") and SymWeb (" $SymbolsOnSymWeb ")"
Expand Down Expand Up @@ -116,18 +123,35 @@ function CountMissingSymbols {

function CheckSymbolsAvailable {
if (Test-Path $ExtractPath) {
Remove-Item -recurse $ExtractPath
Remove-Item $ExtractPath -Force -Recurse -ErrorAction SilentlyContinue
}

Get-ChildItem "$InputPath\*.nupkg" |
ForEach-Object {
$FileName = $_.Name

# These packages from Arcade-Services include some native libraries that
# our current symbol uploader can't handle. Below is a workaround until
# we get issue: https://github.com/dotnet/arcade/issues/2457 sorted.
if ($FileName -Match "Microsoft\.DotNet\.Darc\.") {
Write-Host "Ignoring Arcade-services file: $FileName"
Write-Host
return
}
elseif ($FileName -Match "Microsoft\.DotNet\.Maestro\.Tasks\.") {
Write-Host "Ignoring Arcade-services file: $FileName"
Write-Host
return
}

Write-Host "Validating $FileName "
$Status = CountMissingSymbols "$InputPath\$FileName"

if ($Status -ne 0) {
Write-Error "Missing symbols for $Status modules in the package $FileName"
}

Write-Host
}
}

Expand Down
15 changes: 15 additions & 0 deletions fcs/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,19 @@
<IntermediateOutputPath>$(ArtifactsObjDir)\fcs</IntermediateOutputPath>
<DisableCompilerRedirection>true</DisableCompilerRedirection>
</PropertyGroup>

<!-- SDK targets override -->
<PropertyGroup>
<FSharpSourcesRoot>$(MSBuildThisFileDirectory)..\src</FSharpSourcesRoot>
<VersionPrefix>22.0.3</VersionPrefix>
<OtherFlags>--version:$(VersionPrefix)</OtherFlags>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<!-- FSharp.Compiler.Tools is currently only used to get a working FSI.EXE to execute some scripts during the build -->
<!-- The LKG FSI.EXE requires MSBuild 15 to be installed, which is painful -->
<ToolsetFsiToolPath>$(FSharpSourcesRoot)\..\packages\FSharp.Compiler.Tools.4.1.27\tools</ToolsetFsiToolPath>
<ToolsetFsiToolExe>fsi.exe</ToolsetFsiToolExe>
<ProtoOutputPath>$(ArtifactsBinDir)\FSharp.Build\Proto\net472</ProtoOutputPath>
<FcsFSharpCorePkgVersion>4.6.2</FcsFSharpCorePkgVersion>
<FcsTargetNetFxFramework>net461</FcsTargetNetFxFramework>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<FSharpSourcesRoot>$(MSBuildProjectDirectory)\..\..\src</FSharpSourcesRoot>
</PropertyGroup>
<Import Project="..\fcs.props" />
<Import Project="..\netfx.props" />
<PropertyGroup>
<TargetFrameworks>net461</TargetFrameworks>
<TargetFrameworks>$(FcsTargetNetFxFramework)</TargetFrameworks>
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
<DefineConstants>$(DefineConstants);CROSS_PLATFORM_COMPILER</DefineConstants>
<DefineConstants>$(DefineConstants);ENABLE_MONO_SUPPORT</DefineConstants>
Expand All @@ -28,7 +24,7 @@
<ItemGroup>
<Reference Include="System.Runtime" />
<Reference Include="System.IO" />
<PackageReference Include="FSharp.Core" Version="4.6.2" />
<PackageReference Include="FSharp.Core" Version="$(FcsFSharpCorePkgVersion)" />
<PackageReference Include="FSharp.Compiler.Service.MSBuild.v12.0" Version="1.0.0" />
<ProjectReference Include="..\FSharp.Compiler.Service\FSharp.Compiler.Service.fsproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\fcs.props" />
<Import Project="..\netfx.props" />
<PropertyGroup>
<TargetFrameworks>net461</TargetFrameworks>
<TargetFrameworks>$(FcsTargetNetFxFramework)</TargetFrameworks>
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
</PropertyGroup>
<PropertyGroup>
Expand All @@ -20,14 +19,14 @@
<Link>ProjectCrackerOptions.fs</Link>
</Compile>
<Compile Include="ProjectCracker.fs" />
<Content Include="..\FSharp.Compiler.Service.ProjectCrackerTool\FSharp.Compiler.Service.ProjectCracker.targets" PackagePath="build\net461" />
<Content Include="$(ArtifactsBinDir)\fcs\net461\FSharp.Compiler.Service.ProjectCrackerTool.exe" PackagePath="utilities\net461" />
<Content Include="$(ArtifactsBinDir)\fcs\net461\FSharp.Compiler.Service.ProjectCrackerTool.exe.config" PackagePath="utilities\net461" />
<Content Include="..\FSharp.Compiler.Service.ProjectCrackerTool\FSharp.Compiler.Service.ProjectCracker.targets" PackagePath="build\$(FcsTargetNetFxFramework)" />
<Content Include="$(ArtifactsBinDir)\fcs\$(FcsTargetNetFxFramework)\FSharp.Compiler.Service.ProjectCrackerTool.exe" PackagePath="utilities\$(FcsTargetNetFxFramework)" />
<Content Include="$(ArtifactsBinDir)\fcs\$(FcsTargetNetFxFramework)\FSharp.Compiler.Service.ProjectCrackerTool.exe.config" PackagePath="utilities\$(FcsTargetNetFxFramework)" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Runtime" />
<Reference Include="System.IO" />
<PackageReference Include="FSharp.Core" Version="4.6.2" />
<PackageReference Include="FSharp.Core" Version="$(FcsFSharpCorePkgVersion)" />
<ProjectReference Include="..\FSharp.Compiler.Service\FSharp.Compiler.Service.fsproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="ProjectCrackerToolCopy" AfterTargets="Build">
<Copy SourceFiles="$(MSBuildThisFileDirectory)\..\..\utilities\net461\FSharp.Compiler.Service.ProjectCrackerTool.exe" DestinationFolder="$(OutputPath)" />
<Copy SourceFiles="$(MSBuildThisFileDirectory)\..\..\utilities\net461\FSharp.Compiler.Service.ProjectCrackerTool.exe.config" DestinationFolder="$(OutputPath)" />
<Copy SourceFiles="$(MSBuildThisFileDirectory)..\..\utilities\net461\FSharp.Compiler.Service.ProjectCrackerTool.exe" DestinationFolder="$(OutputPath)" />
<Copy SourceFiles="$(MSBuildThisFileDirectory)..\..\utilities\net461\FSharp.Compiler.Service.ProjectCrackerTool.exe.config" DestinationFolder="$(OutputPath)" />
</Target>
</Project>
Loading

0 comments on commit a2e4c63

Please sign in to comment.