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

Regression in com-lihaoyi/fastparse for inlines / term-dependant types #20286

Closed
WojciechMazur opened this issue Apr 29, 2024 · 1 comment · Fixed by #20295
Closed

Regression in com-lihaoyi/fastparse for inlines / term-dependant types #20286

WojciechMazur opened this issue Apr 29, 2024 · 1 comment · Fixed by #20295
Assignees
Labels
area:experimental area:inline itype:bug regression This worked in a previous version but doesn't anymore
Milestone

Comments

@WojciechMazur
Copy link
Contributor

WojciechMazur commented Apr 29, 2024

Based on OpenCB failure for com-lahaoyi/fastparse - build logs

Compiler version

Last good release: 3.5.0-RC1-bin-20240404-a7f00e2-NIGHTLY
First bad release: 3.5.0-RC1-bin-20240405-85672a0-NIGHTLY
Bisect points to f055cee

Minimized code

// test.scala
implicit inline def LiteralStr(s: String)(implicit ctx: P[Any]): P[Unit] = ???

extension [T](inline parse0: P[T]) {
  inline def ~[V, R](inline other: P[V])(using
      ctx: P[?]
  ): P[R] = ${ MacroInlineImpls.parsedSequence0[T, V, R]('parse0, 'other) }

  inline def flatMapX[V](inline f: T => P[V]): P[V] =
    MacroInlineImpls.flatMapXInline[T, V](parse0)(f)
}

def deeper[$: P]: P[Int] = ???
def newline[$: P]: P[Unit] = ???
def blockBody[p: P]: P[Seq[Int]] = newline ~ deeper.flatMapX { i =>
  val y = LiteralStr("")(using ???)
  ???
}
// test.macros.scala
import scala.quoted.*

type P[+T] = ParsingRun[T]
trait ParsingRun[+T] {
  var successValue: Any
  def freshSuccessUnit(): ParsingRun[Unit]

}

object MacroInlineImpls {
  inline def flatMapXInline[T, V](
      lhs: ParsingRun[T]
  )(inline f: T => ParsingRun[V]): ParsingRun[V] = {
    f(lhs.successValue.asInstanceOf[T])
  }

  def parsedSequence0[T: Type, V: Type, R: Type](
      lhs: Expr[ParsingRun[T]],
      rhs: Expr[ParsingRun[V]]
  )(using quotes: Quotes): Expr[ParsingRun[R]] = {
    import quotes.reflect.*
    '{ $rhs.asInstanceOf[ParsingRun[R]] }
  }
}

Output

18 |  val y = LiteralStr("")(using ???)
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^
   |Term-dependent types are experimental,
   |they must be enabled with a `experimental.dependent` language import or setting
   |----------------------------------------------------------------------------
   |Inline stack trace
   |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   |This location contains code that was inlined from sandbox.scala:3
 3 |implicit inline def LiteralStr(s: String)(implicit ctx: P[Any]): P[Unit] = ???
   |                                                                 ^^^^^^^
    ----------------------------------------

Expectation

The compiler should be be assuming to using the experimental term-depandant types, the library is not using them explicitly.

@nicolasstucki
Copy link
Contributor

The issue is that we are trying to replace Unit with () in

 3 |implicit inline def LiteralStr(s: String)(implicit ctx: P[Any]): P[Unit] = ???

nicolasstucki added a commit that referenced this issue Apr 30, 2024
@Kordyjan Kordyjan added this to the 3.5.0 milestone May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:experimental area:inline itype:bug regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants