Skip to content

Commit

Permalink
Merge pull request #1515 from eed3si9n/wip/merge-1.10.x
Browse files Browse the repository at this point in the history
[2.x] Merge 1.x
  • Loading branch information
eed3si9n authored Dec 16, 2024
2 parents 02abfbb + a8992c6 commit 4984165
Show file tree
Hide file tree
Showing 113 changed files with 536 additions and 237 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ jobs:
if: ${{ matrix.jobtype == 3 }}
shell: bash
run: |
sbt -v -Dfile.encoding=UTF-8 scalafmtCheckAll scalafmtSbtCheck
sbt -v -Dfile.encoding=UTF-8 scalafmtCheckAll scalafmtSbtCheck headerCheck "Test/headerCheck" generateContrabands
git diff --exit-code
- name: Benchmark (Scalac) (4)
if: ${{ matrix.jobtype == 4 }}
shell: bash
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/cla.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ jobs:
AUTHOR: ${{ github.event.pull_request.user.login }}
run: |
echo "Pull request submitted by $AUTHOR";
signed=$(curl -s "https://www.lightbend.com/contribute/cla/scala/check/$AUTHOR" | jq -r ".signed");
signed=$(curl -s "https://contribute.akka.io/contribute/cla/scala/check/$AUTHOR" | jq -r ".signed");
if [ "$signed" = "true" ] ; then
echo "CLA check for $AUTHOR successful";
else
echo "CLA check for $AUTHOR failed";
echo "Please sign the Scala CLA to contribute to the Scala compiler.";
echo "Go to https://www.lightbend.com/contribute/cla/scala and then";
echo "Go to https://contribute.akka.io/contribute/cla/scala and then";
echo "comment on the pull request to ask for a new check.";
echo "";
echo "Check if CLA is signed: https://www.lightbend.com/contribute/cla/scala/check/$AUTHOR";
echo "Check if CLA is signed: https://contribute.akka.io/contribute/cla/scala/check/$AUTHOR";
exit 1;
fi;
10 changes: 5 additions & 5 deletions .scala-steward.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# either. hopefully this is a reasonable compromise value?
pullRequests.frequency = "14 days"

updates.ignore = [
# as per discussion on sbt/zinc#1236, this is
# "if it ain't broke don't fix it" territory
{ groupId = "com.google.protobuf" },
{ groupId = "org.eclipse.jgit" }
updates.pin = [
{ groupId = "com.google.protobuf", artifactId = "protobuf-java", version="3." },
{ groupId = "com.google.protobuf", artifactId = "protoc", version="3." },
# jgit 7 requires Java 17+
{ groupId = "org.eclipse.jgit", artifactId = "org.eclipse.jgit", version="6." }
]
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
* Zinc - The incremental compiler for Scala.
* Copyright Scala Center, Lightbend, and Mark Harrah
*
* Licensed under Apache License 2.0
* SPDX-License-Identifier: Apache-2.0
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*/

package scala.reflect

import scala.tools.nsc.Global
Expand Down
26 changes: 25 additions & 1 deletion internal/compiler-bridge/src/main/scala/xsbt/Dependency.scala
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,27 @@ final class Dependency(val global: CallbackGlobal) extends LocateClassFile with
* but when it does we must ensure the incremental compiler tries its best no to lose
* any dependency. Therefore, we do a last-time effort to get the origin of the symbol
* by inspecting the classpath manually.
*
* UPDATE: This can also happen without compiler bugs if the symbol is simply uninitialized.
* Example, `class Client { def foo = Server.foo }`. When compiling client, the type `Foo` returned
* by `Server.foo` does not need to be initialized as we do not select from it or check its
* conformance to another type.
*
* Initializing `targetSymbol` before calling `assosicatedFile` would work but is problematic
* see zinc/zinc#949
*
* Perhaps consider this?
* val file = targetSymbol.associatedFile match {
* case NoAbstractFile => sym.rawInfo match {
* case cfl: global.loaders.ClassfileLoader =>
* val f = cfl.associatedFile(sym) // Gets the file from the loader
* if (f.exists) f else NoAbstractFile
* case f => f
* }
* }
*
* Or the status quo might just be perfectly fine -- if compilation doesn't need to force `Foo`,
* then there isn't a real dependency.
*/
val fqn = fullName(targetSymbol, '.', targetSymbol.moduleSuffix, false)
global.findAssociatedFile(fqn) match {
Expand Down Expand Up @@ -291,9 +312,12 @@ final class Dependency(val global: CallbackGlobal) extends LocateClassFile with
assert(fromClass.isClass, Feedback.expectedClassSymbol(fromClass))
val depClass = enclOrModuleClass(dep)
val dependency = ClassDependency(fromClass, depClass)
// An anonymous class be the enclosing class of an existential type symbol inferred from refinements,
// prior to https://github.com/scala/scala/pull/10940. Allowing this here leads to a dependency on class name
// that does not exist. Guard against it here to avoid the issue with legacy compiler versions.
if (
!cache.contains(dependency) &&
!depClass.isRefinementClass
!depClass.isAnonOrRefinementClass
) {
process(dependency)
cache.add(dependency)
Expand Down
5 changes: 3 additions & 2 deletions internal/compiler-bridge/src/main/scala/xsbt/ExtractAPI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import xsbti.api._
import scala.annotation.tailrec
import scala.tools.nsc.Global
import scala.PartialFunction.cond
import ExtractAPI.ConstructorWithDefaultArgument

/**
* Extracts full (including private members) API representation out of Symbols and Types.
Expand Down Expand Up @@ -836,9 +837,8 @@ class ExtractAPI[GlobalType <: Global](
constructorNameAsString(s.enclClass)
else {
val decoded = name.decode
val constructorWithDefaultArgument = "<init>\\$default\\$(\\d+)".r
decoded match {
case constructorWithDefaultArgument(index) => constructorNameAsString(s.enclClass, index)
case ConstructorWithDefaultArgument(index) => constructorNameAsString(s.enclClass, index)
case _ => decoded
}
}
Expand Down Expand Up @@ -866,4 +866,5 @@ class ExtractAPI[GlobalType <: Global](

object ExtractAPI {
private val emptyAnnotationArray = new Array[xsbti.api.Annotation](0)
private val ConstructorWithDefaultArgument = "<init>\\$default\\$(\\d+)".r
}
11 changes: 11 additions & 0 deletions internal/compiler-bridge/src/main/scala/xsbt/trace.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
* Zinc - The incremental compiler for Scala.
* Copyright Scala Center, Lightbend, and Mark Harrah
*
* Licensed under Apache License 2.0
* SPDX-License-Identifier: Apache-2.0
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*/

package xsbt

object trace extends TraceSyntax {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
* Zinc - The incremental compiler for Scala.
* Copyright Lightbend, Inc. and Mark Harrah
* Copyright Scala Center, Lightbend, and Mark Harrah
*
* Licensed under Apache License 2.0
* (http://www.apache.org/licenses/LICENSE-2.0).
* SPDX-License-Identifier: Apache-2.0
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
* Zinc - The incremental compiler for Scala.
* Copyright Lightbend, Inc. and Mark Harrah
* Copyright Scala Center, Lightbend, and Mark Harrah
*
* Licensed under Apache License 2.0
* (http://www.apache.org/licenses/LICENSE-2.0).
* SPDX-License-Identifier: Apache-2.0
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

/**
* Implement a Scala `lazy val` in Java for the facing sbt interface.
*
* <p>
* It holds a reference to a thunk that is lazily evaluated and then
* its reference is clear to avoid memory leaks in memory-intensive code.
* It needs to be defined in [[xsbti]] or a subpackage, see [[xsbti.api.Lazy]]
Expand All @@ -34,12 +34,7 @@ public static <T> xsbti.api.Lazy<T> apply(Supplier<T> sbtThunk) {
/** Return a sbt [[xsbti.api.Lazy]] from a strict value. */
public static <T> xsbti.api.Lazy<T> strict(T value) {
// Convert strict parameter to sbt function returning it
return apply(new Supplier<T>() {
@Override
public T get() {
return value;
}
});
return new StrictImpl<T>(value);
}

private static final class Thunky<T> {
Expand Down Expand Up @@ -68,4 +63,10 @@ public T get() {
return t.result;
}
}

private static final class StrictImpl<T> extends xsbti.api.AbstractLazy<T> {
private final T value;
StrictImpl(T value) { this.value = value; }
public T get() { return value; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ static AnalysisStore sync(AnalysisStore analysisStore) {
*/
void set(AnalysisContents analysisContents);

/**
* Resets in memory cached {@link AnalysisContents}
*/
default void clearCache() {}

final class CachedAnalysisStore implements AnalysisStore {
private AnalysisStore underlying;
private Optional<AnalysisContents> lastStore = Optional.empty();
Expand All @@ -121,6 +126,10 @@ public void set(AnalysisContents analysisContents) {
underlying.set(analysisContents);
lastStore = Optional.of(analysisContents);
}

public void clearCache() {
lastStore = Optional.empty();
}
}

final class SyncedAnalysisStore implements AnalysisStore {
Expand All @@ -141,5 +150,11 @@ public void set(AnalysisContents analysisContents) {
underlying.set(analysisContents);
}
}

public void clearCache() {
if (underlying instanceof CachedAnalysisStore) {
underlying.clearCache();
}
}
}
}
46 changes: 33 additions & 13 deletions internal/zinc-apiinfo/src/main/scala/xsbt/api/APIUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ object APIUtil {
def minimizeDefinition(d: Definition): Array[Definition] =
d match {
case c: ClassLike => Array(minimizeClass(c))
case _ => Array()
case _ => emptyDefs
}
def minimizeClass(c: ClassLike): ClassLike = {
val savedAnnotations = Discovery.defAnnotations(c.structure, (_: Any) => true).toArray[String]
Expand All @@ -73,7 +73,7 @@ object APIUtil {
c.modifiers,
c.annotations,
c.definitionType,
lzy(emptyType),
emptyTypeLzy,
lzy(struct),
savedAnnotations,
c.childrenOfSealedClass,
Expand All @@ -91,8 +91,10 @@ object APIUtil {
def filterDefinitions(
ds: Array[ClassDefinition],
isModule: Boolean
): Lazy[Array[ClassDefinition]] =
lzy(if (isModule) ds filter Discovery.isMainMethod else Array())
): Lazy[Array[ClassDefinition]] = {
val mains = if (isModule) ds.filter(Discovery.isMainMethod) else emptyClassDefs
if (mains.isEmpty) emptyClassDefsLzy else lzy(mains)
}

def isNonPrivate(d: Definition): Boolean = isNonPrivate(d.access)

Expand All @@ -104,23 +106,41 @@ object APIUtil {
}
private val emptyModifiers =
new Modifiers(false, false, false, false, false, false, false, false)
private val emptyStructure = Structure.of(lzy(Array.empty), lzy(Array.empty), lzy(Array.empty))
def emptyClassLike(name: String, definitionType: DefinitionType): ClassLike =
xsbti.api.ClassLike.of(
name,
private[this] val emptyType = EmptyType.of()
private val emptyTypeLzy = lzy(emptyType: Type)
private val emptyDefs = Array.empty[Definition]
private val emptyClassDefs = Array.empty[ClassDefinition]
private val emptyClassDefsLzy = lzy(emptyClassDefs)
private val emptyStructure = Structure.of(lzy(Array.empty), emptyClassDefsLzy, emptyClassDefsLzy)
private val emptyStructureLzy = lzy(emptyStructure)
private val emptyClassLikeTemplate =
ClassLike.of(
null,
Public.of(),
emptyModifiers,
Array.empty,
definitionType,
lzy(emptyType),
lzy(emptyStructure),
null,
emptyTypeLzy,
emptyStructureLzy,
Array.empty,
Array.empty,
true,
Array.empty
)
def emptyClassLike(name: String, definitionType: DefinitionType): ClassLike =
ClassLike.of(
name,
emptyClassLikeTemplate.access,
emptyClassLikeTemplate.modifiers,
emptyClassLikeTemplate.annotations,
definitionType,
emptyTypeLzy,
emptyStructureLzy,
emptyClassLikeTemplate.savedAnnotations,
emptyClassLikeTemplate.childrenOfSealedClass,
emptyClassLikeTemplate.topLevel,
emptyClassLikeTemplate.typeParameters,
)

private[this] def lzy[T <: AnyRef](t: T): Lazy[T] = SafeLazyProxy.strict(t)

private[this] val emptyType = EmptyType.of()
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import java.util.function.Supplier

/**
* Proxy `SafeLazy` functionality from the Java implementation
* implementation in xsbt.api.SafeLazy to Scala helpers.
* in xsbt.api.SafeLazy to Scala helpers.
*
* The implementation of these helpers are not reused between each
* other because they create intermediate anonymous functions and
Expand All @@ -35,7 +35,6 @@ object SafeLazyProxy {
* Return a lazy implementation of a strict value.
*/
def strict[T](s: T): Lazy[T] = {
val sbtThunk = new Supplier[T] { override def get() = s }
SafeLazy.apply(sbtThunk)
SafeLazy.strict(s)
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
* Zinc - The incremental compiler for Scala.
* Copyright Lightbend, Inc. and Mark Harrah
* Copyright Scala Center, Lightbend, and Mark Harrah
*
* Licensed under Apache License 2.0
* (http://www.apache.org/licenses/LICENSE-2.0).
* SPDX-License-Identifier: Apache-2.0
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
* Zinc - The incremental compiler for Scala.
* Copyright Lightbend, Inc. and Mark Harrah
* Copyright Scala Center, Lightbend, and Mark Harrah
*
* Licensed under Apache License 2.0
* (http://www.apache.org/licenses/LICENSE-2.0).
* SPDX-License-Identifier: Apache-2.0
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
* Zinc - The incremental compiler for Scala.
* Copyright Lightbend, Inc. and Mark Harrah
* Copyright Scala Center, Lightbend, and Mark Harrah
*
* Licensed under Apache License 2.0
* (http://www.apache.org/licenses/LICENSE-2.0).
* SPDX-License-Identifier: Apache-2.0
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
* Zinc - The incremental compiler for Scala.
* Copyright Lightbend, Inc. and Mark Harrah
* Copyright Scala Center, Lightbend, and Mark Harrah
*
* Licensed under Apache License 2.0
* (http://www.apache.org/licenses/LICENSE-2.0).
* SPDX-License-Identifier: Apache-2.0
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
* Zinc - The incremental compiler for Scala.
* Copyright Lightbend, Inc. and Mark Harrah
* Copyright Scala Center, Lightbend, and Mark Harrah
*
* Licensed under Apache License 2.0
* (http://www.apache.org/licenses/LICENSE-2.0).
* SPDX-License-Identifier: Apache-2.0
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
Expand Down
Loading

0 comments on commit 4984165

Please sign in to comment.