MCPcopy Create free account
hub / github.com/ciphermodelabs/ciphercore / inline_operations

Function inline_operations

ciphercore-base/src/inline/inline_ops.rs:139–178  ·  view source on GitHub ↗

Creates a new context from the given context, recursively inlining operations in the main graph with accordance to the given InlineConfig. In case of inlined operations with graph dependencies, these graphs are recursively processed with the same config. The inlining process preserves node annotations and names of nodes in the main graph. The name of a to-be-inlined Call/Iterate node is passed to

(context: Context, config: InlineConfig)

Source from the content-addressed store, hash-verified

137/// The inlining process preserves node annotations and names of nodes in the main graph.
138/// The name of a to-be-inlined Call/Iterate node is passed to a node containing its output.
139pub fn inline_operations(context: Context, config: InlineConfig) -> Result<Context> {
140 context.check_finalized()?;
141 // First, collect all graphs reachable from the main graph which won't be
142 // inlined.
143 let mut graph_ids_to_process = HashSet::<u64>::new();
144 let mut graph_ids_seen = HashSet::<u64>::new();
145 let main_graph = context.get_main_graph()?;
146 graph_ids_to_process.insert(main_graph.get_id());
147 graph_ids_seen.insert(main_graph.get_id());
148 collect_graphs(
149 main_graph.clone(),
150 config.clone(),
151 &mut graph_ids_to_process,
152 &mut graph_ids_seen,
153 )?;
154 let output_context = create_context()?;
155 let mut inlining_context = InliningContext {
156 config,
157 context_mapping: ContextMappings::default(),
158 ephemeral_context_mapping: ContextMappings::default(),
159 };
160 // Now, apply inlining to all of the collected graphs in the topological order.
161 for graph in context.get_graphs() {
162 if graph_ids_to_process.contains(&graph.get_id()) {
163 let new_graph = output_context.create_graph()?;
164 for annotation in graph.get_annotations()? {
165 new_graph.add_annotation(annotation)?;
166 }
167 inlining_context.insert_graph(graph.clone(), new_graph.clone());
168 let output_node =
169 recursively_inline_graph(graph, new_graph.clone(), &mut inlining_context)?;
170 new_graph.set_output_node(output_node)?;
171 new_graph.finalize()?;
172 }
173 }
174
175 output_context.set_main_graph(inlining_context.get_graph(main_graph))?;
176 output_context.finalize()?;
177 Ok(output_context)
178}
179
180/// Determines all subgraphs reachable from graph which won't be inlined.
181fn collect_graphs(

Callers 15

test_oblivious_transferFunction · 0.85
test_permutationFunction · 0.85
test_duplicationFunction · 0.85
prepare_contextFunction · 0.85
get_binary_adder_graphFunction · 0.85
prepare_contextFunction · 0.85

Calls 15

collect_graphsFunction · 0.85
recursively_inline_graphFunction · 0.85
cloneMethod · 0.80
get_annotationsMethod · 0.80
add_annotationMethod · 0.80
create_contextFunction · 0.50
check_finalizedMethod · 0.45
get_main_graphMethod · 0.45
insertMethod · 0.45
get_idMethod · 0.45
get_graphsMethod · 0.45
create_graphMethod · 0.45

Tested by 15

test_oblivious_transferFunction · 0.68
test_permutationFunction · 0.68
test_duplicationFunction · 0.68
test_prf_idFunction · 0.68
test_noopFunction · 0.68
test_inline_call_simpleFunction · 0.68