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:
@@ -508,6 +508,41 @@ func (obj *FuncSingleton) GraphFunc() (*pgraph.Graph, Func, error) {
|
||||
return obj.g, obj.f, nil
|
||||
}
|
||||
|
||||
// ValueEnv is a future potential argument to the Value() method on Expr.
|
||||
// XXX: Consider using this if we want to improve graph shape even more.
|
||||
type ValueEnv struct {
|
||||
Variables map[Expr]types.Value
|
||||
}
|
||||
|
||||
// EmptyValueEnv returns the zero, empty value for the value env, with all the
|
||||
// internal maps initialized appropriately.
|
||||
func EmptyValueEnv() *ValueEnv {
|
||||
return &ValueEnv{
|
||||
Variables: make(map[Expr]types.Value),
|
||||
}
|
||||
}
|
||||
|
||||
// Copy makes a copy of the ValueEnv struct. This ensures that if the internal
|
||||
// maps are changed, it doesn't affect other copies of the ValueEnv. It does
|
||||
// *not* copy or change the pointers contained within, since these are
|
||||
// references, and we need those to be consistently pointing to the same things
|
||||
// after copying.
|
||||
func (obj *ValueEnv) Copy() *ValueEnv {
|
||||
if obj == nil { // allow copying nil envs
|
||||
return EmptyValueEnv()
|
||||
}
|
||||
|
||||
variables := make(map[Expr]types.Value)
|
||||
|
||||
for k, v := range obj.Variables { // copy
|
||||
variables[k] = v // we don't copy the values!
|
||||
}
|
||||
|
||||
return &ValueEnv{
|
||||
Variables: variables,
|
||||
}
|
||||
}
|
||||
|
||||
// Arg represents a name identifier for a func or class argument declaration and
|
||||
// is sometimes accompanied by a type. This does not satisfy the Expr interface.
|
||||
type Arg struct {
|
||||
|
||||
Reference in New Issue
Block a user