Table of Contents

Class LayoutDivergence

Namespace
Typhon.Schema.Definition
Assembly
Typhon.Schema.Definition.dll

Detects component types whose MANAGED layout — the one the engine reads them through ((T), Span<T>, ref T) — may differ from their MARSHALLED layout, which is all that OffsetOf(Type, string) can report.

public static class LayoutDivergence
Inheritance
LayoutDivergence
Inherited Members

Remarks

The two agree for every ordinary blittable primitive and diverge for exactly two types: bool is 1 byte managed and 4 marshalled, and char is 2 and 1 under the default CharSet.Ansi. Anywhere either appears, offsets read by reflection may describe a different layout from the one the bytes are addressed by — and for char the two can total the SAME size, so no size comparison at any layer detects it.

Presence of such a field is a proxy for divergence, not a proof of it, so the cases where the declaration itself reconciles the two layouts are excluded: CharSet.Unicode (a char then marshals as 2 bytes, like managed), an explicit [MarshalAs] (the width is the author's to define), LayoutKind.Explicit (offsets are declared outright, so both layouts report what the author wrote), and a fixed buffer (element count times element width in either layout). Everything left over is refused.

Lives in the schema contract assembly because the engine's definition builder and the CLI's assembly schema loader must apply the SAME rule. A second, shallower copy of this policy in one of them is how the hole reopens (#819, rule SCHEMA-07).

Fields

UnverifiableNesting

Sentinel reported as the divergence kind for a type too deeply nested to finish inspecting.

public const string UnverifiableNesting = "unverifiable nesting"

Field Value

string

Methods

Detect(Type, out string, out string)

Searches type for a field whose managed and marshalled representations may differ, at any nesting depth.

public static bool Detect(Type type, out string path, out string kind)

Parameters

type Type

The component's CLR type.

path string

Receives a dotted path to the offending field, for diagnostics; null when none is found.

kind string

Receives "bool", "char" or UnverifiableNesting; null when none is found.

Returns

bool

true when the type's reflected offsets must not be trusted.

Remarks

Walks the CLR type's instance fields rather than a schema's field list, and includes non-public ones. A nested struct the schema does not model is dropped from that list yet still occupies bytes, and therefore still displaces every field declared after it — scanning the schema's own view would look straight past it.