convex icon indicating copy to clipboard operation
convex copied to clipboard

`schedule` cannot access local bindings

Open helins opened this issue 3 years ago • 3 comments

Given the current implementation, it is very easy reaching a situation where a scheduled transaction fails silently. Notably, the following example is counter-intuitive:

(let [x 42] (expand '(schedule 0 (def foo x))))

;; (schedule* 0 (compile (quote (def foo x))))
;; Of course, `x` is not defined anymore ; fails silently

I don't think this is fixable given that nothing is supposed to be evaluated in advance. Maybe we should remove schedule and use only explicit templating with schedule*.

helins avatar Feb 22 '22 12:02 helins

Interesting. Making the schedule contain an anonymous function would potentially solve this, with a slight overhead.

mikera avatar Feb 23 '22 08:02 mikera

Different from #353 but sounds like both should be coordinated.

I think I'd fancy templating more than a lambda:

  • Don't have to store a closure (and pay for what you don't need)
  • More in line with stuff like deploy

helins avatar Feb 24 '22 22:02 helins

Yeah you can template / build whatever you like with schedule*. The question I guess is how to make the helper macro schedule most intuitive.

If we want to preserve things like let bindings I think we have two main options:

  1. Use a lambda. Easy since the support for locals is already there, but does add a bit of cost
  2. Figure out some way to embed let bindings in compile so that they don't need a lookup lookup later.

Option 2 is probably optimal, just needs a bit of careful though on the semantics. Should compile always inline let-bound variables, for example?

mikera avatar Feb 25 '22 07:02 mikera