Coding standards and idioms

June 3, 2026 · View on GitHub

The F# compiler code base is slowly being updated to better coding standards. There is a long way to go.

The future work includes

  • Consistent use of fantomas formatting across as much of the codebase as feasible
  • Consistent naming conventions
  • Reduction in line length
  • Reduction in single-character identifiers
  • XML documentation for all types, members and cross-module functions

Abbreviations

The compiler codebase uses various abbreviations. Here are some of the most common ones.

AbbreviationMeaning
adAccessor domain, meaning the permissions the accessing code has to access other constructs
amapAssembly map, saying how to map IL references to F# CCUs
argArgument (parameter)
argtyArgument (parameter) type
arginfoArgument (parameter) metadata
boxityIL boxity (ILBoxity = AsObject | AsValue), the IL-level marker distinguishing the reference (boxed) and value-type forms of a type
ccontCancellation continuation in the Async CPS model: OperationCanceledException -> AsyncReturn, invoked when an async computation is cancelled
ccuReference to a compilation unit (CcuThunk): any referenced assembly (F# or otherwise; CcuData.IsFSharp distinguishes), possibly the assembly currently being compiled
celemCustom attribute element
cenvCompilation environment. Means different things in different contexts, but usually a parameter for a single compilation state object being passed through a set of related functions in a single phase. The compilation state is often mutable.
cgbufCode-generation buffer (CodeGenBuffer): the mutable buffer accumulating IL instructions, locals, exception clauses and sequence points for one method body in IlxGen
clocCompile location (CompileLocation): IL scope + top-level impl name + namespace + enclosing-type path (+ source-file qualified name and range) used to place a generated IL entity
cloinfoIL closure information (IlxClosureInfo): the IlxGen descriptor for an emitted F# closure (free variables, formal signature, IL type)
contContinuation. In FSharp.Core async, the success continuation cont<'T> = 'T -> AsyncReturn (async.fs). In compiler lowering passes (LowerCalls, LowerComputedCollections, LowerStateMachines), the conventional name for a generic CPS-style callback (typically Expr -> Expr / Expr -> Expr option)
cpathCompilation path (CompilationPath = CompPath of ILScopeRef * SyntaxAccess * (string * ModuleOrNamespaceKind) list): the IL scope + access + enclosing module/namespace path (the A.B.C container) for a type or module definition
cssConstraint solver state.
ctokCompilation thread token (CompilationThreadToken): a phantom token witnessing that code runs on the single compilation thread; gates access to the (partially mutable) TAST/TcImports data, type-provider resolution and SourceCodeServices/IncrementalBuild caches
ctxtContext (spelled ctxt rather than the more common ctx): in ilread.fs this is an ILMetadataReader threaded through the seekRead* helpers when parsing .NET metadata; elsewhere it can be a different context type (e.g. ExecutionContext in IlxGen.LookupGeneratedValue)
csenvConstraint solver environment (ConstraintSolverEnv): the per-call solver context (range, equivalence env, display env, suspicion/trace state). Threaded through every Solve*/Add* helper in ConstraintSolver.fs; distinct from the mutable css (ConstraintSolverState)
cuspecCompiled-union spec (IlxUnionSpec): the IL-level descriptor of a discriminated union (type ref, generic args, cases) used by EraseUnions
denvDisplay Environment. Parameters guiding the formatting of types
dtreeDecision tree (DecisionTree, with cases TDSwitch/TDSuccess/TDBind): the compiled pattern-match tree, carried as the decision field of Expr.Match
einfoAn info object for an event (whether a .NET event, an F# event or a provided event)
eExpression
econtException continuation in the Async CPS model: ExceptionDispatchInfo -> AsyncReturn, invoked when an async computation faults
eenvIlxGen emit environment (IlxGenEnv): the threaded code-generation context carrying ValStorage mappings (valsInScope), witnesses-in-scope, type-parameter representation env (tyenv), CompileLocation (cloc), live-locals set and IL-emit flags during IL emission
emenvReflection.Emit / dynamic-assembly emit env (ILDynamicAssemblyEmitEnv, in code spelled emEnv): maps compiler IL refs to live System.Reflection.Emit types/methods/fields (used by FSI dynamic codegen)
envEnvironment. Means different things in different contexts, but usually immutable state being passed and adjusted through a set of related functions in a single phase.
erefEntity reference (EntityRef): a reference to a TypedTree Entity (Tycon/Module). Common bindings: let eref = ERefNonLocalPreResolved … (IlxGen), (eref: EntityRef) parameters in TypedTree helpers, the Parent eref case of ParentRef
fdefIL field definition (ILFieldDef); also commonly spelled fd in AbstractIL helpers — these are synonyms
finfoAn info object for a field (whether a .NET field or a provided field)
frefA reference to an ILFieldRef Abstract IL node for a field reference. Would normally be modernized to ilFieldRef
fspecField spec — usually an ILFieldSpec in IL emit/read code, also a RecdField (record/class field declaration) in TypedTree code paths. These are distinct types, not synonyms — the name collision is historical
fvsFree variables (FreeVars): the structured record of variables/typars free in an expression (computed by freeInExpr/accFreevars*), used by DetupleArgs, closure conversion and InnerLambdasToTopLevelFuncs
gThe TcGlobals value
hierVisual Studio hierarchy (IVsHierarchy): the VS shell projection of a project tree (project nodes + items)
idIdentifier
ilgIL globals (ILGlobals): cached well-known IL types/primitives (typ_Object, typ_Int32, …); the AbsIL counterpart of TcGlobals, usually reached as g.ilg
itemidVisual Studio item id (VSITEMID, a uint32) identifying a node within an IVsHierarchy, with sentinels VSITEMID_ROOT/_NIL/_SELECTION
lidLong Identifier (LongIdent = Ident list); SyntaxTree DU fields conventionally use the full-form synonym longId
mA source code range (file-and-position span). Not to be confused with Mark, the IL code-label type in IlxGen
mdefUsually an IL method definition (ILMethodDef) being emitted, also frequently spelled md — these are synonyms. In some IlxGen module walks mdef is also a module body (ModuleOrNamespaceContents/ILModuleDef) — distinct types
mgbufModule/assembly generation buffer (the IlxGen AssemblyBuilder): collects type defs, method defs, anonymous-record types and resources for the whole assembly being emitted
mimplIn IL emit/morph code, an ILMethodImplDef (an explicit method-implementation override, often for an interface). In the Symbols layer (Symbols/Exprs.fs), the parameter name for a CheckedImplFile (a typed implementation file). These are distinct types, not synonyms
minfoAn info object for a method (whether a .NET method, an F# method or a provided method)
minstMethod instantiation — in TypedTree code a TypeInst (TType list) of method type arguments (the per-method analogue of tinst); in AbstractIL method specs an ILGenericArgs
mkMeans make in old fashioned F#/OCaml coding style
modrefModule or namespace reference — usually ModuleOrNamespaceRef (an alias for EntityRef, the parallel of tcref/vref); in AbstractIL ILScopeRef.Module patterns it is an ILModuleRef
modulIn TypedTree contexts a ModuleOrNamespace (the typed structure for a namespace or F# module). In AbstractIL contexts (ilread/ilwrite/ilprint/ilmorph/ilreflect), the same name is used for an ILModuleDef (the IL/CLI module being read or emitted; also spelled ilModule). These are distinct types, not synonyms
mrefIL method reference (ILMethodRef): the IL-level identity of an uninstantiated method (declaring type ref, calling convention, name, generic arity, argument types, return type)
mspecUsually an ILMethodSpec (IL-level descriptor of an instantiated method) in IL emit code; also ModuleOrNamespace in TypedTree module-binding code (ModuleOrNamespaceBinding.Module(mspec, …)) and related IlxGen module-location helpers. These are distinct types, not synonyms
mtyModule type (ModuleOrNamespaceType, also spelled mtyp — these are synonyms): the signature/contents (sub-modules, types, vals) of a module or namespace — used both for the type-checked contents of an implementation and for the declared contents of a signature
ncenvName resolver (NameResolver): the cenv-style state object (globals/amap/infoReader) threaded through name resolution
nenvName resolution environment (NameResolutionEnv): the in-scope name → Item lookup tables active at a program point
nlerefNon-local entity reference (NonLocalEntityRef of CcuThunk * string[]): an in-memory path-indexed reference into the namespace/module structure of a CCU (often another assembly, but possibly the CCU being compiled)
nlrNon-local reference — usually NonLocalEntityRef (as the nlr field of EntityRef), occasionally NonLocalValOrMemberRef (the nlr field of ValRef). Distinct types, not synonyms — different reference layers
patPattern, a syntactic AST node representing part of a pattern in a pattern match
pcProgram counter — the int state label allocated per resumption point in LowerSequences/LowerStateMachines
penvPass environment — a pass-local cenv-style record threaded through an Optimizer pass (e.g. penv in DetupleArgs.fs, RewriteContext in InnerLambdasToTopLevelFuncs.fs)
pinfoAn info object for a property (whether a .NET property, an F# property or a provided property)
plidPartial long identifier (a string list): the dotted prefix typed so far during IDE completion (the "Foo.Bar." path)
qIn FSharp.Core (Linq.fs, Query.fs, query/quotation transforms), an F# quotation value (Quotations.Expr or Quotations.Expr<'T>) being inspected or transformed; occasionally a parser/matcher function in quotation helpers
rdtRunning Document Table (IVsRunningDocumentTable): the Visual Studio service that tracks all open documents and their buffers
reqdtyRequired type (reqdTy, a TType): the expected/target type flowed into expression type checking
rfinfoRecord/class field info (RecdFieldInfo): an rfref together with the enclosing type's instantiation (i.e. a field viewed through a concrete type)
rfrefRecord or class field reference, a reference to a Typed Tree node for a record or class field
scorefScope reference (ILScopeRef) for an IL metadata reference: Local, Module of ILModuleRef, Assembly of ILAssemblyRef, or PrimaryAssembly
smResumable state machine (a byref<ResumableStateMachine<_>>) passed through CE builder methods, tasks and resumable code; also byref<TaskStateMachine<_>> in task-specific paths
spSequence points or debug points
spatSimple Pattern, a syntactic AST node representing part of a pattern in a pattern match
tauA type with the "forall" nodes stripped off (i.e. the nodes which represent generic type parameters). Comes from the notation 𝛕 used in type theory
tcaugType constructor augmentation (TyconAugmentation, accessed via tcref.TypeContents): the mutable bag of interfaces, members and compiler-synthesized overrides (Compare/Equals/Hash) added to a Tycon
tcrefType constructor reference (TyconRef, an alias for EntityRef; long-form synonym tyconRef is also used): the parallel of modref/vref/eref for class/record/union/exception/abbreviation/measure type constructors
tdefIL type definition (ILTypeDef); also commonly spelled td in AbstractIL helpers — these are synonyms
tinstType instantiation
tpenvType parameter environment, tracks the type parameters in scope during type checking
tpsType parameter list (Typars = Typar list; long-form synonym typars is also used): the typars paired with tau in TType_forall(tps, tau) / Expr.TyChoose(tps, …)
tpsorigOriginal typars (spelled tpsorig in code, a Typar list): the user-written typars before freshening/renaming, paired with the copied set (tps)
traitinfoTrait constraint info (TraitConstraintInfo, spelled traitInfo): the SRTP "method-like" constraint (support types, name, argument types, return type)
trefIL type reference (ILTypeRef): Scope (ILScopeRef) + Enclosing (string list of enclosing type names) + Name. For non-nested types the namespace is encoded in Name; nested types use Enclosing
ty (not: typ)Type, usually a Typed Tree type
tyconType constructor (Tycon, an alias for Entity): a type or exception definition (class/record/union/abbreviation/exception/measure) in the TypedTree; tcref.Deref returns one. Modules and namespaces use the parallel alias ModuleOrNamespace
typarType Parameter
tys (not: typs)List of types, usually Typed Tree types
tyvarType Variable, usually referring to an IL type variable, the compiled form of an F# type parameter
ucrefUnion case reference, a reference to a Typed Tree node for a union case
vinfoValue info — in the Optimizer, the abstract value of an expression: ExprValueInfo (the DU with cases UnknownValue/SizeValue/ValValue/TupleValue/RecdValue/UnionCaseValue/ConstValue/CurriedLambdaValue/…) or the per-binding wrapper ValInfo (ValMakesNoCriticalTailcalls + ValExprInfo). Distinct types, not synonymsValInfo wraps an ExprValueInfo
vrefValue reference (ValRef; long-form synonym valRef is also used): a reference to a Typed Tree node for a value
vspecVal "spec" — a Val (the underlying definition behind a vref, typically obtained via vref.Deref). Often shortened to just v in tight scopes
Phase AbbreviationMeaning
SynAbstract Syntax Tree
TcType-checker
ILAbstract IL = F# representation of .NET IL
IlxExtended Abstract IL = .NET IL plus a couple of constructs that get erased