Skip to content

Commit

Permalink
Merge branch 'dev16.1' into merges/master-to-dev16.1
Browse files Browse the repository at this point in the history
  • Loading branch information
brettfo authored Feb 19, 2019
2 parents 7376e22 + 2422d4c commit 70b5d2a
Show file tree
Hide file tree
Showing 599 changed files with 4,429 additions and 3,687 deletions.
2 changes: 1 addition & 1 deletion FSharpBuild.Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<BaseOutputPath>$(ArtifactsBinDir)\$(MSBuildProjectName)</BaseOutputPath>
<BaseIntermediateOutputPath>$(ArtifactsObjDir)\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<SymStoreDirectory>$(ArtifactsDir)\SymStore</SymStoreDirectory>
<ProtoOutputPath Condition="'$(OS)' != 'Unix'">$(ArtifactsBinDir)\fsc\Proto\net46</ProtoOutputPath>
<ProtoOutputPath Condition="'$(OS)' != 'Unix'">$(ArtifactsBinDir)\fsc\Proto\net472</ProtoOutputPath>
<ProtoOutputPath Condition="'$(OS)' == 'Unix'">$(ArtifactsBinDir)/fsc/Proto/netcoreapp2.1</ProtoOutputPath>
<ValueTupleImplicitPackageVersion>4.4.0</ValueTupleImplicitPackageVersion>
</PropertyGroup>
Expand Down
6 changes: 3 additions & 3 deletions FSharpTests.Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<PropertyGroup Condition="'$(FSharpTestCompilerVersion)' == 'net40'">
<DisableAutoSetFscCompilerPath>true</DisableAutoSetFscCompilerPath>

<FscToolPath>$(MSBuildThisFileDirectory)artifacts\bin\fsc\$(Configuration)\net46</FscToolPath>
<FscToolPath>$(MSBuildThisFileDirectory)artifacts\bin\fsc\$(Configuration)\net472</FscToolPath>
<FscToolExe>fsc.exe</FscToolExe>
<DotnetFscCompilerPath></DotnetFscCompilerPath>

<FsiToolPath>$(MSBuildThisFileDirectory)artifacts\bin\fsi\$(Configuration)\net46</FsiToolPath>
<FsiToolPath>$(MSBuildThisFileDirectory)artifacts\bin\fsi\$(Configuration)\net472</FsiToolPath>
<FsiToolExe>fsi.exe</FsiToolExe>
<DotnetFsiCompilerPath></DotnetFsiCompilerPath>
</PropertyGroup>
Expand All @@ -28,7 +28,7 @@

<!-- SDK targets override -->
<PropertyGroup>
<_FSharpBuildTargetFramework Condition="'$(FSharpTestCompilerVersion)' == 'net40'">net46</_FSharpBuildTargetFramework>
<_FSharpBuildTargetFramework Condition="'$(FSharpTestCompilerVersion)' == 'net40'">net472</_FSharpBuildTargetFramework>
<_FSharpBuildTargetFramework Condition="'$(FSharpTestCompilerVersion)' == 'coreclr'">netstandard2.0</_FSharpBuildTargetFramework>
<_FSharpBuildBinPath>$(MSBuildThisFileDirectory)artifacts\bin\FSharp.Build\$(Configuration)\$(_FSharpBuildTargetFramework)</_FSharpBuildBinPath>

Expand Down
2 changes: 1 addition & 1 deletion RoslynPackageVersion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.9.0-beta8-63208-01
2.11.0-beta1-63431-08
33 changes: 20 additions & 13 deletions benchmarks/Benchmarks.sln
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.136
# Visual Studio Version 16
VisualStudioVersion = 16.0.28407.52
MinimumVisualStudioVersion = 10.0.40219.1
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "CompilerServiceBenchmarks", "CompilerServiceBenchmarks\CompilerServiceBenchmarks.fsproj", "{9A3C565C-B514-4AE0-8B01-CA80E8453EB0}"
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "CompilerServiceBenchmarks", "CompilerServiceBenchmarks\CompilerServiceBenchmarks.fsproj", "{9A3C565C-B514-4AE0-8B01-CA80E8453EB0}"
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FSharp.Core", "..\src\fsharp\FSharp.Core\FSharp.Core.fsproj", "{BB9EAE76-194A-49D8-9618-586CBE7031D9}"
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FSharp.Core", "..\src\fsharp\FSharp.Core\FSharp.Core.fsproj", "{DED3BBD7-53F4-428A-8C9F-27968E768605}"
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FSharp.Compiler.Private", "..\src\fsharp\FSharp.Compiler.Private\FSharp.Compiler.Private.fsproj", "{F57B02B1-CF26-4D93-9211-8CEB4F1572F0}"
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FSharp.Compiler.Private", "..\src\fsharp\FSharp.Compiler.Private\FSharp.Compiler.Private.fsproj", "{2E4D67B4-522D-4CF7-97E4-BA940F0B18F3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Proto|Any CPU = Proto|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9A3C565C-B514-4AE0-8B01-CA80E8453EB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9A3C565C-B514-4AE0-8B01-CA80E8453EB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9A3C565C-B514-4AE0-8B01-CA80E8453EB0}.Proto|Any CPU.ActiveCfg = Release|Any CPU
{9A3C565C-B514-4AE0-8B01-CA80E8453EB0}.Proto|Any CPU.Build.0 = Release|Any CPU
{9A3C565C-B514-4AE0-8B01-CA80E8453EB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9A3C565C-B514-4AE0-8B01-CA80E8453EB0}.Release|Any CPU.Build.0 = Release|Any CPU
{BB9EAE76-194A-49D8-9618-586CBE7031D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BB9EAE76-194A-49D8-9618-586CBE7031D9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BB9EAE76-194A-49D8-9618-586CBE7031D9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BB9EAE76-194A-49D8-9618-586CBE7031D9}.Release|Any CPU.Build.0 = Release|Any CPU
{F57B02B1-CF26-4D93-9211-8CEB4F1572F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F57B02B1-CF26-4D93-9211-8CEB4F1572F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F57B02B1-CF26-4D93-9211-8CEB4F1572F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F57B02B1-CF26-4D93-9211-8CEB4F1572F0}.Release|Any CPU.Build.0 = Release|Any CPU
{DED3BBD7-53F4-428A-8C9F-27968E768605}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DED3BBD7-53F4-428A-8C9F-27968E768605}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DED3BBD7-53F4-428A-8C9F-27968E768605}.Proto|Any CPU.ActiveCfg = Debug|Any CPU
{DED3BBD7-53F4-428A-8C9F-27968E768605}.Proto|Any CPU.Build.0 = Debug|Any CPU
{DED3BBD7-53F4-428A-8C9F-27968E768605}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DED3BBD7-53F4-428A-8C9F-27968E768605}.Release|Any CPU.Build.0 = Release|Any CPU
{2E4D67B4-522D-4CF7-97E4-BA940F0B18F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2E4D67B4-522D-4CF7-97E4-BA940F0B18F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2E4D67B4-522D-4CF7-97E4-BA940F0B18F3}.Proto|Any CPU.ActiveCfg = Debug|Any CPU
{2E4D67B4-522D-4CF7-97E4-BA940F0B18F3}.Proto|Any CPU.Build.0 = Debug|Any CPU
{2E4D67B4-522D-4CF7-97E4-BA940F0B18F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2E4D67B4-522D-4CF7-97E4-BA940F0B18F3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<FSharpSourcesRoot>$(MSBuildProjectDirectory)\..\..\src</FSharpSourcesRoot>
</PropertyGroup>

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net472</TargetFramework>
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
<DisableImplicitSystemValueTupleReference>true</DisableImplicitSystemValueTupleReference>
<DefaultValueTuplePackageVersion>$(SystemValueTuplePackageVersion)</DefaultValueTuplePackageVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>

<ItemGroup>
Expand All @@ -11,11 +22,12 @@

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.11.3" />
<PackageReference Include="Microsoft.CodeAnalysis.EditorFeatures.Text" Version="2.9.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\fsharp\FSharp.Compiler.Private\FSharp.Compiler.Private.fsproj" />
<ProjectReference Include="..\..\src\fsharp\FSharp.Core\FSharp.Core.fsproj" />
<ProjectReference Include="$(FSharpSourcesRoot)\fsharp\FSharp.Compiler.Private\FSharp.Compiler.Private.fsproj" />
<ProjectReference Include="$(FSharpSourcesRoot)\fsharp\FSharp.Core\FSharp.Core.fsproj" />
</ItemGroup>

</Project>
166 changes: 155 additions & 11 deletions benchmarks/CompilerServiceBenchmarks/Program.fs
Original file line number Diff line number Diff line change
@@ -1,13 +1,87 @@
open System
open System.IO
open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Running
open System.Text
open Microsoft.FSharp.Compiler.ErrorLogger
open Microsoft.FSharp.Compiler.SourceCodeServices
open System.Text
open Microsoft.FSharp.Compiler.Text
open Microsoft.FSharp.Compiler.AbstractIL
open Microsoft.FSharp.Compiler.AbstractIL.IL
open Microsoft.FSharp.Compiler.AbstractIL.ILBinaryReader
open Microsoft.CodeAnalysis.Text
open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Running

module private SourceText =

open System.Runtime.CompilerServices

let weakTable = ConditionalWeakTable<SourceText, ISourceText>()

let create (sourceText: SourceText) =

let sourceText =
{ new ISourceText with

member __.Item with get index = sourceText.[index]

member __.GetLineString(lineIndex) =
sourceText.Lines.[lineIndex].ToString()

member __.GetLineCount() =
sourceText.Lines.Count

member __.GetLastCharacterPosition() =
if sourceText.Lines.Count > 0 then
(sourceText.Lines.Count, sourceText.Lines.[sourceText.Lines.Count - 1].Span.Length)
else
(0, 0)

member __.GetSubTextString(start, length) =
sourceText.GetSubText(TextSpan(start, length)).ToString()

member __.SubTextEquals(target, startIndex) =
if startIndex < 0 || startIndex >= sourceText.Length then
raise (ArgumentOutOfRangeException("startIndex"))

if String.IsNullOrEmpty(target) then
raise (ArgumentException("Target is null or empty.", "target"))

let lastIndex = startIndex + target.Length
if lastIndex <= startIndex || lastIndex >= sourceText.Length then
raise (ArgumentException("Target is too big.", "target"))

let mutable finished = false
let mutable didEqual = true
let mutable i = 0
while not finished && i < target.Length do
if target.[i] <> sourceText.[startIndex + i] then
didEqual <- false
finished <- true // bail out early
else
i <- i + 1

didEqual

member __.ContentEquals(sourceText) =
match sourceText with
| :? SourceText as sourceText -> sourceText.ContentEquals(sourceText)
| _ -> false

[<ClrJob(baseline = true)>]
type CompilerServiceParsing() =
member __.Length = sourceText.Length

member __.CopyTo(sourceIndex, destination, destinationIndex, count) =
sourceText.CopyTo(sourceIndex, destination, destinationIndex, count)
}

sourceText

type SourceText with

member this.ToFSharpSourceText() =
SourceText.weakTable.GetValue(this, Runtime.CompilerServices.ConditionalWeakTable<_,_>.CreateValueCallback(SourceText.create))

[<MemoryDiagnoser>]
type CompilerService() =

let mutable checkerOpt = None

Expand All @@ -24,6 +98,17 @@ type CompilerServiceParsing() =
IsExe = false
}

let mutable assembliesOpt = None

let readerOptions =
{
pdbDirPath = None
ilGlobals = mkILGlobals ILScopeRef.Local
reduceMemoryUsage = ReduceMemoryFlag.No
metadataOnly = MetadataOnlyFlag.Yes
tryGetMetadataSnapshot = fun _ -> None
}

[<GlobalSetup>]
member __.Setup() =
match checkerOpt with
Expand All @@ -32,29 +117,88 @@ type CompilerServiceParsing() =

match sourceOpt with
| None ->
let source = File.ReadAllText("""..\..\..\..\..\src\fsharp\TypeChecker.fs""")
sourceOpt <- Some(source)
sourceOpt <- Some <| SourceText.From(File.OpenRead("""..\..\..\..\..\src\fsharp\TypeChecker.fs"""), Encoding.Default, SourceHashAlgorithm.Sha1, true)
| _ -> ()

match assembliesOpt with
| None ->
assembliesOpt <-
System.AppDomain.CurrentDomain.GetAssemblies()
|> Array.map (fun x -> (x.Location))
|> Some
| _ -> ()

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

[<Benchmark>]
member __.Parsing() =
match checkerOpt, sourceOpt with
| None, _ -> failwith "no checker"
| _, None -> failwith "no source"
| Some(checker), Some(source) ->
let results = checker.ParseFile("TypeChecker.fs", source, parsingOptions) |> Async.RunSynchronously
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()

[<Benchmark>]
member __.ILReading() =
match assembliesOpt with
| None -> failwith "no assemblies"
| Some(assemblies) ->
// We try to read most of everything in the assembly that matter, mainly types with their properties, methods, and fields.
// CustomAttrs and SecurityDecls are lazy until you call them, so we call them here for benchmarking.
assemblies
|> Array.iter (fun (fileName) ->
let reader = OpenILModuleReader fileName readerOptions

let ilModuleDef = reader.ILModuleDef

let ilAssemblyManifest = ilModuleDef.Manifest.Value

ilAssemblyManifest.CustomAttrs |> ignore
ilAssemblyManifest.SecurityDecls |> ignore
ilAssemblyManifest.ExportedTypes.AsList
|> List.iter (fun x ->
x.CustomAttrs |> ignore
)

ilModuleDef.CustomAttrs |> ignore
ilModuleDef.TypeDefs.AsArray
|> Array.iter (fun ilTypeDef ->
ilTypeDef.CustomAttrs |> ignore
ilTypeDef.SecurityDecls |> ignore

ilTypeDef.Methods.AsArray
|> Array.iter (fun ilMethodDef ->
ilMethodDef.CustomAttrs |> ignore
ilMethodDef.SecurityDecls |> ignore
)

ilTypeDef.Fields.AsList
|> List.iter (fun ilFieldDef ->
ilFieldDef.CustomAttrs |> ignore
)

ilTypeDef.Properties.AsList
|> List.iter (fun ilPropertyDef ->
ilPropertyDef.CustomAttrs |> ignore
)
)
)

[<EntryPoint>]
let main argv =
let _ = BenchmarkRunner.Run<CompilerServiceParsing>()
let _ = BenchmarkRunner.Run<CompilerService>()
0
3 changes: 3 additions & 0 deletions benchmarks/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove('FSharp.Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
</Project>
3 changes: 3 additions & 0 deletions benchmarks/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove('FSharp.Directory.Build.targets', '$(MSBuildThisFileDirectory)../'))" />
</Project>
Loading

0 comments on commit 70b5d2a

Please sign in to comment.