This commit is contained in:
eugene yokota 2026-07-19 10:56:56 +09:00 committed by GitHub
commit 750c57541a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 47 additions and 3 deletions

View File

@ -664,6 +664,10 @@ lazy val coreMacrosProj = (project in file("core-macros"))
name := "Core Macros",
SettingKey[Boolean]("exportPipelining") := false,
mimaSettings,
mimaBinaryIssueFilters ++= Seq(
exclude[ReversedMissingMethodProblem]("sbt.internal.util.appmacro.ContextUtil.*"),
exclude[DirectMissingMethodProblem]("sbt.internal.util.appmacro.ContextUtil#Input.*"),
),
)
// Fixes scope=Scope for Setting (core defined in collectionProj) to define the settings system used in build definitions

View File

@ -306,7 +306,7 @@ trait Cont:
.asExprOf[BuildWideCacheConfiguration]
inputs.foreach: input =>
if !input.isCacheInput then
if !Cont.transientAllowSet(input.sym.name) then
if !Cont.transientAllowSet(input.sym.name) && !input.isWarnSuppressed then
report.warning(
s"transient key ${input.sym.name} is excluded from the cache input"
)
@ -430,6 +430,7 @@ trait Cont:
val WrapOutputName = "wrapOutput_\u2603\u2603"
val WrapOutputDirectoryName = "wrapOutputDirectory_\u2603\u2603"
var nowarnQuals: Set[String] = Set.empty
// Called when transforming the tree to add an input.
// For `qual` of type F[A], and a `selection` qual.value.
val record = [a] =>
@ -470,12 +471,18 @@ trait Cont:
}.asTerm)
case None => oldTree
case _ =>
// todo cache opt-out attribute
inputBuf += Input(TypeRepr.of[a], qual, replacement, freshName("q"))
inputBuf += Input(
TypeRepr.of[a],
qual,
replacement,
freshName("q"),
isWarnSuppressed = nowarnQuals.contains(qual.show),
)
oldTree
}
val exprWithConfig =
cacheConfigExprOpt.map(config => '{ $config; $expr }).getOrElse(expr)
nowarnQuals = collectNowarnQuals(exprWithConfig.asTerm)
val body = transformWrappers(exprWithConfig.asTerm, record, Symbol.spliceOwner)
val r = inputBuf.toList match
case Nil => pure(body)

View File

@ -76,11 +76,13 @@ trait ContextUtil[C <: Quotes & scala.Singleton](val valStart: Int):
private val cacheLevelSym = Symbol.requiredClass("sbt.util.cacheLevel")
private val transientSym = Symbol.requiredClass("scala.transient")
private val nowarnAnnotSym = Symbol.requiredClass("scala.annotation.nowarn")
final class Input(
val tpe: TypeRepr,
val qual: Term,
val term: Term,
val name: String,
val isWarnSuppressed: Boolean,
):
override def toString: String =
s"Input($tpe, $qual, $term, $name, $tags)"
@ -194,6 +196,28 @@ trait ContextUtil[C <: Quotes & scala.Singleton](val valStart: Int):
def idTransform[F[_]]: TermTransform[F] = in => in
/** Collects `qual.show` for each `.value` call wrapped in `@nowarn`, e.g. `(state.value: @nowarn)`. */
def collectNowarnQuals(tree: Term): Set[String] =
val result = mutable.HashSet[String]()
@tailrec def extractQual(t: Term): Unit = t match
case Inlined(_, _, inner) => extractQual(inner)
case Typed(inner, _) => extractQual(inner)
case Apply(TypeApply(Select(_, _), _ :: Nil), qual :: Nil) => result += qual.show
case Apply(TypeApply(Ident(_), _ :: Nil), qual :: Nil) => result += qual.show
case _ => ()
object scanner extends TreeTraverser:
override def traverseTree(t: Tree)(owner: Symbol): Unit = t match
case Typed(inner, tpt) =>
tpt.tpe match
case AnnotatedType(_, annot) if annot.tpe.typeSymbol == nowarnAnnotSym =>
extractQual(inner)
case _ =>
super.traverseTree(t)(owner)
case _ => super.traverseTree(t)(owner)
end scanner
scanner.traverseTree(tree)(Symbol.spliceOwner)
result.toSet
def collectDefs(tree: Term, isWrapper: (String, TypeRepr, Term) => Boolean): Set[Symbol] =
val defs = mutable.HashSet[Symbol]()
object traverser extends TreeTraverser:

View File

@ -0,0 +1,7 @@
import scala.annotation.nowarn
lazy val check = taskKey[Unit]("")
check := {
val s = (state.value: @nowarn)
println("hi")
}

View File

@ -0,0 +1 @@
Compile / scalacOptions += "-Werror"

View File

@ -0,0 +1 @@
> about