Fabrication

Fabrication

305k Downloads

[Discussion] AccessWideners

LambdAurora opened this issue ยท 3 comments

commented

This is mostly a discussion/question dev-side and not really user-side, hope it's okay.

I noticed sodium-fabric#445 and saw:

I will accept a closed issue and punt back to my side and use MethodHandles. Wanted to send over what I knew.

Being curious as I am I looked at Fabrication's access widener and got quite surprised as in Fabric's wiki it's something really unrecommended to use and only for like inner classes case, or cases in which mixins cannot help.

I can understand why MethodHandles are really not a good solution, though I was wondering, for methods, why not use Invokers? They would solve the visibility issue, should cost less performance-wise than MethodHandle, the only thing that can be annoying is the casting of the Minecraft's object as a duck-interface.

Here's a link on Invoker usage if needed: https://github.com/2xsaiko/mixin-cheatsheet/blob/master/invoker.md

commented

A MethodHandle is nearly free; it's their entire purpose. Even standard reflection is cheap if you cache the objects instead of doing lookups every time.

The only reason I use primarily use AccessWideners is because, while I was around for Mixin's creation, I'm more of a manual bytecode engineer and a lot of Mixin's nuances escape me. Another advantage is Forgery can convert them directly to Forge AccessTransformers.

Originally Fabrication used only reflection, using the reflect-into-reflection trick to set finals, but that was broken in Java 9. I will probably replace most of my usages of them with MethodHandles, regardless of the outcome of the Sodium issue. I only haven't done it because I was done modding for the day.

Evidently I missed that they're discouraged. I haven't really read up or paid attention to writing on AccessTransformers since ~1.7.10, where I learnt to use Forge's ATs. In old-Forge land they're encouraged because Mixin doesn't exist.

commented

Ok, understandable! Wasn't aware of that Forge part.

Even if MethodHandle is nearly free, I guess most still use Mixin's Invokers just because they're remapped while for MethodHandle the lookup must be done "manually".

Thank you for the answer! It's more clear now ^^

commented

All access wideners have been removed save for those that remove a final or make a private inner class accessible.