Skip to content

Sharpen a type in Inliner #5884

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 1 commit into from
Feb 8, 2019
Merged
Changes from all commits
Commits
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
16 changes: 8 additions & 8 deletions compiler/src/dotty/tools/dotc/typer/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
private val thisProxy = new mutable.HashMap[ClassSymbol, TermRef]

/** A buffer for bindings that define proxies for actual arguments */
private val bindingsBuf = new mutable.ListBuffer[MemberDef]
private val bindingsBuf = new mutable.ListBuffer[ValOrDefDef]

private def newSym(name: Name, flags: FlagSet, info: Type): Symbol =
ctx.newSymbol(ctx.owner, name, flags, info, coord = call.span)
Expand All @@ -223,7 +223,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
* @param bindingsBuf the buffer to which the definition should be appended
*/
private def paramBindingDef(name: Name, paramtp: Type, arg: Tree,
bindingsBuf: mutable.ListBuffer[MemberDef]): MemberDef = {
bindingsBuf: mutable.ListBuffer[ValOrDefDef]): ValOrDefDef = {
val argtpe = arg.tpe.dealiasKeepAnnots
val isByName = paramtp.dealias.isInstanceOf[ExprType]
var inlineFlag = InlineProxy
Expand Down Expand Up @@ -585,7 +585,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
* - reduce its rhs if it is a projection and adjust its type accordingly,
* - record symbol -> rhs in the InlineBindings context propery.
*/
def normalizeBinding(binding: MemberDef)(implicit ctx: Context) = {
def normalizeBinding(binding: ValOrDefDef)(implicit ctx: Context) = {
val binding1 = binding match {
case binding: ValDef =>
val rhs1 = reduceProjection(binding.rhs)
Expand All @@ -608,7 +608,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
private object InlineableArg {
lazy val paramProxies = paramProxy.values.toSet
def unapply(tree: Trees.Ident[_])(implicit ctx: Context): Option[Tree] = {
def search(buf: mutable.ListBuffer[MemberDef]) = buf.find(_.name == tree.name)
def search(buf: mutable.ListBuffer[ValOrDefDef]) = buf.find(_.name == tree.name)
if (paramProxies.contains(tree.typeOpt))
search(bindingsBuf) match {
case Some(vdef: ValDef) if vdef.symbol.is(Inline) =>
Expand Down Expand Up @@ -651,7 +651,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
case Apply(Select(cl @ closureDef(ddef), nme.apply), args) if defn.isFunctionType(cl.tpe) =>
ddef.tpe.widen match {
case mt: MethodType if ddef.vparamss.head.length == args.length =>
val bindingsBuf = new mutable.ListBuffer[MemberDef]
val bindingsBuf = new mutable.ListBuffer[ValOrDefDef]
val argSyms = (mt.paramNames, mt.paramInfos, args).zipped.map { (name, paramtp, arg) =>
arg.tpe.dealias match {
case ref @ TermRef(NoPrefix, _) => ref.symbol
Expand Down Expand Up @@ -694,7 +694,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
* bindings for variables bound in this pattern to `bindingsBuf`.
*/
def reducePattern(
bindingsBuf: mutable.ListBuffer[MemberDef],
bindingsBuf: mutable.ListBuffer[ValOrDefDef],
fromBuf: mutable.ListBuffer[TypeSymbol],
toBuf: mutable.ListBuffer[TypeSymbol],
scrut: TermRef,
Expand Down Expand Up @@ -859,7 +859,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
val scrutineeBinding = normalizeBinding(ValDef(scrutineeSym, scrutinee))

def reduceCase(cdef: CaseDef): MatchRedux = {
val caseBindingsBuf = new mutable.ListBuffer[MemberDef]()
val caseBindingsBuf = new mutable.ListBuffer[ValOrDefDef]()
def guardOK(implicit ctx: Context) = cdef.guard.isEmpty || {
val guardCtx = ctx.fresh.setNewScope
caseBindingsBuf.foreach(binding => guardCtx.enter(binding.symbol))
Expand Down Expand Up @@ -1105,7 +1105,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
)

val Block(termBindings1, tree1) = inlineTypeBindings(Block(termBindings, tree))
inlineTermBindings(termBindings1.asInstanceOf[List[MemberDef]], tree1)
inlineTermBindings(termBindings1.asInstanceOf[List[ValOrDefDef]], tree1)
}
}
}