Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make FSharpReferencedProject representation public #15266

Merged
merged 6 commits into from
May 29, 2023
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
26 changes: 9 additions & 17 deletions src/Compiler/Service/FSharpCheckerResults.fs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ open FSharp.Compiler.AbstractIL.ILBinaryReader
type FSharpUnresolvedReferencesSet = FSharpUnresolvedReferencesSet of UnresolvedAssemblyReference list

[<Sealed>]
type internal DelayedILModuleReader =

type DelayedILModuleReader =
val private name: string
val private gate: obj
val mutable private getStream: (CancellationToken -> Stream option)
Expand All @@ -77,6 +76,8 @@ type internal DelayedILModuleReader =
result = Unchecked.defaultof<_>
}

member this.OutputFile = this.name

member this.TryGetILModuleReader() =
// fast path
match box this.result with
Expand Down Expand Up @@ -117,32 +118,23 @@ type internal DelayedILModuleReader =
[<RequireQualifiedAccess; NoComparison; CustomEquality>]
type FSharpReferencedProject =
| FSharpReference of projectOutputFile: string * options: FSharpProjectOptions
| PEReference of projectOutputFile: string * getStamp: (unit -> DateTime) * delayedReader: DelayedILModuleReader
| PEReference of getStamp: (unit -> DateTime) * delayedReader: DelayedILModuleReader
| ILModuleReference of projectOutputFile: string * getStamp: (unit -> DateTime) * getReader: (unit -> ILModuleReader)

member this.OutputFile =
match this with
| FSharpReference (projectOutputFile = projectOutputFile)
| PEReference (projectOutputFile = projectOutputFile)
| ILModuleReference (projectOutputFile = projectOutputFile) -> projectOutputFile

static member CreateFSharp(projectOutputFile, options) =
FSharpReference(projectOutputFile, options)

static member CreatePortableExecutable(projectOutputFile, getStamp, getStream) =
PEReference(projectOutputFile, getStamp, DelayedILModuleReader(projectOutputFile, getStream))

static member CreateFromILModuleReader(projectOutputFile, getStamp, getReader) =
ILModuleReference(projectOutputFile, getStamp, getReader)
| PEReference (delayedReader = reader) -> reader.OutputFile

override this.Equals(o) =
match o with
| :? FSharpReferencedProject as o ->
match this, o with
| FSharpReference (projectOutputFile1, options1), FSharpReference (projectOutputFile2, options2) ->
projectOutputFile1 = projectOutputFile2 && options1 = options2
| PEReference (projectOutputFile1, getStamp1, _), PEReference (projectOutputFile2, getStamp2, _) ->
projectOutputFile1 = projectOutputFile2 && (getStamp1 ()) = (getStamp2 ())
| PEReference (getStamp1, reader1), PEReference (getStamp2, reader2) ->
reader1.OutputFile = reader2.OutputFile && (getStamp1 ()) = (getStamp2 ())
| ILModuleReference (projectOutputFile1, getStamp1, _), ILModuleReference (projectOutputFile2, getStamp2, _) ->
projectOutputFile1 = projectOutputFile2 && (getStamp1 ()) = (getStamp2 ())
| _ -> false
Expand Down Expand Up @@ -192,8 +184,8 @@ and FSharpProjectOptions =
match r1, r2 with
| FSharpReferencedProject.FSharpReference (n1, a), FSharpReferencedProject.FSharpReference (n2, b) ->
n1 = n2 && FSharpProjectOptions.AreSameForChecking(a, b)
| FSharpReferencedProject.PEReference (n1, getStamp1, _), FSharpReferencedProject.PEReference (n2, getStamp2, _) ->
n1 = n2 && (getStamp1 ()) = (getStamp2 ())
| FSharpReferencedProject.PEReference (getStamp1, reader1), FSharpReferencedProject.PEReference (getStamp2, reader2) ->
reader1.OutputFile = reader2.OutputFile && (getStamp1 ()) = (getStamp2 ())
| _ -> false)
&& options1.LoadTime = options2.LoadTime

Expand Down
49 changes: 21 additions & 28 deletions src/Compiler/Service/FSharpCheckerResults.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ open FSharp.Compiler.Text

/// Delays the creation of an ILModuleReader
[<Sealed>]
type internal DelayedILModuleReader =
type DelayedILModuleReader =

new: name: string * getStream: (CancellationToken -> Stream option) -> DelayedILModuleReader

member OutputFile: string

/// Will lazily create the ILModuleReader.
/// Is only evaluated once and can be called by multiple threads.
member TryGetILModuleReader: unit -> Cancellable<ILModuleReader option>
member internal TryGetILModuleReader: unit -> Cancellable<ILModuleReader option>

/// <summary>Unused in this API</summary>
type public FSharpUnresolvedReferencesSet = internal FSharpUnresolvedReferencesSet of UnresolvedAssemblyReference list
Expand Down Expand Up @@ -92,50 +94,41 @@ type public FSharpProjectOptions =
/// Compute the project directory.
member internal ProjectDirectory: string

and [<NoComparison; CustomEquality>] public FSharpReferencedProject =
internal
| FSharpReference of projectOutputFile: string * options: FSharpProjectOptions
| PEReference of projectOutputFile: string * getStamp: (unit -> DateTime) * delayedReader: DelayedILModuleReader
| ILModuleReference of
projectOutputFile: string *
getStamp: (unit -> DateTime) *
getReader: (unit -> ILModuleReader)

/// <summary>
/// The fully qualified path to the output of the referenced project. This should be the same value as the <c>-r</c>
/// reference in the project options for this referenced project.
/// </summary>
member OutputFile: string
and [<NoComparison; CustomEquality; RequireQualifiedAccess>] FSharpReferencedProject =

/// <summary>
/// Creates a reference for an F# project. The physical data for it is stored/cached inside of the compiler service.
/// A reference for an F# project. The physical data for it is stored/cached inside of the compiler service.
/// </summary>
/// <param name="projectOutputFile">The fully qualified path to the output of the referenced project. This should be the same value as the <c>-r</c> reference in the project options for this referenced project.</param>
/// <param name="options">The Project Options for this F# project</param>
static member CreateFSharp: projectOutputFile: string * options: FSharpProjectOptions -> FSharpReferencedProject
| FSharpReference of projectOutputFile: string * options: FSharpProjectOptions

/// <summary>
/// Creates a reference for any portable executable, including F#. The stream is owned by this reference.
/// A reference for any portable executable, including F#. The stream is owned by this reference.
/// The stream will be automatically disposed when there are no references to FSharpReferencedProject and is GC collected.
/// Once the stream is evaluated, the function that constructs the stream will no longer be referenced by anything.
/// If the stream evaluation throws an exception, it will be automatically handled.
/// </summary>
/// <param name="projectOutputFile">The fully qualified path to the output of the referenced project. This should be the same value as the <c>-r</c> reference in the project options for this referenced project.</param>
/// <param name="getStamp">A function that calculates a last-modified timestamp for this reference. This will be used to determine if the reference is up-to-date.</param>
/// <param name="getStream">A function that opens a Portable Executable data stream for reading.</param>
static member CreatePortableExecutable:
projectOutputFile: string * getStamp: (unit -> DateTime) * getStream: (CancellationToken -> Stream option) ->
FSharpReferencedProject
/// <param name="delayedReader">A function that opens a Portable Executable data stream for reading.</param>
| PEReference of getStamp: (unit -> DateTime) * delayedReader: DelayedILModuleReader

/// <summary>
/// Creates a reference from an ILModuleReader.
/// A reference from an ILModuleReader.
/// </summary>
/// <param name="projectOutputFile">The fully qualified path to the output of the referenced project. This should be the same value as the <c>-r</c> reference in the project options for this referenced project.</param>
/// <param name="getStamp">A function that calculates a last-modified timestamp for this reference. This will be used to determine if the reference is up-to-date.</param>
/// <param name="getReader">A function that creates an ILModuleReader for reading module data.</param>
static member CreateFromILModuleReader:
projectOutputFile: string * getStamp: (unit -> DateTime) * getReader: (unit -> ILModuleReader) ->
FSharpReferencedProject
| ILModuleReference of
projectOutputFile: string *
getStamp: (unit -> DateTime) *
getReader: (unit -> ILModuleReader)

/// <summary>
/// The fully qualified path to the output of the referenced project. This should be the same value as the <c>-r</c>
/// reference in the project options for this referenced project.
/// </summary>
member OutputFile: string

/// Represents the use of an F# symbol from F# source code
[<Sealed>]
Expand Down
4 changes: 2 additions & 2 deletions src/Compiler/Service/service.fs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ type BackgroundCompiler
member x.FileName = nm
}

| FSharpReferencedProject.PEReference (nm, getStamp, delayedReader) ->
| FSharpReferencedProject.PEReference (getStamp, delayedReader) ->
{ new IProjectReference with
member x.EvaluateRawContents() =
node {
Expand All @@ -273,7 +273,7 @@ type BackgroundCompiler
}

member x.TryGetLogicalTimeStamp _ = getStamp () |> Some
member x.FileName = nm
member x.FileName = delayedReader.OutputFile
}

| FSharpReferencedProject.ILModuleReference (nm, getStamp, getReader) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1945,6 +1945,9 @@ FSharp.Compiler.AbstractIL.ILBinaryReader: FSharp.Compiler.AbstractIL.ILBinaryRe
FSharp.Compiler.AbstractIL.ILBinaryReader: FSharp.Compiler.AbstractIL.ILBinaryReader+MetadataOnlyFlag
FSharp.Compiler.AbstractIL.ILBinaryReader: FSharp.Compiler.AbstractIL.ILBinaryReader+ReduceMemoryFlag
FSharp.Compiler.AbstractIL.ILBinaryReader: FSharp.Compiler.AbstractIL.ILBinaryReader+Shim
FSharp.Compiler.CodeAnalysis.DelayedILModuleReader: System.String OutputFile
FSharp.Compiler.CodeAnalysis.DelayedILModuleReader: System.String get_OutputFile()
FSharp.Compiler.CodeAnalysis.DelayedILModuleReader: Void .ctor(System.String, Microsoft.FSharp.Core.FSharpFunc`2[System.Threading.CancellationToken,Microsoft.FSharp.Core.FSharpOption`1[System.IO.Stream]])
FSharp.Compiler.CodeAnalysis.DocumentSource+Custom: Microsoft.FSharp.Core.FSharpFunc`2[System.String,Microsoft.FSharp.Control.FSharpAsync`1[Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.ISourceText]]] Item
FSharp.Compiler.CodeAnalysis.DocumentSource+Custom: Microsoft.FSharp.Core.FSharpFunc`2[System.String,Microsoft.FSharp.Control.FSharpAsync`1[Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.ISourceText]]] get_Item()
FSharp.Compiler.CodeAnalysis.DocumentSource+Tags: Int32 Custom
Expand Down Expand Up @@ -2165,11 +2168,40 @@ FSharp.Compiler.CodeAnalysis.FSharpProjectOptions: System.String[] SourceFiles
FSharp.Compiler.CodeAnalysis.FSharpProjectOptions: System.String[] get_OtherOptions()
FSharp.Compiler.CodeAnalysis.FSharpProjectOptions: System.String[] get_SourceFiles()
FSharp.Compiler.CodeAnalysis.FSharpProjectOptions: Void .ctor(System.String, Microsoft.FSharp.Core.FSharpOption`1[System.String], System.String[], System.String[], FSharp.Compiler.CodeAnalysis.FSharpReferencedProject[], Boolean, Boolean, System.DateTime, Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.CodeAnalysis.FSharpUnresolvedReferencesSet], Microsoft.FSharp.Collections.FSharpList`1[System.Tuple`3[FSharp.Compiler.Text.Range,System.String,System.String]], Microsoft.FSharp.Core.FSharpOption`1[System.Int64])
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject+FSharpReference: FSharp.Compiler.CodeAnalysis.FSharpProjectOptions get_options()
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject+FSharpReference: FSharp.Compiler.CodeAnalysis.FSharpProjectOptions options
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject+FSharpReference: System.String get_projectOutputFile()
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject+FSharpReference: System.String projectOutputFile
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject+ILModuleReference: Microsoft.FSharp.Core.FSharpFunc`2[Microsoft.FSharp.Core.Unit,FSharp.Compiler.AbstractIL.ILBinaryReader+ILModuleReader] getReader
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject+ILModuleReference: Microsoft.FSharp.Core.FSharpFunc`2[Microsoft.FSharp.Core.Unit,FSharp.Compiler.AbstractIL.ILBinaryReader+ILModuleReader] get_getReader()
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject+ILModuleReference: Microsoft.FSharp.Core.FSharpFunc`2[Microsoft.FSharp.Core.Unit,System.DateTime] getStamp
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject+ILModuleReference: Microsoft.FSharp.Core.FSharpFunc`2[Microsoft.FSharp.Core.Unit,System.DateTime] get_getStamp()
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject+ILModuleReference: System.String get_projectOutputFile()
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject+ILModuleReference: System.String projectOutputFile
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject+PEReference: FSharp.Compiler.CodeAnalysis.DelayedILModuleReader delayedReader
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject+PEReference: FSharp.Compiler.CodeAnalysis.DelayedILModuleReader get_delayedReader()
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject+PEReference: Microsoft.FSharp.Core.FSharpFunc`2[Microsoft.FSharp.Core.Unit,System.DateTime] getStamp
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject+PEReference: Microsoft.FSharp.Core.FSharpFunc`2[Microsoft.FSharp.Core.Unit,System.DateTime] get_getStamp()
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject+Tags: Int32 FSharpReference
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject+Tags: Int32 ILModuleReference
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject+Tags: Int32 PEReference
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject: Boolean Equals(System.Object)
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject: FSharp.Compiler.CodeAnalysis.FSharpReferencedProject CreateFSharp(System.String, FSharp.Compiler.CodeAnalysis.FSharpProjectOptions)
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject: FSharp.Compiler.CodeAnalysis.FSharpReferencedProject CreateFromILModuleReader(System.String, Microsoft.FSharp.Core.FSharpFunc`2[Microsoft.FSharp.Core.Unit,System.DateTime], Microsoft.FSharp.Core.FSharpFunc`2[Microsoft.FSharp.Core.Unit,FSharp.Compiler.AbstractIL.ILBinaryReader+ILModuleReader])
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject: FSharp.Compiler.CodeAnalysis.FSharpReferencedProject CreatePortableExecutable(System.String, Microsoft.FSharp.Core.FSharpFunc`2[Microsoft.FSharp.Core.Unit,System.DateTime], Microsoft.FSharp.Core.FSharpFunc`2[System.Threading.CancellationToken,Microsoft.FSharp.Core.FSharpOption`1[System.IO.Stream]])
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject: Boolean IsFSharpReference
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject: Boolean IsILModuleReference
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject: Boolean IsPEReference
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject: Boolean get_IsFSharpReference()
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject: Boolean get_IsILModuleReference()
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject: Boolean get_IsPEReference()
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject: FSharp.Compiler.CodeAnalysis.FSharpReferencedProject NewFSharpReference(System.String, FSharp.Compiler.CodeAnalysis.FSharpProjectOptions)
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject: FSharp.Compiler.CodeAnalysis.FSharpReferencedProject NewILModuleReference(System.String, Microsoft.FSharp.Core.FSharpFunc`2[Microsoft.FSharp.Core.Unit,System.DateTime], Microsoft.FSharp.Core.FSharpFunc`2[Microsoft.FSharp.Core.Unit,FSharp.Compiler.AbstractIL.ILBinaryReader+ILModuleReader])
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject: FSharp.Compiler.CodeAnalysis.FSharpReferencedProject NewPEReference(Microsoft.FSharp.Core.FSharpFunc`2[Microsoft.FSharp.Core.Unit,System.DateTime], FSharp.Compiler.CodeAnalysis.DelayedILModuleReader)
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject: FSharp.Compiler.CodeAnalysis.FSharpReferencedProject+FSharpReference
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject: FSharp.Compiler.CodeAnalysis.FSharpReferencedProject+ILModuleReference
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject: FSharp.Compiler.CodeAnalysis.FSharpReferencedProject+PEReference
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject: FSharp.Compiler.CodeAnalysis.FSharpReferencedProject+Tags
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject: Int32 GetHashCode()
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject: Int32 Tag
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject: Int32 get_Tag()
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject: System.String OutputFile
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject: System.String ToString()
FSharp.Compiler.CodeAnalysis.FSharpReferencedProject: System.String get_OutputFile()
Expand Down
Loading