Skip to content

Support leak non-hot values to constructors #12711

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

Merged
merged 36 commits into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8cdb1ed
Add definition
liufengyun Jun 3, 2021
a431955
Add doc for env
liufengyun Jun 3, 2021
2a47d89
Fix compilation
liufengyun Jun 3, 2021
5a82985
Refactor trace
liufengyun Jun 4, 2021
08f040c
Support Value.source for friendly error message
liufengyun Jun 4, 2021
632b7d3
Disallow non-hot arguments to non-constructors
liufengyun Jun 4, 2021
0faa404
Handle access of parameters in constructors
liufengyun Jun 4, 2021
0af900a
Handle exception
liufengyun Jun 4, 2021
f00b0c9
No exceptions
liufengyun Jun 4, 2021
746373b
Fix Env.isHot
liufengyun Jun 4, 2021
748edc1
Add missing checks for arguments
liufengyun Jun 4, 2021
bfaef00
Handle new expression with only cold args
liufengyun Jun 4, 2021
c5475b4
Fix soundness test
liufengyun Jun 4, 2021
1e98f5c
Reorganize tests
liufengyun Jun 4, 2021
11d4325
Add test
liufengyun Jun 4, 2021
74fa3a3
Add test for secondary constructor
liufengyun Jun 4, 2021
c965315
Refactor promotion
liufengyun Jun 4, 2021
629f57c
Add test
liufengyun Jun 4, 2021
6edc40a
More logging
liufengyun Jun 4, 2021
9842479
Fix bug with promotion of this
liufengyun Jun 4, 2021
436609e
Refactor code: introduce ArgInfo instead of Value.source
liufengyun Jun 4, 2021
3ce2532
Handle O.this outside of it's definition
liufengyun Jun 4, 2021
2804eec
Fix owner of values with static flag
liufengyun Jun 4, 2021
a6d96ef
Add documentation about caching
liufengyun Jun 4, 2021
bc0cce3
Add test
liufengyun Jun 4, 2021
c033c9e
Add another neg test for promotion of ThisRef
liufengyun Jun 4, 2021
218f56b
Handle outers of trait as the same in concrete semantics
liufengyun Jun 4, 2021
a4b504a
Address review (thanks @michelou)
liufengyun Jun 5, 2021
03f0cde
Rename isFullyInitialized to isFullyFilled to avoid confusion
liufengyun Jun 5, 2021
0214051
Restrict function arguments to be hot
liufengyun Jun 5, 2021
29cc844
Add documentation
liufengyun Jun 5, 2021
cea9f26
Address review
liufengyun Jun 7, 2021
ec1de2f
Simplify logic for checking local classes inside secondary constructors
liufengyun Jun 7, 2021
d9892f9
Address review: simplify logic
liufengyun Jun 8, 2021
ae566b4
Abstract parameters of non-local constructor parameters as cold
liufengyun Jun 8, 2021
7fde75e
Update docs
liufengyun Jun 9, 2021
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
9 changes: 6 additions & 3 deletions compiler/src/dotty/tools/dotc/transform/init/Checker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ class Checker extends MiniPhase {
if (instantiable && cls.enclosingPackageClass != defn.StdLibPatchesPackage.moduleClass) {
import semantic._
val tpl = tree.rhs.asInstanceOf[Template]
val thisRef = ThisRef(cls)
val obj = Objekt(cls, fields = mutable.Map.empty, outers = mutable.Map(cls -> Hot))
val thisRef = ThisRef(cls).ensureExists

val paramValues = tpl.constr.termParamss.flatten.map(param => param.symbol -> Hot).toMap

given Promoted = Promoted.empty
given Trace = Trace.empty
heap.update(thisRef, obj)
given Env = Env(paramValues)

val res = eval(tpl, thisRef, cls)
res.errors.foreach(_.issue)
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/init/Errors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ object Errors {

/** Promote `this` under initialization to fully-initialized */
case class PromoteError(msg: String, source: Tree, trace: Seq[Tree]) extends Error {
def show(using Context): String = "Promote the value under initialization to fully-initialized. " + msg
def show(using Context): String = "Promote the value under initialization to fully-initialized. " + msg + "."
}

case class AccessCold(field: Symbol, source: Tree, trace: Seq[Tree]) extends Error {
def show(using Context): String =
"Access field " + source.show + " on a value with an unknown initialization status" + "."
"Access field " + source.show + " on a value with an unknown initialization status."
}

case class CallCold(meth: Symbol, source: Tree, trace: Seq[Tree]) extends Error {
Expand Down
Loading