-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Safe initialization for Scala #7789
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
Changes from all commits
Commits
Show all changes
112 commits
Select commit
Hold shift + click to select a range
baccbd8
Add basic definitions
liufengyun 337c4b6
Add Env definition
liufengyun 52c8441
Add SuperRef as potential
liufengyun 91baf28
Add phase SetDefTree
liufengyun 68ec7ec
Add summarization of expression
liufengyun f47577a
Add documentation for Warm
liufengyun fa6c182
Tweak summariztion
liufengyun bb513dc
Handle Lazy ValDef
liufengyun 891d6d8
Handle TypeDef and DefDef in summarization
liufengyun 1ac3356
WIP - add checking
liufengyun 0494ac1
WIP - implementation linearization
liufengyun cbc4a31
Handle lazy fields
liufengyun 820c67b
Support traceOp
liufengyun 6f11bf6
Summarize bindings in inlined
liufengyun c58a967
WIP - summarization of new
liufengyun 073eec2
WIP - introduce ClassSummary
liufengyun 594c1bf
Add show to ClassSummary
liufengyun 94267d7
Add code to summarize class
liufengyun b94ce00
Fix typing errors
liufengyun 67e7165
Fix Summary and Summarization errors
liufengyun e5e1c68
Fix more typing errors in Checking
liufengyun dc680dc
Remove obsolete cases in Checking
liufengyun 5310886
More fixes
liufengyun 6e6a181
WIP
liufengyun 994c240
Add asSeenFrom
liufengyun 4eb8eaa
WIP - Fix expand
liufengyun 9244e27
WIP - Fix more type checking
liufengyun 06ee111
Fix compilation: overloading does not work well with extension methods
liufengyun e923bf4
Fix compilation warnings
liufengyun 617a6d9
Handle outer
liufengyun 4f76c6a
WIP - asSeenFrom
liufengyun 554620c
Fix Potentials.asSeenFrom
liufengyun 949a009
Fix Effects.asSeenFrom
liufengyun 5c59fee
Lazy access as method calls
liufengyun 13ce15e
Remove virtual from MethodCall and MethodReturn
liufengyun 917ac30
Remove RootPotential
liufengyun 5d34ea1
Code refactoring
liufengyun 9f7c853
Implement resolve and resolveSuper
liufengyun ac2b9dc
Add checker phase
liufengyun bcd7c58
Add initialization to compiler phases
liufengyun 077eb5b
First example works
liufengyun 8a9c0cf
Handle class parameters
liufengyun 25c7a90
Handle ignored methods
liufengyun bf917a7
Ignore non-instantiable classes
liufengyun 8ba171c
Handle A & B for this via self type
liufengyun 99679b8
Fix classSymbol in parents
liufengyun 43d46cd
Fix summarization of class
liufengyun 9b99ffc
A method call might be a field access
liufengyun ec03ffd
Parent child tests are green
liufengyun 6e3e41d
Fix infinite loop in asSeenFrom
liufengyun 8ab9c8b
Handle Lazy field access in checking
liufengyun 38c2d1d
Handle constructor select properly
liufengyun c7d2a0a
Fix missing pot in constructor selection
liufengyun d0e54b0
Fix summarization of lambdas and ValDef
liufengyun 10c620d
Fix primary constructor effects
liufengyun d2d498b
Fix missed effects in new-expressions
liufengyun 97e4ee4
Fix length of field select which causes non-termination
liufengyun 9996f50
Remove obsolete freedom tests
liufengyun e6cabb4
Migrate feature tests
liufengyun f351d80
Migrate tests
liufengyun 60cbb7d
Migrate function tests
liufengyun 1a9b409
Migrate hybrid tests
liufengyun 58c8dc1
Fix secondary constructor
liufengyun 0a1fbfa
Handle HKLambdaType in new expression
liufengyun 56d402e
Treat local methods as called
liufengyun 3ea4894
Fix lazy val access
liufengyun 89b0815
Fix expansion of SuperRef
liufengyun 99e42b5
Fix asSeenFrom
liufengyun 79de26c
Handle reference of ConstantType in summarization
liufengyun 02ddbd7
Mark Object.synchronized as ignored
liufengyun 10f51f7
Ignore EnumValues.register
liufengyun c48a8e4
All misc tests green
liufengyun 41ffc62
Fix indentation warning
liufengyun 89972d3
Add back lazylists
liufengyun 4c96a4b
Respect @unchecked annotation
liufengyun 3cf5dcb
Refactor crash tests
liufengyun cd57149
Fix crash due to var x:T = _
liufengyun 11e5767
Enable more tests
liufengyun 1e04d6e
Fix exception in super resolution
liufengyun 2976e97
Initial work on documentation
liufengyun bef686a
Doc tweaks
liufengyun 414d8a8
Add link in sidebar
liufengyun 0480b96
Fix typo in docs
liufengyun d2a3a8b
Explain the potential Outer in docs
liufengyun eb1a49c
Add scopability an explicit principle
liufengyun 3c16fd9
Fix typos in documentation
liufengyun 21b5662
Make doc align with paper
liufengyun 2e0268c
Address review and add docs
liufengyun a9a6742
Rename Leak to Promote
liufengyun b2b4976
Add definition of Errors
liufengyun 2ac188f
More errors
liufengyun 085cf64
Accumulate errors in effect checking
liufengyun 9b12559
Add error reporting
liufengyun 4a5c718
Refine error messages
liufengyun ce42450
Fix tests: more friendly error messages for functions
liufengyun 8ed50b8
Enforce that only initialized values may be returned
liufengyun 49e3efb
Use build-in mechanism to get definitions
liufengyun d4b54a7
Address review
liufengyun 3c2d818
Refine error messages
liufengyun a42bab2
Fix exception
liufengyun 6ded31f
Fix exception: not all traits have constructors
liufengyun 2e54c6a
Fix exception: Any and AnyVal don't have constructors
liufengyun 328f6a9
Fix exception
liufengyun ba63e45
Fix extractor for closureDef
liufengyun d3ce80a
Fix crash: SuperType.supertpe can be AndType
liufengyun 4d500bd
Fix crash: polymorphic function apply does not have symbols
liufengyun 8379ee1
Fix crash: handle annotations in parents
liufengyun 8192b2c
Handle by-name parameters properly
liufengyun 5581d74
Refactor expand
liufengyun 7b5fc1a
Better explain scopability
liufengyun 1694e4a
Refine stacktrace printing
liufengyun 6a4d06a
Fix syntax change
liufengyun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
compiler/src/dotty/tools/dotc/transform/init/Checker.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package dotty.tools.dotc | ||
package transform | ||
package init | ||
|
||
|
||
import dotty.tools.dotc._ | ||
import ast.tpd | ||
|
||
import dotty.tools.dotc.core._ | ||
import Contexts.Context | ||
import Types._ | ||
|
||
import dotty.tools.dotc.transform._ | ||
import MegaPhase._ | ||
|
||
|
||
import scala.collection.mutable | ||
|
||
|
||
class Checker extends MiniPhase { | ||
import tpd._ | ||
|
||
val phaseName = "initChecker" | ||
|
||
// cache of class summary | ||
private val baseEnv = Env(null, mutable.Map.empty) | ||
|
||
override val runsAfter = Set(Pickler.name) | ||
|
||
override def isEnabled(implicit ctx: Context): Boolean = | ||
super.isEnabled && ctx.settings.YcheckInit.value | ||
|
||
override def transformTypeDef(tree: TypeDef)(implicit ctx: Context): tpd.Tree = { | ||
if (!tree.isClassDef) return tree | ||
|
||
val cls = tree.symbol.asClass | ||
val instantiable: Boolean = | ||
cls.is(Flags.Module) || | ||
!cls.isOneOf(Flags.AbstractOrTrait) && { | ||
// see `Checking.checkInstantiable` in typer | ||
val tp = cls.appliedRef | ||
val stp = SkolemType(tp) | ||
val selfType = cls.givenSelfType.asSeenFrom(stp, cls) | ||
!selfType.exists || stp <:< selfType | ||
} | ||
|
||
// A concrete class may not be instantiated if the self type is not satisfied | ||
if (instantiable) { | ||
implicit val state = Checking.State( | ||
visited = mutable.Set.empty, | ||
path = Vector.empty, | ||
thisClass = cls, | ||
fieldsInited = mutable.Set.empty, | ||
parentsInited = mutable.Set.empty, | ||
env = baseEnv.withCtx(ctx) | ||
) | ||
|
||
Checking.checkClassBody(tree) | ||
} | ||
|
||
tree | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.