lang: Improve graph shape with speculative execution

Most of the time, we don't need to have a dynamic call sub graph, since
the actual function call could be represented statically as it
originally was before lambda functions were implemented. Simplifying the
graph shape has important performance benefits in terms of both keep the
graph smaller (memory, etc) and in avoiding the need to run transactions
at runtime (speed) to reshape the graph.

Co-authored-by: Samuel Gélineau <gelisam@gmail.com>
This commit is contained in:
James Shubin
2025-03-17 02:31:01 -04:00
parent 9c9f2f558a
commit 37bb67dffd
139 changed files with 1871 additions and 262 deletions

View File

@@ -93,6 +93,9 @@ func (obj *LookupDefaultFunc) ArgGen(index int) (string, error) {
// runs.
func (obj *LookupDefaultFunc) Build(typ *types.Type) (*types.Type, error) {
// typ is the KindFunc signature we're trying to build...
if typ == nil {
return nil, fmt.Errorf("nil type") // happens b/c of Copy()
}
if typ.Kind != types.KindFunc {
return nil, fmt.Errorf("input type must be of kind func")
}
@@ -172,7 +175,9 @@ func (obj *LookupDefaultFunc) Info() *interfaces.Info {
if obj.fn == nil {
return &interfaces.Info{
Pure: true,
Memo: false,
Memo: true,
Fast: true,
Spec: true,
Sig: types.NewType("func(?1, ?2, ?3) ?3"), // func kind
Err: obj.Validate(),
}
@@ -199,6 +204,9 @@ func (obj *LookupDefaultFunc) Stream(ctx context.Context) error {
// Call returns the result of this function.
func (obj *LookupDefaultFunc) Call(ctx context.Context, args []types.Value) (types.Value, error) {
if obj.fn == nil {
return nil, funcs.ErrCantSpeculate
}
cf, ok := obj.fn.(interfaces.CallableFunc)
if !ok {
// programming error