Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 58 additions & 14 deletions src/Compiler/DependencyManager/DependencyProvider.fs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ module ReflectionHelper =

let resolveDependenciesMethodName = "ResolveDependencies"

let clearResultsCacheMethodName = "ClearResultsCache"

let namePropertyName = "Name"

let keyPropertyName = "Key"
Expand Down Expand Up @@ -127,7 +129,7 @@ type IDependencyManagerProvider =
abstract Name: string
abstract Key: string
abstract HelpMessages: string[]

abstract ClearResultsCache: unit -> unit
abstract ResolveDependencies:
scriptDir: string *
mainScriptName: string *
Expand All @@ -139,7 +141,7 @@ type IDependencyManagerProvider =
timeout: int ->
IResolveDependenciesResult

type ReflectionDependencyManagerProvider
type ReflectionDependencyManagerProvider
(
theType: Type,
nameProperty: PropertyInfo,
Expand All @@ -149,10 +151,17 @@ type ReflectionDependencyManagerProvider
resolveDepsEx: MethodInfo option,
resolveDepsExWithTimeout: MethodInfo option,
resolveDepsExWithScriptInfoAndTimeout: MethodInfo option,
outputDir: string option
) =
clearResultCache: MethodInfo option,
outputDir: string option,
useResultsCache: bool
) =

let instance =
if not(isNull (theType.GetConstructor([|typeof<string option>; typeof<bool>|]))) then
Activator.CreateInstance(theType, [| outputDir :> obj; useResultsCache :> obj |])
else
Activator.CreateInstance(theType, [| outputDir :> obj |])

let instance = Activator.CreateInstance(theType, [| outputDir :> obj |])
let nameProperty = nameProperty.GetValue >> string
let keyProperty = keyProperty.GetValue >> string

Expand All @@ -163,7 +172,7 @@ type ReflectionDependencyManagerProvider
| Some helpMessagesProperty -> helpMessagesProperty.GetValue >> toStringArray
| None -> fun _ -> [||]

static member InstanceMaker(theType: Type, outputDir: string option) =
static member InstanceMaker(theType: Type, outputDir: string option, useResultsCache: bool) =
match getAttributeNamed theType dependencyManagerAttributeName,
getInstanceProperty<string> theType namePropertyName,
getInstanceProperty<string> theType keyPropertyName,
Expand All @@ -172,7 +181,6 @@ type ReflectionDependencyManagerProvider
| None, _, _, _
| _, None, _, _
| _, _, None, _ -> None

| Some _, Some nameProperty, Some keyProperty, None ->
let resolveMethod =
getInstanceMethod<bool * string list * string list>
Expand Down Expand Up @@ -223,6 +231,11 @@ type ReflectionDependencyManagerProvider
|]
resolveDependenciesMethodName

let clearResultsCacheMethod =
getInstanceMethod<unit>
theType [||]
clearResultsCacheMethodName

Some(fun () ->
ReflectionDependencyManagerProvider(
theType,
Expand All @@ -233,7 +246,9 @@ type ReflectionDependencyManagerProvider
resolveMethodEx,
resolveMethodExWithTimeout,
resolveDepsExWithScriptInfoAndTimeout,
outputDir
clearResultsCacheMethod,
outputDir,
useResultsCache
)
:> IDependencyManagerProvider)

Expand Down Expand Up @@ -287,6 +302,11 @@ type ReflectionDependencyManagerProvider
|]
resolveDependenciesMethodName

let clearResultsCacheMethod =
getInstanceMethod<unit>
theType [||]
clearResultsCacheMethodName

Some(fun () ->
ReflectionDependencyManagerProvider(
theType,
Expand All @@ -297,7 +317,9 @@ type ReflectionDependencyManagerProvider
resolveMethodEx,
resolveMethodExWithTimeout,
resolveDepsExWithScriptInfoAndTimeout,
outputDir
clearResultsCacheMethod,
outputDir,
useResultsCache
)
:> IDependencyManagerProvider)

Expand Down Expand Up @@ -377,6 +399,13 @@ type ReflectionDependencyManagerProvider
/// Key of dependency Manager: used for #r "key: ... " E.g nuget
member _.Key = instance |> keyProperty

/// Clear the dependency manager caches
member _.ClearResultsCache () =
match clearResultCache with
| Some clearResultsCache ->
clearResultsCache.Invoke(instance, [||]) |> ignore
| None -> ()

/// Key of dependency Manager: used for #help
member _.HelpMessages = instance |> helpMessagesProperty

Expand Down Expand Up @@ -454,7 +483,7 @@ type ReflectionDependencyManagerProvider

/// Provides DependencyManagement functions.
/// Class is IDisposable
type DependencyProvider internal (assemblyProbingPaths: AssemblyResolutionProbe option, nativeProbingRoots: NativeResolutionProbe option) =
type DependencyProvider internal (assemblyProbingPaths: AssemblyResolutionProbe option, nativeProbingRoots: NativeResolutionProbe option, useResultsCache: bool) =

// Note: creating a NativeDllResolveHandler currently installs process-wide handlers
let dllResolveHandler = new NativeDllResolveHandler(nativeProbingRoots)
Expand Down Expand Up @@ -508,7 +537,7 @@ type DependencyProvider internal (assemblyProbingPaths: AssemblyResolutionProbe
let loadedProviders =
enumerateDependencyManagerAssemblies compilerTools reportError
|> Seq.collect (fun a -> a.GetTypes())
|> Seq.choose (fun t -> ReflectionDependencyManagerProvider.InstanceMaker(t, outputDir))
|> Seq.choose (fun t -> ReflectionDependencyManagerProvider.InstanceMaker(t, outputDir, useResultsCache))
|> Seq.map (fun maker -> maker ())

defaultProviders
Expand All @@ -523,11 +552,18 @@ type DependencyProvider internal (assemblyProbingPaths: AssemblyResolutionProbe
ConcurrentDictionary<_, Result<IResolveDependenciesResult, _>>(HashIdentity.Structural)

new(assemblyProbingPaths: AssemblyResolutionProbe, nativeProbingRoots: NativeResolutionProbe) =
new DependencyProvider(Some assemblyProbingPaths, Some nativeProbingRoots)
new DependencyProvider(Some assemblyProbingPaths, Some nativeProbingRoots, true)

new(assemblyProbingPaths: AssemblyResolutionProbe, nativeProbingRoots: NativeResolutionProbe, useResultsCache) =
new DependencyProvider(Some assemblyProbingPaths, Some nativeProbingRoots, useResultsCache)

new(nativeProbingRoots: NativeResolutionProbe) = new DependencyProvider(None, Some nativeProbingRoots)
new(nativeProbingRoots: NativeResolutionProbe, useResultsCache) =
new DependencyProvider(None, Some nativeProbingRoots, useResultsCache)

new() = new DependencyProvider(None, None)
new(nativeProbingRoots: NativeResolutionProbe) =
new DependencyProvider(None, Some nativeProbingRoots, true)

new() = new DependencyProvider(None, None, true)

/// Returns a formatted help messages for registered dependencymanagers for the host to present
member _.GetRegisteredDependencyManagerHelpText(compilerTools, outputDir, errorReport) =
Expand All @@ -540,6 +576,14 @@ type DependencyProvider internal (assemblyProbingPaths: AssemblyResolutionProbe
yield! dm.HelpMessages
|]

/// Clear the DependencyManager results caches
member _.ClearResultsCache(compilerTools, outputDir, errorReport) =
let managers =
RegisteredDependencyManagers compilerTools (Option.ofString outputDir) errorReport

for kvp in managers do
kvp.Value.ClearResultsCache()

/// Returns a formatted error message for the host to present
member _.CreatePackageManagerUnknownError
(
Expand Down
19 changes: 18 additions & 1 deletion src/Compiler/DependencyManager/DependencyProvider.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Helper members to integrate DependencyManagers into F# codebase
namespace FSharp.Compiler.DependencyManager

open System
open System.Runtime.InteropServices
open Internal.Utilities.Library

Expand Down Expand Up @@ -53,6 +54,9 @@ type IDependencyManagerProvider =
/// The help messages for this dependency manager inster
abstract HelpMessages: string[]

/// Clear the results cache
abstract ClearResultsCache: unit -> unit

/// Resolve the dependencies, for the given set of arguments, go find the .dll references, scripts and additional include values.
abstract ResolveDependencies:
scriptDir: string *
Expand Down Expand Up @@ -80,20 +84,33 @@ type ResolvingErrorReport = delegate of ErrorReportType * int * string -> unit
/// provided each time the TryFindDependencyManagerByKey and TryFindDependencyManagerInPath are
/// executed, which are assumed to be invariant over the lifetime of the DependencyProvider.
type DependencyProvider =
interface System.IDisposable
interface IDisposable

/// Construct a new DependencyProvider with no dynamic load handlers (only for compilation/analysis)
new: unit -> DependencyProvider

/// Construct a new DependencyProvider with only native resolution
new: nativeProbingRoots: NativeResolutionProbe -> DependencyProvider

/// Construct a new DependencyProvider with only native resolution and specify caching
new: nativeProbingRoots: NativeResolutionProbe * useResultsCache: bool -> DependencyProvider

/// Construct a new DependencyProvider with managed and native resolution
new: assemblyProbingPaths: AssemblyResolutionProbe * nativeProbingRoots: NativeResolutionProbe -> DependencyProvider

/// Construct a new DependencyProvider with managed and native resolution and specify caching
new:
assemblyProbingPaths: AssemblyResolutionProbe *
nativeProbingRoots: NativeResolutionProbe *
useResultsCache: bool ->
DependencyProvider

/// Returns a formatted help messages for registered dependencymanagers for the host to present
member GetRegisteredDependencyManagerHelpText: string seq * string * ResolvingErrorReport -> string[]

/// Clear the DependencyManager results caches
member ClearResultsCache: string seq * string * ResolvingErrorReport -> unit

/// Returns a formatted error message for the host to present
member CreatePackageManagerUnknownError: string seq * string * string * ResolvingErrorReport -> int * string

Expand Down
3 changes: 3 additions & 0 deletions src/Compiler/Driver/CompilerConfig.fs
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ type TcConfigBuilder =
mutable subsystemVersion: int * int
mutable useHighEntropyVA: bool
mutable inputCodePage: int option
mutable clearResultsCache: bool
mutable embedResources: string list
mutable diagnosticsOptions: FSharpDiagnosticOptions
mutable mlCompatibility: bool
Expand Down Expand Up @@ -631,6 +632,7 @@ type TcConfigBuilder =
diagnosticsOptions = FSharpDiagnosticOptions.Default
embedResources = []
inputCodePage = None
clearResultsCache = false
subsystemVersion = 4, 0 // per spec for 357994
useHighEntropyVA = false
mlCompatibility = false
Expand Down Expand Up @@ -1217,6 +1219,7 @@ type TcConfig private (data: TcConfigBuilder, validate: bool) =
member _.subsystemVersion = data.subsystemVersion
member _.useHighEntropyVA = data.useHighEntropyVA
member _.inputCodePage = data.inputCodePage
member _.clearResultsCache = data.clearResultsCache
member _.embedResources = data.embedResources
member _.diagnosticsOptions = data.diagnosticsOptions
member _.mlCompatibility = data.mlCompatibility
Expand Down
4 changes: 4 additions & 0 deletions src/Compiler/Driver/CompilerConfig.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ type TcConfigBuilder =

mutable inputCodePage: int option

mutable clearResultsCache: bool

mutable embedResources: string list

mutable diagnosticsOptions: FSharpDiagnosticOptions
Expand Down Expand Up @@ -566,6 +568,8 @@ type TcConfig =

member inputCodePage: int option

member clearResultsCache: bool

member embedResources: string list

member diagnosticsOptions: FSharpDiagnosticOptions
Expand Down
12 changes: 11 additions & 1 deletion src/Compiler/Driver/CompilerOptions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,17 @@ let noFrameworkFlag isFsc tcConfigB =
)

let advancedFlagsFsi tcConfigB =
advancedFlagsBoth tcConfigB @ [ noFrameworkFlag false tcConfigB ]
advancedFlagsBoth tcConfigB
@ [
CompilerOption(
"clearResultsCache",
tagNone,
OptionUnit(fun () -> tcConfigB.clearResultsCache <- true),
None,
Some(FSComp.SR.optsClearResultsCache ())
)
noFrameworkFlag false tcConfigB
]

let advancedFlagsFsc tcConfigB =
advancedFlagsBoth tcConfigB
Expand Down
1 change: 1 addition & 0 deletions src/Compiler/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,7 @@ optsHelp,"Display this usage message (Short form: -?)"
optsVersion,"Display compiler version banner and exit"
optsResponseFile,"Read response file for more options"
optsCodepage,"Specify the codepage used to read source files"
optsClearResultsCache,"Clear the package manager results cache"
optsUtf8output,"Output messages in UTF-8 encoding"
optsFullpaths,"Output messages with fully qualified paths"
optsLib,"Specify a directory for the include path which is used to resolve source files and assemblies (Short form: -I)"
Expand Down
2 changes: 2 additions & 0 deletions src/Compiler/Interactive/fsi.fs
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,8 @@ type internal FsiCommandLineOptions(fsi: FsiEvaluationSessionHostConfig,
let dependencyProvider = new DependencyProvider(NativeResolutionProbe(tcConfigB.GetNativeProbingRoots))

do
if tcConfigB.clearResultsCache then
dependencyProvider.ClearResultsCache(tcConfigB.compilerToolPaths, getOutputDir tcConfigB, reportError rangeCmdArgs)
if tcConfigB.utf8output then
let prev = Console.OutputEncoding
Console.OutputEncoding <- Encoding.UTF8
Expand Down
5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,11 @@
<target state="translated">Vytiskněte odvozená rozhraní všech kompilovaných souborů do přidružených souborů podpisu.</target>
<note />
</trans-unit>
<trans-unit id="optsClearResultsCache">
<source>Clear the package manager results cache</source>
<target state="new">Clear the package manager results cache</target>
<note />
</trans-unit>
<trans-unit id="optsInvalidRefAssembly">
<source>Invalid use of emitting a reference assembly, do not use '--staticlink', or '--refonly' and '--refout' together.</source>
<target state="new">Invalid use of emitting a reference assembly, do not use '--staticlink', or '--refonly' and '--refout' together.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,11 @@
<target state="translated">Drucken der abgeleiteten Schnittstellen aller Dateien an zugehörige Signaturdateien</target>
<note />
</trans-unit>
<trans-unit id="optsClearResultsCache">
<source>Clear the package manager results cache</source>
<target state="new">Clear the package manager results cache</target>
<note />
</trans-unit>
<trans-unit id="optsInvalidRefAssembly">
<source>Invalid use of emitting a reference assembly, do not use '--staticlink', or '--refonly' and '--refout' together.</source>
<target state="new">Invalid use of emitting a reference assembly, do not use '--staticlink', or '--refonly' and '--refout' together.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,11 @@
<target state="translated">Imprimir las interfaces deducidas de todos los archivos de compilación en los archivos de signatura asociados</target>
<note />
</trans-unit>
<trans-unit id="optsClearResultsCache">
<source>Clear the package manager results cache</source>
<target state="new">Clear the package manager results cache</target>
<note />
</trans-unit>
<trans-unit id="optsInvalidRefAssembly">
<source>Invalid use of emitting a reference assembly, do not use '--staticlink', or '--refonly' and '--refout' together.</source>
<target state="new">Invalid use of emitting a reference assembly, do not use '--staticlink', or '--refonly' and '--refout' together.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,11 @@
<target state="translated">Imprimer les interfaces inférées de tous les fichiers de compilation sur les fichiers de signature associés</target>
<note />
</trans-unit>
<trans-unit id="optsClearResultsCache">
<source>Clear the package manager results cache</source>
<target state="new">Clear the package manager results cache</target>
<note />
</trans-unit>
<trans-unit id="optsInvalidRefAssembly">
<source>Invalid use of emitting a reference assembly, do not use '--staticlink', or '--refonly' and '--refout' together.</source>
<target state="new">Invalid use of emitting a reference assembly, do not use '--staticlink', or '--refonly' and '--refout' together.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,11 @@
<target state="translated">Stampare le interfacce derivate di tutti i file di compilazione nei file di firma associati</target>
<note />
</trans-unit>
<trans-unit id="optsClearResultsCache">
<source>Clear the package manager results cache</source>
<target state="new">Clear the package manager results cache</target>
<note />
</trans-unit>
<trans-unit id="optsInvalidRefAssembly">
<source>Invalid use of emitting a reference assembly, do not use '--staticlink', or '--refonly' and '--refout' together.</source>
<target state="new">Invalid use of emitting a reference assembly, do not use '--staticlink', or '--refonly' and '--refout' together.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,11 @@
<target state="translated">すべてのコンパイル ファイルの推定されたインターフェイスを関連する署名ファイルに印刷します</target>
<note />
</trans-unit>
<trans-unit id="optsClearResultsCache">
<source>Clear the package manager results cache</source>
<target state="new">Clear the package manager results cache</target>
<note />
</trans-unit>
<trans-unit id="optsInvalidRefAssembly">
<source>Invalid use of emitting a reference assembly, do not use '--staticlink', or '--refonly' and '--refout' together.</source>
<target state="new">Invalid use of emitting a reference assembly, do not use '--staticlink', or '--refonly' and '--refout' together.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,11 @@
<target state="translated">모든 컴파일 파일의 유추된 인터페이스를 관련 서명 파일로 인쇄합니다.</target>
<note />
</trans-unit>
<trans-unit id="optsClearResultsCache">
<source>Clear the package manager results cache</source>
<target state="new">Clear the package manager results cache</target>
<note />
</trans-unit>
<trans-unit id="optsInvalidRefAssembly">
<source>Invalid use of emitting a reference assembly, do not use '--staticlink', or '--refonly' and '--refout' together.</source>
<target state="new">Invalid use of emitting a reference assembly, do not use '--staticlink', or '--refonly' and '--refout' together.</target>
Expand Down
Loading