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

Function optimize_context

ciphercore-base/src/optimizer/optimize.rs:15–42  ·  view source on GitHub ↗

Applies common optimizations to all graphs in the context. The graphs must be fully inlined. The primary targets of the optimizations here are to remove inefficiencies which happen because of the boilerplate from Iterate inlining.

(context: Context, mut evaluator: T)

Source from the content-addressed store, hash-verified

13/// The primary targets of the optimizations here are to remove inefficiencies
14/// which happen because of the boilerplate from Iterate inlining.
15pub fn optimize_context<T: Evaluator>(context: Context, mut evaluator: T) -> Result<Context> {
16 context.check_finalized()?;
17 evaluator.preprocess(context.clone())?;
18 let output_context = create_context()?;
19 for graph in context.get_graphs() {
20 let (_const_context, const_graph) = graph_in_new_context(graph.clone())?;
21 optimize_graph_constants(graph.clone(), const_graph.clone(), &mut evaluator)?;
22 const_graph.finalize()?;
23
24 let (_meta_context, meta_graph) = graph_in_new_context(graph.clone())?;
25 optimize_graph_meta_operations(const_graph.clone(), meta_graph.clone())?;
26 meta_graph.finalize()?;
27
28 let (_dup_context, dup_graph) = graph_in_new_context(graph.clone())?;
29 optimize_graph_duplicates(meta_graph.clone(), dup_graph.clone())?;
30 dup_graph.finalize()?;
31
32 let final_graph = add_graph_to_context(output_context.clone(), graph.clone())?;
33 optimize_graph_dangling_nodes(dup_graph.clone(), final_graph.clone())?;
34 final_graph.finalize()?;
35
36 if graph == context.get_main_graph()? {
37 final_graph.set_as_main()?;
38 }
39 }
40 output_context.finalize()?;
41 Ok(output_context)
42}
43
44fn add_graph_to_context(context: Context, source_graph: Graph) -> Result<Graph> {
45 let new_graph = context.create_graph()?;

Callers 3

test_simpleFunction · 0.70
prepare_contextFunction · 0.50
compile_contextFunction · 0.50

Calls 14

graph_in_new_contextFunction · 0.85
optimize_graph_constantsFunction · 0.85
add_graph_to_contextFunction · 0.85
preprocessMethod · 0.80
cloneMethod · 0.80
create_contextFunction · 0.50
check_finalizedMethod · 0.45
get_graphsMethod · 0.45
finalizeMethod · 0.45

Tested by 1

test_simpleFunction · 0.56