TypeOrdering class
Defined in module l0_backend_ordering (l0_backend_ordering.py).
Value-type dependency ordering and type-definition emission.
Public static attributes
- static BackendState state
Protected functions
- auto _extract_value_type_dependencies(self, Type typ) -> set[SymbolKey]
- Extract type dependencies for VALUE fields only.
- auto _build_type_dependency_graph(self) -> dict[SymbolKey, set[SymbolKey]]
- Build dependency graph for type definitions.
- auto _find_cycle_details(self, dict] graph[SymbolKey, set[SymbolKey], list unresolved[SymbolKey]) -> str
- Find and format cycle details for error message.
- auto _topological_sort(self, dict] graph[SymbolKey, set[SymbolKey]) -> list[SymbolKey]
- Perform topological sort on type dependency graph using Kahn's algorithm.
- auto _find_struct_decl(self, str module_name, str struct_name) -> StructDecl|None
- Find the StructDecl AST node for a given struct.
- auto _find_enum_decl(self, str module_name, str enum_name) -> EnumDecl|None
- Find the EnumDecl AST node for a given enum.
- auto _emit_type_definitions(self) -> None
- Order value types and emit each definition with its optional wrapper.
Function documentation
set[SymbolKey] l0_backend_ordering:: TypeOrdering:: _extract_value_type_dependencies(self,
Type typ) protected
Extract type dependencies for VALUE fields only.
| Parameters | |
|---|---|
| typ | The type to extract dependencies from. |
| Returns | Set of (module, name) tuples for types that must be defined first. |
Value-type fields create dependencies (types must be fully defined). Pointer-type fields do NOT create dependencies (forward declarations suffice).
Examples:
- StructType("main", "Point") -> {("main", "Point")}
- EnumType("main", "Status") -> {("main", "Status")}
- PointerType(StructType("main", "Node")) -> {} (no dependency, forward decl works)
- NullableType(PointerType(...)) -> {} (pointer-optional, no dependency)
- NullableType(BuiltinType("int")) -> {} (value-optional of builtin, no dependency)
- NullableType(StructType("main", "Point")) -> {("main", "Point")} (value-optional of struct)
- BuiltinType("int") -> {} (no dependency)
dict[SymbolKey, set[SymbolKey]] l0_backend_ordering:: TypeOrdering:: _build_type_dependency_graph(self) protected
Build dependency graph for type definitions.
| Returns | Dict mapping (module, type_name) -> Set of (module, type_name) dependencies. |
|---|
A type X depends on type Y if X has a VALUE field of type Y. Pointer fields do NOT create dependencies (forward declarations handle them).
str l0_backend_ordering:: TypeOrdering:: _find_cycle_details(self,
dict] graph[SymbolKey, set[SymbolKey],
list unresolved[SymbolKey]) protected
Find and format cycle details for error message.
| Parameters | |
|---|---|
| graph | The type dependency graph. |
| unresolved | List of unresolved nodes. |
| Returns | A string describing the detected cycle details. |
list[SymbolKey] l0_backend_ordering:: TypeOrdering:: _topological_sort(self,
dict] graph[SymbolKey, set[SymbolKey]) protected
Perform topological sort on type dependency graph using Kahn's algorithm.
| Parameters | |
|---|---|
| graph | The type dependency graph. |
| Returns | List of (module, type_name) in dependency order (dependencies first). |
| Exceptions | |
| InternalCompilerError | On cycles (value-type cycles are impossible in valid L0). |
StructDecl|None l0_backend_ordering:: TypeOrdering:: _find_struct_decl(self,
str module_name,
str struct_name) protected
Find the StructDecl AST node for a given struct.
| Parameters | |
|---|---|
| module_name | Name of the module. |
| struct_name | Name of the struct. |
| Returns | The StructDecl if found, otherwise None. |
EnumDecl|None l0_backend_ordering:: TypeOrdering:: _find_enum_decl(self,
str module_name,
str enum_name) protected
Find the EnumDecl AST node for a given enum.
| Parameters | |
|---|---|
| module_name | Name of the module. |
| enum_name | Name of the enum. |
| Returns | The EnumDecl if found, otherwise None. |