Expand description
Pragmas for Polydat source.
Pragmas are first-class Polydat statements that opt a scope into compile-time checks (polydat_grammar.md §14). They cover the strict-wire modes that complement the const-constraint metadata (graph_compiler.md §2):
pragma strict_values
pragma strict_types
pragma strict // both, and strict name checking
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 are a distinct syntactic
construct, not comments.
§Recognised pragma names
strict_values— check every wire into a port that declares a value constraint: a compile-time constant source is checked at build, and any other source gets a value assertion node.strict_types— accepted and acknowledged, with no effect on the graph. Wires are statically typed and a resolved wire’s type is the sink port’s type, so a runtime type assertion has nothing to catch.strict— a pragma of its own: it impliesstrict_typesandstrict_values, and it turns on strict name checking, under which a comprehension that reads a name nothing binds is refused (comprehension_forms.md §5 V3). Outside it such a name compiles with a warning and reads None.
Unknown pragmas are recorded and warned about, not errored: pragmas are forward-compatible by design so old binaries can parse modules that opt into newer features they don’t support.
§Scoping
Scoping is lexical. A pragma applies to the scope it is written in
and to every scope nested in it: a program, a for body, and a
module body are scopes. A for body is nested in the scope it is
written in and compiles under PragmaSet::nested, its enclosing
set plus the pragmas its own statements declare. A module body is
nested in no host and compiles under its own pragmas alone. A tile
is not a scope: it compiles under the set of the scope it is
written in. Pragmas are presence-only, so a nested scope can add to
the set and never conflicts with it.
A host that compiles strictly seeds the program’s top scope with
strict (PragmaSet::host): the host switch and a pragma strict
at the top of the program mean the same thing.
Structs§
- Pragma
- One pragma entry parsed from the source.
- Pragma
Set - The pragmas in force in one Polydat scope: those the scope declares and those of every scope enclosing it.
Functions§
- collect_
from_ ast - Walk a parsed program and collect the pragmas it declares at its
top level into a
PragmaSet: the set the program’s own bindings compile under. Pragmas inside aforbody or a module body belong to that scope. - declared_
in - The pragmas
statementsdeclare at their own level. - is_
known - Recognised pragma names. Add new names here as features land.