Skip to content

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

Merged
merged 4 commits into from
Apr 14, 2021

Conversation

retronym
Copy link
Member

@retronym retronym commented Mar 2, 2021

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

retronym added 2 commits March 2, 2021 13:27
  - 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.
@scala-jenkins scala-jenkins added this to the 2.12.14 milestone Mar 2, 2021
Copy link
Contributor

@harpocrates harpocrates left a 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
Copy link
Contributor

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

Suggested change
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 = {
Copy link
Contributor

@harpocrates harpocrates Apr 4, 2021

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...).

Copy link
Member Author

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.

@retronym retronym force-pushed the topic/macro-indy-fixes branch from 59ca5f1 to 48f5a79 Compare April 12, 2021 00:13
@dwijnand dwijnand self-requested a review April 14, 2021 13:18
@retronym retronym merged commit dd72f12 into scala:2.12.x Apr 14, 2021
@retronym retronym deleted the topic/macro-indy-fixes branch April 14, 2021 23:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants