MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / visit

Method visit

src/transform/src/analysis.rs:312–367  ·  view source on GitHub ↗

Complete the building: perform analyses and return the resulting `Derivation`.

(mut self, expr: &MirRelationExpr)

Source from the content-addressed store, hash-verified

310 }
311 /// Complete the building: perform analyses and return the resulting `Derivation`.
312 pub fn visit(mut self, expr: &MirRelationExpr) -> Derived {
313 // A stack of expressions to process (`Ok`) and let bindings to fill (`Err`).
314 let mut todo = vec![Ok(expr)];
315 // Expressions in reverse post-order: each expression, followed by its children in reverse order.
316 // We will reverse this to get the post order, but must form it in reverse.
317 let mut rev_post_order = Vec::new();
318 while let Some(command) = todo.pop() {
319 match command {
320 // An expression to visit.
321 Ok(expr) => {
322 match expr {
323 MirRelationExpr::Let { id, value, body } => {
324 todo.push(Ok(value));
325 todo.push(Err(*id));
326 todo.push(Ok(body));
327 }
328 MirRelationExpr::LetRec {
329 ids, values, body, ..
330 } => {
331 for (id, value) in ids.iter().zip_eq(values) {
332 todo.push(Ok(value));
333 todo.push(Err(*id));
334 }
335 todo.push(Ok(body));
336 }
337 _ => {
338 todo.extend(expr.children().map(Ok));
339 }
340 }
341 rev_post_order.push(expr);
342 }
343 // A local id to install
344 Err(local_id) => {
345 // Capture the *remaining* work, which we'll need to flip around.
346 let prior = self.result.bindings.insert(local_id, rev_post_order.len());
347 assert_none!(prior, "Shadowing not allowed");
348 }
349 }
350 }
351 // Flip the offsets now that we know a length.
352 for value in self.result.bindings.values_mut() {
353 *value = rev_post_order.len() - *value - 1;
354 }
355 // Visit the pre-order in reverse order: post-order.
356 rev_post_order.reverse();
357
358 // Apply each analysis to `expr` in order.
359 for id in self.result.order.iter() {
360 if let Some(mut bundle) = self.result.analyses.remove(id) {
361 bundle.analyse(&rev_post_order[..], &self.result);
362 self.result.analyses.insert(*id, bundle);
363 }
364 }
365
366 self.result
367 }
368 }
369

Callers 10

annotate_planFunction · 0.45
refresh_typesFunction · 0.45
transformMethod · 0.45
actionMethod · 0.45

Calls 11

values_mutMethod · 0.80
analyseMethod · 0.80
childrenMethod · 0.65
popMethod · 0.45
pushMethod · 0.45
iterMethod · 0.45
extendMethod · 0.45
mapMethod · 0.45
insertMethod · 0.45
lenMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected