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

Optimize type interfaces reading from metadata #17382

Merged
merged 10 commits into from
Aug 29, 2024
2 changes: 2 additions & 0 deletions docs/release-notes/.FSharp.Compiler.Service/9.0.100.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@
* Applied nullable reference types to FSharp.Compiler.Service itself ([PR #15310](https://github.com/dotnet/fsharp/pull/15310))
* Ensure that isinteractive multi-emit backing fields are not public. ([Issue #17439](https://github.com/dotnet/fsharp/issues/17438)), ([PR #17439](https://github.com/dotnet/fsharp/pull/17439))
* Better error reporting for unions with duplicated fields. ([PR #17521](https://github.com/dotnet/fsharp/pull/17521))
* Optimize ILTypeDef interface impls reading from metadata. ([PR #17382](https://github.com/dotnet/fsharp/pull/17382))

### Breaking Changes
48 changes: 27 additions & 21 deletions src/Compiler/AbstractIL/ilread.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1425,16 +1425,10 @@ let seekReadParamRow (ctxt: ILMetadataReader) mdv idx =
(flags, seq, nameIdx)

/// Read Table InterfaceImpl.
let private seekReadInterfaceImplRow (ctxt: ILMetadataReader) mdv idx =
let private seekReadInterfaceIdx (ctxt: ILMetadataReader) mdv idx =
let mutable addr = ctxt.rowAddr TableNames.InterfaceImpl idx
let tidx = seekReadUntaggedIdx TableNames.TypeDef ctxt mdv &addr
let intfIdx = seekReadTypeDefOrRefOrSpecIdx ctxt mdv &addr

struct {|
TypeIdx = tidx
IntfIdx = intfIdx
IntImplIdx = idx
|}
let _tidx = seekReadUntaggedIdx TableNames.TypeDef ctxt mdv &addr
seekReadTypeDefOrRefOrSpecIdx ctxt mdv &addr

/// Read Table MemberRef.
let seekReadMemberRefRow (ctxt: ILMetadataReader) mdv idx =
Expand Down Expand Up @@ -1653,11 +1647,11 @@ let seekReadGenericParamRow (ctxt: ILMetadataReader) mdv idx =
(idx, seq, flags, ownerIdx, nameIdx)

// Read Table GenericParamConstraint.
let seekReadGenericParamConstraintRow (ctxt: ILMetadataReader) mdv idx =
let seekReadGenericParamConstraintIdx (ctxt: ILMetadataReader) mdv idx =
let mutable addr = ctxt.rowAddr TableNames.GenericParamConstraint idx
let pidx = seekReadUntaggedIdx TableNames.GenericParam ctxt mdv &addr
let _pidx = seekReadUntaggedIdx TableNames.GenericParam ctxt mdv &addr
let constraintIdx = seekReadTypeDefOrRefOrSpecIdx ctxt mdv &addr
(pidx, constraintIdx)
constraintIdx

/// Read Table ILMethodSpec.
let seekReadMethodSpecRow (ctxt: ILMetadataReader) mdv idx =
Expand Down Expand Up @@ -2248,11 +2242,16 @@ and seekReadNestedTypeDefs (ctxt: ILMetadataReader) tidx =
and seekReadInterfaceImpls (ctxt: ILMetadataReader) mdv numTypars tidx =
seekReadIndexedRows (
ctxt.getNumRows TableNames.InterfaceImpl,
seekReadInterfaceImplRow ctxt mdv,
(fun x -> x.TypeIdx),
simpleIndexCompare tidx,
id,
id,
(fun idx ->
let mutable addr = ctxt.rowAddr TableNames.InterfaceImpl idx
let _tidx = seekReadUntaggedIdx TableNames.TypeDef ctxt mdv &addr
simpleIndexCompare tidx _tidx),
isSorted ctxt TableNames.InterfaceImpl,
(fun x -> (seekReadTypeDefOrRef ctxt numTypars AsObject [] x.IntfIdx), (ctxt.customAttrsReader_InterfaceImpl, x.IntImplIdx))
(fun idx ->
let intfIdx = seekReadInterfaceIdx ctxt mdv idx
seekReadTypeDefOrRef ctxt numTypars AsObject [] intfIdx, (ctxt.customAttrsReader_InterfaceImpl, idx))
psfinaki marked this conversation as resolved.
Show resolved Hide resolved
)

and seekReadGenericParams ctxt numTypars (a, b) : ILGenericParameterDefs =
Expand All @@ -2262,12 +2261,14 @@ and seekReadGenericParamsUncached ctxtH (GenericParamsIdx(numTypars, a, b)) =
let (ctxt: ILMetadataReader) = getHole ctxtH
let mdv = ctxt.mdfile.GetView()

let key = TaggedIndex(a, b)

let pars =
seekReadIndexedRows (
ctxt.getNumRows TableNames.GenericParam,
seekReadGenericParamRow ctxt mdv,
(fun (_, _, _, tomd, _) -> tomd),
tomdCompare (TaggedIndex(a, b)),
tomdCompare key,
isSorted ctxt TableNames.GenericParam,
(fun (gpidx, seq, flags, _, nameIdx) ->
let flags = int32 flags
Expand Down Expand Up @@ -2299,11 +2300,16 @@ and seekReadGenericParamsUncached ctxtH (GenericParamsIdx(numTypars, a, b)) =
and seekReadGenericParamConstraints (ctxt: ILMetadataReader) mdv numTypars gpidx =
seekReadIndexedRows (
ctxt.getNumRows TableNames.GenericParamConstraint,
seekReadGenericParamConstraintRow ctxt mdv,
fst,
simpleIndexCompare gpidx,
id,
id,
(fun idx ->
let mutable addr = ctxt.rowAddr TableNames.GenericParamConstraint idx
let pidx = seekReadUntaggedIdx TableNames.GenericParam ctxt mdv &addr
simpleIndexCompare gpidx pidx),
isSorted ctxt TableNames.GenericParamConstraint,
(snd >> seekReadTypeDefOrRef ctxt numTypars AsObject [])
(fun idx ->
let constraintIdx = seekReadGenericParamConstraintIdx ctxt mdv idx
seekReadTypeDefOrRef ctxt numTypars AsObject [] constraintIdx)
)

and seekReadTypeDefAsType (ctxt: ILMetadataReader) boxity (ginst: ILTypes) idx =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,6 @@
! AssemblyReference: System.Reflection.Emit.ILGeneration
! AssemblyReference: System.Reflection.Metadata
! AssemblyReference: netstandard
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: <IntImplIdx>j__TPar IntImplIdx
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: <IntImplIdx>j__TPar get_IntImplIdx()
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: <IntfIdx>j__TPar IntfIdx
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: <IntfIdx>j__TPar get_IntfIdx()
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: <TypeIdx>j__TPar TypeIdx
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: <TypeIdx>j__TPar get_TypeIdx()
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Boolean Equals(<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar])
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Boolean Equals(<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar], System.Collections.IEqualityComparer)
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Boolean Equals(System.Object)
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Boolean Equals(System.Object, System.Collections.IEqualityComparer)
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Int32 CompareTo(<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar])
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Int32 CompareTo(System.Object)
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Int32 CompareTo(System.Object, System.Collections.IComparer)
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Int32 GetHashCode()
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Int32 GetHashCode(System.Collections.IEqualityComparer)
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: System.String ToString()
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Void .ctor(<IntImplIdx>j__TPar, <IntfIdx>j__TPar, <TypeIdx>j__TPar)
FSharp.Compiler.AbstractIL.IL+ILArgConvention+Tags: Int32 CDecl
FSharp.Compiler.AbstractIL.IL+ILArgConvention+Tags: Int32 Default
FSharp.Compiler.AbstractIL.IL+ILArgConvention+Tags: Int32 FastCall
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,6 @@
! AssemblyReference: System.Reflection.Emit.ILGeneration
! AssemblyReference: System.Reflection.Metadata
! AssemblyReference: netstandard
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: <IntImplIdx>j__TPar IntImplIdx
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: <IntImplIdx>j__TPar get_IntImplIdx()
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: <IntfIdx>j__TPar IntfIdx
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: <IntfIdx>j__TPar get_IntfIdx()
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: <TypeIdx>j__TPar TypeIdx
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: <TypeIdx>j__TPar get_TypeIdx()
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Boolean Equals(<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar])
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Boolean Equals(<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar], System.Collections.IEqualityComparer)
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Boolean Equals(System.Object)
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Boolean Equals(System.Object, System.Collections.IEqualityComparer)
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Int32 CompareTo(<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar])
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Int32 CompareTo(System.Object)
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Int32 CompareTo(System.Object, System.Collections.IComparer)
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Int32 GetHashCode()
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Int32 GetHashCode(System.Collections.IEqualityComparer)
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: System.String ToString()
<>f__AnonymousType10003411232265`3[<IntImplIdx>j__TPar,<IntfIdx>j__TPar,<TypeIdx>j__TPar]: Void .ctor(<IntImplIdx>j__TPar, <IntfIdx>j__TPar, <TypeIdx>j__TPar)
FSharp.Compiler.AbstractIL.IL+ILArgConvention+Tags: Int32 CDecl
FSharp.Compiler.AbstractIL.IL+ILArgConvention+Tags: Int32 Default
FSharp.Compiler.AbstractIL.IL+ILArgConvention+Tags: Int32 FastCall
Expand Down
Loading