Skip to content

Improve use of boolean defaults #23564

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
29 changes: 15 additions & 14 deletions compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ object GenericSignatures {

@noinline
def jsig(tp0: Type, toplevel: Boolean = false, unboxedVCs: Boolean = true): Unit = {
inline def jsig1(tp0: Type): Unit = jsig(tp0, toplevel = false, unboxedVCs = true)

val tp = tp0.dealias
tp match {
Expand All @@ -242,41 +243,41 @@ object GenericSignatures {
val erasedUnderlying = fullErasure(ref.underlying.bounds.hi)
// don't emit type param name if the param is upper-bounded by a primitive type (including via a value class)
if erasedUnderlying.isPrimitiveValueType then
jsig(erasedUnderlying, toplevel, unboxedVCs)
jsig(erasedUnderlying, toplevel = toplevel, unboxedVCs = unboxedVCs)
else typeParamSig(ref.paramName.lastPart)

case defn.ArrayOf(elemtp) =>
if (isGenericArrayElement(elemtp, isScala2 = false))
jsig(defn.ObjectType)
jsig1(defn.ObjectType)
else
builder.append(ClassfileConstants.ARRAY_TAG)
elemtp match
case TypeBounds(lo, hi) => jsig(hi.widenDealias)
case _ => jsig(elemtp)
case TypeBounds(lo, hi) => jsig1(hi.widenDealias)
case _ => jsig1(elemtp)

case RefOrAppliedType(sym, pre, args) =>
if (sym == defn.PairClass && tupleArity(tp) > Definitions.MaxTupleArity)
jsig(defn.TupleXXLClass.typeRef)
jsig1(defn.TupleXXLClass.typeRef)
else if (isTypeParameterInSig(sym, sym0)) {
assert(!sym.isAliasType || sym.info.isLambdaSub, "Unexpected alias type: " + sym)
typeParamSig(sym.name.lastPart)
}
else if (defn.specialErasure.contains(sym))
jsig(defn.specialErasure(sym).typeRef)
jsig1(defn.specialErasure(sym).typeRef)
else if (sym == defn.UnitClass || sym == defn.BoxedUnitModule)
jsig(defn.BoxedUnitClass.typeRef)
jsig1(defn.BoxedUnitClass.typeRef)
else if (sym == defn.NothingClass)
builder.append("Lscala/runtime/Nothing$;")
else if (sym == defn.NullClass)
builder.append("Lscala/runtime/Null$;")
else if (sym.isPrimitiveValueClass)
if (!unboxedVCs) jsig(defn.ObjectType)
else if (sym == defn.UnitClass) jsig(defn.BoxedUnitClass.typeRef)
if (!unboxedVCs) jsig1(defn.ObjectType)
else if (sym == defn.UnitClass) jsig1(defn.BoxedUnitClass.typeRef)
else builder.append(defn.typeTag(sym.info))
else if (sym.isDerivedValueClass) {
if (unboxedVCs) {
val erasedUnderlying = fullErasure(tp)
jsig(erasedUnderlying, toplevel)
jsig(erasedUnderlying, toplevel = toplevel, unboxedVCs = true)
} else classSig(sym, pre, args)
}
else if (defn.isSyntheticFunctionClass(sym)) {
Expand All @@ -286,20 +287,20 @@ object GenericSignatures {
else if sym.isClass then
classSig(sym, pre, args)
else
jsig(erasure(tp), toplevel, unboxedVCs)
jsig(erasure(tp), toplevel = toplevel, unboxedVCs = unboxedVCs)

case ExprType(restpe) if toplevel =>
builder.append("()")
methodResultSig(restpe)

case ExprType(restpe) =>
jsig(defn.FunctionType(0).appliedTo(restpe))
jsig1(defn.FunctionType(0).appliedTo(restpe))

case mtd: MethodOrPoly =>
val (tparams, vparams, rte) = collectMethodParams(mtd)
if (toplevel && !sym0.isConstructor) polyParamSig(tparams)
builder.append('(')
for vparam <- vparams do jsig(vparam)
for vparam <- vparams do jsig1(vparam)
builder.append(')')
methodResultSig(rte)

Expand All @@ -316,7 +317,7 @@ object GenericSignatures {
val (reprParents, _) = splitIntersection(parents)
val repr =
reprParents.find(_.typeSymbol.is(TypeParam)).getOrElse(reprParents.head)
jsig(repr, unboxedVCs = unboxedVCs)
jsig(repr, toplevel = false, unboxedVCs = unboxedVCs)

case ci: ClassInfo =>
val tParams = tp.typeParams
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/patmat/Space.scala
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,8 @@ object SpaceEngine {
val inArray = tycon.isRef(defn.ArrayClass) || tp.translucentSuperType.isRef(defn.ArrayClass)
val args2 =
if isTyped && !inArray then args.map(_ => WildcardType)
else args.map(arg => erase(arg, inArray = inArray, isValue = false))
tp.derivedAppliedType(erase(tycon, inArray, isValue = false), args2)
else args.map(arg => erase(arg, inArray = inArray, isValue = false, isTyped = false))
tp.derivedAppliedType(erase(tycon, inArray = inArray, isValue = false, isTyped = false), args2)

case tp @ OrType(tp1, tp2) =>
OrType(erase(tp1, inArray, isValue, isTyped), erase(tp2, inArray, isValue, isTyped), tp.isSoft)
Expand Down
Loading