code: func (c *Compiler) rewriteRefsInHead() {
  	for _, name := range c.sorted {
  		mod := c.Modules[name]
  		f := newEqualityFactory(newLocalVarGenerator(mod))
  		WalkRules(mod, func(rule *Rule) bool {
  			if requiresEval(rule.Head.Key) {
  				expr := f.Generate(rule.Head.Key)
  				rule.Head.Key = expr.Operand(0)
  				rule.Body.Append(expr)
  			}
  			if requiresEval(rule.Head.Value) {
  				expr := f.Generate(rule.Head.Value)
  				rule.Head.Value = expr.Operand(0)
  				rule.Body.Append(expr)
  			}
  			for i := 0; i < len(rule.Head.Args); i++ {
  				if requiresEval(rule.Head.Args[i]) {
  					expr := f.Generate(rule.Head.Args[i])
  					rule.Head.Args[i] = expr.Operand(0)
  					rule.Body.Append(expr)
  				}
  			}
  			return false
  		})
  	}
  }
docs: // rewriteTermsInHead will rewrite rules so that the head does not contain any
  // terms that require evaluation (e.g., refs or comprehensions). If the key or
  // value contains or more of these terms, the key or value will be moved into
  // the body and assigned to a new variable. The new variable will replace the
  // key or value in the head.
  //
  // For instance, given the following rule:
  //
  // p[{"foo": data.foo[i]}] { i < 100 }
  //
  // The rule would be re-written as:
  //
  // p[__local0__] { i < 100; __local0__ = {"foo": data.foo[i]} }