Skip to content

[BEAM-3388] Use general untyped function call mechanism in Go SDK runtime#4443

Merged
lukecwik merged 4 commits intoapache:go-sdkfrom
herohde:runtime7
Jan 19, 2018
Merged

[BEAM-3388] Use general untyped function call mechanism in Go SDK runtime#4443
lukecwik merged 4 commits intoapache:go-sdkfrom
herohde:runtime7

Conversation

@herohde
Copy link
Contributor

@herohde herohde commented Jan 18, 2018

  • Dynamic functions can thus use it directly and avoid reflection
  • Change decoders/encodes to simple wrappers to unify arity instead of full specialization.
  • Moved type-specialized code into separate package and import it in beamx
  • Made templates more easily reusable for other types.

  * Dynamic functions can thus use it directly and avoid reflection
  * Change decoders/encodes to simple wrappers over a reflectx.Func.
@herohde
Copy link
Contributor Author

herohde commented Jan 18, 2018

R: @lostluck @wcn3

// T is the type of the generated function
T reflect.Type
// Data holds the data for the generator.
// Data holds the data for the generator. This data is trivially serializable.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we don't need the comment. What []byte isn't trivially serializable?

Or maybe this is a comment for DynFn, that they are trivially serializable because of this, which is why they are awesome, and we built them? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clarified the comment.

//go:generate specialize --input=callers.tmpl --x=data,universals

// NOTE(herohde) 12/11/2017: the below helpers are ripe for type-specialization,
// if the reflection overhead here turns out to be significant. It would
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment still relevant? Seems we're doing all the type specialization now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed :)

@herohde
Copy link
Contributor Author

herohde commented Jan 19, 2018

Thanks @wcn3. PTAL


// RegisterCaller registers an custom caller factory for the given type, such as
// "func(int)bool". If multiple caller factories are registered for the same type,
// RegisterFunc registers an custom reflectFunc factory for the given type, such as
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reflectFunc -> reflectx.Func ?
Or maybe just Func? it seems appropriate to drop the package specifier for local Exported types.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


package optimized

// NOTE(herohde) 1/18/2018: omit []byte for encodes to avoid re-registration due to symmetry.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a TODO, or is it something that's actually done already? It sounds like a TODO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's already done. The command for encoders use "primitives" instead of "data".

encodersMu.Lock()
defer encodersMu.Unlock()
func makeEncoder(fn reflectx.Func) Encoder {
// Detect one of the valid decoder forms and allow it to be invoked
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

encoder forms

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

callersMu.Lock()
maker, exists := callers[reflect.TypeOf(fn).String()]
callersMu.Unlock()
// MakeFunc returns a reflectFunc for given function.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's confusing to refer to an unexported type in godoc. Consider simply calling it Func instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

// RegisterCaller registers an custom caller factory for the given type, such as
// "func(int)bool". If multiple caller factories are registered for the same type,
// RegisterFunc registers an custom reflectFunc factory for the given type, such as
// "func(int)bool". If multiple func factories are registered for the same type,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the intent is to refer to the type, consider Func instead of func.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@herohde
Copy link
Contributor Author

herohde commented Jan 19, 2018

Thanks!

@herohde
Copy link
Contributor Author

herohde commented Jan 19, 2018

R: @lukecwik (please merge)

@lukecwik lukecwik merged commit e019f19 into apache:go-sdk Jan 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants