diff options
author | Felix Mulder <felix.mulder@gmail.com> | 2017-01-03 16:24:15 +0100 |
---|---|---|
committer | Felix Mulder <felix.mulder@gmail.com> | 2017-01-31 14:29:17 +0100 |
commit | fe4c9a63b9c98bbf6d71e99d3b8215e9cd48a3ff (patch) | |
tree | 512641c7685c8259455139f2c146812fbd1858c1 /compiler/src/dotty/tools | |
parent | 302126067d6b05b26c7f2fffe7fda5d058b32b33 (diff) | |
download | dotty-fe4c9a63b9c98bbf6d71e99d3b8215e9cd48a3ff.tar.gz dotty-fe4c9a63b9c98bbf6d71e99d3b8215e9cd48a3ff.tar.bz2 dotty-fe4c9a63b9c98bbf6d71e99d3b8215e9cd48a3ff.zip |
Document `IsInstanceOfEvaluator` using markdown style docstrings
Diffstat (limited to 'compiler/src/dotty/tools')
-rw-r--r-- | compiler/src/dotty/tools/dotc/core/Phases.scala | 7 | ||||
-rw-r--r-- | compiler/src/dotty/tools/dotc/transform/IsInstanceOfEvaluator.scala | 58 |
2 files changed, 37 insertions, 28 deletions
diff --git a/compiler/src/dotty/tools/dotc/core/Phases.scala b/compiler/src/dotty/tools/dotc/core/Phases.scala index 6a53e1b30..773d8dbe8 100644 --- a/compiler/src/dotty/tools/dotc/core/Phases.scala +++ b/compiler/src/dotty/tools/dotc/core/Phases.scala @@ -266,6 +266,13 @@ object Phases { trait Phase extends DotClass { + /** A name given to the `Phase` that can be used to debug the compiler. For + * instance, it is possible to print trees after a given phase using: + * + * ```none + * $ ./bin/dotc -Xprint:<phaseNameHere> sourceFile.scala + * ``` + */ def phaseName: String /** List of names of phases that should precede this phase */ diff --git a/compiler/src/dotty/tools/dotc/transform/IsInstanceOfEvaluator.scala b/compiler/src/dotty/tools/dotc/transform/IsInstanceOfEvaluator.scala index 8bc4a2aa9..e6b1f5aac 100644 --- a/compiler/src/dotty/tools/dotc/transform/IsInstanceOfEvaluator.scala +++ b/compiler/src/dotty/tools/dotc/transform/IsInstanceOfEvaluator.scala @@ -7,43 +7,45 @@ import core._ import Contexts.Context, Types._, Constants._, Decorators._, Symbols._ import TypeUtils._, TypeErasure._, Flags._ - /** Implements partial evaluation of `sc.isInstanceOf[Sel]` according to: - * - * +-------------+----------------------------+----------------------------+------------------+ - * | Sel\sc | trait | class | final class | - * +-------------+----------------------------+----------------------------+------------------+ - * | trait | ? | ? | statically known | - * | class | ? | false if classes unrelated | statically known | - * | final class | false if classes unrelated | false if classes unrelated | statically known | - * +-------------+----------------------------+----------------------------+------------------+ - * - * This is a generalized solution to raising an error on unreachable match - * cases and warnings on other statically known results of `isInstanceOf`. - * - * Steps taken: - * - * 1. evalTypeApply will establish the matrix and choose the appropriate - * handling for the case: - * 2. a) Sel/sc is a value class or scrutinee is `Any` - * b) handleStaticallyKnown - * c) falseIfUnrelated with `scrutinee <:< selector` - * d) handleFalseUnrelated - * e) leave as is (aka `happens`) - * 3. Rewrite according to step taken in `2` - */ + * + * | Sel\sc | trait | class | final class | + * | ----------: | :------------------------: | :------------------------: | :--------------: | + * | trait | ? | ? | statically known | + * | class | ? | false if classes unrelated | statically known | + * | final class | false if classes unrelated | false if classes unrelated | statically known | + * + * This is a generalized solution to raising an error on unreachable match + * cases and warnings on other statically known results of `isInstanceOf`. + * + * Steps taken: + * + * 1. `evalTypeApply` will establish the matrix and choose the appropriate + * handling for the case: + * - Sel/sc is a value class or scrutinee is `Any` + * - `handleStaticallyKnown` + * - `falseIfUnrelated` with `scrutinee <:< selector` + * - `handleFalseUnrelated` + * - leave as is (`happens`) + * 2. Rewrite according to steps taken in 1 + */ class IsInstanceOfEvaluator extends MiniPhaseTransform { thisTransformer => import dotty.tools.dotc.ast.tpd._ - def phaseName = "isInstanceOfEvaluator" + /** @inheritdoc */ + val phaseName = "isInstanceOfEvaluator" + + /** Transforms a [TypeApply](dotty.tools.dotc.ast.Trees.TypeApply) in order to + * evaluate an `isInstanceOf` check according to the rules defined above. + */ override def transformTypeApply(tree: TypeApply)(implicit ctx: Context, info: TransformerInfo): Tree = { val defn = ctx.definitions /** Handles the four cases of statically known `isInstanceOf`s and gives - * the correct warnings, or an error if statically known to be false in - * match - */ + * the correct warnings, or an error if statically known to be false in + * match + */ def handleStaticallyKnown(select: Select, scrutinee: Type, selector: Type, inMatch: Boolean, pos: Position): Tree = { val scrutineeSubSelector = scrutinee <:< selector if (!scrutineeSubSelector && inMatch) { |