Skip to content

Check safe initialization of global objects #10550

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

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
12def6b
Remove unused file
liufengyun Nov 27, 2020
b7ccd17
Add definitions to support check global objects
liufengyun Nov 27, 2020
62665c9
Analyzing global effects and potentials
liufengyun Nov 27, 2020
9ede51a
WIP - check global effects
liufengyun Nov 27, 2020
70cdf2d
WIP - check global effects except promotion
liufengyun Nov 27, 2020
574f163
Propagate global potentials
liufengyun Nov 27, 2020
3a4c57d
Refactor: remove useless parameter
liufengyun Nov 27, 2020
4d74787
Better summary for new expressions with static path
liufengyun Nov 27, 2020
2bed5fb
Make summary a proper class
liufengyun Nov 27, 2020
7068ea7
Rename isInternal to hasSource
liufengyun Nov 28, 2020
1718b30
Check promotion of potentials
liufengyun Nov 28, 2020
a2c30c9
Cache safely promoted potential
liufengyun Nov 28, 2020
0bd9fae
Refactor ignored methods handling
liufengyun Nov 28, 2020
28652bc
Fix debugging code
liufengyun Nov 28, 2020
f61ddd8
Don't produce duplicate select effect in potential expansion
liufengyun Nov 28, 2020
365e0f9
Enable hijacking check
liufengyun Nov 28, 2020
c7864b9
Fix test case tests/init/neg/hybrid2.scala
liufengyun Nov 29, 2020
0e35f9e
Split effect check into multiple methods
liufengyun Nov 29, 2020
232a4fb
Fix range for promotion effects
liufengyun Nov 29, 2020
0677fe5
Simplify promotion logic for warm
liufengyun Nov 29, 2020
16c4977
Refactor promotion of this
liufengyun Nov 29, 2020
62f03f3
Fix tests
liufengyun Nov 29, 2020
d90dce2
Fix non-termination
liufengyun Nov 29, 2020
2334a0d
Revert #9673
liufengyun Nov 29, 2020
ef30873
Add promotion tests
liufengyun Nov 29, 2020
d425f9d
Fix missing return
liufengyun Nov 29, 2020
ca2ade2
Ignore constructor call on Any, Object and AnyVal
liufengyun Nov 29, 2020
990079c
Ignore external global method calls
liufengyun Nov 29, 2020
b097980
Member promotion result override outer promotion result
liufengyun Nov 29, 2020
fb88ebf
Refactor
liufengyun Nov 29, 2020
299e048
Introduce fast and full check modes
liufengyun Nov 29, 2020
be53c79
Fix #9176: Handle parent call argument effects in full mode
liufengyun Nov 29, 2020
cf468aa
Add test cases
liufengyun Nov 29, 2020
9052e24
update documentation
liufengyun Nov 30, 2020
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/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class ScalaSettings extends Settings.SettingGroup {
val YnoKindPolymorphism: Setting[Boolean] = BooleanSetting("-Yno-kind-polymorphism", "Disable kind polymorphism.")
val YexplicitNulls: Setting[Boolean] = BooleanSetting("-Yexplicit-nulls", "Make reference types non-nullable. Nullable types can be expressed with unions: e.g. String|Null.")
val YerasedTerms: Setting[Boolean] = BooleanSetting("-Yerased-terms", "Allows the use of erased terms.")
val YcheckInit: Setting[Boolean] = BooleanSetting("-Ycheck-init", "Check initialization of objects")
val YcheckInit: Setting[String] = ChoiceSetting("-Ycheck-init", "mode", "Check initialization of objects: fast | full", List("fast", "full"), "")
val YrequireTargetName: Setting[Boolean] = BooleanSetting("-Yrequire-targetName", "Warn if an operator is defined without a @targetName annotation")

/** Area-specific debug output */
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Symbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ object Symbols {
ctx.settings.YretainTrees.value ||
denot.owner.isTerm || // no risk of leaking memory after a run for these
denot.isOneOf(InlineOrProxy) || // need to keep inline info
ctx.settings.YcheckInit.value // initialization check
ctx.settings.YcheckInit.value.nonEmpty // initialization check

/** The last denotation of this symbol */
private var lastDenot: SymDenotation = _
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/init/Checker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Checker extends MiniPhase {
override val runsAfter = Set(Pickler.name)

override def isEnabled(using Context): Boolean =
super.isEnabled && ctx.settings.YcheckInit.value
super.isEnabled && ctx.settings.YcheckInit.value.nonEmpty

override def transformTypeDef(tree: TypeDef)(using Context): tpd.Tree = {
if (!tree.isClassDef) return tree
Expand All @@ -47,7 +47,7 @@ class Checker extends MiniPhase {
// A concrete class may not be instantiated if the self type is not satisfied
if (instantiable) {
implicit val state: Checking.State = Checking.State(
visited = Set.empty,
checked = Set.empty,
path = Vector.empty,
thisClass = cls,
fieldsInited = mutable.Set.empty,
Expand Down
Loading