@@ -248,7 +248,7 @@ impl<'a> Elaborator<'a> {
248248 seen_this_traversal. remove ( & x_val) ;
249249 }
250250 let ( best_value_y, new_seen_y) = self . best_value_traversal ( y, seen_this_traversal) ;
251- // Usually, right will be better. But if not, choose x and restore seen_this_traversal state
251+ // Usually, y will be better. But if not, choose x and restore seen_this_traversal state
252252 if best_value_x. 0 < best_value_y. 0 {
253253 for x_val in new_seen_x. keys ( ) {
254254 seen_this_traversal. insert ( x_val. clone ( ) ) ;
@@ -316,12 +316,25 @@ impl<'a> Elaborator<'a> {
316316 let best = BestEntry ( cost, value) ;
317317 union_of_new_seen[ value] = best;
318318 trace ! ( " -> cost of value {} = {:?}" , value, cost) ;
319+
320+ // AVH TODO REMOVE
321+ trace ! ( "size of new {}" , union_of_new_seen. capacity( ) ) ;
319322 return ( best, union_of_new_seen) ;
320323 }
321324 }
322325 } ;
323326 }
324327
328+ // Elaborate the best value (from required/skeleton use). If we have already found a best value,
329+ // we can just return that. Otherwise, we traverse the aegraph from this point, keeping track
330+ // of previously seen values along argument paths to avoid double-counting DAG entries (e.g., to
331+ // have a cost function that does not repeat costs for subexpressions). This involves carefully
332+ // handling union nodes, only counting their values as permanently seen once a choice is made between
333+ // the unioned values.
334+
335+ // Once the `best_value_traversal` helper is complete, we know we have found a best value for the
336+ // current node, and every node newly seen in its chosen traversal. We can thus add all of these
337+ // values to our per-function `value_to_best_value` map.
325338 fn elaborate_best_value ( & mut self , value : Value ) -> BestEntry {
326339 let best_found = self . value_to_best_value [ value] ;
327340 if !best_found. 1 . is_reserved_value ( ) {
0 commit comments