-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Default constructor for Record? #10
Comments
I did take a look at records a bit the last time I bumped the ASM version. At that time, I wasn't exactly sure what utility emitting records from Clojure would have, other than just emulating Java/ It seems like this might be a worthy addition, and with a minor change to support primitives ( Also, I'd be curious to know if you have a use case for emitting records that I may have missed? Thanks. |
First, you are correct regarding some of the methods I neglected. That was my oversight, I simply didn't read the bytecode fully, instead focusing on the constructor.
I think records are slightly different at the jvm level than regular classes. I wasn't able to find it with a cursory glance at the source code, but iirc them being immutable value classes makes things easier for the JIT compiler, but I'm not sure. |
You are right about the JIT having an easier time with immutable classes, but until I hear something about records being additionally optimized or otherwise treated specially by the JVM more than just normal immutable value classes, I think I'll put first class support for records in the core on hold.
Sounds like a useful feature, maybe you could call your implementation Now that I think about it, if we eventually do support records, something like you've mentioned may really just belong in a different namespace like Anyway, thanks for opening this. We can leave it open for the time being for any additional discussion. |
Another thing to keep in mind which will be different in terms of bytecode and JVM representation is primitive classes (so records are defrecord- while primitive records will be --) |
I got curious and tried emitting a record with the library.
The awesome part is it just worked. The "hard" part was it did not emit the default constructor emitted by javac, so I had to write one myself.
Looking at some bytecode, generating it seems straightforward:
Do you think it should be added by default when no
init
is provided with the samedesc
? (when the class's flags have:record
)The text was updated successfully, but these errors were encountered: