2 comments

  • gigatexal1 hour ago
    But isn’t the enum far more readable and maintainable than having to do bit operations on things?
    • compiler-guy25 minutes ago
      The reason the enum is so nice is that it works as a terrific language-supplied abstraction that covers up those bit manipulations. It&#x27;s very nice to get those abstractions for free like you do in Rust, but it can&#x27;t be optimal for every specialized use case.<p>This new code also supplies similar abstractions. That actual specific code is much harder to reason about, but most users--and even the next person who works on the interpreter--simply won&#x27;t care, or even know what is going on underneath the hood. The abstractions provided by the author do that work and apparently do it cleanly.<p>For most use-cases, that extra hand-written code isn&#x27;t worth it. But in specific cases it can be, and the author has actually measured the value and determined that it is.
    • tom_59 minutes ago
      The computer&#x27;s the one running the code, and it&#x27;ll be running it a lot (or so its author hopes), so it&#x27;s probably worth bearing its limitations in mind in the interests of making its life easier (so to speak) rather than prioritising the people who will modify the interpreter - a far less common occurrence.<p>The bit operations involved are pretty simple and won&#x27;t take you long to figure out even if you&#x27;ve never done them before.
    • steveklabnik39 minutes ago
      &gt; As you can see, it has many convenience methods to make it easy to work with, compensating for the loss of the Rust enum.<p>Also, Rust does try to do some of these optimizations itself. These aren&#x27;t exposed in the stable language to let you do some more advanced things, but it wouldn&#x27;t be impossible for you to get the best of both worlds by letting you communicate this stuff more directly to the compiler. Right now those things are more like &quot;this value is where you should put the tag&quot; than the more advanced stuff here, though. Would be cool to see someday!
      • lowbloodsugar28 minutes ago
        quibble: unsafe is stable. you can&#x27;t do this in safe rust, but you can do it in unsafe rust. just isolate all the unsafe code in a single type, ideally a tiny crate.
    • mwkaufma7 minutes ago
      If you add &quot;fits in a register&quot; to your list of correctness requirements, then it&#x27;s no-go even if the source has less cognitive overhead.
  • lowbloodsugar57 minutes ago
    Take a look at triomphe&#x27;s ArcUnion and extrapolate from there. Basically make a crate for just your 64bit union type, do it unsafe there, test with miri, and now you have a safe 64bit type you can use with match. You&#x27;re happy digging around assembly so this is well within your wheelhouse. The only challenge will be if you do use miri to verify then you need to use the &#x27;provenance-preserving&#x27; pointer adjusting functions. Worth the learning experience in my opinion. I did one for my system and it was super fun and had the performance impact you describe.