-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Improve support for macros targeting invokedynamic #9528
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
Conversation
- Support macro varargs bootstrap methods - Support method handle bootstrap arguments Demonstrated with a test case that passes a Constant(symbol) through to a static bootstrap MethodHandle argument. This bootstrap also accepts a trailing varargs array of parameter names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR was almost exactly what I needed to put together a macro to start testing out how we could indy-fy case class
methods (like equals
/hashCode
/etc.) with something like what Java 16 does for records. Thank you!
@@ -131,7 +131,8 @@ abstract class BTypesFromSymbols[G <: Global](val global: G) extends BTypes { | |||
|
|||
def bootstrapMethodArg(t: Constant, pos: Position): AnyRef = t match { | |||
case Constant(mt: Type) => methodBTypeFromMethodType(transformedType(mt), isConstructor = false).toASMType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While you are at it, this could be tweaked to also support Class
constants
case Constant(mt: Type) => methodBTypeFromMethodType(transformedType(mt), isConstructor = false).toASMType | |
case Constant(t: Type) => | |
transformedType(t) match { | |
case mt: MethodType => methodBTypeFromMethodType(mt, isConstructor = false).toASMType | |
case t: Type => typeToBType(t).toASMType | |
} | |
@@ -149,6 +150,23 @@ abstract class BTypesFromSymbols[G <: Global](val global: G) extends BTypes { | |||
new asm.Handle(asm.Opcodes.H_INVOKESTATIC, ownerInternalName, sym.name.encoded, descriptor, isInterface) | |||
} | |||
|
|||
def handleFromMethodSymbol(sym: Symbol): asm.Handle = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there is an isField
on Symbol
, it would be quite nice to generate a asm.Opcodes.H_GETFIELD
handle for those. I don't have a good code suggestion though since I'm not sure how to unmangle the field name and its trailing whitespace (I ended up hacking the name with if (isField) sym.name.toString.init
...).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'll leave this to a followup improvement.
59ca5f1
to
48f5a79
Compare
Demonstrated with a test case that passes a Constant(symbol) through to a
static bootstrap MethodHandle argument. This bootstrap also accepts a
trailing varargs array of parameter names.