functions-summaries-curry-call.ts 1.1 KB

12345678910111213141516171819
  1. // Curry + .call: g = make(topic) returns an arrow capturing make's param a; then
  2. // g.call(null, extra) invokes it. At runtime BOTH topic (captured) and extra
  3. // (positional) flow into ask#1. Probes that the captured flow survives .call
  4. // (placeholder through the summary) while the positional one is misaligned.
  5. //
  6. // The snapshot also carries a SOUND extra edge `extra(ask#3) -> sink` (not a bug): on the
  7. // first fixpoint pass make's summary is not yet computed, so `g` carries no `.fns` and
  8. // `g.call(null, extra)` is analyzed as an unknown call — which correctly returns the union
  9. // of its arguments (extra included). Gen-only monotonicity then keeps that edge. This is an
  10. // inherent higher-order fixpoint-warmup over-approximation, not specific to `.call`.
  11. const judge = agent("judge");
  12. function make(a: string): (b: string) => Node<string> {
  13. return (b: string) => judge.ask<string>(`judge ${a} ${b}`);
  14. }
  15. const topic = await agent("t").ask<string>("topic");
  16. const extra = await agent("e").ask<string>("extra");
  17. const g = make(topic);
  18. const out = await g.call(null, extra);
  19. return out;