function process_ir (scope_data) {
  var pushed = 0;
  var scope_map = {};
  var sorted_scopes = sort_scopes(scope_data.scopes);

  // Pushdown computables for valid instances.
  sorted_scopes.forEach(function (scope) {
    var instances = get_optimizable_instances(scope);

    instances.forEach(function (instance) {
      pushed += pushdown_computables(instance, scope_map);
    });
  });

  // Replace old scopes with new ones.
  scope_data.scopes.forEach(function (scope, i) {
    var scope_id = scope.get_identity();
    if (scope_map[scope_id]) {
      scope_data.scopes[i] = scope_map[scope_id];
    }
  });

  // Console log the number of pushed computables.
  if (pushed) {
    var plural = pushed === 1 ? 'computable' : 'computables';
    console.log('Pushed', pushed, plural + '.');
  }

  return scope_data;
}
/**
 * This optimization takes any ScopeInstance or PolymorphicScopeInstance
 * of a Scope with only one instance and recreates both the instance and
 * the scope(s). Any computables in the parent scope which are only used
 * by the instance are pushed down into that instance's scope(s). This
 * prevents those computables from being processed in the parent scope
 * when the scope instance is not shown or needed yet.
 *
 * @param {Object} scope_data
 * @returns {Object} optimized scope_data
 */
This optimization takes any ScopeInstance or PolymorphicScopeInstance
of a Scope with only one instance and recreates both the instance and
the scope(s). Any computables in the parent scope which are only used
by the instance are pushed down into that instance's scope(s). This
prevents those computables from being processed in the parent scope
when the scope instance is not shown or needed yet.

@param {Object} scope_data
@returns {Object} optimized scope_data
This optimization takes any ScopeInstance or PolymorphicScopeInstance of a Scope with only one instance and recreates both the instance and the scope ( s ) . Any computables in the parent scope which are only used by the instance are pushed down into that instance ' s scope ( s ) . This prevents those computables from being processed in the parent scope when the scope instance is not shown or needed yet . @param { Object } scope_data @returns { Object } optimized scope_data
function process_ir (scope_data) {
  var pushed = 0;
  var scope_map = {};
  var sorted_scopes = sort_scopes(scope_data.scopes);
  sorted_scopes.forEach(function (scope) {
    var instances = get_optimizable_instances(scope);
    instances.forEach(function (instance) {
      pushed += pushdown_computables(instance, scope_map);
    });
  });
  scope_data.scopes.forEach(function (scope, i) {
    var scope_id = scope.get_identity();
    if (scope_map[scope_id]) {
      scope_data.scopes[i] = scope_map[scope_id];
    }
  });
  if (pushed) {
    var plural = pushed === 1 ? 'computable' : 'computables';
    console.log('Pushed', pushed, plural + '.');
  }
  return scope_data;
}
function process_ir ( scope_data ) { var pushed = 0 ; var scope_map = { } ; var sorted_scopes = sort_scopes ( scope_data . scopes ) ; sorted_scopes . forEach ( function ( scope ) { var instances = get_optimizable_instances ( scope ) ; instances . forEach ( function ( instance ) { pushed += pushdown_computables ( instance , scope_map ) ; } ) ; } ) ; scope_data . scopes . forEach ( function ( scope , i ) { var scope_id = scope . get_identity ( ) ; if ( scope_map [ scope_id ] ) { scope_data . scopes [ i ] = scope_map [ scope_id ] ; } } ) ; if ( pushed ) { var plural = pushed === 1 ? 'computable' : 'computables' ; console . log ( 'Pushed' , pushed , plural + '.' ) ; } return scope_data ; }
This optimization takes any ScopeInstance or PolymorphicScopeInstance
 of a Scope with only one instance and recreates both the instance and
 the scope(s).
This optimization takes any ScopeInstance or PolymorphicScopeInstance of a Scope with only one instance and recreates both the instance and the scope ( s ) .
// Pushdown computables for valid instances. // Replace old scopes with new ones. // Console log the number of pushed computables.