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

Merge main to release/dev17.8 #15967

Merged
merged 4 commits into from
Sep 14, 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
4 changes: 2 additions & 2 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
</Dependency>
</ProductDependencies>
<ToolsetDependencies>
<Dependency Name="Microsoft.DotNet.Arcade.Sdk" Version="8.0.0-beta.23451.1">
<Dependency Name="Microsoft.DotNet.Arcade.Sdk" Version="8.0.0-beta.23461.2">
<Uri>https://github.com/dotnet/arcade</Uri>
<Sha>4665b3d04e1da3796b965c3c3e3b97f55c449a6e</Sha>
<Sha>4a908c64757841121e67fda7adaf776c93893163</Sha>
<SourceBuild RepoName="arcade" ManagedOnly="true" />
</Dependency>
<Dependency Name="Microsoft.DotNet.XliffTasks" Version="1.0.0-beta.23426.1" CoherentParentDependency="Microsoft.DotNet.Arcade.Sdk">
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"perl": "5.38.0.1"
},
"msbuild-sdks": {
"Microsoft.DotNet.Arcade.Sdk": "8.0.0-beta.23451.1",
"Microsoft.DotNet.Arcade.Sdk": "8.0.0-beta.23461.2",
"Microsoft.DotNet.Helix.Sdk": "8.0.0-beta.23255.2"
}
}
2 changes: 1 addition & 1 deletion src/Compiler/Service/IncrementalBuild.fs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ type BoundModel private (
if enableBackgroundItemKeyStoreAndSemanticClassification then
use _ = Activity.start "IncrementalBuild.CreateItemKeyStoreAndSemanticClassification" [|Activity.Tags.fileName, fileName|]
let sResolutions = sink.GetResolutions()
let builder = ItemKeyStoreBuilder()
let builder = ItemKeyStoreBuilder(tcGlobals)
let preventDuplicates = HashSet({ new IEqualityComparer<struct(pos * pos)> with
member _.Equals((s1, e1): struct(pos * pos), (s2, e2): struct(pos * pos)) = Position.posEq s1 s2 && Position.posEq e1 e2
member _.GetHashCode o = o.GetHashCode() })
Expand Down
127 changes: 121 additions & 6 deletions src/Compiler/Service/ItemKey.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ open FSharp.Compiler.Text.Range
open FSharp.Compiler.TypedTree
open FSharp.Compiler.TypedTreeBasics
open FSharp.Compiler.Syntax.PrettyNaming
open FSharp.Compiler.TypedTreeOps
open FSharp.Compiler.TcGlobals

#nowarn "9"
#nowarn "51"
Expand Down Expand Up @@ -96,8 +98,82 @@ module ItemKeyTags =
[<Literal>]
let parameters = "p$p$"

[<AutoOpen>]
module DebugKeyStore =

/// A debugging tool to show what's being written into the ItemKeyStore in a more human readable way in the debugger.
type DebugKeyStore() =

let mutable debugCurrentItem = ResizeArray()

member val Items = ResizeArray()

member _.WriteRange(m: range) = debugCurrentItem.Add("range", $"{m}")

member _.WriteEntityRef(eref: EntityRef) =
debugCurrentItem.Add("EntityRef", $"{eref}")

member _.WriteILType(ilTy: ILType) =
debugCurrentItem.Add("ILType", $"%A{ilTy}")

member _.WriteType isStandalone (ty: TType) =
debugCurrentItem.Add("Type", $"{isStandalone} %A{ty}")

member _.WriteMeasure isStandalone (ms: Measure) =
debugCurrentItem.Add("Measure", $"{isStandalone} %A{ms}")

member _.WriteTypar (isStandalone: bool) (typar: Typar) =
debugCurrentItem.Add("Typar", $"{isStandalone} %A{typar}")

member _.WriteValRef(vref: ValRef) =
debugCurrentItem.Add("ValRef", $"{vref}")

member _.WriteValue(vref: ValRef) =
debugCurrentItem.Add("Value", $"{vref}")

member _.WriteActivePatternCase (apInfo: ActivePatternInfo) index =
debugCurrentItem.Add("ActivePatternCase", $"{apInfo} {index}")

member this.FinishItem(item, length) =
debugCurrentItem.Add("length", $"{length}")
this.Items.Add(item, debugCurrentItem)
let itemCount = this.Items.Count
assert (itemCount > 0)
debugCurrentItem <- ResizeArray()

member _.New() = DebugKeyStore()

/// A replacement for DebugKeyStore for when we're not debugging.
type _DebugKeyStoreNoop() =

member inline _.Items = Unchecked.defaultof<_>

member inline _.WriteRange(_m: range) = ()

member inline _.WriteEntityRef(_eref: EntityRef) = ()

member inline _.WriteILType(_ilTy: ILType) = ()

member inline _.WriteType _isStandalone (_ty: TType) = ()

member inline _.WriteMeasure _isStandalone (_ms: Measure) = ()

member inline _.WriteTypar (_isStandalone: bool) (_typar: Typar) = ()

member inline _.WriteValRef(_vref: ValRef) = ()

member inline _.WriteValue(_vref: ValRef) = ()

member inline _.WriteActivePatternCase (_apInfo: ActivePatternInfo) _index = ()

member inline _.FinishItem(_item, _length) = ()

member inline this.New() = this

let DebugKeyStoreNoop = _DebugKeyStoreNoop ()

[<Sealed>]
type ItemKeyStore(mmf: MemoryMappedFile, length) =
type ItemKeyStore(mmf: MemoryMappedFile, length, tcGlobals, debugStore) =

let rangeBuffer = Array.zeroCreate<byte> sizeof<range>

Expand All @@ -107,6 +183,8 @@ type ItemKeyStore(mmf: MemoryMappedFile, length) =
if isDisposed then
raise (ObjectDisposedException("ItemKeyStore"))

member _.DebugStore = debugStore

member _.ReadRange(reader: byref<BlobReader>) =
reader.ReadBytes(sizeof<range>, rangeBuffer, 0)
MemoryMarshal.Cast<byte, range>(Span(rangeBuffer)).[0]
Expand All @@ -133,7 +211,7 @@ type ItemKeyStore(mmf: MemoryMappedFile, length) =
member this.FindAll(item: Item) =
checkDispose ()

let builder = ItemKeyStoreBuilder()
let builder = ItemKeyStoreBuilder(tcGlobals)
builder.Write(range0, item)

match builder.TryBuildAndReset() with
Expand Down Expand Up @@ -166,10 +244,13 @@ type ItemKeyStore(mmf: MemoryMappedFile, length) =
isDisposed <- true
mmf.Dispose()

and [<Sealed>] ItemKeyStoreBuilder() =
and [<Sealed>] ItemKeyStoreBuilder(tcGlobals: TcGlobals) =

let b = BlobBuilder()

// Change this to DebugKeyStore() for debugging (DebugStore will be available on ItemKeyStore)
let mutable debug = DebugKeyStoreNoop

let writeChar (c: char) = b.WriteUInt16(uint16 c)

let writeUInt16 (i: uint16) = b.WriteUInt16 i
Expand All @@ -181,16 +262,20 @@ and [<Sealed>] ItemKeyStoreBuilder() =
let writeString (str: string) = b.WriteUTF16 str

let writeRange (m: range) =
debug.WriteRange m
let mutable m = m
let ptr = &&m |> NativePtr.toNativeInt |> NativePtr.ofNativeInt<byte>
b.WriteBytes(ptr, sizeof<range>)

let writeEntityRef (eref: EntityRef) =
debug.WriteEntityRef eref
writeString ItemKeyTags.entityRef
writeString eref.CompiledName
eref.CompilationPath.MangledPath |> List.iter (fun str -> writeString str)

let rec writeILType (ilTy: ILType) =
debug.WriteILType ilTy

match ilTy with
| ILType.TypeVar n ->
writeString "!"
Expand Down Expand Up @@ -231,6 +316,8 @@ and [<Sealed>] ItemKeyStoreBuilder() =
writeILType mref.ReturnType

let rec writeType isStandalone (ty: TType) =
debug.WriteType isStandalone ty

match stripTyparEqns ty with
| TType_forall (_, ty) -> writeType false ty

Expand Down Expand Up @@ -268,6 +355,8 @@ and [<Sealed>] ItemKeyStoreBuilder() =
writeString nm

and writeMeasure isStandalone (ms: Measure) =
debug.WriteMeasure isStandalone ms

match ms with
| Measure.Var typar ->
writeString ItemKeyTags.typeMeasureVar
Expand All @@ -278,20 +367,38 @@ and [<Sealed>] ItemKeyStoreBuilder() =
| _ -> ()

and writeTypar (isStandalone: bool) (typar: Typar) =
debug.WriteTypar isStandalone typar

match typar.Solution with
| Some ty -> writeType isStandalone ty
| _ ->
if isStandalone then
writeInt64 typar.Stamp

let writeValRef (vref: ValRef) =
debug.WriteValRef vref

match vref.MemberInfo with
| Some memberInfo ->
writeString ItemKeyTags.itemValueMember
writeEntityRef memberInfo.ApparentEnclosingEntity

match vref.IsOverrideOrExplicitImpl, vref.MemberInfo with
| true,
Some {
ImplementedSlotSigs = slotSig :: _tail
} -> slotSig.DeclaringType |> writeType false
| _ -> writeEntityRef memberInfo.ApparentEnclosingEntity

writeString vref.LogicalName
writeString ItemKeyTags.parameters
writeType false vref.Type

match vref.IsInstanceMember, tryDestFunTy tcGlobals vref.Type with
// In case of an instance member, we will skip the type of "this" because it will differ
// between the definition and overrides. Also it's not needed to uniquely identify the reference.
| true, ValueSome (_thisTy, funTy) -> funTy
| _ -> vref.Type
|> writeType false

| _ ->
writeString ItemKeyTags.itemValue
writeString vref.LogicalName
Expand All @@ -307,6 +414,8 @@ and [<Sealed>] ItemKeyStoreBuilder() =
| Parent eref -> writeEntityRef eref

let writeValue (vref: ValRef) =
debug.WriteValue vref

if vref.IsPropertyGetterMethod || vref.IsPropertySetterMethod then
writeString ItemKeyTags.itemProperty
writeString vref.PropertyName
Expand All @@ -322,6 +431,8 @@ and [<Sealed>] ItemKeyStoreBuilder() =
writeValRef vref

let writeActivePatternCase (apInfo: ActivePatternInfo) index =
debug.WriteActivePatternCase apInfo index

writeString ItemKeyTags.itemActivePattern

match apInfo.ActiveTagsWithRanges with
Expand Down Expand Up @@ -474,6 +585,7 @@ and [<Sealed>] ItemKeyStoreBuilder() =
let postCount = b.Count

fixup.WriteInt32(postCount - preCount)
debug.FinishItem(item, postCount - preCount)

member _.TryBuildAndReset() =
if b.Count > 0 then
Expand All @@ -495,7 +607,10 @@ and [<Sealed>] ItemKeyStoreBuilder() =

b.Clear()

Some(new ItemKeyStore(mmf, length))
let result = Some(new ItemKeyStore(mmf, length, tcGlobals, debug.Items))
debug <- debug.New()
result
else
b.Clear()
debug <- debug.New()
None
3 changes: 2 additions & 1 deletion src/Compiler/Service/ItemKey.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace FSharp.Compiler.CodeAnalysis
open System
open FSharp.Compiler.NameResolution
open FSharp.Compiler.Text
open FSharp.Compiler.TcGlobals

/// Stores a list of item key strings and their ranges in a memory mapped file.
[<Sealed>]
Expand All @@ -17,7 +18,7 @@ type internal ItemKeyStore =
[<Sealed>]
type internal ItemKeyStoreBuilder =

new: unit -> ItemKeyStoreBuilder
new: TcGlobals -> ItemKeyStoreBuilder

member Write: range * Item -> unit

Expand Down
Loading