hydra.codegen module

Pure code generation pipeline for bootstrapping Hydra across languages.

hydra.codegen.build_schema_map(g: Graph) Mapping[Name, Type]

Build a schema map (Name -> Type) from a graph’s schema types.

hydra.codegen.decode_module_from_json(bs_graph: Graph, universe_modules: Sequence[Module], json_val: Value) object

Decode a single module from a JSON value.

hydra.codegen.escape_control_chars_in_json(input: Sequence[int]) Sequence[int]

Escape unescaped control characters inside JSON string literals.

hydra.codegen.format_primitive(prim: Primitive) str

Format a primitive for the lexicon.

hydra.codegen.format_term_binding(binding: Binding) str

Format a term binding for the lexicon.

hydra.codegen.format_type_binding(graph: Graph, binding: Binding) object

Format a type binding for the lexicon.

hydra.codegen.generate_coder_modules(codec: Callable[[T0, Graph, T1], object], bs_graph: Graph, universe_modules: Sequence[Module], type_modules: Sequence[T1], cx: T0) object

Generate encoder or decoder modules for a list of type modules.

hydra.codegen.generate_lexicon(graph: Graph) object

Generate the lexicon content from a graph.

hydra.codegen.generate_source_files(print_definitions: Callable[[Module, Sequence[Definition], InferenceContext, Graph], object], lang: Language, do_infer: bool, bs_graph: Graph, universe_modules: Sequence[Module], mods_to_generate: Sequence[Module], cx: InferenceContext) object

Pure core of code generation: given a coder, language, infer flag, bootstrap graph, universe, and modules to generate, produce a list of (filePath, content) pairs. Emission flags doExpand/doHoistCaseStatements/doHoistPolymorphicLetBindings are derived from the absence of the matching LanguageFeature in lang.supportedFeatures: a target that lacks partialApplication needs eta expansion (doExpand=true), and so on.

hydra.codegen.infer_and_generate_lexicon(cx: InferenceContext, bs_graph: Graph, kernel_modules: Sequence[Module]) object

Perform type inference and generate the lexicon for a set of modules.

hydra.codegen.infer_modules(cx: InferenceContext, bs_graph: Graph, universe_mods: Sequence[Module], target_mods: Sequence[Module]) object

Perform type inference on modules and reconstruct with inferred types.

hydra.codegen.infer_modules_given(cx: InferenceContext, bs_graph: Graph, universe_mods: Sequence[Module], target_mods: Sequence[Module]) object

Infer types for target modules in the context of a typed universe.

hydra.codegen.lower_primitive_definitions(m: Module) Module

Lower Definition.primitive arms to Definition.term arms with term-encoded PrimitiveDefinition.

hydra.codegen.module_deps_transitive(ns_map: Mapping[ModuleName, Module], modules: Sequence[Module]) Sequence[Module]

Compute transitive closure of dependencies for a set of modules.

hydra.codegen.module_name_to_path(ns: ModuleName) str

Convert a module name to a file path (e.g., hydra.core -> hydra/core).

hydra.codegen.module_to_json(schema_map: Mapping[Name, Type], m: Module) object

Convert a Module to a JSON string.

hydra.codegen.module_to_source_module(m: Module) Module

Convert a generated Module into a Source module.

hydra.codegen.modules_to_graph(bs_graph: Graph, universe_modules: Sequence[Module], modules: Sequence[Module]) Graph

Build a graph from universe modules and working modules, using an explicit bootstrap graph.

hydra.codegen.refresh_module(inferred_elements: Sequence[Binding], m: Module) Module

Rebuild a module’s term definitions using freshly inferred bindings.

hydra.codegen.transitive_deps(get_deps: Callable[[Module], Sequence[ModuleName]], ns_map: Mapping[ModuleName, Module], start_mods: Sequence[Module]) Set[ModuleName]

Compute transitive closure of module dependencies.