lang: Functions that build should be copyable
It's not entirely clear if this is required, but it's probably a good idea. We should consider making it a requirement of the BuildableFunc interface.
This commit is contained in:
@@ -354,6 +354,16 @@ func (obj *PrintfFunc) Stream(ctx context.Context) error {
|
||||
}
|
||||
}
|
||||
|
||||
// Copy is implemented so that the obj.Type value is not lost if we copy this
|
||||
// function.
|
||||
func (obj *PrintfFunc) Copy() interfaces.Func {
|
||||
return &PrintfFunc{
|
||||
Type: obj.Type, // don't copy because we use this after unification
|
||||
|
||||
init: obj.init, // likely gets overwritten anyways
|
||||
}
|
||||
}
|
||||
|
||||
// Call this function with the input args and return the value if it is possible
|
||||
// to do so at this time.
|
||||
func (obj *PrintfFunc) Call(ctx context.Context, args []types.Value) (types.Value, error) {
|
||||
|
||||
@@ -393,6 +393,17 @@ func (obj *TemplateFunc) Stream(ctx context.Context) error {
|
||||
}
|
||||
}
|
||||
|
||||
// Copy is implemented so that the obj.built value is not lost if we copy this
|
||||
// function.
|
||||
func (obj *TemplateFunc) Copy() interfaces.Func {
|
||||
return &TemplateFunc{
|
||||
Type: obj.Type, // don't copy because we use this after unification
|
||||
built: obj.built,
|
||||
|
||||
init: obj.init, // likely gets overwritten anyways
|
||||
}
|
||||
}
|
||||
|
||||
// Call this function with the input args and return the value if it is possible
|
||||
// to do so at this time.
|
||||
func (obj *TemplateFunc) Call(ctx context.Context, args []types.Value) (types.Value, error) {
|
||||
|
||||
@@ -134,6 +134,16 @@ func (obj *HistoryFunc) Build(typ *types.Type) (*types.Type, error) {
|
||||
return obj.sig(), nil
|
||||
}
|
||||
|
||||
// Copy is implemented so that the type value is not lost if we copy this
|
||||
// function.
|
||||
func (obj *HistoryFunc) Copy() interfaces.Func {
|
||||
return &HistoryFunc{
|
||||
Type: obj.Type, // don't copy because we use this after unification
|
||||
|
||||
init: obj.init, // likely gets overwritten anyways
|
||||
}
|
||||
}
|
||||
|
||||
// Validate makes sure we've built our struct properly. It is usually unused for
|
||||
// normal functions that users can use directly.
|
||||
func (obj *HistoryFunc) Validate() error {
|
||||
|
||||
@@ -459,3 +459,13 @@ func (obj *FilterFunc) replaceSubGraph(subgraphInput interfaces.Func) error {
|
||||
|
||||
return obj.init.Txn.Commit()
|
||||
}
|
||||
|
||||
// Copy is implemented so that the type value is not lost if we copy this
|
||||
// function.
|
||||
func (obj *FilterFunc) Copy() interfaces.Func {
|
||||
return &FilterFunc{
|
||||
Type: obj.Type, // don't copy because we use this after unification
|
||||
|
||||
init: obj.init, // likely gets overwritten anyways
|
||||
}
|
||||
}
|
||||
|
||||
@@ -454,3 +454,14 @@ func (obj *MapFunc) replaceSubGraph(subgraphInput interfaces.Func) error {
|
||||
|
||||
return obj.init.Txn.Commit()
|
||||
}
|
||||
|
||||
// Copy is implemented so that the type values are not lost if we copy this
|
||||
// function.
|
||||
func (obj *MapFunc) Copy() interfaces.Func {
|
||||
return &MapFunc{
|
||||
Type: obj.Type, // don't copy because we use this after unification
|
||||
RType: obj.RType, // don't copy because we use this after unification
|
||||
|
||||
init: obj.init, // likely gets overwritten anyways
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,6 +195,20 @@ func (obj *LookupFunc) Build(typ *types.Type) (*types.Type, error) {
|
||||
return obj.fn.Build(typ)
|
||||
}
|
||||
|
||||
// Copy is implemented so that the type value is not lost if we copy this
|
||||
// function.
|
||||
func (obj *LookupFunc) Copy() interfaces.Func {
|
||||
fn := &LookupFunc{
|
||||
Type: obj.Type, // don't copy because we use this after unification
|
||||
|
||||
//init: obj.init, // likely gets overwritten anyways
|
||||
}
|
||||
if _, err := fn.Build(obj.Type); err != nil {
|
||||
// ignore, since we just didn't set the type
|
||||
}
|
||||
return fn
|
||||
}
|
||||
|
||||
// Validate tells us if the input struct takes a valid form.
|
||||
func (obj *LookupFunc) Validate() error {
|
||||
if obj.fn == nil { // build must be run first
|
||||
|
||||
@@ -140,6 +140,21 @@ func (obj *LookupDefaultFunc) Build(typ *types.Type) (*types.Type, error) {
|
||||
return obj.fn.Build(typ)
|
||||
}
|
||||
|
||||
// Copy is implemented so that the type value is not lost if we copy this
|
||||
// function.
|
||||
func (obj *LookupDefaultFunc) Copy() interfaces.Func {
|
||||
fn := &LookupDefaultFunc{
|
||||
Type: obj.Type, // don't copy because we use this after unification
|
||||
//fn: get this through Build()
|
||||
|
||||
//init: obj.init, // likely gets overwritten anyways
|
||||
}
|
||||
if _, err := fn.Build(obj.Type); err != nil {
|
||||
// ignore, since we just didn't set the type
|
||||
}
|
||||
return fn
|
||||
}
|
||||
|
||||
// Validate tells us if the input struct takes a valid form.
|
||||
func (obj *LookupDefaultFunc) Validate() error {
|
||||
if obj.fn == nil { // build must be run first
|
||||
|
||||
@@ -181,6 +181,16 @@ func (obj *GetFunc) Build(typ *types.Type) (*types.Type, error) {
|
||||
return obj.sig(), nil
|
||||
}
|
||||
|
||||
// Copy is implemented so that the type value is not lost if we copy this
|
||||
// function.
|
||||
func (obj *GetFunc) Copy() interfaces.Func {
|
||||
return &GetFunc{
|
||||
Type: obj.Type, // don't copy because we use this after unification
|
||||
|
||||
init: obj.init, // likely gets overwritten anyways
|
||||
}
|
||||
}
|
||||
|
||||
// Validate makes sure we've built our struct properly. It is usually unused for
|
||||
// normal functions that users can use directly.
|
||||
func (obj *GetFunc) Validate() error {
|
||||
|
||||
@@ -247,6 +247,17 @@ func (obj *ScheduleFunc) Build(typ *types.Type) (*types.Type, error) {
|
||||
return obj.sig(), nil
|
||||
}
|
||||
|
||||
// Copy is implemented so that the type value is not lost if we copy this
|
||||
// function.
|
||||
func (obj *ScheduleFunc) Copy() interfaces.Func {
|
||||
return &ScheduleFunc{
|
||||
Type: obj.Type, // don't copy because we use this after unification
|
||||
built: obj.built,
|
||||
|
||||
init: obj.init, // likely gets overwritten anyways
|
||||
}
|
||||
}
|
||||
|
||||
// Validate tells us if the input struct takes a valid form.
|
||||
func (obj *ScheduleFunc) Validate() error {
|
||||
if !obj.built {
|
||||
|
||||
@@ -722,6 +722,16 @@ func (obj *OperatorFunc) Stream(ctx context.Context) error {
|
||||
}
|
||||
}
|
||||
|
||||
// Copy is implemented so that the obj.Type value is not lost if we copy this
|
||||
// function.
|
||||
func (obj *OperatorFunc) Copy() interfaces.Func {
|
||||
return &OperatorFunc{
|
||||
Type: obj.Type, // don't copy because we use this after unification
|
||||
|
||||
init: obj.init, // likely gets overwritten anyways
|
||||
}
|
||||
}
|
||||
|
||||
// Call this function with the input args and return the value if it is possible
|
||||
// to do so at this time.
|
||||
func (obj *OperatorFunc) Call(ctx context.Context, args []types.Value) (types.Value, error) {
|
||||
|
||||
Reference in New Issue
Block a user