Skip to content
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

Stub implementation of xml interpolator #5096

Merged
merged 1 commit into from
Sep 19, 2018

Conversation

allanrenucci
Copy link
Contributor

No description provided.

@allanrenucci allanrenucci force-pushed the xml-interpolation branch 3 times, most recently from facdf69 to e07e72e Compare September 12, 2018 16:14
List(Typed(Repeated(values), _)))) if values.forall(isStringConstant) =>
values.collect { case Literal(Constant.String(value)) => value }
case _ =>
???
Copy link
Contributor

Choose a reason for hiding this comment

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

This should only happen if you write explicitly something like

val sc = new StringContext(...)
new XmlQuote(sc).xml(...)

you can emit an error in this case using new scala.quoted.QuotedError(...) which will be translated into a compilation error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. I think we are still missing the ability to report an error at a custom position

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes we are. Should not be hard to add.

val parts = ctx.toTasty match {
case Inlined(_, _,
Apply(
Select(Select(Select(Ident("_root_"), "scala", _), "StringContext", _), "apply", _),
Copy link
Contributor

Choose a reason for hiding this comment

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

In tasty.definition you should have types or symbols for root and scala. You should be able to test this in the guard.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't look simpler. It is more correct?

Copy link
Contributor

Choose a reason for hiding this comment

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

Then this is fine. I expected it to look simpler


case class Xml(parts: String, arg: Any)

class XmlQuote(ctx: StringContext) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this class extend AnyVal?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I doesn't matter for performance. The code is elided by the macro. So the simpler, the better

Copy link
Contributor

Choose a reason for hiding this comment

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

Even the allocation of the XmlQuote is elided?

Copy link
Contributor Author

@allanrenucci allanrenucci Sep 14, 2018

Choose a reason for hiding this comment

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

Actually my intuition (based on how Scala 2 macros work) was wrong. The receiver of the macro doesn't get elided. I opened #5110

@allanrenucci
Copy link
Contributor Author

@nicolasstucki @biboudis I think this is good enough as a test and a proof of concept. Real development is happening here

case class Xml(parts: String, args: List[Any])

// Ideally should be an implicit class but the implicit conversion
// has to be a rewrite method
Copy link
Contributor

Choose a reason for hiding this comment

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

Good point, I think this is the best solution. Otherwise, we would need something like implicit rewrite class XmlQuote(...). Maybe with proper extension methods this will not be an issue.

@nicolasstucki
Copy link
Contributor

We will still need to enable the test when #5119 is fixed.

@nicolasstucki nicolasstucki merged commit 7a42360 into scala:master Sep 19, 2018
@nicolasstucki nicolasstucki deleted the xml-interpolation branch September 19, 2018 16:44
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