MASS4.Graph.Generator
1.2.0
dotnet add package MASS4.Graph.Generator --version 1.2.0
NuGet\Install-Package MASS4.Graph.Generator -Version 1.2.0
<PackageReference Include="MASS4.Graph.Generator" Version="1.2.0" />
<PackageVersion Include="MASS4.Graph.Generator" Version="1.2.0" />
<PackageReference Include="MASS4.Graph.Generator" />
paket add MASS4.Graph.Generator --version 1.2.0
#r "nuget: MASS4.Graph.Generator, 1.2.0"
#:package MASS4.Graph.Generator@1.2.0
#addin nuget:?package=MASS4.Graph.Generator&version=1.2.0
#tool nuget:?package=MASS4.Graph.Generator&version=1.2.0
MASS4.Graph.Generator
MASS4.Graph.Generator is a compile-time analyzer reference. It targets net10.0 and runs in the .NET 10+ SDK compiler; framework-hosted compiler environments are not supported. It has a private Roslyn dependency and adds no runtime dependency to the core or consumers. Reference Graph.Generator.csproj with OutputItemType="Analyzer" and ReferenceOutputAssembly="false", or install the analyzer package alongside the core and the semantics packages your declarations use.
Declare one [assembly: GraphModule("Your.Namespace.Module", typeof(DataflowNodes))] per assembly. The analyzer supplies internal declaration attributes during post-initialization; they add no public runtime API to the core. Prerequisites are explicit types exposing Register(GraphTypeRegistry); registration never scans assemblies. Declarations are top-level, nongeneric static partial classes. See the shader, FSM and compositor declarations for complete examples.
[GraphValue(id, name, typeof(T))]emits aPortTypeand its dataflow storage binding together. An optionalSerializerpreserves custom wire formats;JsonContextuses source-generatedJsonTypeInfo<T>. A class value gets reference storage and an unmanaged value gets inline storage.[GraphNode(id, name)]emitsType, with ordered[GraphPort(member, key, name, direction, typeof(ValueDeclaration))]declarations. The typed form takes the port's type identity and CLR storage from that[GraphValue]declaration, so source renames follow the symbol and an identity change updates every port. Use[GraphPort(member, key, name, direction, typeId, typeof(T))]only for types declared elsewhere, such asStateFlow. Inputs default to single connections and outputs to multiple;Multiplicityoverrides that.Keys.Memberexposes the persistent key, andIndices.Memberfollows declaration order for dataflow, state and control behaviors.[GraphBehavior]emits the corresponding dataflow, control, state or transition binding. Dataflow declarations name a static evaluation method and can declareVolatileand requiredFeatures; the generatedDataflowNodeenforces those features through the backend's normal contract. Other semantics bind an explicit behavior implementation.[GraphPayload(typeof(Payload), JsonContext = typeof(Context), DefaultFactory = nameof(Default))]emits serialization and the optional new-node default. For a single-value payload, useValue = typeof(ValueDeclaration)andMemberinstead ofJsonContext: serialization reuses that value's serializer and constructs the wrapper directly.[GraphSignal]and[GraphRenamedFrom]emit signal identities and rename entries. A signal declaration exposesTypeandRaise(graph, instances, instance); transition helpers take thatSignalTypeas their trigger, never a bare identity, so a renamed or removed signal fails at compile time. Renames apply to node and value declarations as well. IDs are always explicit GUIDs; source names never determine persistent identity. Port keys are scoped to their node, preserving existing documents that share keys across node types. New declarations can give every port its own key.[GraphMigration(fromVersion, typeof(Owner), nameof(Owner.Migrate))]emits a migration step. A node withGuard = typeof(BooleanDeclaration)(orGuardType = "boolean-type-guid"for an external type) usesStateNodes.CreateGuardedTransitionand automatically emitsStateNodes.AddTransitionMigrationfor its domain identity. Custom transition payloads such asAfterPayloadremain independent of that legacy State payload migration.
The generated module implements IGraphTypeModule: registry.Add(new Module()) registers its prerequisites, types, renames and migrations, once per module type; built-in prerequisites shared by several modules register once. When its declarations need those semantics, the module also implements IDataflowModule, IControlModule or IStateModule: ConfigureDataflow, ConfigureControl and ConfigureState add its bindings to a shared semantics object, so a host composing modules from several assemblies runs them in one interpreter. CreateDataflow, CreateControl and CreateState return a new, configured semantics object. Value declarations expose Bind(document, compiledGraph, variable) for typed unmanaged or reference handles; writable scopes are Input and External.
Node.Add(editor, payload) returns a handle with typed GraphInput<T> and GraphOutput<T> ports. editor.Connect(source.Out, target.In) only compiles for matching CLR types; explicit conversion nodes bridge differing types. Normal editor validation still checks persistent type identities, multiplicity and graph rules. Transition(editor, from.Exit, to.Enter, payload, SeePlayer.Type, priority) adds and wires a domain transition as one reversible, atomic edit; StateGraphBuilder offers the same typed helpers for the built-in entry, state and transition nodes. Reference outputs expose ReuseMember(context, state, static (previous, state) => ...), so behaviors can reuse their own buffers without a capturing delegate.
Analyzer package
The MASS4.Graph.Generator package contains only analyzers/dotnet/cs/MASS4.Graph.Generator.dll: no runtime library and no dependencies. A user assembly needs the core and this package. Add the semantics packages its behaviors bind to: generated code emits dataflow storage, control or state bindings only when the matching package is referenced. A behavior or guarded transition without its package reports MG5007, naming the package to add. Graph.Samples.CustomNodes is a core-only user assembly, and CI builds it against the freshly packed analyzer.
<PackageReference Include="MASS4.Graph" Version="…" />
<PackageReference Include="MASS4.Graph.Generator" Version="…" PrivateAssets="all" />
Compiled assets
[GraphAsset("Assets/material.graph.json")] public sealed partial class MaterialGraph; compiles a saved asset into an ICompiledGraph. List the file as an AdditionalFiles item. The generator reruns the interpreter's planning at build time: wildcard inference, the slot layout, per-instance caching and the state machine's transition order. It then emits straight-line code. Each node has an ensure method that refreshes its stale sources and calls the declared behavior method directly. Each state's transitions are unrolled in check order, and storage is typed slots in the interpreter's exact layout. No dictionaries, delegates or reflection run per tick, and ticking allocates nothing.
new MaterialGraph(document) binds the loaded asset; MaterialGraph.Backend is an IGraphBackend for hosts and the differential harness. Payloads, variable defaults and trigger identities stay runtime data from the document. Topology does not: another asset, or a changed node, port, edge, variable, variable reference, priority or trigger presence, fails with MG6004 until the project is rebuilt. Assets may use declared value, dataflow, state and transition types, the built-in variable, output, entry, state, transition and guarded-transition nodes, and conversion nodes. Coercions and control flow report MG6002. MG6001 reports a missing file and MG6003 an invalid declaration.
JSON contexts are user-declared with [JsonSerializable], including their naming policies and converters. Roslyn generators cannot see ordinary output from other generators, so the Graph generator consumes the context's generated metadata rather than emitting a context for the JSON generator to discover. Missing metadata fails explicitly during registration. This follows Roslyn's generator execution contract.
Build errors MG5001–MG5005 cover invalid/missing GUIDs, duplicate or still-registered renamed identities, duplicate node-local port keys or member names, malformed conversion shapes and unsupported declaration shapes, including typed ports naming a non-[GraphValue] type and guards whose declaration does not store bool. MG5006 rejects a Serializer that is not a constructible IValueSerializer and a JsonContext without [JsonSerializable] for the value or payload type, which would otherwise fail only at registration. MG5007 reports a missing semantics package. Conflicts across independently compiled assemblies remain registry errors at composition time.
The hand-written sample registrations remain the oracle. Sample tests compare type identities, ordered port declarations, rename entries, migrations, defaults, value/payload JSON, semantics bindings (value storage, conversions, behavior volatility, required features and state roles) and reloads, then run scenarios through independently configured interpreters. The generated FSM fixture uses the hand library's simulated renamedSeePlayer release. Its domain guarded transition is also loaded from a version 1 payload, proving automatic migration registration. Generated-backend tests require each compiled sample asset to match the interpreter observation for observation, with the same instance layout, and the guard to tick 1000 instances without allocating. Generator tests check compiler diagnostics and emitted-code compilation; Graph.AotSmoke verifies registration and persistence in a native executable with JSON reflection disabled.
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.