Comments (4)
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.
from gomacro.
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)?
from gomacro.
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
from gomacro.
Thank you very much for documenting this.
from gomacro.
Related Issues (20)
- I'm unable to compile code importing gomacro on Mac OS m1 pro HOT 7
- Is there a way to Eval a folder HOT 5
- recursive type error cases: call of reflect.Value.Interface on zero Value HOT 6
- can't import fsm package HOT 4
- Different compilation behaviour from native go HOT 2
- undefined: pkgpath HOT 3
- Cannot convert struct to interface if it has an embedded struct with a method HOT 4
- Cannot import third party packages on Linux (not even the ones in the README) HOT 2
- Third-party imported type method is not callable from fast.Interp.Eval [gomacro repl works] HOT 4
- Idea for making adding third party packages to Gomacro easier when plugins aren't available HOT 3
- recursive type error cases: call of reflect.Value.Interface on zero Value
- can not import 3rd party packages HOT 13
- package <package> exports zero constants, functions, types, and variables HOT 3
- Caching of interp.Eval1 results HOT 13
- Way to disable go get import and enforce to use only defined import list HOT 3
- An error will be reported when using third-party packages on Windows HOT 2
- tls.Dialer ใConfig missing HOT 2
- Problem with accessing uint64 variable inside condition in a loop HOT 1
- can't import _b "github.com/samber/lo"
- I was using it in my go.mod project and encountered an error: error loading plugin plugin was built with a different version of package internal/abi
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gomacro.