MCPcopy Index your code
hub / github.com/ciphermodelabs/ciphercore / process_instantiation

Function process_instantiation

ciphercore-base/src/custom_ops.rs:532–571  ·  view source on GitHub ↗

Recursive function to find all the necessary instantiations and build a graph of those (appropriately caching things).

(
    instantiation: &Instantiation,
    instantiations_graph_mapping: &mut InstantiationsGraphMapping,
    instantiations_graph: &mut InstantiationsGraph,
)

Source from the content-addressed store, hash-verified

530/// Recursive function to find all the necessary instantiations
531/// and build a graph of those (appropriately caching things).
532fn process_instantiation(
533 instantiation: &Instantiation,
534 instantiations_graph_mapping: &mut InstantiationsGraphMapping,
535 instantiations_graph: &mut InstantiationsGraph,
536) -> Result<()> {
537 let fake_context = create_context()?;
538 let graph = instantiation
539 .op
540 .instantiate(fake_context.clone(), instantiation.arguments_types.clone())?;
541 // `instantiate()` may potentially create some auxiliary graphs, which we now need to process
542 // TODO: add a test that check that this is properly done
543 for fake_graph in fake_context.get_graphs() {
544 for node in fake_graph.get_nodes() {
545 if let Operation::Custom(_) = node.get_operation() {
546 let new_instantiation = Instantiation::create_from_node(node)?;
547 let (node1, already_existed) = get_instantiations_graph_node(
548 &new_instantiation,
549 instantiations_graph_mapping,
550 instantiations_graph,
551 );
552 let (node2, _) = get_instantiations_graph_node(
553 instantiation,
554 instantiations_graph_mapping,
555 instantiations_graph,
556 );
557 instantiations_graph.add_edge(node1, node2, ());
558 if !already_existed {
559 process_instantiation(
560 &new_instantiation,
561 instantiations_graph_mapping,
562 instantiations_graph,
563 )?;
564 }
565 }
566 }
567 }
568 graph.set_as_main()?;
569 fake_context.finalize()?;
570 Ok(())
571}
572
573#[doc(hidden)]
574/// In order to instantiate all the custom operations in a given context,

Callers 1

run_instantiation_passFunction · 0.85

Calls 9

cloneMethod · 0.80
create_contextFunction · 0.70
instantiateMethod · 0.45
get_graphsMethod · 0.45
get_nodesMethod · 0.45
get_operationMethod · 0.45
set_as_mainMethod · 0.45
finalizeMethod · 0.45

Tested by

no test coverage detected