gomacro
gomacro copied to clipboard
gomacro cannot be used with google app engine because it uses the unsafe package
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 ?)
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.
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)?
unsafe is used for the following features:
- in the fast interpreter to optimize and simplify access to interpreted variables
- in gomacro/base/output/output.go
asUnsafeValue
to pretty-print function pointers - in gomacro/xreflect/named.go
unsafeAddMethod
to support redefining existing methods (a current limitation of the go/types package) - 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. - 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) - 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) - 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
Thank you very much for documenting this.