Record type CompileRequest representing one compiler work unit for the Prism editor. Holds graph, mode, targets, HLSL dialect, output name, debug/emit flags, two change hashes, focus node, cancellation token, helper WantsTarget and a custom ToString.
using Editor.Prism.Compiler.Backends;
using Editor.Prism.Core;
using Editor.Prism.Model;
namespace Editor.Prism.Compiler;
/// <summary>
/// One unit of work for the compiler.
/// <para>
/// The two hashes are what keep the live preview fast: a change to <see cref="StructureHash"/>
/// (topology, types, keywords, domain) forces a recompile, while a change to <see cref="ValueHash"/>
/// alone is pushed to the GPU as a render attribute and never recompiles anything.
/// </para>
/// </summary>
public sealed record CompileRequest( IPrismGraph Graph, CompileMode Mode )
{
/// <summary>Backend ids to emit, e.g. <c>sbox-hlsl</c> and <c>slang</c>.</summary>
public IReadOnlyList<string> Targets { get; init; } = [PrismConstants.BackendHlsl];
/// <summary>Which HLSL flavour the s&box backend emits.</summary>
public HlslDialect Dialect { get; init; } = HlslDialect.SboxSlang;
/// <summary>Base name for generated artifacts, without an extension.</summary>
public string OutputName { get; init; } = "prism_shader";
/// <summary>Emit descriptive temp names and per-node comments. What users send us in bug reports.</summary>
public bool DebugSymbols { get; init; }
/// <summary>Emit explanatory comments alongside the generated code.</summary>
public bool EmitComments { get; init; } = true;
/// <summary>Hash of everything that changes the generated text. A change here forces a recompile.</summary>
public ulong StructureHash { get; init; }
/// <summary>Hash of every literal and parameter value. A change here only updates render attributes.</summary>
public ulong ValueHash { get; init; }
/// <summary>
/// The node whose value the preview should display, for <see cref="CompileMode.Preview"/>.
/// Unset means the graph's own output.
/// </summary>
public NodeId FocusNode { get; init; }
/// <summary>Cancels the compile. The service replaces an in-flight compile when the graph changes.</summary>
public CancellationToken Cancellation { get; init; }
/// <summary>True when the request asks for a given backend.</summary>
public bool WantsTarget( string backendId ) => Targets is not null && Targets.Contains( backendId );
/// <inheritdoc/>
public override string ToString() =>
$"{Mode} [{string.Join( ", ", Targets ?? Array.Empty<string>() )}] {OutputName}";
}