Skip to content

Latest commit

 

History

History
46 lines (41 loc) · 16.3 KB

SOUNDNESS-SPEC.md

File metadata and controls

46 lines (41 loc) · 16.3 KB

Specification baseline

LeanCIL models ECMA-335 6th edition as amended by the ECMA-335 augments that Microsoft maintains in dotnet/runtime, pinned at commit b22bfee2010118c58ae143c3b8a1aaee3d0c8c4c. Where the edition and an augment disagree, the augment is the reference. Each augment area below is either modeled, rejected before or during checked execution, or not applicable to the extracted semantics.

A model fault (invalidState, a memory fault or unsupported) is never a successful execution and never a named CLR exception, so "rejected at execution" excludes the path from every proof.

Augment area LeanCIL status Enforcement
Signatures: TypeSpec after CLASS/VALUETYPE or a custom modifier Rejected or not applicable. Mono.Cecil decodes signatures (a trusted component). The one admitted modifier must name a non-TypeSpec System.Runtime InAttribute. InReferences.Unwrap
Signatures: custom modifiers in more places, BYREF before modifiers Rejected except modreq(InAttribute) directly before a modifier-free BYREF parameter and modreq(IsExternalInit) directly on a VOID return. BYREF CMOD T, modopt and other modreq forms fail; locals, other returns and fields with modifiers are unsupported types; typed contract signatures admit none. InReferences.Unwrap, InitAccessors.Unwrap, MetadataValidation.Type, ContractMethodMetadata.RejectModifiers; mutations "nested", "modopt" and "other-modreq", and the init modifier mutations in Tests/StructMethods.cs
Heap sizes Not applicable: metadata heaps are decoded by Mono.Cecil. Trusted components
Metadata merging Not applicable: the CLI does not merge metadata. An extraction reads the selected assembly and each pinned --reference as separate modules, keeps type identities assembly-qualified and rejects a method signature shared by two of them. PinnedAssemblies, MetadataValidation.Validate; pinned references
Metadata logical format (InterfaceImpl order) Not applicable: constrained resolution tests interface membership and rejects ambiguity, so declaration order cannot change the result. resolveConstrained
Module initializer Not modeled; static constructors, including <Module>..cctor, are never extracted. Methods on a type with a static constructor need --assume-initialized; for a generic class the open name, such as Seeded`1, assumes every instantiation's initializer ran. A referenced assembly's type with one is rejected; a readonly static stored by any other module method, including a module initializer, is rejected. MetadataValidation.Validate, StaticValues.Compute; static initialization assumption
Default interface methods Modeled only for static virtual slots: when the receiver records no MethodImpl override and has no public same-signature method, constrained. T; call runs the most specific interface-level body, the runtime's rule: among the slot's own body and every interface MethodImpl of the slot on an interface of the receiver, the one whose interface inherits every other candidate's, instantiated at its closed interface and the site's method type arguments. A recorded override wins; an unrecorded candidate beside a slot body is ambiguous and rejected. Two unrelated overriding interfaces (no unique winner) and a re-abstracting winner are rejected. The receiver's interface list must be closed under inheritance and fully present in the dispatch catalog, so a receiver with an interface outside the extracted and pinned assemblies is rejected. Instance default methods are rejected, since their body would need a boxed receiver. resolveConstrained, mostSpecific_spec, ConstrainedCalls.Resolve; tests default_interface_slot_rejected, static_default_valid, static_override_precedes_default, static_default_ambiguity_rejected, static_derived_body_valid, static_interface_closure_rejected, derived_override_valid, most_derived_body_valid, diamond_rejected, reabstraction_rejected
Static interface methods Modeled: constrained. T; call resolves a static virtual slot of a directly implemented interface, including a generic method slot, to T's static implementation or to the most specific interface-level body, called without a receiver. For a closed generic struct T, the interface is the one its InterfaceImpl names instantiated at T's type arguments, which the catalog entry must state exactly, and the selected method is closed at them. T and the interface may come from different extracted or pinned assemblies; every dispatch catalog entry names its pin, which must scope its type. Method type arguments must be closed and match the slot's arity, and the emitted instance must carry them exactly. callvirt on a static slot, call on an instance slot, constrained. ldftn, generic instance slots and open receivers fail. constrainedSiteWindow, resolveConstrained, ConstrainedCalls.Resolve; tests static_call_valid, call_opcode_mismatch_rejected, static_slot_mismatches_rejected, static_default_arguments_rejected, cross_pin_implementation_valid, unpinned_catalog_rejected
Constant static flag getters Modeled for branch selection only: a parameterless static call, plain or constrained. T; call, to a program method returning System.Boolean whose own feature certificate shows the same 0 or 1 on top of the stack at every reachable ret, and at least one reachable ret, supplies that word to feature flow, which prunes the block it rules out. The getter may compute its word from other such calls, type tests and feature tests at any depth. The call is still emitted, and the callee's certificate is validated by its own obligation in the same whole-program certificate. Pruned pcs are .unsupported holes with no step, so a wrong word, including a self-consistent claim on a call cycle, only sends execution into a hole: it can make a successful outcome unreachable, never provable. Imports and calls past the program are never constant; the extractor also leaves cycles, tail calls and certificates without one 0 or 1 word unknown. The getter's type initialization follows the --assume-initialized rule for extracted methods. constantReturn, calleeConstant, evidenceConstants, ConstantReturns; tests forged_constant_rejected, constant_swap_rejected, constant_body_rejected
Covariant return types Rejected: C# emits a covariant override as a newslot method with an explicit MethodImpl, which class dispatch rejects by name, a class override must match the slot signature exactly, and so must an interface override. VirtualDispatch.Table, resolveVirtualWith, ConstrainedCalls.Resolve, resolveConstrained
Function pointer type identity Stricter than the augment: only the default managed convention is callable, compared exactly; unmanaged conventions are rejected. managedSignature, ManagedPointers.Validate
conv.ovf.<to>.un with float source Not reachable: values have no floating-point form, float constants and conversions are untranslated, and scalar flow requires an integer operand. Value, convertInteger, InstructionTranslation.TranslateCore; floatRaw cases
Ref fields Rejected: a byref field type is unsupported. Span<T> and ReadOnlySpan<T> are runtime-modeled views and are not modeled as structs with a ref field. MetadataValidation.AggregateLayout, SpanView
Managed pointers: null and one past the end Modeled conservatively. Null is a managed-reference value that can be stored, passed and compared; dereferencing or offsetting it is a nullDereference model fault and is not the augment's NullReferenceException. End positions form only as declared sentinels and grant no access. ManagedReference, validPosition, access, referenceAt, instruction, ExecutionFault.clrException
RefSafetyRulesAttribute (escaping this) Not checked. The admitted subset has no box, so a struct receiver is always caller-owned storage and the boxing elimination the rule licenses cannot arise. OPCODES
ByRefLike types in generics (AllowByRefLike 0x20) Modeled: the flag is accepted and every generic method is checked as its closed instantiation. Byref-like elements cannot be heap array elements or fields of heap-storable structs. MethodSpecialization.Instantiate, byRefLikeFieldsValid, Arrays.Storage
Rules for IL rewriters (RVA alignment) Modeled: the extractor rejects static data whose RVA is not a multiple of its .pack (1, 2, 4 or 8). It also rejects data that does not lie within one section's raw data and mapped size, and data in a section whose virtual address and file offset differ by a non-multiple of 8, since the PE format only recommends a 512-byte file alignment and CoreCLR may read an IL-only image flat, at its base plus the file offset. Mapped and converted layouts place sections at a page-aligned base plus their RVA; a flat layout's base is page-aligned for Assembly.Load(byte[]) and files, and 64-byte or wider for single-file bundles (loader, bundler). A flat image the host hands CoreCLR by external probing is used at the host's address, which is assumed 8-byte aligned (see static storage). The descriptor's alignment is that packing and becomes the static allocation's layout alignment. CreateSpan<T> succeeds only when sizeof(T) divides it, which for these powers of two means .pack >= sizeof(T) and so an RVA that is a multiple of sizeof(T); a narrower packing is an unsupported fault and is never the success the CLR would replace with ArgumentException. StaticData.Validate, StaticData.RequireSectionAligned, StaticDescriptor, staticReference, staticSpanAligned, staticInstruction, createSpan_aligned_at_placement; tests "Narrow-packing", "Reject-misaligned-rva" and "Reject-section-file-offset"
Checked user-defined operators Not applicable: operators are ordinary calls resolved by token or exact runtime signature, never by name. RuntimeModels.cs
Atomic reads and writes Not applicable: the model is single-threaded and volatile. is unsupported. SOUNDNESS
Backward branch constraints (deleted) Modeled: stack kinds come from a worklist over all reachable edges; every successor must see the same stack, and inconsistent joins are rejected. NativeOperands.Certify, ScalarFlowValid; fixture "BackwardSwitch" and mutations "stack-height", "stack-type", "local-fact" and "stack-fact"
Transient pointers Modeled: ldloca/ldarga yield frame-owned references that expire at return. Unmanaged pointers share the reference representation, and conversion to integer addresses is rejected. scalarType, OPCODES (conv.u, ldloca)
newobj for SZ arrays Rejected: array constructors are external methods without a runtime model. MetadataValidation.Validate, ImportResolution.Admit
API documentation Not applicable: runtime methods are admitted only through exact signature models. Runtime assumptions
Debug Interchange Format Not applicable to semantics: Portable PDB supplies local names for proofs only. DebugNames.lean
Extended layout (0x18) Rejected: aggregates must be sequential or explicit, enums and value tuples auto. This relies on Mono.Cecil's masked layout flags. MetadataValidation.AggregateLayout, EnumTypes.ValidateStorage
Implicit argument coercion (int32 to native unsigned int) Rejected: no implicit int32-to-native coercion exists. Call arguments, stloc, starg and ret require the slot's kind, and checked stores into eight-byte homes require an i64. Code needs an explicit conv.i or conv.u. storageCompatible, scalarTransfer, localNumber, storeTransfer, otherMemoryInstruction; tests no_implicit_native_coercion, native_home_rejects_int32
Init-only static fields Modeled: stsfld is never extracted, and a readonly value is admitted only when its own static constructor is the sole writer. A scalar whose stored value extraction cannot compute is admitted as unknown and read from the caller's static binding. Writes by unmodeled code are an explicit assumption. InstructionTranslation.TranslateCore, StaticValues.Compute; mutations "store" and "twice"; unknown seeds "Opaque-guessed.lean"

Mixed native/int32 binary operands are widened under III.1.5, not III.1.6, and are listed in opcode coverage.