A motley collection of the state and loosely associated behaviour of the type checker.
A class that records an available implicit
A class that sets up an implicit search.
A Context
focussed on an Import
tree
The context-dependent inferencer part
Calculate the arguments to pass to a macro implementation when expanding the provided tree.
Scratchpad for the macro expander, which is used to store all intermediate data except the details about the runtime.
Is added by the macro engine to originals and results of macro expansions.
Represents all the information that a macro definition needs to know about its implementation.
Describes the role that the macro expandee is performing.
Describes the role that the macro expandee is performing.
Abstracts away resolution of macro runtimes.
Abstracts away resolution of macro runtimes.
There are two key methods in here.
A class which is used to track pending implicits to prevent infinite implicit searches.
A class representing a lazy type with known type parameters.
A buffer for warnings and errors that are accumulated during speculative type checking.
The result of an implicit search
After being synthesized by the parser, primary constructors aren't fully baked yet.
Carries information necessary to expand the host tree.
Carries information necessary to expand the host tree. At times we need to store this info, because macro expansion can be delayed until its targs are inferred. After a macro application has been successfully expanded, this attachment is destroyed.
Checks whether there is any tree resulting from a macro expansion and associated with the current tree.
An extractor for unary function types arg => res
An extractor for types of the form ? { name: ? }
An extractor for types of the form ? { name: (? >: argtpe <: Any*)restp }
Macro def -> macro impl bindings are serialized into a macroImpl
annotation
with synthetic content that carries the payload described in MacroImplBinding
.
A sentinel indicating no implicit was found
A sentinel indicating no implicit was found
When present, suppresses macro expansion for the host.
This is a work in progress, don't take it too seriously.
An explanatory note to be added to error messages when there's a problem with abstract var defs
An explanatory note to be added to error messages when there's a problem with abstract var defs
AnalyzerPlugin.adaptAnnotations
Registers a new analyzer plugin
Registers a new analyzer plugin
Extend the argument list givenArgs
with default arguments.
Extend the argument list givenArgs
with default arguments. Defaults are added
as named arguments calling the corresponding default getter.
Example: given def foo(x: Int = 2, y: String = "def") foo(y = "lt") the argument list (y = "lt") is transformed to (y = "lt", x = foo$default$1())
Add the synthetic methods to case classes.
Add the synthetic methods to case classes.
returns true
if every element is equal to its index
returns true
if every element is equal to its index
Find all views from type tp
(in which tpars
are free)
Find all views from type tp
(in which tpars
are free)
Note that the trees in the search results in the returned list share the same type variables.
Ignore their constr field! The list of type constraints returned along with each tree specifies the constraints that
must be met by the corresponding type parameter in tpars
(for the returned implicit view to be valid).
AnalyzerPlugin.canAdaptAnnotations
Does not force the info of caseclazz
Does not force the info of caseclazz
Generates copy methods for case classes.
Generates copy methods for case classes. Copy only has defaults on the first parameter list, as of SI-5009.
The parameter types of the copy method need to be exactly the same as the parameter
types of the primary constructor. Just copying the TypeTree is not enough: a type C
might refer to something else *inside* the class (i.e. as parameter type of copy
)
than *outside* the class (i.e. in the class parameter list).
One such example is t0054.scala: class A { case class B(x: C) extends A { def copy(x: C = x) = ... } class C {} } (1) (2)
The reference (1) to C is A.this.C
. The reference (2) is B.this.C
- not the same.
This is fixed with a hack currently. Unapplies.caseClassCopyMeth
, which creates the
copy method, uses empty TypeTree()
nodes for parameter types.
In Namers.enterDefDef
, the copy method gets a special type completer (enterCopyMethod
).
Before computing the body type of copy
, the class parameter types are assigned the copy
method parameters.
This attachment class stores the copy method parameter ValDefs as an attachment in the ClassDef of the case class.
The apply method corresponding to a case class
The apply method corresponding to a case class
The module corresponding to a case class; overrides toString to show the module's name
The module corresponding to a case class; overrides toString to show the module's name
The unapply method corresponding to a case class
The unapply method corresponding to a case class
The companion class or companion module of original
.
The companion class or companion module of original
.
Calling .companionModule does not work for classes defined inside methods.
!!! Then why don't we fix companionModule? Does the presence of these methods imply all the places in the compiler calling sym.companionModule are bugs waiting to be reported? If not, why not? When exactly do we need to call this method?
Decreases metalevel of the type, i.
Decreases metalevel of the type, i.e. transforms: * c.Expr[T] to T * Anything else to Any
Metalevels.scala for more information and examples about metalevels
For a parameter with default argument, find the method symbol of the default getter.
For a parameter with default argument, find the method symbol of the default getter.
Macro classloader that is used to resolve and run macro implementations.
Macro classloader that is used to resolve and run macro implementations. Loads classes from from -cp (aka the library classpath). Is also capable of detecting REPL and reusing its classloader.
When -Xmacro-jit is enabled, we sometimes fallback to on-the-fly compilation of macro implementations, which compiles implementations into a virtual directory (very much like REPL does) and then conjures a classloader mapped to that virtual directory.
Expand partial function applications of type type
.
Expand partial function applications of type type
.
p.f(es_1)...(es_n) ==> { private synthetic val eta$f = p.f // if p is not stable ... private synthetic val eta$e_i = e_i // if e_i is not stable ... (ps_1 => ... => ps_m => eta$f([es_1])...([es_m])(ps_1)...(ps_m)) }
tree is already attributed
Look through the base types of the found type for any which might have been valid subtypes if given conformant type arguments.
Look through the base types of the found type for any which might have been valid subtypes if given conformant type arguments. Examine those for situations where the type error would have been eliminated if the variance were different. In such cases, append an additional explanatory message.
TODO: handle type aliases better.
Returns (formals, formalsExpanded)
where formalsExpanded
are the expected types
for the nbSubPats
sub-patterns of an extractor pattern, of which the corresponding
unapply[Seq] call is assumed to have result type resTp
.
Returns (formals, formalsExpanded)
where formalsExpanded
are the expected types
for the nbSubPats
sub-patterns of an extractor pattern, of which the corresponding
unapply[Seq] call is assumed to have result type resTp
.
formals
are the formal types before expanding a potential repeated parameter (must come last in formals
, if at all)
The number of arguments to the extractor pattern
nbSubPats
, unless there is one sub-pattern which, after unwrapping
bind patterns, is a Tuple pattern, in which case it is the number of
elements. Used to issue warnings about binding a TupleN
to a single value.
when the unapply[Seq] definition is ill-typed
The apply method corresponding to a case class
The apply method corresponding to a case class
A map from a set of pre-established macro symbols to their implementations.
A map from a set of pre-established macro symbols to their implementations.
The formal parameter types corresponding to formals
.
The formal parameter types corresponding to formals
.
If formals
has a repeated last parameter, a list of
(nargs - params.length + 1) copies of its type is returned.
By-name types are replaced with their underlying type.
allows keeping ByName parameters. Used in NamesDefaults.
allows keeping repeated parameter (if there's one argument). Used in NamesDefaults.
A fresh type variable with given type parameter as origin.
A fresh type variable with given type parameter as origin.
Determines whether the target is either an original or a result of a macro expansion.
Determines whether the target is either an original or a result of a macro expansion.
The parameter is of type Any
, because macros can expand both into trees and into annotations.
Without any restrictions on macro expansion, macro applications will expand at will, and when type inference is involved, expansions will end up using yet uninferred type params.
Without any restrictions on macro expansion, macro applications will expand at will, and when type inference is involved, expansions will end up using yet uninferred type params.
For some macros this might be ok (thanks to TreeTypeSubstituter that replaces the occurrences of undetparams with their inferred values), but in general case this won't work. E.g. for reification simple substitution is not enough - we actually need to re-reify inferred types.
Luckily, there exists a very simple way to fix the problem: delay macro expansion until everything is inferred. Here are the exact rules. Macro application gets delayed if any of its subtrees contain: 1) type vars (tpe.isInstanceOf[TypeVar]) // [Eugene] this check is disabled right now, because TypeVars seem to be created from undetparams anyways 2) undetparams (sym.isTypeParameter && !sym.isSkolem)
Determines whether the given tree has an associated SuperArgsAttachment.
Determines whether the given tree has an associated SuperArgsAttachment.
Increases metalevel of the type, i.
Increases metalevel of the type, i.e. transforms: * T to c.Expr[T]
Metalevels.scala for more information and examples about metalevels
A friendly wrapper over inferImplicit to be used in macro contexts and toolboxes.
A friendly wrapper over inferImplicit to be used in macro contexts and toolboxes.
Search for an implicit value.
Search for an implicit value. See the comment on result
at the end of class ImplicitSearch
for more info how the search is conducted.
The tree for which the implicit needs to be inserted. (the inference might instantiate some of the undetermined type parameters of that tree.
The expected type of the implicit.
Should ambiguous implicit errors be reported? False iff we search for a view to find out whether one type is coercible to another.
We are looking for a view
The current context
False if any divergent/ambiguous errors should be ignored after implicits search, true if they should be reported (used in further typechecking).
Position that is should be used for tracing and error reporting
(useful when we infer synthetic stuff and pass EmptyTree in the tree
argument)
If it's set NoPosition, then position-based services will use tree.pos
A search result
Map every TypeVar to its constraint.
Determines whether a tree should not be expanded, because someone has put SuppressMacroExpansionAttachment on it or one of its children.
Determines whether a tree should not be expanded, because someone has put SuppressMacroExpansionAttachment on it or one of its children.
Determines whether a tree should or should not be adapted, because someone has put MacroImplRefAttachment on it.
Determines whether a tree should or should not be adapted, because someone has put MacroImplRefAttachment on it.
After macro expansion is completed, links the expandee and the expansion result
by annotating them both with a MacroExpansionAttachment
.
After macro expansion is completed, links the expandee and the expansion result
by annotating them both with a MacroExpansionAttachment
.
After macro expansion is completed, links the expandee and the expansion result by annotating them both with a MacroExpansionAttachment
.
After macro expansion is completed, links the expandee and the expansion result by annotating them both with a MacroExpansionAttachment
.
The expanded
parameter is of type Any
, because macros can expand both into trees and into annotations.
Performs macro expansion on all subtrees of a given tree.
Performs macro expansion on all subtrees of a given tree.
Innermost macros are expanded first, outermost macros are expanded last.
See the documentation for macroExpand
for more information.
Expands a term macro used in apply role as M(2)(3)
in val x = M(2)(3)
.
Expands a term macro used in apply role as M(2)(3)
in val x = M(2)(3)
.
MacroExpander
Expands a term macro used in unapply role as u.Quasiquote(StringContext("", "")).q.unapply(x)
in case q"$x" => ...
.
Expands a term macro used in unapply role as u.Quasiquote(StringContext("", "")).q.unapply(x)
in case q"$x" => ...
.
MacroExpander
Loads underlying MacroExpanderAttachment from a macro expandee or returns a default value for that attachment.
Loads underlying MacroExpanderAttachment from a macro expandee or returns a default value for that attachment.
Marks the tree as a macro impl reference, which is a naked reference to a method.
Marks the tree as a macro impl reference, which is a naked reference to a method.
This is necessary for typechecking macro impl references (see DefaultMacroCompiler.defaultResolveMacroImpl
),
because otherwise typing a naked reference will result in the "follow this method with _' if you want to
treat it as a partially applied function" errors.
This mark suppresses adapt except for when the annottee is a macro application.
A constructor for types ?{ def/type name: tp }, used in infer view to member searches.
A constructor for types ?{ def/type name: tp }, used in infer view to member searches.
Automatically perform the following conversions on expression types: A method type becomes the corresponding function type.
Automatically perform the following conversions on expression types: A method type becomes the corresponding function type. A nullary method type becomes its result type. Implicit parameters are skipped. This method seems to be performance critical.
AnalyzerPlugin.pluginsPt
AnalyzerPlugin.pluginsTypeSig
AnalyzerPlugin.pluginsTypeSigAccessor
AnalyzerPlugin.pluginsTyped
AnalyzerPlugin.pluginsTypedReturn
Does the positioned line assigned to t1 precede that of t2?
Does the positioned line assigned to t1 precede that of t2?
The applied type of class 'to' after inferring anything possible from the knowledge that 'to' must also be of the type given in 'from'.
The applied type of class 'to' after inferring anything possible from the knowledge that 'to' must also be of the type given in 'from'.
Removes name assignments from args.
Removes name assignments from args. Additionally, returns an array mapping argument indices from call-site-order to definition-site-order.
Verifies that names are not specified twice, positional args don't appear after named ones.
maps indices from old to new
For errors which are artifacts of the implementation: such messages indicate that the restriction may be lifted in the future.
For errors which are artifacts of the implementation: such messages indicate that the restriction may be lifted in the future.
List of symbols to import from in a root context.
List of symbols to import from in a root context. Typically that
is java.lang
, scala
, and scala.Predef, in that order. Exceptions:
-Yno-imports
is given, nothing is importedjava.lang
is imported-Yno-predef
is given, if the unit body has an import of Predef
among its leading imports, or if the tree is scala.Predef, Predef
is not imported.
Solve constraint collected in types tvars
.
Solve constraint collected in types tvars
.
All type variables to be instantiated.
The type parameters corresponding to tvars
The variances of type parameters; need to reverse solution direction for all contravariant variables.
When true
search for max solution else min.
Convenience method for SuperArgsAttachment
.
Convenience method for SuperArgsAttachment
.
Compared with MacroRuntimeAttachment
this attachment has different a usage pattern,
so it really benefits from a dedicated extractor.
Suppresses macro expansion of the tree by putting SuppressMacroExpansionAttachment on it.
Suppresses macro expansion of the tree by putting SuppressMacroExpansionAttachment on it.
Transform a function application into a Block, and assigns typer.
Transform a function application into a Block, and assigns typer.context .namedApplyBlockInfo to the new block as side-effect. If tree has the form Apply(fun, args) first the function "fun" (which might be an application itself!) is transformed into a block of the form { val qual$1 = qualifier_of_fun val x$1 = arg_1_of_fun ... val x$n = arg_n_of_fun qual$1.fun[targs](x$1, ...)...(..., x$n) } then for each argument in args, a value is created and entered into the block. finally the application expression of the block is updated. { val qual$1 = .. ... val x$n = ... > val qual$n+1 = arg(1) > ... > val qual$n+m = arg(m) > qual$1.fun[targs](x$1, ...)...(..., x$n)(x$n+1, ..., x$n+m) }
the typer calling this method; this method calls typer.doTypedApply
the mode to use for calling typer.doTypedApply
the expected type for calling typer.doTypedApply
the transformed application (a Block) together with the NamedApplyInfo. if isNamedApplyBlock(tree), returns the existing context.namedApplyBlockInfo
Transforms parameters lists of a macro impl.
Transforms parameters lists of a macro impl.
The transform
function is invoked only for WeakTypeTag evidence parameters.
The transformer takes two arguments: a value parameter from the parameter list and a type parameter that is witnesses by the value parameter.
If the transformer returns a NoSymbol, the value parameter is not included from the result. If the transformer returns something else, this something else is included in the result instead of the value parameter.
Despite of being highly esoteric, this function significantly simplifies signature analysis. For example, it can be used to strip macroImpl.paramss from the evidences (necessary when checking def <-> impl correspondence) or to streamline creation of the list of macro arguments.
Verifies that the body of a macro def typechecks to a reference to a static public non-overloaded method or a top-level macro bundle, and that that method is signature-wise compatible with the given macro definition.
Verifies that the body of a macro def typechecks to a reference to a static public non-overloaded method or a top-level macro bundle, and that that method is signature-wise compatible with the given macro definition.
Macro impl reference for the given macro definition if everything is okay. EmptyTree if an error occurs.
Devising new ways of communicating error info out of desperation to work on error messages.
Devising new ways of communicating error info out of desperation to work on error messages. This is used by typedPattern to wrap its business so we can generate a sensible error message when things go south.
returns unapply or unapplySeq if available
returns unapply or unapplySeq if available
returns unapply member's parameter type.
returns unapply member's parameter type.
returns type list for return type of the extraction
returns type list for return type of the extraction
extractorFormalTypes
The symbol which the given accessor represents (possibly in part).
The symbol which the given accessor represents (possibly in part). This is used for error messages, where we want to speak in terms of the actual declaration or definition, not in terms of the generated setters and getters.
Unmarks the tree as a macro impl reference (see markMacroImplRef
for more information).
Unmarks the tree as a macro impl reference (see markMacroImplRef
for more information).
This is necessary when a tree that was previously deemed to be a macro impl reference, typechecks to be a macro application. Then we need to unmark it, expand it and try to treat its expansion as a macro impl reference.
Unsuppresses macro expansion of the tree by removing SuppressMacroExpansionAttachment from it and its children.
Unsuppresses macro expansion of the tree by removing SuppressMacroExpansionAttachment from it and its children.
Given any number of types, alters the name information in the symbols until they can be distinguished from one another: then executes the given code.
Given any number of types, alters the name information in the symbols until they can be distinguished from one another: then executes the given code. The names are restored and the result is returned.
(Since version 2.10.0) Use companionSymbolOf
instead
(Since version 2.10.0) Use companionSymbolOf
instead
(Since version 2.10.0) Use underlyingSymbol instead
Tree checker