GithubHelp home page GithubHelp logo

Comments (4)

cosmos72 avatar cosmos72 commented on August 21, 2024

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.

morangorin avatar morangorin commented on August 21, 2024

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.

cosmos72 avatar cosmos72 commented on August 21, 2024

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

from gomacro.

morangorin avatar morangorin commented on August 21, 2024

Thank you very much for documenting this.

from gomacro.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.