Type Verification Phases

I noticed that the type controller works in stages. Sometimes scalac returns only a few errors, which makes you think that they are almost there, but as soon as you fix them all - boom - the next phases, you will suddenly get many errors that were not there before.

What are the different stages of type checking?

Is there a way to find out in which phase the validating type abandoned my code (other than error recognition)?

+4
source share
2 answers

Compiler option for this -Yissue-debug. It issues a stack trace at 2.10 when an error is thrown.

, , 2.11 , . ( - , , , , -, . , push -f.)

2.12 , . , API- , , ..

:

class C { def f: Int ; def g: Int = "" ; def h = "\000" }

, , .

, , "typer", typecheck , . ( , " ".)

C ( -Xfuture) , g, refchecks , undefined ( ) f. , , . , , , .

, , .

package myrep

import scala.tools.nsc.Settings
import scala.tools.nsc.reporters.ConsoleReporter

import scala.reflect.internal.util._

class DebugReporter(ss: Settings) extends ConsoleReporter(ss) {
  override def warning(pos: Position, msg: String) = debug {
    super.warning(pos, msg)
  }
  override def error(pos: Position, msg: String) = debug {
    super.error(pos, msg)
  }
  // let it ride
  override def hasErrors = false

  private def debug(body: => Unit): Unit = {
    val pkgs = Set("nsc.ast.parser", "nsc.typechecker", "nsc.transform")
    def compilerPackages(e: StackTraceElement): Boolean = pkgs exists (e.getClassName contains _)
    def classname(e: StackTraceElement): String = (e.getClassName split """\.""").last
    if (ss.Yissuedebug) echo {
      ((new Throwable).getStackTrace filter compilerPackages map classname).distinct mkString ("Issued from: ", ",", "\n")
    }
    body
  }
}

, .

, " ":

scalacm -toolcp repdir -Xreporter myrep.DebugReporter -Yissue-debug -deprecation errs.scala

$ scalacm -version
Scala compiler version 2.12.0-M2 -- Copyright 2002-2013, LAMP/EPFL

:

Issued from: Scanners$UnitScanner,Scanners$Scanner,Parsers$Parser,Parsers$Parser$$anonfun$templateStat$1,Parsers$Parser$$anonfun$topStat$1,Parsers$SourceFileParser,Parsers$UnitParser,SyntaxAnalyzer,SyntaxAnalyzer$ParserPhase
errs.scala:4: warning: Octal escape literals are deprecated, use \u0000 instead.
class C { def f: Int ; def g: Int = "" ; def h = "\000" }
                                                  ^
Issued from: Contexts$ImmediateReporter,Contexts$ContextReporter,Contexts$Context,ContextErrors$ErrorUtils$,ContextErrors$TyperContextErrors$TyperErrorGen$,Typers$Typer,Analyzer$typerFactory$$anon$3
errs.scala:4: error: type mismatch;
 found   : String("")
 required: Int
class C { def f: Int ; def g: Int = "" ; def h = "\000" }
                                    ^
Issued from: RefChecks$RefCheckTransformer,Transform$Phase
errs.scala:4: error: class C needs to be abstract, since method f is not defined
class C { def f: Int ; def g: Int = "" ; def h = "\000" }
      ^
one warning found
two errors found
+1

@Felix, :

$ scalac -version
Scala compiler version 2.11.6 -- Copyright 2002-2013, LAMP/EPFL
$ scalac -Xshow-phases
    phase name  id  description
    ----------  --  -----------
        parser   1  parse source into ASTs, perform simple desugaring
         namer   2  resolve names, attach symbols to named trees
packageobjects   3  load package objects
         typer   4  the meat and potatoes: type the trees
        patmat   5  translate match expressions
superaccessors   6  add super accessors in traits and nested classes
    extmethods   7  add extension methods for inline classes
       pickler   8  serialize symbol tables
     refchecks   9  reference/override checking, translate nested objects
       uncurry  10  uncurry, translate function values to anonymous classes
     tailcalls  11  replace tail calls by jumps
    specialize  12  @specialized-driven class and method specialization
 explicitouter  13  this refs to outer pointers
       erasure  14  erase types, add interfaces for traits
   posterasure  15  clean up erased inline classes
      lazyvals  16  allocate bitmaps, translate lazy vals into lazified defs
    lambdalift  17  move nested functions to top level
  constructors  18  move field definitions into constructors
       flatten  19  eliminate inner classes
         mixin  20  mixin composition
       cleanup  21  platform-specific cleanups, generate reflective calls
    delambdafy  22  remove lambdas
         icode  23  generate portable intermediate code
           jvm  24  generate JVM bytecode
      terminal  25  the last phase during a compilation run

, ( )?

-verbose scalac, . ,

, scalac , . typer .

+3

Source: https://habr.com/ru/post/1611954/


All Articles