Cache attributes read by compiler— replace repeated string matching with O(1) enum lookups#19394
Open
Cache attributes read by compiler— replace repeated string matching with O(1) enum lookups#19394
Conversation
…Attributes flag enums Add three [<Flags>] enums for O(1) well-known attribute lookups: - WellKnownILAttributes (uint32) in AbstractIL/il.fs/.fsi - WellKnownEntityAttributes (uint64) in TypedTree/TypedTree.fs/.fsi - WellKnownValAttributes (uint64) in TypedTree/TypedTree.fs/.fsi Each enum uses power-of-2 bit values with NotComputed at the sign bit. Purely additive — no existing code modified. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add computeILWellKnownFlags function in TypedTreeOps.fs that maps all 19 WellKnownILAttributes enum values to their TcGlobals attrib_* fields - Add HasWellKnownAttribute extension members on ILAttributesStored, ILTypeDef, ILMethodDef, and ILFieldDef - Migrate 12 IL-domain existence-only check sites from O(N) TryFindILAttribute scans to O(1) HasWellKnownAttribute calls - Fix pre-existing ILAttributesStored sealed class callers (Given -> CreateGiven, customAttrsReader -> CreateReader pattern in ilread.fs) - Keep 3 data-extracting sites (ReflectedDefinition, AutoOpen, InternalsVisibleTo) and 2 individual-attribute iteration sites unchanged - TypeHierarchy.fs sites use TryFindILAttribute on storedAttrs.CustomAttrs (scope comparison prevents full HasWellKnownAttribute migration) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…gration, remove dead enums - Fix computeILWellKnownFlags to use name+enclosing comparison (not full ILTypeRef equality with scope) matching isILAttrib semantics. This fixes silent failures when BCL reference assemblies use ILScopeRef.Local while TcGlobals uses ILScopeRef.Assembly. - Migrate TypeHierarchy.fs sites #6 and #7 (IsReadOnlyAttribute, RequiresLocationAttribute) to use HasWellKnownAttribute. - Remove unused WellKnownEntityAttributes and WellKnownValAttributes enums from TypedTree.fs/TypedTree.fsi (dead code not part of this sprint). - Update surface area baseline. - Run dotnet fantomas on all changed files. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sprint 2: Entity Container And Infrastructure - Add WellKnownEntityAttributes flags enum (27 flags + NotComputed sentinel) - Add WellKnownEntityAttribs struct wrapper with O(1) attribute lookup - Change Entity.entity_attribs field type from Attribs to WellKnownEntityAttribs - Entity.Attribs still returns Attrib list via .AsList() - Add Entity.EntityAttribs and Entity.SetEntityAttribs members - Fix Entity.IsLinked for struct field (null check on AsList()) - Add computeEntityWellKnownFlags and EntityHasWellKnownAttribute in TypedTreeOps - Update TypedTreePickle.fs to pickle/unpickle through the wrapper - Update all entity_attribs assignments across the compiler Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace O(N) HasFSharpAttribute calls with O(1) EntityHasWellKnownAttribute bit tests for entity-level existence-only attribute checks across: - AugmentWithHashCompare.fs (1 site) - CheckDeclarations.fs (12 sites) - ConstraintSolver.fs (4 sites) - CheckExpressions.fs (1 site) - NameResolution.fs (9 sites) - PostInferenceChecks.fs (2 sites) - IlxGen.fs (2 sites) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add WellKnownValAttributes flags enum (25 flags + NotComputed sentinel) - Add WellKnownValAttribs wrapper struct mirroring WellKnownEntityAttribs - Change ValOptionalData.val_attribs field type to WellKnownValAttribs - Add Val.ValAttribs property returning WellKnownValAttribs - Add Val.SetValAttribs accepting WellKnownValAttribs - Val.Attribs still returns Attrib list, Val.SetAttribs still accepts Attribs - Change ArgReprInfo.Attribs field type to WellKnownValAttribs - Add computeValWellKnownFlags covering all 25 enum flags - Add ValHasWellKnownAttribute helper in TypedTreeOps - Update TypedTreePickle for val_attribs and ArgReprInfo serialization - Fix all downstream usage sites across compiler Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…wn attribute flags - Add ArgReprInfoHasWellKnownAttribute helper in TypedTreeOps.fs/.fsi - Migrate 11 Val sites to ValHasWellKnownAttribute (O(1) flag test) - Migrate 19 ArgReprInfo sites to ArgReprInfoHasWellKnownAttribute - Migrate 7 Attrib list sites using computeValWellKnownFlags - Migrate 2 Entity sites to EntityHasWellKnownAttribute - Total: 39 existence-only attribute check sites migrated Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add mapILFlagToEntityFlag and mapILFlagToValFlag mapping functions to TypedTreeOps.fs for translating WellKnownILAttributes flags to their Entity and Val equivalents. Add TyconRefHasWellKnownAttribute unified hybrid check function that dispatches on IL vs F# vs provided type metadata using O(1) flag tests. Migrate 5 existence-only TyconRef hybrid sites: - NameResolution.fs: ExtensionAttribute check - PostInferenceChecks.fs: IsByRefLikeAttribute and IsReadOnlyAttribute checks - TypedTreeOps.fs: IsByRefLikeAttribute (isByrefLikeTyconRef) and IsReadOnlyAttribute (isTyconRefReadOnly) checks Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ribInfo - Wrap mapILFlagToAttribInfo in #if !NO_TYPEPROVIDERS to fix FS1182 unused value error on netstandard2.0 target - Simplify ProvidedTypeMetadata case in TyconRefHasWellKnownAttribute to reuse TyconRefHasAttribute via the new helper - All component tests pass (6630/6630) - All import tests pass (63/63) - All CompilerCompat cross-version tests pass (6/6) - All service tests pass (2089/2089) - All scripting tests pass (99/99) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Revert isByrefLikeTyconRef from TyconRefHasWellKnownAttribute (type-identity) back to TyconRefHasAttributeByName (name-based) to preserve RFC FS-1053 compatibility. User code can define its own IsByRefLikeAttribute, so this function must match by attribute name, not by type identity. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ing per RFC FS-1053 The IsByRefLikeAttribute check in CheckEntityDefn was incorrectly changed to type-identity matching (TyconRefHasWellKnownAttribute) during Sprint 6. This breaks user-defined IsByRefLikeAttribute per RFC FS-1053. Reverted to name-based matching (TyconRefHasAttributeByName) for consistency with isByrefLikeTyconRef in TypedTreeOps.fs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace flat if/elif chain of 27 tyconRefEq comparisons with a two-phase dispatch: first check assembly identity (ccuEq), then array pattern match on the namespace path. User-defined attributes from unrelated assemblies are rejected in 1-2 cheap checks instead of 27 comparisons. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace flat if/elif chain of tyconRefEq calls with two-phase assembly/path routing and array pattern matching, matching the approach used in computeEntityWellKnownFlags. User attributes are rejected in 1-2 cheap checks instead of O(N×K) comparisons. All 25 well-known val attributes are covered. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace flat if/elif chain of nameMatch calls against 16 AttribInfo references with a prefix-based dispatch on ILTypeRef.Name. User-defined attributes bail out after 1-2 prefix checks instead of scanning all 16+ comparisons. Key changes: - Remove 16 AttribInfo extractions from TcGlobals at function top - Remove inline nameMatch helper - Group by StartsWith prefix: System.Runtime.CompilerServices (13), Microsoft.FSharp.Core (4), then remaining (3) - Cover SetsRequiredMembersAttribute from both CompilerServices and CodeAnalysis namespaces Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace 7 TryFindFSharpBoolAttribute linear scans with cached EntityHasWellKnownAttribute lookups. Update all pattern match sites in CheckAugmentationAttribs, TyconIsCandidateForAugmentationWithCompare, and TyconIsCandidateForAugmentationWithEquals from bool option to bool. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace TryFindFSharpBoolAttribute/HasFSharpAttribute/TryFindFSharpAttribute calls with EntityHasWellKnownAttribute/ValHasWellKnownAttribute at 10 sites: - CheckDeclarations.fs: StructuralComparison, StructuralEquality - NameResolution.fs: AutoOpen (CanAutoOpenTyconRef, module auto-open) - Optimizer.fs: CLIMutable - IlxGen.fs: CLIMutable, ComVisible (fast negative guard), LiteralAttribute, EntryPoint - fsi.fs: EntryPoint (fast negative guard) GeneralizableValueAttribute site left as-is (enum case is on Entity, not Val). ComVisible uses conservative fast negative guard to preserve exact semantics. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ttributes Add ClassAttribute, InterfaceAttribute, StructAttribute, MeasureAttribute to WellKnownEntityAttributes enum (bits 0x8000000u-0x40000000u). Add NoCompilerInliningAttribute to WellKnownValAttributes enum (0x2000000uL). Update computeEntityWellKnownFlags and computeValWellKnownFlags to recognize the new attribute names in FSharp.Core paths. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add _True/_False flag pairs for attributes that carry boolean semantics: Entity enum: DefaultAugmentationAttribute_True/_False, AutoSerializableAttribute_True/_False (widened enum to uint64) Val enum: ReflectedDefinitionAttribute_True/_False, DefaultValueAttribute_True/_False, NoDynamicInvocationAttribute_True/_False Compute functions now extract bool args from attribute constructors and set the appropriate flag. Added EntityTryGetBoolAttribute and ValTryGetBoolAttribute helpers. Migrated all TODO WELLKNOWN_ATTRIB bool extraction call sites: - TypedTreeOps.fs: HasDefaultAugmentationAttribute, isSealedTy - IlxGen.fs: DefaultAugmentation, NoDynamicInvocation, AutoSerializable - PostInferenceChecks.fs: DefaultAugmentation - infos.fs: ReflectedDefinition on ArgReprInfo Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…alse semantics) The original code used TryFindFSharpBoolAttributeAssumeFalse for these two attributes, which defaults to false when no explicit bool argument is present. The | _ -> fallback incorrectly set _True; corrected to _False. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The existence check at PostInferenceChecks.fs line 2122 must check both _True and _False flags since [<ReflectedDefinition>] without explicit bool arg sets _False (matching TryFindFSharpBoolAttributeAssumeFalse semantics). Without this fix, bare [<ReflectedDefinition>] on struct members would not trigger the FS1220 error. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace the Computed(ILAttributes * WellKnownILAttributes) DU case with a separate mutable wellKnownFlags field on ILAttributesStored. This avoids allocating a new DU case on every GetOrComputeWellKnownFlags call, reducing GC pressure for IL type definitions, methods, and fields. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add fast negative guard for StructLayoutAttribute in IlxGen.fs - Add fast negative guard for AttributeUsageAttribute in CheckExpressions.fs - Optimize CombineCcuContentFragments to avoid list concat when one side is empty - Use WellKnownEntityAttribs.Add for extension attribute additions - Remove TODO: WELLKNOWN_ATTRIB comments from guarded sites Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace WellKnownValAttribs.Create([]) with WellKnownValAttribs.Empty in NicePrint.fs, CompilerDiagnostics.fs, Symbols.fs, and TypedTreeBasics.fs. This avoids unnecessary list allocations. Also remove findings.yaml leftover artifact. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…WellKnownAttribs<'TItem, 'TFlags> Extract the near-identical struct implementations into a single generic struct WellKnownAttribs<'TItem, 'TFlags> defined in a separate file (WellKnownAttribs.fs/fsi) outside the module rec context. The two flag enums (WellKnownEntityAttributes, WellKnownValAttributes) are also moved to the new file to avoid FS0073 bootstrap compiler limitations with enum<uint64> constraints in module rec. WellKnownEntityAttribs and WellKnownValAttribs become type aliases with companion modules for factory functions (Empty, Create, CreateWithFlags). All instance methods (HasWellKnownAttribute, AsList, Flags, Add, Append, WithRecomputedFlags) live on the generic struct and work through the type aliases unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- DllImport: IlxGen.IsValRefIsDllImport and TailCallChecks to ValHasWellKnownAttribute - CLIEventAttribute: Add flag, add ValCompileAsEvent, migrate 4 val-based callers - ComVisibleAttribute: Split into True/False flags, migrate IlxGen bool check - ComImportAttribute: Add True flag, migrate isComInteropTy - CompilationRepresentation: Add ModuleSuffix/PermitNull/Instance/Static entity flags, migrate TyconHasUseNullAsTrueValueAttribute - ObsoleteAttribute: Add to WellKnownILAttributes + WellKnownEntityAttributes, add CheckILAttributesForUnseenStored using O(1) flag check, migrate NameResolution.IsTyconUnseenObsoleteSpec Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
All callers migrated to decodeBoolAttribFlag in compute functions. Inline TryFindFSharpBoolAttribute (default=true) directly. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace redundant HasFSharpAttribute/TryFindFSharpBoolAttribute calls with direct flag tests on the entityFlags that are already computed 3 lines above. - SealedAttribute: split into _True/_False flag pair for three-state semantics - MeasureableAttribute: add to WellKnownEntityAttributes enum - hasMeasureAttr, hasMeasureableAttr, hasAllowNullLiteralAttr: test entityFlags bits - structLayoutAttr: kept as TryFindFSharpInt32Attribute (needs LayoutKind int) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace HasFSharpAttribute with computeEntityWellKnownFlags + bit test in TcTyconDefnCore_Phase1B and TyparsAllHaveMeasureDeclEarlyCheck. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace HasFSharpAttribute/HasFSharpAttributeOpt with computeValWellKnownFlags + bit tests for: LiteralAttribute (3 sites), DllImportAttribute (1 site), NoCompilerInliningAttribute (1 site). ComputeInlineFlag computes flags once for both NoCompilerInlining and DllImport checks. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ion hot path Migrate NoEagerConstraintApplicationAttribute (2 callers in MethodCalls + CheckExpressions) and ExtensionAttribute (NameResolution) from linear-scan MethInfoHasAttribute to cached-flag MethInfoHasWellKnownAttribute. The new function dispatches to ILMethodDef.HasWellKnownAttribute (cached IL flags) for ILMeth and ValHasWellKnownAttribute (cached val flags) for FSMeth, with ProvidedMeth fallback to the old API. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ownAttribute, cleanup - Refactor resolveAttribPath from callback to struct(bclPath, fsharpCorePath) return value. Eliminates mutable-captured-by-closure in all 3 classifiers, removes 1 nesting level, makes control flow linear and purely functional. - Merge mapILFlagToAttribInfo + mapILFlagToEntityFlag into single mapILFlag returning struct(EntityFlag * AttribInfo option). One match, no drift risk. - Remove HasWellKnownAttribute from .fsi — callers must use CheckFlag. - Remove dead _g parameter from CheckCompilerFeatureRequiredAttribute. - Add NoEagerConstraintApplicationAttribute to WellKnownValAttributes for complete MethInfoHasWellKnownAttribute coverage on FSMeth path. - Add comment on dual-namespace SetsRequiredMembersAttribute. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…LUnseen, tryGetAssemblyAttribString - Extract tryGetWarnOnWithoutNullMessage helper from duplicated 8-line decode logic at two CheckExpressions.fs callsites - CheckILAttributesForUnseen now uses ILAttributes.HasWellKnownAttribute (non-caching) — same logic as CheckILAttributesForUnseenStored, no decode - Add tryGetAssemblyAttribString for single-attrib string extraction, eliminating [attr] singleton-list wrapping in IncrementalBuild.fs Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…IlxGen single-scan Dead code removed: - WellKnownAttribs.Append (zero callers) - ILAttributesStored.CreateGiven(idx,attrs) two-arg overload (zero callers) - ILAttributesStored.GetCustomAttrs(int32) shim (ignored arg, fix import.fs) - MetadataIndex + GetOrComputeWellKnownFlags removed from il.fsi (no external callers) Encapsulation: - CheckFlag now returns needsWriteBack bool, removing need to expose .Flags - .Flags removed from WellKnownAttribs.fsi Migration: - TyconRefAllowsNull replaces 5 TryFindTyconRefBoolAttribute AllowNullLiteral sites with cached flag path (IL: HasWellKnownAttribute, F#: EntityTryGetBoolAttribute) Efficiency: - GenParamAttribs: gate tryFindValAttribByFlag with flag check, merge MarshalAs filter into single pass, pass valFlags to GenMarshal - GenMarshal: accept valFlags, skip all scans when MarshalAs absent - ComputeMethodImplAttribs: compute flags once, gate attribsHave + filterOut Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… lookup Replace List.exists with string comparison on hot path in Val.IsCompiledAsStaticPropertyWithoutField and PostInferenceChecks with cached WellKnownValAttributes flag check. - Add ValueAsStaticPropertyAttribute flag at bit 39 in WellKnownValAttributes - Add classifyValAttrib entry for the attribute - Simplify Val.IsCompiledAsStaticPropertyWithoutField to use HasWellKnownAttribute - Replace inline string scan in PostInferenceChecks with ValHasWellKnownAttribute - Expose HasWellKnownAttribute and Flags in WellKnownAttribs.fsi Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…aching Add convenience members that encapsulate the CheckFlag + write-back pattern directly on Entity and Val types. This eliminates the need for callers to manually remember the write-back step when checking well-known attribute flags. - Entity.HasWellKnownAttribute(flag, computeFlags) encapsulates cache update - Val.HasWellKnownAttribute(flag, computeFlags) encapsulates cache update - EntityHasWellKnownAttribute now forwards to entity.HasWellKnownAttribute - ValHasWellKnownAttribute now forwards to v.HasWellKnownAttribute - EntityTryGetBoolAttribute uses entity.HasWellKnownAttribute for first check - Both members declared in .fsi signature files Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…k parameters Introduce WellKnownMethAttribute struct that bundles ILFlag, ValFlag, and AttribInfo for well-known attribute checks on MethInfo. Add MethInfoHasWellKnownAttributeSpec overload that takes the bundled struct, delegating to the original function. Update all 3 callsites to use the new struct-based API, eliminating the risk of passing mismatched flags. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Mirrors EntityTryGetBoolAttribute to provide symmetric API for querying True/False/NotPresent attribute states on Val nodes. Supports flag pairs: ReflectedDefinition, DefaultValue, NoDynamicInvocation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Remove unused _g from CheckILExperimentalAttributes (private) - Remove unused _m from CheckILAttributesForUnseenStored and update .fsi - Remove unused _m from CheckFSharpAttributesForUnseen and update .fsi - Prefix newly-unused m params with _ in PropInfoIsUnseen and IsValUnseen - Add cross-reference doc comments between CheckILAttributesForUnseen variants - Update all callsites in NameResolution.fs and AttributeChecking.fs Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…classifyILAttrib Replace hand-rolled isILAttribByName checks with the modern classifyILAttrib flag-based API for consistency with the rest of the attribute classification infrastructure. Remove unused tname_AutoOpenAttr binding. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add a comprehensive navigation comment block before the attribute helpers section in TypedTreeOps.fs. The comment documents all well-known attribute APIs organized by category: existence checks, ad-hoc checks, data extraction active patterns, bool queries, IL-level operations, cross-metadata dispatch, and classification functions. Notes that MethInfoHasWellKnownAttribute lives in AttributeChecking.fs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… newlines - Commit updated surface area baseline removing stale ILAttributesStored entries - Fix reserved keyword 'sealed' used as variable name in CompilerCompat Program.fs - Fully qualify StructRecord.Y field for cross-project resolution - Add trailing newlines to Library.fs and AttributeUsage.fs Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ookup - Add TailCallAttribute = (1uL <<< 40) to WellKnownValAttributes enum (.fs and .fsi) - Add TailCallAttribute classification in classifyValAttrib under Microsoft.FSharp.Core - Remove HasTailCallAttrib from TcGlobals; replace with hasTailCallAttrib helper in TailCallChecks - Helper uses O(1) flag lookup with fallback for user-defined shadow attributes Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…mblyAttrib Add WellKnownAssemblyAttributes.TypeProviderAssemblyAttribute flag and classify it under Microsoft.FSharp.Core.CompilerServices in classifyAssemblyAttrib. Fold detection into the existing assembly attribute classification loop in IncrementalBuild.fs and TransparentCompiler.fs, eliminating a duplicate List.exists scan over topAttrs.assemblyAttrs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Extract shared tryBindTyconRefAttributeCore with WellKnownILAttributes voption parameter. Both TryBindTyconRefAttribute and TryBindTyconRefAttributeWithILFlag delegate to it, eliminating code duplication while preserving the O(1) flag check fast-path on the IL metadata path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The test 'DefaultAugmentation(false) suppresses helpers' in AttributeUsage.fs was a near-duplicate of the more specific 'Is* discriminated union properties are unavailable with DefaultAugmentation(false)' test in DiscriminatedUnionTests.fs. Remove the duplicate per TEST-CODE-QUALITY verifier feedback. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
…orts # Conflicts: # src/Compiler/Checking/Expressions/CheckExpressions.fs
…ads it GenParamAttribs was filtering MarshalAsAttribute from the attribs list before passing it to GenMarshal, which then couldn't find the attribute data (UnmanagedType value). Remove MarshalAs from the pre-filter mask and let GenMarshal handle its own filtering. Fixes: Marshal_fs IL baseline test (all platforms) Fixes: attributes-FSC_OPTIMIZED/FSI (Windows Desktop) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Attribute checks in the compiler (e.g.
IsStruct,IsAbstractClass,AllowNullLiteral,NoComparison, …) were implemented as linear scans + string comparisons every time they were queried. This PR replaces that with a compute-once / query-by-flag model.Core idea
All well-known attribute information for a given compiler item is encoded into a single
uint64flags enum — one bit per attribute. This covers:WellKnownILAttributes— attributes on imported IL types (e.g.IsReadOnly,IsByRefLike,Extension,Obsolete)WellKnownEntityAttributes— attributes on F# types and modules (~49 flags:Sealed,AbstractClass,NoComparison,StructuralEquality,CLIMutable,AutoOpen, …)WellKnownValAttributes— attributes on F# values and members (~41 flags:DllImport,Literal,InlineIfLambda,CallerMemberName,TailCall, …)WellKnownAssemblyAttributes— assembly-level attributes (AutoOpen,InternalsVisibleTo,TypeProviderAssembly, …)The flags encode two kinds of information:
AbstractClassAttribute,LiteralAttribute)_True/_False) to distinguish[<Sealed(true)>]from[<Sealed(false)>]from absent.CompilationRepresentationsimilarly encodes its four known flag values as separate bits.This does not attempt to cache high-cardinality or variable-size attribute data (strings, byte arrays, arbitrary integers). Those are still extracted on demand via typed active patterns (
EntityAttribString,ValAttribInt, etc.) that compose on top of the base flag check.How it works
classifyEntityAttrib/classifyValAttrib/classifyILAttribmap an attribute to its enum case via multi-level namespace+name dispatch. Computed once when the attribute list is first set; after that, every check is a single bitwise AND.WellKnownAttribs<'TItem, 'TFlags>struct pairs the original attribute list with its precomputed flags. Bit 63 (NotComputed) acts as a lazy-init sentinel.MethInfoHasWellKnownAttributeprovides the same O(1) check for method infos on the overload resolution hot path.Migration
~60
TryFindFSharpAttribute/IsMatchingFSharpAttribute/TryDecodeILAttributecall sites migrated. Dead helpers and ~18g.attrib_*TcGlobalsmembers deleted.