Skip to content

Support constant folding for s, f and raw interpolators. #10315

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

Open
nicolasstucki opened this issue Nov 13, 2020 · 6 comments
Open

Support constant folding for s, f and raw interpolators. #10315

nicolasstucki opened this issue Nov 13, 2020 · 6 comments

Comments

@nicolasstucki
Copy link
Contributor

We should be able to constant fold s, f and raw interpolator with constant inputs.

  val r: "abc" = s"ab${"c"}"

This would be useful when combined with inlining

inline val x = "abc"
inline val y = s"${y}dce"

A realistic use of this feature would be with the scala.compiletime.error method.

inline def f(x: Int) = 
  compiletime.error(s"Error code: $x")

f(3) // error: `Error code: 3`

This would need to happen when typing, probably in Inliner.

@nicolasstucki nicolasstucki changed the title Support constant folding for s, f and raw intrpolators. Support constant folding for s, f and raw interpolators. May 11, 2021
@soronpo
Copy link
Contributor

soronpo commented May 13, 2021

@nicolasstucki Say I want to tackle this, I have some questions regarding the implementation.

  1. Where should I start? Where are these implemented in the compiler?
  2. Does changing s, f, etc. to inline affect binary compatibility?
  3. Theoretically we can special case this only within the context of compiletime.error(), since we can read the tree as a raw StringContext and constant fold it accordingly. Is this better, or should we treat interpolation just like arithmetic operations that are inlined anywhere?

@soronpo soronpo self-assigned this May 13, 2021
@SethTisue
Copy link
Member

@soronpo shall we un-assign you at this point...?

@soronpo soronpo removed their assignment Feb 11, 2025
@soronpo
Copy link
Contributor

soronpo commented Feb 11, 2025

@soronpo shall we un-assign you at this point...?

Thank you Seth, just did.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants