Skip to content

Commit da1b028

Browse files
committed
Reword error messages to be more user friendly.
1 parent f445807 commit da1b028

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

compiler/src/dotty/tools/dotc/transform/init/Errors.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ object Errors:
4747

4848
case class AccessCold(field: Symbol)(val trace: Trace) extends Error:
4949
def show(using Context): String =
50-
"Access field " + field.show + " on a cold object." + stacktrace
50+
"Access field " + field.show + " on an uninitialized (Cold) object." + stacktrace
5151

5252
case class CallCold(meth: Symbol)(val trace: Trace) extends Error:
5353
def show(using Context): String =
54-
"Call method " + meth.show + " on a cold object." + stacktrace
54+
"Call method " + meth.show + " on an uninitialized (Cold) object." + stacktrace
5555

5656
case class CallUnknown(meth: Symbol)(val trace: Trace) extends Error:
5757
def show(using Context): String =
@@ -62,7 +62,7 @@ object Errors:
6262
case class UnsafePromotion(msg: String, error: Error)(val trace: Trace) extends Error:
6363
def show(using Context): String =
6464
msg + stacktrace + "\n" +
65-
"Promoting the value to hot (transitively initialized) failed due to the following problem:\n" + {
65+
"Promoting the value to transitively initialized (Hot) failed due to the following problem:\n" + {
6666
val ctx2 = ctx.withProperty(IsFromPromotion, Some(true))
6767
error.show(using ctx2)
6868
}
@@ -96,5 +96,5 @@ object Errors:
9696
acc + text2
9797
}
9898
val verb = if multiple then " are " else " is "
99-
val adjective = "not hot (transitively initialized)."
99+
val adjective = "not transitively initialized (Hot)."
100100
subject + verb + adjective

compiler/src/dotty/tools/dotc/transform/init/Semantic.scala

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,18 @@ object Semantic:
6464
sealed abstract class Value:
6565
def show(using Context): String = this match
6666
case ThisRef(klass) =>
67-
"ThisRef[" + klass.show + "]"
67+
"the original object of type " + klass.show + " that started this trace"
6868
case Warm(klass, outer, ctor, args) =>
6969
val argsText = if args.nonEmpty then ", args = " + args.map(_.show).mkString("(", ", ", ")") else ""
70-
"Warm[" + klass.show + "] { outer = " + outer.show + argsText + " }"
70+
"an initialized (Warm) object of type " + klass.show + "{ outer = " + outer.show + argsText + " }"
7171
case Fun(expr, thisV, klass) =>
72-
"Fun { this = " + thisV.show + ", owner = " + klass.show + " }"
72+
"a function { this = " + thisV.show + ", owner = " + klass.show + " }"
7373
case RefSet(values) =>
7474
values.map(_.show).mkString("Set { ", ", ", " }")
75-
case _ =>
76-
this.toString()
75+
case Hot =>
76+
"a transitively initialized (Hot) object"
77+
case Cold =>
78+
"an uninitialized (Cold) object"
7779

7880
def isHot = this == Hot
7981
def isCold = this == Cold
@@ -470,7 +472,7 @@ object Semantic:
470472
def widenArg: Contextual[Value] =
471473
a match
472474
case _: Ref | _: Fun =>
473-
val hasError = Reporter.hasErrors { a.promote("Argument cannot be promoted to hot") }
475+
val hasError = Reporter.hasErrors { a.promote("Argument cannot be promoted to transitively initialized (Hot)") }
474476
if hasError then Cold else Hot
475477

476478
case RefSet(refs) =>
@@ -707,7 +709,9 @@ object Semantic:
707709
// no source code available
708710
promoteArgs()
709711
// try promoting the receiver as last resort
710-
val hasErrors = Reporter.hasErrors { ref.promote("try promote value to hot") }
712+
val hasErrors = Reporter.hasErrors {
713+
ref.promote(ref.show + " has no source code and could not be proven to be transitively initialized (Hot).")
714+
}
711715
if hasErrors then
712716
val error = CallUnknown(target)(trace)
713717
reporter.report(error)
@@ -992,7 +996,7 @@ object Semantic:
992996
eval(body, thisV, klass)
993997
}
994998
given Trace = Trace.empty.add(body)
995-
res.promote("The function return value is not hot. Found = " + res.show + ".")
999+
res.promote("Only transitively initialized (Hot) values can be returned by functions. The function " + fun.show + " returned " + res.show + ".")
9961000
}
9971001
if errors.nonEmpty then
9981002
reporter.report(UnsafePromotion(msg, errors.head)(trace))
@@ -1036,7 +1040,7 @@ object Semantic:
10361040
//
10371041
// This invariant holds because of the Scala/Java/JVM restriction that we cannot use `this` in super constructor calls.
10381042
if subClassSegmentHot && !isHotSegment then
1039-
report.error("[Internal error] Expect current segment to hot in promotion, current klass = " + klass.show +
1043+
report.error("[Internal error] Expect current segment to be transitively initialized (hot) in promotion, current klass = " + klass.show +
10401044
", subclass = " + subClass.show + Trace.show, Trace.position)
10411045

10421046
// If the outer and parameters of a class are all hot, then accessing fields and methods of the current
@@ -1053,12 +1057,12 @@ object Semantic:
10531057
val args = member.info.paramInfoss.flatten.map(_ => new ArgInfo(Hot: Value, Trace.empty))
10541058
val res = warm.call(member, args, receiver = warm.klass.typeRef, superType = NoType)
10551059
withTrace(trace.add(member.defTree)) {
1056-
res.promote("Cannot prove that the return value of " + member.show + " is hot. Found = " + res.show + ".")
1060+
res.promote("Could not verify that the return value of " + member.show + " is transitively initialized (Hot). It was found to be " + res.show + ".")
10571061
}
10581062
else
10591063
val res = warm.select(member, receiver = warm.klass.typeRef)
10601064
withTrace(trace.add(member.defTree)) {
1061-
res.promote("Cannot prove that the field " + member.show + " is hot. Found = " + res.show + ".")
1065+
res.promote("Could not verify that the field " + member.show + " is transitively initialized (Hot). It was found to be " + res.show + ".")
10621066
}
10631067
end for
10641068

@@ -1144,7 +1148,7 @@ object Semantic:
11441148

11451149
extension (arg: ArgInfo)
11461150
def promote: Contextual[Unit] = withTrace(arg.trace) {
1147-
arg.value.promote("Cannot prove the method argument is hot. Only hot values are safe to leak.\nFound = " + arg.value.show + ".")
1151+
arg.value.promote("Could not verify that the method argument is transitively initialized (Hot). It was found to be " + arg.value.show + ". Only transitively initialized arguments may be passed to methods outside the analyzed initialization region.")
11481152
}
11491153

11501154
/** Evaluate an expression with the given value for `this` in a given class `klass`
@@ -1285,12 +1289,12 @@ object Semantic:
12851289
eval(qual, thisV, klass)
12861290
val res = eval(rhs, thisV, klass)
12871291
extendTrace(expr) {
1288-
res.ensureHot("The RHS of reassignment must be hot. Found = " + res.show + ". ")
1292+
res.ensureHot("The RHS of reassignment must be transitively initialized (Hot). It was found to be " + res.show + ". ")
12891293
}
12901294
case id: Ident =>
12911295
val res = eval(rhs, thisV, klass)
12921296
extendTrace(expr) {
1293-
res.ensureHot("The RHS of reassignment must be hot. Found = " + res.show + ". ")
1297+
res.ensureHot("The RHS of reassignment must be transitively initialized (Hot). It was found to be " + res.show + ". ")
12941298
}
12951299

12961300
case closureDef(ddef) =>
@@ -1313,14 +1317,14 @@ object Semantic:
13131317
case Match(selector, cases) =>
13141318
val res = eval(selector, thisV, klass)
13151319
extendTrace(selector) {
1316-
res.ensureHot("The value to be matched needs to be hot. Found = " + res.show + ". ")
1320+
res.ensureHot("The value to be matched needs to be transitively initialized (Hot). It was found to be " + res.show + ". ")
13171321
}
13181322
eval(cases.map(_.body), thisV, klass).join
13191323

13201324
case Return(expr, from) =>
13211325
val res = eval(expr, thisV, klass)
13221326
extendTrace(expr) {
1323-
res.ensureHot("return expression must be hot. Found = " + res.show + ". ")
1327+
res.ensureHot("return expression must be transitively initialized (Hot). It was found to be " + res.show + ". ")
13241328
}
13251329

13261330
case WhileDo(cond, body) =>

0 commit comments

Comments
 (0)