From 31f77f74fe5207b199acf865f213d6ee8509366b Mon Sep 17 00:00:00 2001 From: Eugene Auduchinok Date: Thu, 13 Aug 2026 12:03:34 +0200 Subject: [PATCH 1/3] Reuse the cached ILTypeRef in ILTypeInfo.FromType For a TILObjectRepr entity, Entity.CompiledRepresentation already caches exactly 'mkRefForNestedILTypeDef scoref (enc, tdef)'. Take the ILTypeRef from there instead of rebuilding an equal one - and its enclosing-name list, and its hash - on every ILTypeInfo.FromType call. Co-Authored-By: Claude Opus 5 (1M context) --- .../.FSharp.Compiler.Service/11.0.100.md | 1 + src/Compiler/Checking/infos.fs | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md b/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md index e11e34a5c88..ad361fd9469 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md +++ b/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md @@ -162,6 +162,7 @@ * Support for the `` XML documentation tag: at compile time, documentation is copied from an external XML file selected by an XPath query and emitted into the generated documentation file. `` remains unsupported. ([Issue #19175](https://github.com/dotnet/fsharp/issues/19175), [PR #19186](https://github.com/dotnet/fsharp/pull/19186)) * Expand `` at tooling time. In IDE tooltips, completion, and signature help, documentation is inherited from base classes, interfaces, overridden members, and constructors (matched by parameter signature). The FCS Symbols API (`FSharpSymbol.XmlDoc`) additionally resolves explicit `cref` targets, but does not expand constructor inheritance. The compiler emits the tag verbatim into generated XML documentation files, matching C#; `` is not implemented. ([Issue #19175](https://github.com/dotnet/fsharp/issues/19175), [PR #19188](https://github.com/dotnet/fsharp/pull/19188)) * Add symbol and type highlighting to F# diagnostics ([PR #20097](https://github.com/dotnet/fsharp/pull/20097)) +* `ILTypeInfo.FromType` now reuses the `ILTypeRef` already cached in `Entity.CompiledRepresentation` instead of rebuilding an equal one with `mkRefForNestedILTypeDef` (along with its enclosing-name list and hash) on every call. ### Improved diff --git a/src/Compiler/Checking/infos.fs b/src/Compiler/Checking/infos.fs index 5f9d4f41ba4..b42f58fd4d0 100644 --- a/src/Compiler/Checking/infos.fs +++ b/src/Compiler/Checking/infos.fs @@ -461,14 +461,15 @@ type ILTypeInfo = let metadataTy = convertToTypeWithMetadataIfPossible g ty assert (isILAppTy g metadataTy) let metadataTyconRef = tcrefOfAppTy g metadataTy - let (TILObjectReprData(scoref, enc, tdef)) = metadataTyconRef.ILTyconInfo - let metadataILTypeRef = mkRefForNestedILTypeDef scoref (enc, tdef) - ILTypeInfo(g, ty, metadataILTypeRef, tdef) + let (TILObjectReprData(_, _, tdef)) = metadataTyconRef.ILTyconInfo + // Entity.CompiledRepresentation caches exactly 'mkRefForNestedILTypeDef scoref (enc, tdef)' + // for a TILObjectRepr entity, so take it from there rather than rebuilding a duplicate + // ILTypeRef (and its enclosing-name list, and its hash) on every call. + ILTypeInfo(g, ty, metadataTyconRef.CompiledRepresentationForNamedType, tdef) elif isILAppTy g ty then let tcref = tcrefOfAppTy g ty - let (TILObjectReprData(scoref, enc, tdef)) = tcref.ILTyconInfo - let tref = mkRefForNestedILTypeDef scoref (enc, tdef) - ILTypeInfo(g, ty, tref, tdef) + let (TILObjectReprData(_, _, tdef)) = tcref.ILTyconInfo + ILTypeInfo(g, ty, tcref.CompiledRepresentationForNamedType, tdef) else failwith ("ILTypeInfo.FromType - no IL metadata for type" + Environment.StackTrace) From 3c52801c0423b3122f8ac18da7204a052bfb748b Mon Sep 17 00:00:00 2001 From: Eugene Auduchinok Date: Thu, 13 Aug 2026 13:01:57 +0200 Subject: [PATCH 2/3] Release notes --- docs/release-notes/.FSharp.Compiler.Service/11.0.100.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md b/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md index ad361fd9469..6745b881aaf 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md +++ b/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md @@ -162,7 +162,7 @@ * Support for the `` XML documentation tag: at compile time, documentation is copied from an external XML file selected by an XPath query and emitted into the generated documentation file. `` remains unsupported. ([Issue #19175](https://github.com/dotnet/fsharp/issues/19175), [PR #19186](https://github.com/dotnet/fsharp/pull/19186)) * Expand `` at tooling time. In IDE tooltips, completion, and signature help, documentation is inherited from base classes, interfaces, overridden members, and constructors (matched by parameter signature). The FCS Symbols API (`FSharpSymbol.XmlDoc`) additionally resolves explicit `cref` targets, but does not expand constructor inheritance. The compiler emits the tag verbatim into generated XML documentation files, matching C#; `` is not implemented. ([Issue #19175](https://github.com/dotnet/fsharp/issues/19175), [PR #19188](https://github.com/dotnet/fsharp/pull/19188)) * Add symbol and type highlighting to F# diagnostics ([PR #20097](https://github.com/dotnet/fsharp/pull/20097)) -* `ILTypeInfo.FromType` now reuses the `ILTypeRef` already cached in `Entity.CompiledRepresentation` instead of rebuilding an equal one with `mkRefForNestedILTypeDef` (along with its enclosing-name list and hash) on every call. +* IL: reuse the cached ILTypeRef in ILTypeInfo.FromType ([PR #20255](https://github.com/dotnet/fsharp/pull/20255)) ### Improved From 3953d3dc9f6b1151becb067c872677ae630e7c38 Mon Sep 17 00:00:00 2001 From: Eugene Auduchinok Date: Thu, 13 Aug 2026 13:02:50 +0200 Subject: [PATCH 3/3] Cleanup --- src/Compiler/Checking/infos.fs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Compiler/Checking/infos.fs b/src/Compiler/Checking/infos.fs index b42f58fd4d0..b9fba8f548c 100644 --- a/src/Compiler/Checking/infos.fs +++ b/src/Compiler/Checking/infos.fs @@ -462,9 +462,6 @@ type ILTypeInfo = assert (isILAppTy g metadataTy) let metadataTyconRef = tcrefOfAppTy g metadataTy let (TILObjectReprData(_, _, tdef)) = metadataTyconRef.ILTyconInfo - // Entity.CompiledRepresentation caches exactly 'mkRefForNestedILTypeDef scoref (enc, tdef)' - // for a TILObjectRepr entity, so take it from there rather than rebuilding a duplicate - // ILTypeRef (and its enclosing-name list, and its hash) on every call. ILTypeInfo(g, ty, metadataTyconRef.CompiledRepresentationForNamedType, tdef) elif isILAppTy g ty then let tcref = tcrefOfAppTy g ty @@ -2653,4 +2650,4 @@ let (|DifferentGetterAndSetter|_|) (pinfo: PropInfo) = // Getter has an index parameter getValReprInfo.TotalArgCount > 1 -> ValueSome (getValRef, setValRef) | _ -> ValueNone - | _ -> ValueNone \ No newline at end of file + | _ -> ValueNone