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

Nowarn fix for Whitespace macro #310

Merged
merged 17 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .mill-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.11.7-29-f2e220
0.11.7-86-18d144
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ lazy val readme = scalatex.ScalatexReadme(
source = "Readme",
autoResources = List("out.js", "JProfiler.png")
).settings(
(resources in Compile) += baseDirectory.value/".."/"out"/"demo"/"fullOpt.dest"/"out.js",
scalaVersion := "2.12.18"
(Compile / resources) += baseDirectory.value/".."/"out"/"demo"/"fullOpt.dest"/"out.js",
scalaVersion := "2.12.19"
)

17 changes: 9 additions & 8 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import $ivy.`com.github.lolgab::mill-mima::0.0.23`
import de.tobiasroeser.mill.vcs.version.VcsVersion
import com.github.lolgab.mill.mima._

val scala3 = "3.3.1"
val scala213 = "2.13.10"
val scala212 = "2.12.17"
val scalaJS1 = "1.12.0"
val scalaNative04 = "0.5.0"
val scala3 = "3.3.3"
val scala213 = "2.13.14"
Copy link
Contributor Author

@He-Pin He-Pin May 19, 2024

Choose a reason for hiding this comment

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

it's now 2.13.14, and the nsc is updated scala/scala#10406

@lihaoyi cc

val scala212 = "2.12.19"
val scalaJS1 = "1.16.0"
val scalaNative05 = "0.5.1"
val crossVersions = Seq(scala3, scala213, scala212)

object fastparse extends Module{
Expand Down Expand Up @@ -47,7 +47,7 @@ object fastparse extends Module{

object native extends Cross[fastparseNativeModule](crossVersions)
trait fastparseNativeModule extends FastparseModule with ScalaNativeModule {
def scalaNativeVersion = scalaNative04
def scalaNativeVersion = scalaNative05

object test extends ScalaNativeTests with CommonTestModule
}
Expand Down Expand Up @@ -112,7 +112,7 @@ trait FastparseModule extends CommonCrossModule with Mima{
else super.mimaPreviousArtifacts()

def mimaBinaryIssueFilters = super.mimaBinaryIssueFilters() ++ Seq(
ProblemFilter.exclude[IncompatibleResultTypeProblem]("fastparse.Parsed#Failure.unapply")
ProblemFilter.exclude[IncompatibleResultTypeProblem]("fastparse.Parsed#Failure.unapply"),
)
}

Expand Down Expand Up @@ -170,7 +170,7 @@ trait ExampleParseJvmModule extends CommonCrossModule{
}

trait ExampleParseNativeModule extends CommonCrossModule with ScalaNativeModule{
def scalaNativeVersion = scalaNative04
def scalaNativeVersion = scalaNative05
def moduleDeps = Seq(fastparse.native())

object test extends ScalaNativeTests with CommonTestModule
Expand Down Expand Up @@ -208,6 +208,7 @@ trait CommonTestModule extends ScalaModule with TestModule.Utest{
super.scalacOptions() ++
Agg.when(scalaVersion() == scala213)(
"-Xfatal-warnings",
"-Xlint:unused",
"-Wconf:cat=feature:s,cat=deprecation:s"
)
}
Expand Down
1 change: 1 addition & 0 deletions cssparse/test/src-jvm/cssparse/TestUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ object TestUtil {
def warning(ex: CSSParseException) = println("WARNING " + ex)
})
val sheet = parser.parseStyleSheet(source, null, null)
assert(sheet != null)
errors.toSeq
}

Expand Down
5 changes: 0 additions & 5 deletions fastparse/src-2.11/fastparse/internal/NoWarn.scala

This file was deleted.

1 change: 1 addition & 0 deletions fastparse/src-2.12/fastparse/internal/NoWarn.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fastparse.internal

object NoWarn{
@deprecated("Use scala.annotation.nowarn instead", "3.1.1")
class nowarn(msg: String = "")
}
1 change: 1 addition & 0 deletions fastparse/src-2.13/fastparse/internal/NoWarn.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fastparse.internal

object NoWarn{
@deprecated("Use scala.annotation.nowarn instead", "3.1.1")
type nowarn = scala.annotation.nowarn
}
29 changes: 16 additions & 13 deletions fastparse/src-2/fastparse/internal/MacroRepImpls.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ object MacroRepImpls{
val parsedMsg = TermName(c.freshName("parsedMsg"))
val lastAgg = TermName(c.freshName("lastAgg"))
val parsedAgg = TermName(c.freshName("parsedAgg"))
val ((endSnippet, aggregateSnippet), minCut) = min match{
val ((endSnippet, _), minCut) = min match{
case None =>
q"""
$ctx1.freshSuccess($repeater1.result($acc), $startIndex, $originalCut)
Expand All @@ -47,22 +47,25 @@ object MacroRepImpls{
q"""$originalCut && ($count < $min1)"""
}

val wsSnippet = whitespace match{
case None => q"$rec($beforeSepIndex, $count + 1, $parsedAgg)"
case Some(ws) =>
q"""

@fastparse.internal.NoWarn.nowarn
val isNotNoWhitespace = $ws ne _root_.fastparse.NoWhitespace.noWhitespaceImplicit
if (isNotNoWhitespace) {
_root_.fastparse.internal.Util.consumeWhitespace($ws, $ctx1)
}
val rhsSnippet =
q"""
if (!$ctx1.isSuccess && $ctx1.cut) $ctx1.asInstanceOf[_root_.fastparse.ParsingRun[scala.Nothing]]
else{
else {
$ctx1.cut = false
$rec($beforeSepIndex, $count + 1, $parsedAgg)
}
"""
"""

val wsSnippet = whitespace match{
case None => q"$rec($beforeSepIndex, $count + 1, $parsedAgg)"
case Some(ws) =>
if (ws.tpe =:= typeOf[fastparse.NoWhitespace.noWhitespaceImplicit.type])
rhsSnippet
else
q"""
_root_.fastparse.internal.Util.consumeWhitespace($ws, $ctx1)
$rhsSnippet
"""
}

q"""
Expand Down
4 changes: 2 additions & 2 deletions fastparse/src-2/fastparse/package.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fastparse.internal._
import fastparse.internal.{Instrument, Logger}

import language.experimental.macros
import scala.language.experimental.macros
import scala.language.implicitConversions

package object fastparse extends fastparse.SharedPackageDefs {
/**
Expand Down
1 change: 1 addition & 0 deletions fastparse/src-3/fastparse/internal/NoWarn.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fastparse.internal

object NoWarn{
@deprecated("Use scala.annotation.nowarn instead", "3.1.1")
type nowarn = scala.annotation.nowarn
}
5 changes: 2 additions & 3 deletions fastparse/src/fastparse/Whitespace.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package fastparse

import fastparse._
import fastparse.internal.Util
import fastparse.internal.{Msgs, Util}

import scala.annotation.{Annotation, switch, tailrec}
import fastparse.internal.Msgs
import scala.annotation.{switch, tailrec}

trait Whitespace{
def apply(ctx: ParsingRun[_]): ParsingRun[Unit]
Expand Down
2 changes: 1 addition & 1 deletion fastparse/test/src-2.12+/fastparse/IteratorTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ object IteratorTests extends TestSuite {
}

test("whitespaceImmediateCutDrop"){
import NoWhitespace.{noWhitespaceImplicit => _, _}
import NoWhitespace.{noWhitespaceImplicit => _}
implicit val whitespace: Whitespace = { implicit ctx: P[_] =>
import NoWhitespace.noWhitespaceImplicit
" ".? ~ " ".rep
Expand Down
3 changes: 2 additions & 1 deletion fastparse/test/src/fastparse/ExampleTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ object ExampleTests extends TestSuite{
val tests = Tests{
test("basic"){
test("simple"){
import fastparse._, NoWhitespace._
import fastparse._
def parseA[$: P] = P("a")

val Parsed.Success(value, successIndex) = parse("a", parseA(_))
Expand Down Expand Up @@ -243,6 +243,7 @@ object ExampleTests extends TestSuite{
def even[$: P] = P( digits.filter(_ % 2 == 0) )
val Parsed.Success(12, _) = parse("12", even(_))
val failure = parse("123", even(_)).asInstanceOf[Parsed.Failure]
assert(!failure.isSuccess)
}
test("opaque"){
def digit[$: P] = CharIn("0-9")
Expand Down
1 change: 0 additions & 1 deletion fastparse/test/src/fastparse/IndentationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package test.fastparse

import utest._
import fastparse._
import fastparse.internal.Util

/**
* Same as MathTests, but demonstrating the use of whitespace
Expand Down
1 change: 0 additions & 1 deletion fastparse/test/src/fastparse/JsonTests.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

package test.fastparse

import fastparse._
import fastparse._
import utest._

Expand Down
3 changes: 1 addition & 2 deletions fastparse/test/src/fastparse/ParsingTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import utest._
object ParsingTests extends TestSuite{


import Parsed.{Success, Failure}
import Parsed.Success

def check[T](parser: P[_] => P[T], input: (String, Int), rhs: Parsed[T]) = {
val (str, index) = input
Expand Down Expand Up @@ -105,7 +105,6 @@ object ParsingTests extends TestSuite{
}
test("fail"){
import fastparse._
import NoWhitespace._
def fail1[T: P] = Fail.!
val wat = "Shouldn't success"
val Parsed.Failure(_, _, _) = parse(wat, fail1(_))
Expand Down
8 changes: 5 additions & 3 deletions fastparse/test/src/fastparse/TypeTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ package test.fastparse

import fastparse.Implicits

import scala.annotation.nowarn

/**
* Make sure the type-level logic does the right thing. Doesn't
* actually need to execute; compiling is enough!
*/
object TypeTests {
class P[T]{
def ~[V, R](other: P[V])(implicit sum: Implicits.Sequencer[T, V, R]): P[R] = new P[R]
def rep[R](implicit rep: Implicits.Repeater[T, R]): P[R] = new P[R]
def ?[R](implicit rep: Implicits.Optioner[T, R]): P[R] = new P[R]
def ~[V, R](other: P[V])(implicit @nowarn("msg=never used") sum: Implicits.Sequencer[T, V, R]): P[R] = new P[R]
def rep[R](implicit @nowarn("msg=never used") rep: Implicits.Repeater[T, R]): P[R] = new P[R]
def ?[R](implicit @nowarn("msg=never used") rep: Implicits.Optioner[T, R]): P[R] = new P[R]
}

def P[T] = new P[T]
Expand Down
2 changes: 1 addition & 1 deletion mill
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
set -e

if [ -z "${DEFAULT_MILL_VERSION}" ] ; then
DEFAULT_MILL_VERSION=0.11.1
DEFAULT_MILL_VERSION=0.11.7
fi

if [ -z "$MILL_VERSION" ] ; then
Expand Down
2 changes: 0 additions & 2 deletions pythonparse/test/src/pythonparse/RegressionTests.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package pythonparse
import utest._
import fastparse._

object RegressionTests extends TestSuite{
import Ast.expr._
import Ast.stmt._
import Ast.expr_context._
import Ast.cmpop._
import Ast.operator._
import Ast.unaryop._
import Ast._
Expand Down
2 changes: 1 addition & 1 deletion pythonparse/test/src/pythonparse/UnitTests.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package pythonparse

import utest._
import fastparse._

/**
* Tests to cover most basic syntactic constructs. It's likely there are
* interactions between the constructs that will cause problems, but these
Expand Down
10 changes: 4 additions & 6 deletions scalaparse/test/src-2-jvm/scalaparse/ProjectTests.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package scalaparse

import java.io.File
import java.nio.file.{Files, Path, Paths}



import java.nio.file.{Files, Paths}
import concurrent.ExecutionContext.Implicits.global
import utest._

import scala.annotation.nowarn
import scala.concurrent.duration.Duration
import scala.concurrent.{Await, Future}

Expand All @@ -16,7 +14,8 @@ object ProjectTests extends TestSuite{
println("running")
def tests = this{

def checkDir(path: String, filter: String => Boolean = _ => true) = {
@nowarn
def checkDir(path: String, filter: String => Boolean = _ => true): Unit = {
println("Checking Dir " + path)
def listFiles(s: File): Seq[String] = {
val (dirs, files) = Option(s.listFiles).getOrElse(Array[File]()).partition(_.isDirectory)
Expand Down Expand Up @@ -53,7 +52,6 @@ object ProjectTests extends TestSuite{

if (scala.util.Properties.javaVersion.startsWith("1.8")) {
val repo = "https://github.com/" + testPath.value.last
import sys.process._
val name = repo.split("/").last
println("CLONING?")
val path = Paths.get("out", "repos", name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object ScalacParser{
val global = new Global(settings)

def checkParseFails(input: String) = this.synchronized{
val run = new global.Run()
new global.Run()
var fail = false
import global.syntaxAnalyzer.Offset
val cu = new global.CompilationUnit(global.newSourceFile(input))
Expand Down
61 changes: 61 additions & 0 deletions scalaparse/test/src-2.13-jvm/scalaparse/ScalacParser.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package scalaparse
Copy link
Member

Choose a reason for hiding this comment

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

@He-Pin is this change intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, because the api in nsc is different in Scala 2.12 and newer version of scala 2.13.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I have to separate this test for Scala 2.12 and Scala 2.13, maybe I can split it into a dedicated PR. but as the commits is one by one, maybe that's fine too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

related link: scala/scala#10406


import scala.reflect.internal.util.CodeAction
import scala.tools.nsc.{Global, Settings}

object ScalacParser{
var current = Thread.currentThread().getContextClassLoader
val files = collection.mutable.Buffer.empty[java.io.File]
files.appendAll(
System.getProperty("sun.boot.class.path")
.split(":")
.map(new java.io.File(_))
)
while(current != null){
current match{
case t: java.net.URLClassLoader =>
files.appendAll(t.getURLs.map(u => new java.io.File(u.toURI)))
case _ =>
}
current = current.getParent
}

val settings = new Settings()
settings.usejavacp.value = true
settings.embeddedDefaults[ScalacParser.type]
settings.classpath.append(files.mkString(":"))

val global = new Global(settings)

def checkParseFails(input: String) = this.synchronized{
new global.Run()
var fail = false
import global.syntaxAnalyzer.Offset
val cu = new global.CompilationUnit(global.newSourceFile(input))
val parser = new global.syntaxAnalyzer.UnitParser(cu, Nil){
override def newScanner() = new global.syntaxAnalyzer.UnitScanner(cu, Nil){
override def error(off: Offset, msg: String) = {
fail = true
}
override def syntaxError(off: Offset, msg: String) = {
fail = true
}
override def incompleteInputError(off: Offset, msg: String) = {
fail = true
}
}

override def incompleteInputError(msg: String, actions: List[CodeAction]): Unit = {
fail = true
super.incompleteInputError(msg, actions)
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 new api has a actions

}

override def syntaxError(offset: global.syntaxAnalyzer.Offset, msg: String, actions: List[CodeAction]): Unit = {
fail = true
super.syntaxError(offset, msg, actions)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

so does syntaxError method. otherwise, it will report override nothing error.

}
}
parser.parse()
fail
}
}
Loading
Loading