Skip to content

Encode pickled primitives directly using reflection #10232

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

nicolasstucki
Copy link
Contributor

@nicolasstucki nicolasstucki commented Nov 8, 2020

This removes the need of some extra helper methods in the internal package.

Add asExpr to have a variant of asExprOf[Any] that does not need the extra type test at runtime.
Also add an equivalent asType method.

@nicolasstucki
Copy link
Contributor Author

Step towards #10222

@nicolasstucki nicolasstucki force-pushed the reify-null-and-unit-quotes-directly-as-literals branch 2 times, most recently from 86d8b30 to fa93686 Compare November 8, 2020 12:46
@nicolasstucki nicolasstucki changed the title Pickle '{} and '{null} directly as Literal Encode pickled primitives directly using reflection Nov 8, 2020
@nicolasstucki nicolasstucki force-pushed the reify-null-and-unit-quotes-directly-as-literals branch from fa93686 to c60ee85 Compare November 8, 2020 12:55
This removes the need of some extra helper methods in the internal package.

Also add `asExpr` to have a variant of `asExprOf[Any]` that does not need the extra type test at runtime.
…` directly

This removes the need of some extra helper methods in the internal package.
@nicolasstucki nicolasstucki force-pushed the reify-null-and-unit-quotes-directly-as-literals branch from c60ee85 to bff91a8 Compare November 8, 2020 13:50
@nicolasstucki nicolasstucki marked this pull request as ready for review November 8, 2020 14:47
* '{ val x: t = ... }
* ```
*/
def asType: scala.quoted.Type[?]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the difference with seal?

Copy link
Contributor Author

@nicolasstucki nicolasstucki Nov 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will replace seal. But that needs to be removed after #10207 is merged. In that PR we remove the unseal method from Type. I decided to do it this way to avoid conflicts with #10207.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find the name asType is not as informative as seal, because the name Type in the context of TypeRepr is vague, it could refer to both TypeRepr and quoted.Type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The next step is to find a way to inject this type in the context directly. Something like

typeRep.asTypeInContext { [T] =>>
   // Type[T] is given in this context
}

def asTypeInContext[U](body: [T] =>> (using Type[T]) => U): U = ...

Copy link
Contributor

@liufengyun liufengyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

* '{ val x: t = ... }
* ```
*/
def asType: scala.quoted.Type[?]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find the name asType is not as informative as seal, because the name Type in the context of TypeRepr is vague, it could refer to both TypeRepr and quoted.Type.

@nicolasstucki nicolasstucki merged commit ab42870 into scala:master Nov 9, 2020
@nicolasstucki nicolasstucki deleted the reify-null-and-unit-quotes-directly-as-literals branch November 9, 2020 08:25
@Kordyjan Kordyjan added this to the 3.0.0 milestone Aug 2, 2023
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.

4 participants