openllb / hlb

A developer-first language to build and test any software efficiently
https://openllb.github.io/hlb/
Apache License 2.0
108 stars 12 forks source link

Evaluate arguments asynchronously and delay register to value un-lazying #306

Closed hinshun closed 2 years ago

hinshun commented 2 years ago

This makes codegen fully asynchronous, as arguments will also be evaluating asynchronously.

fs default() {
    image "alpine"
    copy image("other") "/etc/os-release" "/a"
}

Previously in https://github.com/openllb/hlb/pull/289, SetAsync was introduced and each block literal was executed asynchronously by creating a chain of goroutines piping to each other. However in the example above, image("other") will only start resolving image config once image "alpine" was done because each line depended on the line above it.

In this PR, image("other") will be executed asynchronously, and copy will block until its arguments have resolved.

If a builtin Callable required an argument like input Value instead of input Filesystem, it is further delayed until the builtin decides to resolve input to a Filesystem, allowing the builtin to do things asynchronously before consuming input. (Used in a the fs cache(fs input, string ref) experiment). This is implemented by lazyValue.