Skip to content

Commit 3770ee8

Browse files
authored
Improve use of boolean defaults (#23564)
A couple of cases where recursing with default booleans was especially confusing. Spellcheck would like to change booleans to beanpoles. I know the project hates so-called style PRs. But if I see something morally wrong, I cannot but act upon it. I must confirm that inlined helper such as `jsig1` allows `tailrec`. Maybe it's enough to annotate jsig? Edit: I see goto 0 only. With tailrec, it complains about the RHS of the helper `inline def jsig1`, which is spurious.
1 parent a5c26cd commit 3770ee8

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ object GenericSignatures {
234234

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

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

248249
case defn.ArrayOf(elemtp) =>
249250
if (isGenericArrayElement(elemtp, isScala2 = false))
250-
jsig(defn.ObjectType)
251+
jsig1(defn.ObjectType)
251252
else
252253
builder.append(ClassfileConstants.ARRAY_TAG)
253254
elemtp match
254-
case TypeBounds(lo, hi) => jsig(hi.widenDealias)
255-
case _ => jsig(elemtp)
255+
case TypeBounds(lo, hi) => jsig1(hi.widenDealias)
256+
case _ => jsig1(elemtp)
256257

257258
case RefOrAppliedType(sym, pre, args) =>
258259
if (sym == defn.PairClass && tupleArity(tp) > Definitions.MaxTupleArity)
259-
jsig(defn.TupleXXLClass.typeRef)
260+
jsig1(defn.TupleXXLClass.typeRef)
260261
else if (isTypeParameterInSig(sym, sym0)) {
261262
assert(!sym.isAliasType || sym.info.isLambdaSub, "Unexpected alias type: " + sym)
262263
typeParamSig(sym.name.lastPart)
263264
}
264265
else if (defn.specialErasure.contains(sym))
265-
jsig(defn.specialErasure(sym).typeRef)
266+
jsig1(defn.specialErasure(sym).typeRef)
266267
else if (sym == defn.UnitClass || sym == defn.BoxedUnitModule)
267-
jsig(defn.BoxedUnitClass.typeRef)
268+
jsig1(defn.BoxedUnitClass.typeRef)
268269
else if (sym == defn.NothingClass)
269270
builder.append("Lscala/runtime/Nothing$;")
270271
else if (sym == defn.NullClass)
271272
builder.append("Lscala/runtime/Null$;")
272273
else if (sym.isPrimitiveValueClass)
273-
if (!unboxedVCs) jsig(defn.ObjectType)
274-
else if (sym == defn.UnitClass) jsig(defn.BoxedUnitClass.typeRef)
274+
if (!unboxedVCs) jsig1(defn.ObjectType)
275+
else if (sym == defn.UnitClass) jsig1(defn.BoxedUnitClass.typeRef)
275276
else builder.append(defn.typeTag(sym.info))
276277
else if (sym.isDerivedValueClass) {
277278
if (unboxedVCs) {
278279
val erasedUnderlying = fullErasure(tp)
279-
jsig(erasedUnderlying, toplevel)
280+
jsig(erasedUnderlying, toplevel = toplevel, unboxedVCs = true)
280281
} else classSig(sym, pre, args)
281282
}
282283
else if (defn.isSyntheticFunctionClass(sym)) {
@@ -286,20 +287,20 @@ object GenericSignatures {
286287
else if sym.isClass then
287288
classSig(sym, pre, args)
288289
else
289-
jsig(erasure(tp), toplevel, unboxedVCs)
290+
jsig(erasure(tp), toplevel = toplevel, unboxedVCs = unboxedVCs)
290291

291292
case ExprType(restpe) if toplevel =>
292293
builder.append("()")
293294
methodResultSig(restpe)
294295

295296
case ExprType(restpe) =>
296-
jsig(defn.FunctionType(0).appliedTo(restpe))
297+
jsig1(defn.FunctionType(0).appliedTo(restpe))
297298

298299
case mtd: MethodOrPoly =>
299300
val (tparams, vparams, rte) = collectMethodParams(mtd)
300301
if (toplevel && !sym0.isConstructor) polyParamSig(tparams)
301302
builder.append('(')
302-
for vparam <- vparams do jsig(vparam)
303+
for vparam <- vparams do jsig1(vparam)
303304
builder.append(')')
304305
methodResultSig(rte)
305306

@@ -316,7 +317,7 @@ object GenericSignatures {
316317
val (reprParents, _) = splitIntersection(parents)
317318
val repr =
318319
reprParents.find(_.typeSymbol.is(TypeParam)).getOrElse(reprParents.head)
319-
jsig(repr, unboxedVCs = unboxedVCs)
320+
jsig(repr, toplevel = false, unboxedVCs = unboxedVCs)
320321

321322
case ci: ClassInfo =>
322323
val tParams = tp.typeParams

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,8 @@ object SpaceEngine {
455455
val inArray = tycon.isRef(defn.ArrayClass) || tp.translucentSuperType.isRef(defn.ArrayClass)
456456
val args2 =
457457
if isTyped && !inArray then args.map(_ => WildcardType)
458-
else args.map(arg => erase(arg, inArray = inArray, isValue = false))
459-
tp.derivedAppliedType(erase(tycon, inArray, isValue = false), args2)
458+
else args.map(arg => erase(arg, inArray = inArray, isValue = false, isTyped = false))
459+
tp.derivedAppliedType(erase(tycon, inArray = inArray, isValue = false, isTyped = false), args2)
460460

461461
case tp @ OrType(tp1, tp2) =>
462462
OrType(erase(tp1, inArray, isValue, isTyped), erase(tp2, inArray, isValue, isTyped), tp.isSoft)

0 commit comments

Comments
 (0)