hydra.dependencies module
Dependency extraction, binding sort, and let normalization.
- hydra.dependencies.definitions_with_dependencies(cx: T0, graph: Graph, original: Sequence[Binding]) object
Get definitions with their dependencies.
- hydra.dependencies.inline_type(schema: Mapping[Name, Type], typ: Type) object
Inline all type variables in a type using the provided schema (Either version). Note: this function is only appropriate for nonrecursive type definitions.
- hydra.dependencies.is_lambda(term: Term) bool
Check whether a term is a lambda, possibly nested within let and/or annotation terms.
- hydra.dependencies.lift_lambda_above_let(term0: Term) Term
Rewrite terms like let foo = bar in λx.baz to λx.let foo = bar in baz, lifting lambda-bound variables above let-bound variables, recursively. This is helpful for targets such as Python.
- hydra.dependencies.prune_let(l: Let) Let
Given a let expression, remove any unused bindings. The resulting expression is still a let, even if has no remaining bindings.
- hydra.dependencies.replace_typedefs(types: Mapping[Name, TypeScheme], typ0: Type) Type
Replace all occurrences of simple typedefs (type aliases) with the aliased types, recursively.
- hydra.dependencies.simplify_term(term: Term) Term
Simplify terms by applying beta reduction where possible.
- hydra.dependencies.term_dependency_names(binds: bool, with_prims: bool, with_noms: bool, term0: Term) Set[Name]
Note: does not distinguish between bound and free variables; use freeVariablesInTerm for that.
- hydra.dependencies.to_short_names(original: Sequence[Name]) Mapping[Name, Name]
Generate short names from a list of fully qualified names.
- hydra.dependencies.topological_sort_binding_map(binding_map: Mapping[Name, Term]) Sequence[Sequence[tuple[Name, Term]]]
Topological sort of connected components, in terms of dependencies between variable/term binding pairs. The SCC partitioning is what makes the result usable as an emission order in every target language: non-recursive bindings emit in dependency order, while a mutually recursive cluster is delivered together so the emitter can wrap it in whatever construct the host requires (mutual `let`s, joint class files, forward declarations).
- hydra.dependencies.topological_sort_bindings(els: Sequence[Binding]) object
Topological sort of bindings based on their dependencies. Returns Right with a flat order when the dependency graph is acyclic; returns Left with the cyclic SCCs when it is not. Use this variant when the consumer needs a strict acyclic ordering and must reject cycles (e.g. import resolution); use topologicalSortBindingMap when mutual recursion should be packaged into SCC groups instead.
- hydra.dependencies.topological_sort_type_definitions(defs: Sequence[TypeDefinition]) Sequence[Sequence[TypeDefinition]]
Topologically sort type definitions by their structural dependencies, grouped into SCCs. The SCC grouping handles mutually recursive types (e.g. a pair of records that reference each other’s names) by delivering them together as one cluster, so the emitter can produce a coherent set of declarations rather than failing with an undefined-name error mid-emission.