Skip to content

Commit b74a9e1

Browse files
T-GroCopilot
andauthored
Split TypedTreeOps.fs (12,569 lines) into 7 focused files (#19521)
* Create TypedTreeOps.Remap.fs and .fsi (Sprint 1 of 7) Extract lines 1-1230 from TypedTreeOps.fs into a new file pair using namespace FSharp.Compiler.TypedTreeOps with three AutoOpen modules: - TypeRemapping: TyparMap, TyconRefMap, ValMap, Remap types and the remapTypeAux/remapValRef let-rec chain plus instantiation wrappers - TypeConstruction: type construction/destruction/query functions, Erasure DU, strip/dest/is functions - TypeEquivalence: TypeEquivEnv, the traitsAEquivAux/typeEquivAux let-rec chain, equivalence wrappers, getErasedTypes Files are not yet added to the fsproj - that happens in a later sprint. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Extract TypedTreeOps.ExprConstruction.fs/.fsi (File 2 of 7) Extract expression construction primitives, collection types, and arity/metadata analysis from TypedTreeOps.fs lines ~1231-2260 into TypedTreeOps.ExprConstruction.fs with matching .fsi file. Organized into 3 [<AutoOpen>] modules: - ExprConstruction: orderings, type builders, expr constructors, MatchBuilder, lambda/let/bind builders - CollectionTypes: ValHash, ValMultiMap, TyconRefMultiMap - ArityAndMetadata: rescoping, field accessors, type testers, TypeDefMetadata, free tyvar accumulators Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Extract TypedTreeOps.FreeVars.fs/.fsi (File 3 of 7) Create File 3 of the TypedTreeOps split: free type variable analysis, pretty-printing, and display environment. Structure: - FreeTypeVars module: FreeVarOptions, collection options, two recursive chains (accFreeTycon..accFreeInVal, boundTyparsLeftToRight..accFreeInTypesLeftToRight), addFreeInModuleTy, public wrappers, checkMemberVal/checkMemberValRef - Display module: GetFSharpViewOfReturnType, TraitConstraintInfo extension, member type functions, nested PrettyTypes and SimplifyTypes modules, GenericParameterStyle, DisplayEnv, display text helpers, superOfTycon Files are not yet added to the project file (will happen in final integration sprint). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Extract TypedTreeOps.Attributes.fs/.fsi (File 4 of 7) Create File 4 of the TypedTreeOps split: IL extensions, attribute helpers, and debug printing. Structure: - ILExtensions module: IL attribute detection functions (isILAttribByName, classifyILAttrib, computeILWellKnownFlags, tryFindILAttribByFlag, (|ILAttribDecoded|_|)) and type extensions on ILAttributesStored, ILTypeDef, ILMethodDef, ILFieldDef, ILAttributes - AttributeHelpers module: F# attribute discovery (resolveAttribPath, classifyEntityAttrib, classifyValAttrib, computeEntityWellKnownFlags, EntityHasWellKnownAttribute, etc.), type construction helpers, and type ValRef extension members - DebugPrinting module: nested DebugPrint module with showType, showExpr, layout functions (exprL, bindingL, atomL, etc.), and wrapModuleOrNamespace* helpers The DebugPrint module is nested inside DebugPrinting to preserve the FSharp.Compiler.TypedTreeOps.DebugPrint reference path used by callers. All let rec ... and chains inside DebugPrint are kept intact. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix TypedTreeOps.Attributes.fsi: remove misplaced declarations Remove 12 val declarations from .fsi that have no implementations in the .fs file. These were from original TypedTreeOps.fs lines outside the ~3523-5462 extraction range: - isInByrefTy, isOutByrefTy, isByrefTy, isNativePtrTy (original ~L1907-1923) - EvalLiteralExprOrAttribArg, EvaledAttribExprEquality (original ~L10943-10969) - IsSimpleSyntacticConstantExpr, ConstToILFieldInit (original ~L10646-10951) - Int32Expr, SpecialComparableHeadType, SpecialEquatableHeadType, SpecialNotEquatableHeadType (original ~L9986-11049) - TyparTy|NullableTypar|... (incomplete signature causing FS0010 parse error) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Extract TypedTreeOps.Remapping.fs/.fsi (File 5 of 7) Create the 5th split file from TypedTreeOps.fs containing: - SignatureOps: signature repackage/hiding types and operations - ExprFreeVars: expression-level free variable analysis (24-function chain) - ExprRemapping: expression remapping and copying (57-function chain) - ExprShapeQueries: type inference, remark, decision tree simplification Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Extract TypedTreeOps.ExprOps.fs/.fsi (File 6 of 7) Create File 6 of the TypedTreeOps split: address-of operations, expression folding, intrinsic call wrappers, and higher-level expression helpers. Extracts original TypedTreeOps.fs lines ~7651-9599 into 4 modules: - AddressOps: Mutates DU, address-of helpers, mkExprAddrOfExpr, field gets - ExprFolding: IterateRecursiveFixups, ExprFolder/ExprFolders, FoldExpr - IntrinsicCalls: 105 mkCall* wrappers, literal constructors, compilation attrs - ExprHelpers: MakeApplicationAndBetaReduce, lambda tupling, subsumption, etc. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Extract TypedTreeOps.Transforms.fs/.fsi (File 7 of 7) Create the final split file containing type encoding, expression rewriting, tuple compilation, integral constants, and attribute checking. Structure: - TypeEncoding: typeEnc, XML doc encoding, nullness helpers, compiled-as - Rewriting: ExprRewritingEnv, RewriteExpr, export remapping - TupleCompilation: mkCompiledTuple, IntegralConst (nested), mkFastForLoop - AttribChecking: CombineCcuContentFragments, Seq patterns, resumable code Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix TypedTreeOps.Transforms.fsi: remove duplicates, misplaced declarations, fix module placement - Remove duplicate declarations: HasConstraint, IsTyparTyWithConstraint, doesActivePatternHaveFreeTypars - Remove declarations belonging to other files (FreeVars: GetMemberTypeInMemberForm, PartitionValTypars*, CountEnclosingTyparsOfActualParentOfVal, ReturnTypeOfPropertyVal, ArgInfosOfPropertyVal, ArgInfosOfMember; ExprOps: mkCallDispose, mkCallSeq, mkCallTypeTest) - Move GetTypeOfIntrinsicMemberInCompiledForm from TypeEncoding to TupleCompilation - Move TraitWitnessInfoHashMap/EmptyTraitWitnessInfoHashMap from TupleCompilation to AttribChecking - Move mkDebugPoint and IfThenElseExpr from AttribChecking to TupleCompilation - Remove TraitConstraintInfo type extension (belongs to FreeVars, not this file) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Split TypedTreeOps into 7 files: wire up project, delete originals, fix cross-file deps Replace the monolithic TypedTreeOps.fs (12,569 lines) and TypedTreeOps.fsi (3,094 lines) with 7 focused files: 1. TypedTreeOps.Remap - Type remapping, instantiation, equivalence 2. TypedTreeOps.ExprConstruction - Expression/type construction helpers 3. TypedTreeOps.FreeVars - Free variable collection, display helpers 4. TypedTreeOps.Attributes - IL extensions, attribute classification 5. TypedTreeOps.Remapping - Signature ops, expr free vars, expr remapping 6. TypedTreeOps.ExprOps - Address ops, folding, intrinsic calls 7. TypedTreeOps.Transforms - Debug printing, pattern matching, transforms All files use namespace FSharp.Compiler.TypedTreeOps with [<AutoOpen>] internal modules, so the 69 callers doing 'open FSharp.Compiler.TypedTreeOps' required zero modifications. Integration fixes: - Added missing opens (FSharp.Compiler, Internal.Utilities.Collections, FSharp.Compiler.Syntax, FSharp.Compiler.CompilerGlobalState) - Fixed .fsi signature mismatches (generic vs concrete type params) - Exposed cross-file functions in .fsi files - Fixed type name references (Mutability -> ValMutability, etc.) - Applied dotnet fantomas formatting to all 14 files Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Create CommonContainers module in file 2, move container type helpers from file 4 Move container type helpers (Option, RefCell, Nullable, Choice, Byref, LinqExpression, etc.) from AttributeHelpers in TypedTreeOps.Attributes.fs to a new CommonContainers module in TypedTreeOps.ExprConstruction.fs. These functions only depend on tyconRefEq, stripTyEqns, tryTcrefOfAppTy, argsOfAppTy from file 1, not attribute infrastructure. Create ByrefAndSpanHelpers module in file 4 for span/byref-like functions that depend on TyconRefHasAttributeByName (must stay in file 4). All modules use [<AutoOpen>] so callers need no changes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Rename modules for coherence, move type constructors and encoding helpers - Rename ArityAndMetadata → TypeTesters (core content is 46 is*Ty predicates) - Rename IntrinsicCalls → Makers (174 mk* expression constructors) - Move mkForallTy/mkForallTyIfNeeded/+-> from ExprConstruction to TypeConstruction - Move commaEncs/angleEnc/typarEnc/ticksAndArgCountTextOfTyconRef from ExprHelpers to TypeEncoding Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Round 2: Move misplaced functions to correct modules - Free var accumulators TypeTesters→FreeTypeVars - Attribute helpers Makers→AttributeHelpers - mkFunTy/mkIteratedFunTy ExprConstruction→TypeConstruction - mk*Ty ExprShapeQueries→TypeConstruction - mk*Type Makers→TypeConstruction - mk*Test TypeEncoding→Makers (except mkIsInstConditional which depends on canUseTypeTestFast in Transforms.fs, compiled after ExprOps.fs) - Linear* APs: kept in SignatureOps (moving to ExprShapeQueries impossible - ExprShapeQueries is at end of Remapping.fs but Linear* are used in ExprFreeVars and ExprRemapping modules which appear earlier in the same file) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Round 3: Move quotation type helpers to TypeConstruction Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Round 4: Move type queries to TypeTesters, member helpers to Display Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Round 5: Move CombineCcuContentFragments to SignatureOps Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Rename TupleCompilation → LoopAndConstantOptimization The module contains tuple compilation, fast for loops, integral range detection, constant evaluation, and loop optimization — not just tuples. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Move unblocked functions to correct modules - underlyingTypeOfEnumTy/normalizeEnumTy ExprRemapping→TypeTesters - ClearValReprInfo ExprRemapping→ExprHelpers - mkArray AddressOps→Makers Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Move mkLabelled from AttribChecking to Makers Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Break rec chain assumptions: move standalone functions to correct modules - isResumableCodeTy/isReturnsResumableCodeTy/isFSharpExceptionTy → TypeTesters - serializeEntity + helpers → DebugPrint - Linear* APs SignatureOps → ExprFreeVars (same file, earlier position) - mkApps group ExprShapeQueries → Makers Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Final placement fixes: isResumableCodeTy, mkArray, isSealedTy, export remapping Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Move updateSeqTypeIsPrefix→SignatureOps, isTyparOrderMismatch→Display Last 2 cross-model agreed misplacements resolved. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Incorporate reviewer findings: move attribute/expr helpers to correct modules - CompileAsEvent/ValCompileAsEvent/ModuleNameIsMangled/MemberIsCompiledAsInstance → AttributeHelpers - valOfBind/valsOfBinds → ExprConstruction - WhileExpr/TryWithExpr/TryFinallyExpr/IntegerForLoopExpr APs → ExprShapeQueries - mkDebugPoint/(|InnerExprPat|)/(|Int32Expr|_|) → ExprConstruction or earlier Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Split TypeEncoding into XmlDocSignatures, NullnessAnalysis, TypeTestsAndPatterns Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Split AttribChecking into ResumableCodePatterns, SeqExprPatterns, ExtensionAndMiscHelpers Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Split TypeConstruction into MeasureOps, TypeBuilders, TypeAbbreviations, TypeDecomposition Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Rename Display→MemberRepresentation, dissolve ExtensionAndMiscHelpers, split LoopAndConstantOptimization Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Rename TypeTesters→TypeQueries, ExprHelpers→ExprTransforms, tighten ExprShapeQueries→ExprAnalysis Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix B-grade outliers: rename CollectionTypes, move dest/is from Makers, move patterns from TupleCompilation - Rename CollectionTypes → TypedTreeCollections - Move destInt32/destThrow/isThrow/isIDelegateEventType/destIDelegateEventType Makers→ExprTransforms - Move (|Int32Expr|_|)/(|IntegralRange|_|) TupleCompilation→ConstantEvaluation Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Rename TypeQueries back to TypeTesters 70% of vals operate on TType, 12% on Tycon, 5% on Val — 'Testers' better describes the is*/dest*/strip* nature than 'Queries'. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Remove accidentally committed scratch files Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix FS0667: disambiguate cenv record update in IlxGen.fs The [<AutoOpen>] split brought multiple record types with 'stackGuard' field into scope (FreeVarOptions, RemapContext, cenv). Add type annotation to resolve ambiguity. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Apply fantomas formatting to all TypedTreeOps files Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 3319018 commit b74a9e1

19 files changed

Lines changed: 19037 additions & 15667 deletions

src/Compiler/CodeGen/IlxGen.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3208,7 +3208,7 @@ and DelayCodeGenMethodForExpr cenv mgbuf (_, _, eenv, _, _, _, _ as args) =
32083208
let change3rdOutOf7 (a1, a2, _, a4, a5, a6, a7) newA3 = (a1, a2, newA3, a4, a5, a6, a7)
32093209

32103210
if eenv.delayCodeGen then
3211-
let cenv =
3211+
let cenv: cenv =
32123212
{ cenv with
32133213
stackGuard = getEmptyStackGuard ()
32143214
}

src/Compiler/Driver/CompilerImports.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ let WriteSignatureData (tcConfig: TcConfig, tcGlobals, exportRemapping, ccu: Ccu
215215
let signatureDataFile =
216216
FileSystem.ChangeExtensionShim(outputFile, ".signature-data.json")
217217

218-
serializeEntity signatureDataFile mspec)
218+
DebugPrint.serializeEntity signatureDataFile mspec)
219219

220220
// For historical reasons, we use a different resource name for FSharp.Core, so older F# compilers
221221
// don't complain when they see the resource.

src/Compiler/FSharp.Compiler.Service.fsproj

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,20 @@
336336
<Compile Include="TypedTree\TypedTreeBasics.fs" />
337337
<Compile Include="TypedTree\TcGlobals.fsi" />
338338
<Compile Include="TypedTree\TcGlobals.fs" />
339-
<Compile Include="TypedTree\TypedTreeOps.fsi" />
340-
<Compile Include="TypedTree\TypedTreeOps.fs" />
339+
<Compile Include="TypedTree\TypedTreeOps.Remap.fsi" />
340+
<Compile Include="TypedTree\TypedTreeOps.Remap.fs" />
341+
<Compile Include="TypedTree\TypedTreeOps.ExprConstruction.fsi" />
342+
<Compile Include="TypedTree\TypedTreeOps.ExprConstruction.fs" />
343+
<Compile Include="TypedTree\TypedTreeOps.FreeVars.fsi" />
344+
<Compile Include="TypedTree\TypedTreeOps.FreeVars.fs" />
345+
<Compile Include="TypedTree\TypedTreeOps.Attributes.fsi" />
346+
<Compile Include="TypedTree\TypedTreeOps.Attributes.fs" />
347+
<Compile Include="TypedTree\TypedTreeOps.Remapping.fsi" />
348+
<Compile Include="TypedTree\TypedTreeOps.Remapping.fs" />
349+
<Compile Include="TypedTree\TypedTreeOps.ExprOps.fsi" />
350+
<Compile Include="TypedTree\TypedTreeOps.ExprOps.fs" />
351+
<Compile Include="TypedTree\TypedTreeOps.Transforms.fsi" />
352+
<Compile Include="TypedTree\TypedTreeOps.Transforms.fs" />
341353
<Compile Include="TypedTree\TypedTreePickle.fsi" />
342354
<Compile Include="TypedTree\TypedTreePickle.fs" />
343355
<Compile Include="TypedTree\UpdatePrettyTyparNames.fsi" />

src/Compiler/TypedTree/TypedTreeOps.Attributes.fs

Lines changed: 2545 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)