Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gomacro cannot be used with google app engine because it uses the unsafe package #43

Open
cosmos72 opened this issue Nov 10, 2018 · 4 comments

Comments

@cosmos72
Copy link
Owner

cosmos72 commented Nov 10, 2018

as highlighted by @morangorin in #42. He also adds:

would it be possible to have a smaller and simpler version of gomacro ? (perhaps at the cost of performance and/or features ?)

@cosmos72
Copy link
Owner Author

cosmos72 commented Nov 10, 2018

The unsafe package is used in several places as an optimization - without it, the gomacro/fast interpreter would be either much slower or much more complex. So, while technically possible to remove them, it's a lot of work - more than I am currently willing to put for the goal of running it on google app engine.

There is also a workaround for some missing features of the reflect package that uses unsafe, and the only way to implement them without unsafe is to patch the reflect package from Go standard library (or live with the missing features).

A possible solution is to use the gomacro/classic interpreter: as I mentioned in #42, it's older and much slower. On the plus side, it's much smaller and does not use unsafe. Unluckly, it currently lacks a command-line REPL but, as again I wrote in #42, it's basically a matter of duplicating gomacro/cmd and replacing the calls to fast interpreter with calls to the classic one. If you are willing to work on this, I will happily accept it as a contribution.

@morangorin
Copy link

For documentation, what would be the list of missing features if one was not to use the unsafe package in reflect (with the classic interpreter)?

@cosmos72
Copy link
Owner Author

cosmos72 commented Nov 12, 2018

unsafe is used for the following features:

  1. in the fast interpreter to optimize and simplify access to interpreted variables
  2. in gomacro/base/output/output.go asUnsafeValue to pretty-print function pointers
  3. in gomacro/xreflect/named.go unsafeAddMethod to support redefining existing methods (a current limitation of the go/types package)
  4. in gomacro/xreflect/named.go unsafeRemoveMethods to support removing methods (currently not supported by the go/types package) - used to remove wrapper methods for embedded struct fields when importing packages, as gomacro scavenges by itself for embedded struct fields and their methods, implementing accurate lookup rules.
  5. in gomacro/base/signal.go Signals.IsEmpty to atomically check in a single step whether four uint8 fields of a struct are all zero (only used by fast interpreter)
  6. in gomacro/base/untyped/lit.go to convert from untyped literals to *big.Int, *big.Rat and *big.Float - a Go language extension specific to gomacro (only used by fast interpreter)
  7. in gomacro/fast/selector.go makeAccessible to support accessing exported fields of embedded structs that are not exported (a current limitation of the reflect package)

As you can guess, removing some of these usages is quite trivial (1 2 5 6 in particular if you stick to the classic interpreter), while removing others (3 4 7) has non-trivial side effects

@morangorin
Copy link

Thank you very much for documenting this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants