Skip to content

Commit 9907f02

Browse files
som-snytttgodzik
authored andcommitted
Improve use of boolean defaults (scala#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 609de0a commit 9907f02

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
@@ -233,6 +233,7 @@ object GenericSignatures {
233233

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

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

247248
case defn.ArrayOf(elemtp) =>
248249
if (isGenericArrayElement(elemtp, isScala2 = false))
249-
jsig(defn.ObjectType)
250+
jsig1(defn.ObjectType)
250251
else
251252
builder.append(ClassfileConstants.ARRAY_TAG)
252253
elemtp match
253-
case TypeBounds(lo, hi) => jsig(hi.widenDealias)
254-
case _ => jsig(elemtp)
254+
case TypeBounds(lo, hi) => jsig1(hi.widenDealias)
255+
case _ => jsig1(elemtp)
255256

256257
case RefOrAppliedType(sym, pre, args) =>
257258
if (sym == defn.PairClass && tupleArity(tp) > Definitions.MaxTupleArity)
258-
jsig(defn.TupleXXLClass.typeRef)
259+
jsig1(defn.TupleXXLClass.typeRef)
259260
else if (isTypeParameterInSig(sym, sym0)) {
260261
assert(!sym.isAliasType, "Unexpected alias type: " + sym)
261262
typeParamSig(sym.name.lastPart)
262263
}
263264
else if (defn.specialErasure.contains(sym))
264-
jsig(defn.specialErasure(sym).nn.typeRef)
265+
jsig1(defn.specialErasure(sym).nn.typeRef)
265266
else if (sym == defn.UnitClass || sym == defn.BoxedUnitModule)
266-
jsig(defn.BoxedUnitClass.typeRef)
267+
jsig1(defn.BoxedUnitClass.typeRef)
267268
else if (sym == defn.NothingClass)
268269
builder.append("Lscala/runtime/Nothing$;")
269270
else if (sym == defn.NullClass)
270271
builder.append("Lscala/runtime/Null$;")
271272
else if (sym.isPrimitiveValueClass)
272-
if (!unboxedVCs) jsig(defn.ObjectType)
273-
else if (sym == defn.UnitClass) jsig(defn.BoxedUnitClass.typeRef)
273+
if (!unboxedVCs) jsig1(defn.ObjectType)
274+
else if (sym == defn.UnitClass) jsig1(defn.BoxedUnitClass.typeRef)
274275
else builder.append(defn.typeTag(sym.info))
275276
else if (sym.isDerivedValueClass) {
276277
if (unboxedVCs) {
277278
val erasedUnderlying = fullErasure(tp)
278-
jsig(erasedUnderlying, toplevel)
279+
jsig(erasedUnderlying, toplevel = toplevel, unboxedVCs = true)
279280
} else classSig(sym, pre, args)
280281
}
281282
else if (defn.isSyntheticFunctionClass(sym)) {
@@ -285,14 +286,14 @@ object GenericSignatures {
285286
else if sym.isClass then
286287
classSig(sym, pre, args)
287288
else
288-
jsig(erasure(tp), toplevel, unboxedVCs)
289+
jsig(erasure(tp), toplevel = toplevel, unboxedVCs = unboxedVCs)
289290

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

294295
case ExprType(restpe) =>
295-
jsig(defn.FunctionType(0).appliedTo(restpe))
296+
jsig1(defn.FunctionType(0).appliedTo(restpe))
296297

297298
case PolyType(tparams, mtpe: MethodType) =>
298299
assert(tparams.nonEmpty)
@@ -320,7 +321,7 @@ object GenericSignatures {
320321
builder.append('(')
321322
// TODO: Update once we support varargs
322323
params.foreach { tp =>
323-
jsig(tp)
324+
jsig1(tp)
324325
}
325326
builder.append(')')
326327
methodResultSig(restpe)
@@ -338,7 +339,7 @@ object GenericSignatures {
338339
val (reprParents, _) = splitIntersection(parents)
339340
val repr =
340341
reprParents.find(_.typeSymbol.is(TypeParam)).getOrElse(reprParents.head)
341-
jsig(repr, unboxedVCs = unboxedVCs)
342+
jsig(repr, toplevel = false, unboxedVCs = unboxedVCs)
342343

343344
case ci: ClassInfo =>
344345
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
@@ -460,8 +460,8 @@ object SpaceEngine {
460460
val inArray = tycon.isRef(defn.ArrayClass) || tp.translucentSuperType.isRef(defn.ArrayClass)
461461
val args2 =
462462
if isTyped && !inArray then args.map(_ => WildcardType)
463-
else args.map(arg => erase(arg, inArray = inArray, isValue = false))
464-
tp.derivedAppliedType(erase(tycon, inArray, isValue = false), args2)
463+
else args.map(arg => erase(arg, inArray = inArray, isValue = false, isTyped = false))
464+
tp.derivedAppliedType(erase(tycon, inArray = inArray, isValue = false, isTyped = false), args2)
465465

466466
case tp @ OrType(tp1, tp2) =>
467467
OrType(erase(tp1, inArray, isValue), erase(tp2, inArray, isValue), tp.isSoft)

0 commit comments

Comments
 (0)