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
28 changes: 3 additions & 25 deletions .fantomasignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,10 @@ src/Compiler/Checking/TypeHierarchy.fs
src/Compiler/Checking/TypeRelations.fs

# Incorrectly formatted: https://github.com/dotnet/fsharp/pull/14645/commits/49443a67ea8a17670c8a7c80c8bdf91f82231e91 or https://github.com/fsprojects/fantomas/issues/2733
# This CompilerImports.fs behavior is not fixed yet, following up in https://github.com/fsprojects/fantomas/issues/2733
src/Compiler/Driver/CompilerImports.fs

src/Compiler/DependencyManager/AssemblyResolveHandler.fs
src/Compiler/DependencyManager/DependencyProvider.fs
src/Compiler/DependencyManager/NativeDllResolveHandler.fs

src/Compiler/Facilities/BuildGraph.fs
src/Compiler/Facilities/CompilerLocation.fs
src/Compiler/Facilities/DiagnosticOptions.fs
src/Compiler/Facilities/DiagnosticResolutionHints.fs
src/Compiler/Facilities/DiagnosticsLogger.fs
src/Compiler/Facilities/LanguageFeatures.fs
src/Compiler/Facilities/Logger.fs
src/Compiler/Facilities/prim-lexing.fs
src/Compiler/Facilities/prim-parsing.fs
src/Compiler/Facilities/ReferenceResolver.fs
src/Compiler/Facilities/SimulatedMSBuildReferenceResolver.fs
src/Compiler/Facilities/TextLayoutRender.fs

src/Compiler/Interactive/ControlledExecution.fs
src/Compiler/Interactive/fsi.fs

src/Compiler/Legacy/LegacyHostedCompilerForTesting.fs
src/Compiler/Legacy/LegacyMSBuildReferenceResolver.fs

# The following files were formatted, but the "format, --check" loop is not stable.
# Fantomas formats them, but still thinks they need formatting
src/Compiler/Optimize/DetupleArgs.fs
src/Compiler/Optimize/InnerLambdasToTopLevelFuncs.fs
src/Compiler/Optimize/LowerCalls.fs
Expand All @@ -89,7 +68,6 @@ src/Compiler/TypedTree/TypedTreeBasics.fs
src/Compiler/TypedTree/TypedTreeOps.fs
src/Compiler/TypedTree/TypedTreePickle.fs
src/Compiler/TypedTree/TypeProviders.fs

# Explicitly unformatted file that needs more care to get it to format well

src/Compiler/SyntaxTree/LexFilter.fs
Expand Down
6 changes: 3 additions & 3 deletions src/Compiler/DependencyManager/AssemblyResolveHandler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ type AssemblyResolveHandlerDeskTop(assemblyProbingPaths: AssemblyResolutionProbe
type AssemblyResolveHandler internal (assemblyProbingPaths: AssemblyResolutionProbe option) =

let handler =
assemblyProbingPaths |> Option.map (fun _ ->
assemblyProbingPaths
|> Option.map (fun _ ->
if isRunningOnCoreClr then
new AssemblyResolveHandlerCoreclr(assemblyProbingPaths) :> IDisposable
else
new AssemblyResolveHandlerDeskTop(assemblyProbingPaths) :> IDisposable
)
new AssemblyResolveHandlerDeskTop(assemblyProbingPaths) :> IDisposable)

new(assemblyProbingPaths: AssemblyResolutionProbe) = new AssemblyResolveHandler(Option.ofObj assemblyProbingPaths)

Expand Down
45 changes: 23 additions & 22 deletions src/Compiler/DependencyManager/DependencyProvider.fs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ type IDependencyManagerProvider =
abstract Key: string
abstract HelpMessages: string[]
abstract ClearResultsCache: unit -> unit

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

type ReflectionDependencyManagerProvider
type ReflectionDependencyManagerProvider
(
theType: Type,
nameProperty: PropertyInfo,
Expand All @@ -154,10 +155,10 @@ type IDependencyManagerProvider =
clearResultCache: MethodInfo option,
outputDir: string option,
useResultsCache: bool
) =
) =

let instance =
if not(isNull (theType.GetConstructor([|typeof<string option>; typeof<bool>|]))) then
if not (isNull (theType.GetConstructor([| typeof<string option>; typeof<bool> |]))) then
Activator.CreateInstance(theType, [| outputDir :> obj; useResultsCache :> obj |])
else
Activator.CreateInstance(theType, [| outputDir :> obj |])
Expand All @@ -173,11 +174,12 @@ type IDependencyManagerProvider =
| None -> fun _ -> [||]

static member InstanceMaker(theType: Type, outputDir: string option, useResultsCache: bool) =
match getAttributeNamed theType dependencyManagerAttributeName,
getInstanceProperty<string> theType namePropertyName,
getInstanceProperty<string> theType keyPropertyName,
getInstanceProperty<string[]> theType helpMessagesPropertyName
with
match
getAttributeNamed theType dependencyManagerAttributeName,
getInstanceProperty<string> theType namePropertyName,
getInstanceProperty<string> theType keyPropertyName,
getInstanceProperty<string[]> theType helpMessagesPropertyName
with
| None, _, _, _
| _, None, _, _
| _, _, None, _ -> None
Expand Down Expand Up @@ -232,9 +234,7 @@ type IDependencyManagerProvider =
resolveDependenciesMethodName

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

Some(fun () ->
ReflectionDependencyManagerProvider(
Expand Down Expand Up @@ -303,9 +303,7 @@ type IDependencyManagerProvider =
resolveDependenciesMethodName

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

Some(fun () ->
ReflectionDependencyManagerProvider(
Expand Down Expand Up @@ -400,10 +398,9 @@ type IDependencyManagerProvider =
member _.Key = instance |> keyProperty

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

/// Key of dependency Manager: used for #help
Expand Down Expand Up @@ -483,7 +480,13 @@ type IDependencyManagerProvider =

/// Provides DependencyManagement functions.
/// Class is IDisposable
type DependencyProvider internal (assemblyProbingPaths: AssemblyResolutionProbe option, nativeProbingRoots: NativeResolutionProbe option, useResultsCache: bool) =
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 @@ -557,11 +560,9 @@ type DependencyProvider internal (assemblyProbingPaths: AssemblyResolutionProbe
new(assemblyProbingPaths: AssemblyResolutionProbe, nativeProbingRoots: NativeResolutionProbe, useResultsCache) =
new DependencyProvider(Some assemblyProbingPaths, Some nativeProbingRoots, useResultsCache)

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

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

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

Expand Down
15 changes: 10 additions & 5 deletions src/Compiler/DependencyManager/NativeDllResolveHandler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ open Internal.Utilities
open Internal.Utilities.FSharpEnvironment
open FSharp.Compiler.IO


type internal ProbingPathsStore() =

let addedPaths = ConcurrentBag<string>()

static member AppendPathSeparator (p: string) =
static member AppendPathSeparator(p: string) =
let separator = string Path.PathSeparator

if not (p.EndsWith(separator, StringComparison.OrdinalIgnoreCase)) then
Expand All @@ -27,14 +26,18 @@ type internal ProbingPathsStore() =
static member RemoveProbeFromProcessPath probePath =
if not (String.IsNullOrWhiteSpace(probePath)) then
let probe = ProbingPathsStore.AppendPathSeparator probePath
let path = ProbingPathsStore.AppendPathSeparator (Environment.GetEnvironmentVariable("PATH"))

let path =
ProbingPathsStore.AppendPathSeparator(Environment.GetEnvironmentVariable("PATH"))

if path.Contains(probe) then
Environment.SetEnvironmentVariable("PATH", path.Replace(probe, ""))

member _.AddProbeToProcessPath probePath =
let probe = ProbingPathsStore.AppendPathSeparator probePath
let path = ProbingPathsStore.AppendPathSeparator (Environment.GetEnvironmentVariable("PATH"))

let path =
ProbingPathsStore.AppendPathSeparator(Environment.GetEnvironmentVariable("PATH"))

if not (path.Contains(probe)) then
Environment.SetEnvironmentVariable("PATH", path + probe)
Expand All @@ -46,12 +49,14 @@ type internal ProbingPathsStore() =

member this.Dispose() =
let mutable probe: string = Unchecked.defaultof<string>

while (addedPaths.TryTake(&probe)) do
ProbingPathsStore.RemoveProbeFromProcessPath(probe)

interface IDisposable with
member _.Dispose() =
let mutable probe: string = Unchecked.defaultof<string>

while (addedPaths.TryTake(&probe)) do
ProbingPathsStore.RemoveProbeFromProcessPath(probe)

Expand Down Expand Up @@ -176,7 +181,7 @@ type NativeDllResolveHandler(nativeProbingRoots: NativeResolutionProbe option) =

let handler: NativeDllResolveHandlerCoreClr option =
nativeProbingRoots
|> Option.filter(fun _ -> isRunningOnCoreClr)
|> Option.filter (fun _ -> isRunningOnCoreClr)
|> Option.map (fun _ -> new NativeDllResolveHandlerCoreClr(nativeProbingRoots))

new(nativeProbingRoots: NativeResolutionProbe) = new NativeDllResolveHandler(Option.ofObj nativeProbingRoots)
Expand Down
14 changes: 9 additions & 5 deletions src/Compiler/Driver/CompilerImports.fs
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,12 @@ let WriteSignatureData (tcConfig: TcConfig, tcGlobals, exportRemapping, ccu: Ccu
tcConfig.outputFile
|> Option.iter (fun outputFile ->
let outputFile = FileSystem.GetFullPathShim(outputFile)
let signatureDataFile = FileSystem.ChangeExtensionShim(outputFile, ".signature-data.json")

let signatureDataFile =
FileSystem.ChangeExtensionShim(outputFile, ".signature-data.json")

serializeEntity signatureDataFile mspec)

// For historical reasons, we use a different resource name for FSharp.Core, so older F# compilers
// don't complain when they see the resource.
let rName, compress =
Expand Down Expand Up @@ -1103,7 +1106,7 @@ and [<Sealed>] TcImports
initialResolutions: TcAssemblyResolutions,
importsBase: TcImports option,
dependencyProviderOpt: DependencyProvider option
)
)
#if !NO_TYPEPROVIDERS
as this
#endif
Expand Down Expand Up @@ -1183,10 +1186,11 @@ and [<Sealed>] TcImports
if publicOnly then
match e.TypeReprInfo with
| TILObjectRepr data ->
let (TILObjectReprData(_, _, tyDef)) = data
let (TILObjectReprData (_, _, tyDef)) = data
tyDef.Access = ILTypeDefAccess.Public
| _ -> false
else true
else
true
| None -> false
| None -> false

Expand Down
20 changes: 9 additions & 11 deletions src/Compiler/Facilities/BuildGraph.fs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ type NodeCodeBuilder() =
(value :> IDisposable).Dispose()
}
)

[<DebuggerHidden; DebuggerStepThrough>]
member _.Using(value: IDisposable, binder: IDisposable -> NodeCode<'U>) =
Node(
Expand All @@ -114,7 +114,6 @@ type NodeCodeBuilder() =
return! binder value |> Async.AwaitNodeCode
}
)


let node = NodeCodeBuilder()

Expand Down Expand Up @@ -192,12 +191,9 @@ type NodeCode private () =

return results.ToArray()
}

static member Parallel (computations: NodeCode<'T> seq) =
computations
|> Seq.map (fun (Node x) -> x)
|> Async.Parallel
|> Node

static member Parallel(computations: NodeCode<'T> seq) =
computations |> Seq.map (fun (Node x) -> x) |> Async.Parallel |> Node

[<RequireQualifiedAccess>]
module GraphNode =
Expand Down Expand Up @@ -238,6 +234,7 @@ type GraphNode<'T> private (computation: NodeCode<'T>, cachedResult: ValueOption
else
node {
Interlocked.Increment(&requestCount) |> ignore

try
let! ct = NodeCode.CancellationToken

Expand All @@ -255,8 +252,8 @@ type GraphNode<'T> private (computation: NodeCode<'T>, cachedResult: ValueOption
.ContinueWith(
(fun _ -> taken <- true),
(TaskContinuationOptions.NotOnCanceled
||| TaskContinuationOptions.NotOnFaulted
||| TaskContinuationOptions.ExecuteSynchronously)
||| TaskContinuationOptions.NotOnFaulted
||| TaskContinuationOptions.ExecuteSynchronously)
)
|> NodeCode.AwaitTask

Expand All @@ -283,7 +280,8 @@ type GraphNode<'T> private (computation: NodeCode<'T>, cachedResult: ValueOption

return! tcs.Task |> NodeCode.AwaitTask
finally
if taken then semaphore.Release() |> ignore
if taken then
semaphore.Release() |> ignore
finally
Interlocked.Decrement(&requestCount) |> ignore
}
Expand Down
5 changes: 3 additions & 2 deletions src/Compiler/Facilities/CompilerLocation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ module internal FSharpEnvironment =
else
None


// The default location of FSharp.Core.dll and fsc.exe based on the version of fsc.exe that is running
// Used for
// - location of design-time copies of FSharp.Core.dll and FSharp.Compiler.Interactive.Settings.dll for the default assumed environment for scripts
Expand Down Expand Up @@ -187,7 +186,9 @@ module internal FSharpEnvironment =

for p in searchToolPaths path compilerToolPaths do
let fileName = Path.Combine(p, assemblyName)
if File.Exists fileName then yield fileName

if File.Exists fileName then
yield fileName
}

let loadFromParentDirRelativeToRuntimeAssemblyLocation designTimeAssemblyName =
Expand Down
14 changes: 9 additions & 5 deletions src/Compiler/Facilities/DiagnosticResolutionHints.fs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ type SuggestionBuffer(idText: string) =
data[i] <- data[i + 1]

data[pos - 1] <- KeyValuePair(k, v)
if tail > 0 then tail <- tail - 1

if tail > 0 then
tail <- tail - 1

member _.Add(suggestion: string) =
if not disableSuggestions then
Expand All @@ -95,10 +97,12 @@ type SuggestionBuffer(idText: string) =
let suggestedText = suggestion.ToUpperInvariant()
let similarity = EditDistance.JaroWinklerDistance uppercaseText suggestedText

if similarity >= highConfidenceThreshold
|| suggestion.EndsWithOrdinal dotIdText
|| (similarity >= minThresholdForSuggestions
&& IsInEditDistanceProximity uppercaseText suggestedText) then
if
similarity >= highConfidenceThreshold
|| suggestion.EndsWithOrdinal dotIdText
|| (similarity >= minThresholdForSuggestions
&& IsInEditDistanceProximity uppercaseText suggestedText)
then
insert (similarity, suggestion)

member _.Disabled = disableSuggestions
Expand Down
Loading