Skip to content

Commit 7f57697

Browse files
committed
Rename Leak to Promote
Promote is more semantically correct than Leak: leaking means something bad, but promotion is neutral or positive. A warning may be reported if the promotion is unsafe.
1 parent c20d6e7 commit 7f57697

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,37 +187,37 @@ object Checking {
187187
implicit val state2: State = state.withVisited(eff)
188188

189189
eff match {
190-
case Leak(pot) =>
190+
case Promote(pot) =>
191191
pot match {
192192
case ThisRef(cls) =>
193193
assert(cls == state.thisClass, "unexpected potential " + pot.show)
194194

195195
theCtx.warning(
196-
"Leaking of this. Calling trace:\n" + state.trace,
196+
"Promote `this` to be initialized while it is not. Calling trace:\n" + state.trace,
197197
eff.source.sourcePos
198198
)
199199

200200
case _: Cold =>
201201
theCtx.warning(
202-
"Leaking of cold value " + eff.source.show +
202+
"Promoting the value " + eff.source.show + " to be initialized while it is under initialization" +
203203
". Calling trace:\n" + state.trace,
204204
eff.source.sourcePos
205205
)
206206

207207
case Warm(cls, outer) =>
208208
theCtx.warning(
209-
"Leaking of value under initialization: " + pot.source.show +
209+
"Promoting the value under initialization to be initialized: " + pot.source.show +
210210
". Calling trace:\n" + state.trace,
211211
eff.source.sourcePos
212212
)
213213

214214
case Fun(pots, effs) =>
215215
effs.foreach { check(_) }
216-
pots.foreach { pot => check(Leak(pot)(eff.source)) }
216+
pots.foreach { pot => check(Promote(pot)(eff.source)) }
217217

218218
case pot =>
219219
val pots = expand(pot)
220-
pots.foreach { pot => check(Leak(pot)(eff.source)) }
220+
pots.foreach { pot => check(Promote(pot)(eff.source)) }
221221
}
222222

223223
case FieldAccess(pot, field) =>
@@ -303,7 +303,7 @@ object Checking {
303303
// TODO: assertion might be false, due to SAM
304304
if (sym.name.toString == "apply") {
305305
effs.foreach { check(_) }
306-
pots.foreach { pot => check(Leak(pot)(eff.source)) }
306+
pots.foreach { pot => check(Promote(pot)(eff.source)) }
307307
}
308308
// curried, tupled, toString are harmless
309309

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ object Effects {
2626
}
2727

2828
/** An effect means that a value that's possibly under initialization
29-
* leaks from the initializing world to fully-initialized world.
29+
* is promoted from the initializing world to the fully-initialized world.
3030
*
3131
* Essentially, this effect enforces that the object pointed to by
3232
* `potential` is fully initialized.
@@ -36,7 +36,7 @@ object Effects {
3636
* - a potential is assigned (not initialize) to a field
3737
* - the selection chain on a potential is too long
3838
*/
39-
case class Leak(potential: Potential)(val source: Tree) extends Effect {
39+
case class Promote(potential: Potential)(val source: Tree) extends Effect {
4040
def size: Int = potential.size
4141
def show(implicit ctx: Context): String =
4242
potential.show + ""
@@ -61,8 +61,8 @@ object Effects {
6161

6262
def asSeenFrom(eff: Effect, thisValue: Potential, currentClass: ClassSymbol, outer: Potentials)(implicit env: Env): Effects =
6363
trace(eff.show + " asSeenFrom " + thisValue.show + ", current = " + currentClass.show + ", outer = " + Potentials.show(outer), init, effs => show(effs.asInstanceOf[Effects])) { eff match {
64-
case Leak(pot) =>
65-
Potentials.asSeenFrom(pot, thisValue, currentClass, outer).leak(eff.source)
64+
case Promote(pot) =>
65+
Potentials.asSeenFrom(pot, thisValue, currentClass, outer).promote(eff.source)
6666

6767
case FieldAccess(pot, field) =>
6868
Potentials.asSeenFrom(pot, thisValue, currentClass, outer).map { pot =>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ object Potentials {
150150
// max potential length
151151
// TODO: it can be specified on a project basis via compiler options
152152
if (pot.size > 2)
153-
(pots, effs + Leak(pot)(source))
153+
(pots, effs + Promote(pot)(source))
154154
else if (symbol.isConstructor)
155155
(pots + pot, effs + MethodCall(pot, symbol)(source))
156156
else if (symbol.isOneOf(Flags.Method | Flags.Lazy))
@@ -162,7 +162,7 @@ object Potentials {
162162
(pots + FieldReturn(pot, symbol)(source), effs + FieldAccess(pot, symbol)(source))
163163
}
164164

165-
def (ps: Potentials) leak(source: Tree): Effects = ps.map(Leak(_)(source))
165+
def (ps: Potentials) promote(source: Tree): Effects = ps.map(Promote(_)(source))
166166

167167
def asSeenFrom(pot: Potential, thisValue: Potential, currentClass: ClassSymbol, outer: Potentials)(implicit env: Env): Potentials =
168168
trace(pot.show + " asSeenFrom " + thisValue.show + ", current = " + currentClass.show + ", outer = " + show(outer), init, pots => show(pots.asInstanceOf[Potentials])) { pot match {

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ object Summarization {
7070
val res = args.foldLeft(summary) { (sum, arg) =>
7171
val (pots1, effs1) = analyze(arg)
7272
if (ignoredCall) sum.withEffs(effs1)
73-
else sum.withEffs(pots1.leak(arg) ++ effs1)
73+
else sum.withEffs(pots1.promote(arg) ++ effs1)
7474
}
7575

7676
if (ignoredCall) (Potentials.empty, res._2)
@@ -114,7 +114,7 @@ object Summarization {
114114

115115
case Assign(lhs, rhs) =>
116116
val (pots, effs) = analyze(rhs)
117-
(Potentials.empty, pots.leak(expr) ++ effs)
117+
(Potentials.empty, pots.promote(expr) ++ effs)
118118

119119
case closureDef(ddef) => // must be before `Block`
120120
val (pots, effs) = analyze(ddef.rhs)
@@ -138,7 +138,7 @@ object Summarization {
138138
case Match(selector, cases) =>
139139
// possible for switches
140140
val (pots, effs) = analyze(selector)
141-
cases.foldLeft((Potentials.empty, pots.leak(selector) ++ effs)) { (acc, cas) =>
141+
cases.foldLeft((Potentials.empty, pots.promote(selector) ++ effs)) { (acc, cas) =>
142142
acc union analyze(cas.body)
143143
}
144144

@@ -170,7 +170,7 @@ object Summarization {
170170
case SeqLiteral(elems, elemtpt) =>
171171
val effsAll: Effects = elems.foldLeft(Effects.empty) { (effs, elem) =>
172172
val (pots1, effs1) = analyze(elem)
173-
pots1.leak(expr) ++ effs1 ++ effs
173+
pots1.promote(expr) ++ effs1 ++ effs
174174
}
175175
(Potentials.empty, effsAll)
176176

@@ -184,7 +184,7 @@ object Summarization {
184184
if (vdef.symbol.owner.isClass)
185185
(Potentials.empty, if (vdef.symbol.is(Flags.Lazy)) Effects.empty else effs)
186186
else
187-
(Potentials.empty, pots.leak(vdef) ++ effs)
187+
(Potentials.empty, pots.promote(vdef) ++ effs)
188188

189189
case Thicket(List()) =>
190190
// possible in try/catch/finally, see tests/crash/i6914.scala
@@ -194,7 +194,7 @@ object Summarization {
194194
val (pots, effs) = analyze(ddef.rhs)
195195

196196
if (ddef.symbol.owner.isClass) Summary.empty
197-
else (Potentials.empty, pots.leak(ddef) ++ effs)
197+
else (Potentials.empty, pots.promote(ddef) ++ effs)
198198

199199
case _: TypeDef =>
200200
Summary.empty

docs/docs/reference/other-new-features/safe-initialization.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ Potentials (π) represent values that are possibly under initialization.
266266

267267
Effects are triggered from potentials:
268268

269-
- `π↑`: leak of the potential `π`
269+
- `π↑`: promote the object pointed to by the potential `π` to fully-initialized
270270
- `π.f!`: access field `f` on the potential `π`
271271
- `π.m!`: call the method `m` on the potential `π`
272272

0 commit comments

Comments
 (0)