Skip to main content

Module pragmas

Module pragmas 

Source
Expand description

Module-level pragmas for Polydat source.

Pragmas are first-class Polydat statements the module author places at the head of a .polydat file or module body to opt into compile-time graph transforms. Today they cover assertion-injection modes that complement the const-constraint metadata (SRD 15):

pragma strict_values
pragma strict_types
pragma strict          // convenience alias for both

id := mod(hash(cycle), 1000)

pragma is a reserved keyword in the Polydat grammar; pragmas are Statement::Pragma in the AST and walked by the compiler the same way other statements are. They’re not comments — distinct syntactic construct, distinguishable from ///# line comments.

§Recognised pragma names

  • strict_types — auto-insert type assertion nodes on wires whose source can’t be statically proven to deliver the right PortType. Design target — see SRD 15 §“Strict Wire Mode”.
  • strict_values — auto-insert value assertion nodes on wires whose downstream node declares a value constraint the source can’t satisfy at compile time.
  • strict — alias for both strict_types + strict_values.

Unknown pragmas are recorded but warned about, not errored: pragmas are forward-compatible by design so old binaries can parse modules that opt into newer features they don’t yet support.

§Scoping (SRD 15 §“Pragma Scope”)

Each Polydat graph or module has its own PragmaSet. Inner contexts inherit the outer scope’s pragmas automatically — an enclosing strict_values applies to every nested module body attached to it. On conflict (an inner pragma whose effective value disagrees with an outer one), the outer scope wins; a warning is emitted in non-strict compilation, and the conflict becomes a hard error in --strict mode.

Structs§

Pragma
One pragma entry parsed from the source.
PragmaConflict
A pragma that disagreed across nested scopes. Used by PragmaSet::attach_to to surface conflicts up to the caller for either advisory logging (non-strict) or hard error (strict). Per SRD 15 §“Pragma Scope” + SRD 13b §“Scope composition”, the outer scope’s value wins; the conflict report is for diagnostics, not for resolution.
PragmaSet
All pragmas declared in one Polydat scope. Multiple PragmaSets chain via PragmaSet::with_parent to model nested scopes (workload → phase → for_each iteration). Per SRD 13b §“Scope composition” + SRD 15 §“Pragma Scope”: each scope is its own PragmaSet, the chain is walked at lookup time, and outer scopes win on conflict.

Functions§

collect_from_ast
Walk a parsed AST and collect every Statement::Pragma into a PragmaSet. This is the canonical extraction path — pragmas are first-class grammar (the pragma keyword) and the parser produces them as proper statements.