Skip to content
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

Check of cyclic object initialization v4 #12698

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4a4284d
Copy file
liufengyun May 26, 2021
afd0822
Define domains
liufengyun May 26, 2021
27d931f
Add environment
liufengyun May 26, 2021
ab877a9
Fix domain operations
liufengyun May 26, 2021
c2ce64e
Fix semantics
liufengyun May 27, 2021
74d80fa
Handle constructor parameters
liufengyun May 28, 2021
167e51f
Fix semantic: compiles
liufengyun May 28, 2021
4607c91
Handle global objects in semantics
liufengyun May 28, 2021
6883b55
Check cycles
liufengyun May 28, 2021
c780ea7
Enable checking of objects
liufengyun May 28, 2021
d2cd2c2
Avoid cycles for givens
liufengyun May 28, 2021
f8aa860
First test works
liufengyun May 28, 2021
6e4327b
Ensure object exists in heap
liufengyun May 28, 2021
35d2d45
Handle fake Java objects
liufengyun May 28, 2021
e6172a2
Add tests
liufengyun May 28, 2021
9175c12
Refine traces
liufengyun May 28, 2021
3910149
Hanlde exception in bootstrapping
liufengyun May 28, 2021
154bac4
Use type abstraction for parameters
liufengyun May 28, 2021
18a4fc8
Add ClassAbs definition
liufengyun May 31, 2021
cb36c57
Fix compilation errors
liufengyun Jun 2, 2021
5a51a2a
Temporary fix for local methods
liufengyun Jun 2, 2021
b2944e3
Fix stacktrace
liufengyun Jun 2, 2021
90afb95
Fix semantics for object access
liufengyun Jun 2, 2021
e5742aa
Replace object leak with object non-init error
liufengyun Jun 2, 2021
1dce9fd
Suppress warnings about unkown external calls
liufengyun Jun 3, 2021
a0933a2
Reorganize tests
liufengyun Jun 3, 2021
3dfcf51
Use type abstraction for all parameters
liufengyun Jun 3, 2021
344738f
Add back outer-sensitivity
liufengyun Jun 7, 2021
32df0d1
Handle outers of trait as the same in concrete semantics
liufengyun Jun 7, 2021
bfeaf4e
Refactor (thanks @michelou)
liufengyun Jun 7, 2021
725bc38
Avoid widening to an address which may not exist
liufengyun Jun 7, 2021
6b2d258
Avoid forcing symbol loaded from libraries in -Ycheck
liufengyun Jun 7, 2021
97cfc55
Code cleanup
liufengyun Jun 7, 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
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/TreeChecker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class TreeChecker extends Phase with SymTransformer {

if (sym.isClass && !sym.isAbsent()) {
val validSuperclass = sym.isPrimitiveValueClass || defn.syntheticCoreClasses.contains(sym) ||
(sym eq defn.ObjectClass) || sym.isOneOf(NoSuperClassFlags) || (sym.asClass.superClass.exists) ||
(sym eq defn.ObjectClass) || sym.isOneOf(NoSuperClassFlags) || (!sym.isCompleted || sym.asClass.superClass.exists) ||
sym.isRefinementClass

assert(validSuperclass, i"$sym has no superclass set")
Expand Down
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/transform/init/Checker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Checker extends MiniPhase {
val phaseName = "initChecker"

private val semantic = new Semantic
private val objects = new Objects

override val runsAfter = Set(Pickler.name)

Expand Down Expand Up @@ -55,6 +56,9 @@ class Checker extends MiniPhase {
heap.update(thisRef, obj)
val res = eval(tpl, thisRef, cls)
res.errors.foreach(_.issue)

if objects.isStaticObjectRef(cls) then
objects.check(cls)
}

tree
Expand Down
19 changes: 18 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/init/Errors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ object Errors {

case class CallUnknown(meth: Symbol, source: Tree, trace: Seq[Tree]) extends Error {
def show(using Context): String =
val prefix = if meth.is(Flags.Method) then "Calling the external method " else "Accessing the external field"
val prefix = if meth.is(Flags.Method) then "Calling the external " else "Accessing the external "
prefix + meth.show + " may cause initialization errors" + "."
}

Expand All @@ -105,4 +105,21 @@ object Errors {
}.mkString)
}
}

case class CyclicObjectInit(objs: Seq[Symbol], trace: Seq[Tree]) extends Error {
def source: Tree = trace.last
def show(using Context): String =
"Cyclic object initialization for " + objs.map(_.show).mkString(", ") + "."

override def issue(using Context): Unit =
report.warning(show + stacktrace, objs.head.srcPos)
}

case class ObjectNotInit(obj: Symbol, trace: Seq[Tree]) extends Error {
def source: Tree = trace.last
def show(using Context): String = obj.show + " not yet initialized " + "."

override def issue(using Context): Unit =
report.warning(show + stacktrace, obj.srcPos)
}
}
Loading