From 5c99b07ec319fceba9f34e6b2b3ae2c7b54b8c87 Mon Sep 17 00:00:00 2001 From: dk14 Date: Tue, 23 Feb 2016 18:57:04 +0700 Subject: explicitly specify insertion-order feature in docs --- src/library/scala/collection/mutable/ListMap.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/library/scala/collection/mutable/ListMap.scala b/src/library/scala/collection/mutable/ListMap.scala index 2ea5b1fa7c..e963af4a8a 100644 --- a/src/library/scala/collection/mutable/ListMap.scala +++ b/src/library/scala/collection/mutable/ListMap.scala @@ -15,7 +15,7 @@ package mutable import generic._ import annotation.tailrec -/** A simple mutable map backed by a list. +/** A simple mutable map backed by a list, so it preserves insertion order. * * @tparam A the type of the keys contained in this list map. * @tparam B the type of the values assigned to keys in this list map. -- cgit v1.2.3 From 1a59c55ed5c6a0d53acd0259090cf57328748451 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Wed, 2 Mar 2016 20:51:49 +1000 Subject: Refactor transform of case apply in refchecks I've identified a dead call to `transformCaseApply` that seems to date back to Scala 2.6 vintages, in which case factory methods were a fictional companion method, rather than a real apply method in a companion module. This commit adds an abort in that code path to aide code review (if our test suite still passes, we know that I've removed dead code, rather than silently changing behaviour.) The following commit will remove it altogether I then inlined a slightly clunky abstraction in the two remaining calls to `transformCaseApply`. It was getting in the way of a clean fix to SI-9546, the topic of the next commit. --- .../scala/tools/nsc/typechecker/RefChecks.scala | 58 +++++++++++----------- test/files/run/t9546b.scala | 13 +++++ test/files/run/t9546c.scala | 13 +++++ test/files/run/t9546d.scala | 16 ++++++ 4 files changed, 72 insertions(+), 28 deletions(-) create mode 100644 test/files/run/t9546b.scala create mode 100644 test/files/run/t9546c.scala create mode 100644 test/files/run/t9546d.scala diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index c5abd756f8..f2607b6bde 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -1503,9 +1503,8 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans } } - private def transformCaseApply(tree: Tree, ifNot: => Unit) = { + private def isSimpleCaseApply(tree: Tree): Boolean = { val sym = tree.symbol - def isClassTypeAccessible(tree: Tree): Boolean = tree match { case TypeApply(fun, targs) => isClassTypeAccessible(fun) @@ -1513,31 +1512,26 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans ( // SI-4859 `CaseClass1().InnerCaseClass2()` must not be rewritten to `new InnerCaseClass2()`; // {expr; Outer}.Inner() must not be rewritten to `new Outer.Inner()`. treeInfo.isQualifierSafeToElide(module) && - // SI-5626 Classes in refinement types cannot be constructed with `new`. In this case, - // the companion class is actually not a ClassSymbol, but a reference to an abstract type. - module.symbol.companionClass.isClass - ) + // SI-5626 Classes in refinement types cannot be constructed with `new`. In this case, + // the companion class is actually not a ClassSymbol, but a reference to an abstract type. + module.symbol.companionClass.isClass + ) } - val doTransform = - sym.isSourceMethod && + sym.isSourceMethod && sym.isCase && sym.name == nme.apply && isClassTypeAccessible(tree) && !tree.tpe.resultType.typeSymbol.primaryConstructor.isLessAccessibleThan(tree.symbol) + } - if (doTransform) { - tree foreach { - case i@Ident(_) => - enterReference(i.pos, i.symbol) // SI-5390 need to `enterReference` for `a` in `a.B()` - case _ => - } - toConstructor(tree.pos, tree.tpe) - } - else { - ifNot - tree + private def transformCaseApply(tree: Tree) = { + tree foreach { + case i@Ident(_) => + enterReference(i.pos, i.symbol) // SI-5390 need to `enterReference` for `a` in `a.B()` + case _ => } + toConstructor(tree.pos, tree.tpe) } private def transformApply(tree: Apply): Tree = tree match { @@ -1577,12 +1571,15 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans // term should have been eliminated by super accessors assert(!(qual.symbol.isTrait && sym.isTerm && mix == tpnme.EMPTY), (qual.symbol, sym, mix)) - transformCaseApply(tree, + if (isSimpleCaseApply(tree)) { + transformCaseApply(tree) + } else { qual match { case Super(_, mix) => checkSuper(mix) case _ => } - ) + tree + } } private def transformIf(tree: If): Tree = { val If(cond, thenpart, elsepart) = tree @@ -1706,7 +1703,10 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans case TypeApply(fn, args) => checkBounds(tree, NoPrefix, NoSymbol, fn.tpe.typeParams, args map (_.tpe)) - transformCaseApply(tree, ()) + if (isSimpleCaseApply(tree)) + transformCaseApply(tree) + else + tree case x @ Apply(_, _) => transformApply(x) @@ -1725,12 +1725,14 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans case Ident(name) => checkUndesiredProperties(sym, tree.pos) - transformCaseApply(tree, - if (name != nme.WILDCARD && name != tpnme.WILDCARD_STAR) { - assert(sym != NoSymbol, "transformCaseApply: name = " + name.debugString + " tree = " + tree + " / " + tree.getClass) //debug - enterReference(tree.pos, sym) - } - ) + if (isSimpleCaseApply(tree)) { + abort("case factory methods are now always selected from prefix (since https://github.com/scala/scala/commit/76c06b4)") + } + if (name != nme.WILDCARD && name != tpnme.WILDCARD_STAR) { + assert(sym != NoSymbol, "transformCaseApply: name = " + name.debugString + " tree = " + tree + " / " + tree.getClass) //debug + enterReference(tree.pos, sym) + } + tree case x @ Select(_, _) => transformSelect(x) diff --git a/test/files/run/t9546b.scala b/test/files/run/t9546b.scala new file mode 100644 index 0000000000..0b4d2d3fe5 --- /dev/null +++ b/test/files/run/t9546b.scala @@ -0,0 +1,13 @@ +package foo { + case class Opt[A](val get: A) extends AnyVal { + } + object Opt { + def mkOpt = Opt("") + } +} + +object Test { + def main(args: Array[String]): Unit = { + foo.Opt.mkOpt + } +} diff --git a/test/files/run/t9546c.scala b/test/files/run/t9546c.scala new file mode 100644 index 0000000000..ea6a5a36b4 --- /dev/null +++ b/test/files/run/t9546c.scala @@ -0,0 +1,13 @@ +package foo { + case class Opt[A] private[foo](val get: A) + object Opt { + def mkOpt = Opt("") + } +} + +object Test { + def main(args: Array[String]): Unit = { + foo.Opt.mkOpt + } +} + diff --git a/test/files/run/t9546d.scala b/test/files/run/t9546d.scala new file mode 100644 index 0000000000..00bf37dc18 --- /dev/null +++ b/test/files/run/t9546d.scala @@ -0,0 +1,16 @@ +class X { + def test: Any = { + object Opt { + def mkOpt = Opt("") + } + case class Opt[A] private[X](val get: A) + Opt.mkOpt + } +} + +object Test { + def main(args: Array[String]): Unit = { + new X().test + } +} + -- cgit v1.2.3 From fe5bd09861994734bc394813d069ea40c89d39de Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Wed, 2 Mar 2016 22:02:15 +1000 Subject: SI-9546 Fix regression in rewrite of case apply to constructor call In SI-9425, I disabled the rewrite of `CaseClass.apply(x)` to `new CaseClass(x)` if the constructor was was less accessible than the apply method. This solved a problem with spurious "constructor cannot be accessed" errors during refchecks for case classes with non-public constructors. However, for polymorphic case classes, refchecks was persistent, and even after refusing to transform the `TypeApply` within: CaseClass.apply[String]("") It *would* try again to transform the enclosing `Select`, a code path only intended for monomorphic case classes. The tree has a `PolyType`, which foiled the newly added accessibility check. I've modified the call to `isSimpleCaseApply` from the transform of `Select` nodes to exclude polymorphic apply's from being considered twice. --- src/compiler/scala/tools/nsc/typechecker/RefChecks.scala | 7 +++---- test/files/run/t9546.scala | 13 +++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 test/files/run/t9546.scala diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index f2607b6bde..517271e5eb 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -1571,7 +1571,9 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans // term should have been eliminated by super accessors assert(!(qual.symbol.isTrait && sym.isTerm && mix == tpnme.EMPTY), (qual.symbol, sym, mix)) - if (isSimpleCaseApply(tree)) { + // SI-9546 isHigherKinded excludes generic case classes which are instead considered when transforming + // the enclosing `TypeApply`. + if (!tree.tpe.isHigherKinded && isSimpleCaseApply(tree)) { transformCaseApply(tree) } else { qual match { @@ -1725,9 +1727,6 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans case Ident(name) => checkUndesiredProperties(sym, tree.pos) - if (isSimpleCaseApply(tree)) { - abort("case factory methods are now always selected from prefix (since https://github.com/scala/scala/commit/76c06b4)") - } if (name != nme.WILDCARD && name != tpnme.WILDCARD_STAR) { assert(sym != NoSymbol, "transformCaseApply: name = " + name.debugString + " tree = " + tree + " / " + tree.getClass) //debug enterReference(tree.pos, sym) diff --git a/test/files/run/t9546.scala b/test/files/run/t9546.scala new file mode 100644 index 0000000000..7016881084 --- /dev/null +++ b/test/files/run/t9546.scala @@ -0,0 +1,13 @@ +package foo { + case class Opt[A] private[foo](val get: A) extends AnyVal + object Opt { + def mkOpt = Opt("") + } +} + +object Test { + def main(args: Array[String]): Unit = { + foo.Opt.mkOpt + } +} + -- cgit v1.2.3 From 5bcc7222b0c703317c70a2b37dfd44e1d221f835 Mon Sep 17 00:00:00 2001 From: Janek Bogucki Date: Thu, 3 Mar 2016 22:21:30 +0000 Subject: Document -Xxml:coalescing in scalac man page The formatting style is based on -g and -target. --- src/manual/scala/man1/scalac.scala | 51 +++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/src/manual/scala/man1/scalac.scala b/src/manual/scala/man1/scalac.scala index 7e8277f5ad..a20c1ac2e6 100644 --- a/src/manual/scala/man1/scalac.scala +++ b/src/manual/scala/man1/scalac.scala @@ -5,10 +5,6 @@ package scala.man1 -/** - * @author Stephane Micheloud - * @version 1.0 - */ object scalac extends Command { import _root_.scala.tools.docutil.ManPage._ @@ -77,7 +73,7 @@ object scalac extends Command { SeqPara( "Specify where to find user class files (on Unix-based systems " & "a colon-separated list of paths, on Windows-based systems, a " & - "semicolon-separate list of paths). This does not override the " & + "semicolon-separated list of paths). This does not override the " & "built-in (" & Mono("\"boot\"") & ") search path.", "The default class path is the current directory. Setting the " & Mono("CLASSPATH") & " variable or using the " & Mono("-classpath") & " " & @@ -153,7 +149,7 @@ object scalac extends Command { "Specify location(s) of source files."), Definition( CmdOptionBound("target:", "{jvm-1.5,jvm-1.6,jvm-1.7,jvm-1.8}"), - SeqPara( + SeqPara( Mono("\"jvm-1.5\"") & " target JVM 1.5 (deprecated),", Mono("\"jvm-1.6\"") & " target JVM 1.6 (default),", Mono("\"jvm-1.7\"") & " target JVM 1.7,", @@ -196,7 +192,7 @@ object scalac extends Command { Definition( CmdOption("Xcheckinit"), "Wrap field accessors to throw an exception on uninitialized access."), - Definition( + Definition( CmdOption("Xdev"), "Enable warnings for developers working on the Scala compiler"), Definition( @@ -212,7 +208,7 @@ object scalac extends Command { Definition( CmdOption("Xfatal-warnings"), "Fail the compilation if there are any warnings."), - Definition( + Definition( CmdOption("Xfull-lubs"), "Retain pre 2.10 behavior of less aggressive truncation of least upper bounds."), Definition( @@ -224,25 +220,25 @@ object scalac extends Command { Definition( CmdOption("Xlint"), "Enable recommended additional warnings."), - Definition( + Definition( CmdOption("Xlog-free-terms"), "Print a message when reification creates a free term."), - Definition( + Definition( CmdOption("Xlog-free-types"), "Print a message when reification resorts to generating a free type."), - Definition( + Definition( CmdOption("Xlog-implicit-conversions"), "Print a message whenever an implicit conversion is inserted."), Definition( CmdOption("Xlog-implicits"), "Show more detail on why some implicits are not applicable."), - Definition( + Definition( CmdOption("Xlog-reflective-calls"), "Print a message when a reflective method call is generated."), - Definition( + Definition( CmdOptionBound("Xmacro-settings:", Argument("option")), "Custom settings for macros."), - Definition( + Definition( CmdOption("Xmain-class", Argument("path")), "Class for manifest's Main-Class entry (only useful with -d )."), Definition( @@ -254,7 +250,7 @@ object scalac extends Command { Definition( CmdOption("Xno-forwarders"), "Do not generate static forwarders in mirror classes."), - Definition( + Definition( CmdOption("Xno-patmat-analysis"), "Don't perform exhaustivity/unreachability analysis. Also, ignore " & MItalic("@switch") & " annotation."), Definition( @@ -312,15 +308,20 @@ object scalac extends Command { Definition( CmdOptionBound("Xsource:", Argument("version")), "Treat compiler input as Scala source for the specified version, see SI-8126."), - Definition( + Definition( CmdOption("Xsource-reader", Argument("classname")), "Specify a custom method for reading source files."), - Definition( + Definition( CmdOption("Xstrict-inference"), "Don't infer known-unsound types."), Definition( CmdOption("Xverify"), "Verify generic signatures in generated bytecode (asm backend only)."), + Definition( + CmdOptionBound("Xxml:", "{coalescing}"), + SeqPara( + "Configure XML parsing.", + Mono("\"coalescing\"") & " convert PCData to Text and coalesce sibling nodes (default in 2.11).")), Definition( CmdOption("Y"), "Print a synopsis of private options.") @@ -335,34 +336,34 @@ object scalac extends Command { Definition( MItalic("namer"), "resolve names, attach symbols to named trees"), - Definition( + Definition( MItalic("packageobjects"), "load package objects"), - Definition( + Definition( MItalic("typer"), "the meat and potatoes: type the trees"), Definition( MItalic("patmat"), "translate match expressions"), - Definition( + Definition( MItalic("superaccessors"), "add super accessors in traits and nested classes"), - Definition( + Definition( MItalic("extmethods"), "add extension methods for inline classes"), - Definition( + Definition( MItalic("pickler"), "serialize symbol tables"), Definition( MItalic("refchecks"), "reference/override checking, translate nested objects"), - Definition( + Definition( MItalic("selectiveanf"), "ANF pre-transform for " & MItalic("@cps") & " (CPS plugin)"), - Definition( + Definition( MItalic("selectivecps"), MItalic("@cps") & "-driven transform of selectiveanf assignments (CPS plugin)"), - Definition( + Definition( MItalic("uncurry"), "uncurry, translate function values to anonymous classes"), Definition( -- cgit v1.2.3 From f08282946647ec4049af965024b4638a4a55f5fd Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Thu, 3 Mar 2016 22:30:39 +1000 Subject: SI-9425 Fix a residual bug with multi-param-list case classes During code review for the fix for SI-9546, we found a corner case in the SI-9425 that remained broken. Using `finalResultType` peels off all the constructor param lists, and solves that problem. --- src/compiler/scala/tools/nsc/typechecker/RefChecks.scala | 13 ++++++++++--- test/files/run/t9546e.scala | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 test/files/run/t9546e.scala diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index 517271e5eb..3b2e07bdbd 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -1522,7 +1522,7 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans sym.isCase && sym.name == nme.apply && isClassTypeAccessible(tree) && - !tree.tpe.resultType.typeSymbol.primaryConstructor.isLessAccessibleThan(tree.symbol) + !tree.tpe.finalResultType.typeSymbol.primaryConstructor.isLessAccessibleThan(tree.symbol) } private def transformCaseApply(tree: Tree) = { @@ -1571,8 +1571,15 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans // term should have been eliminated by super accessors assert(!(qual.symbol.isTrait && sym.isTerm && mix == tpnme.EMPTY), (qual.symbol, sym, mix)) - // SI-9546 isHigherKinded excludes generic case classes which are instead considered when transforming - // the enclosing `TypeApply`. + // Rewrite eligible calls to monomorphic case companion apply methods to the equivalent constructor call. + // + // Note: for generic case classes the rewrite needs to be handled at the enclosing `TypeApply` to transform + // `TypeApply(Select(C, apply), targs)` to `Select(New(C[targs]), )`. In case such a `TypeApply` + // was deemed ineligible for transformation (e.g. the case constructor was private), the refchecks transform + // will recurse to this point with `Select(C, apply)`, which will have a type `[T](...)C[T]`. + // + // We don't need to perform the check on the Select node, and `!isHigherKinded will guard against this + // redundant (and previously buggy, SI-9546) consideration. if (!tree.tpe.isHigherKinded && isSimpleCaseApply(tree)) { transformCaseApply(tree) } else { diff --git a/test/files/run/t9546e.scala b/test/files/run/t9546e.scala new file mode 100644 index 0000000000..b19d0871aa --- /dev/null +++ b/test/files/run/t9546e.scala @@ -0,0 +1,15 @@ +case class A private (x: Int) +case class B private (x: Int)(y: Int) + +class C { + def f = A(1) + def g = B(1)(2) // was: constructor B in class B cannot be accessed in class C +} + +object Test { + def main(args: Array[String]): Unit = { + new C().f + new C().g + } + +} -- cgit v1.2.3 From 4b471eb20ea160144e61d88ce50f6d4a3536c87a Mon Sep 17 00:00:00 2001 From: Seth Tisue Date: Thu, 3 Mar 2016 12:45:07 +0100 Subject: Typesafe -> Lightbend in more places --- CONTRIBUTING.md | 4 ++-- doc/LICENSE.md | 2 +- doc/License.rtf | 2 +- src/scaladoc/scala/tools/nsc/doc/Settings.scala | 2 +- src/scaladoc/scala/tools/nsc/doc/html/page/Template.scala | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 18f07376bd..617734210f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,13 +4,13 @@ We follow the standard GitHub [fork & pull](https://help.github.com/articles/usi You're always welcome to submit your PR straight away and start the discussion (without reading the rest of this wonderful doc, or the `READMEnot^H^H^H.md`). The goal of these notes is to make your experience contributing to Scala as smooth and pleasant as possible. We're happy to guide you through the process once you've submitted your PR. ## The Scala Community -In 2014, you -- the Scala community -- matched the core team at EPFL in number of commits contributed to Scala 2.11, doubling the percentage of commits from outside EPFL/Typesafe since 2.10. Excellent work! (The split was roughly 25/25/50 for you/EPFL/Typesafe.) +In 2014, you -- the Scala community -- matched the core team at EPFL in number of commits contributed to Scala 2.11, doubling the percentage of commits from outside EPFL/Lightbend since 2.10. Excellent work! (The split was roughly 25/25/50 for you/EPFL/Lightbend.) We are super happy about this, and are eager to make your experience contributing to Scala productive and satisfying, so that we can keep up this growth. We can't do this alone (nor do we want to)! This is why we're collecting these notes on how to contribute, and we hope you'll share your experience to improve the process for the next contributor! (Feel free to send a PR for this note, send your thoughts to scala-internals, or tweet about it to @adriaanm.) -By the way, the team at Lightbend (formerly Typesafe) is: @adriaanm, @lrytz, @retronym, @SethTisue, and @szeiger. +By the way, the team at Lightbend is: @adriaanm, @lrytz, @retronym, @SethTisue, and @szeiger. ## What kind of PR are you submitting? diff --git a/doc/LICENSE.md b/doc/LICENSE.md index 90bf842420..c56b38daa2 100644 --- a/doc/LICENSE.md +++ b/doc/LICENSE.md @@ -4,7 +4,7 @@ Scala is licensed under the [BSD 3-Clause License](http://opensource.org/license Copyright (c) 2002-2016 EPFL -Copyright (c) 2011-2016 Lightbend, Inc. (formerly Typesafe, Inc.) +Copyright (c) 2011-2016 Lightbend, Inc. All rights reserved. diff --git a/doc/License.rtf b/doc/License.rtf index 5e4403b69f..c8f24838a2 100644 --- a/doc/License.rtf +++ b/doc/License.rtf @@ -11,7 +11,7 @@ \fs40 \ \fs26 Copyright (c) 2002-2016 EPFL\ -Copyright (c) 2011-2016 Lightbend, Inc. (formerly Typesafe, Inc.)\ +Copyright (c) 2011-2016 Lightbend, Inc.\ All rights reserved.\ \ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\ diff --git a/src/scaladoc/scala/tools/nsc/doc/Settings.scala b/src/scaladoc/scala/tools/nsc/doc/Settings.scala index a63ed1abe8..9679a13e74 100644 --- a/src/scaladoc/scala/tools/nsc/doc/Settings.scala +++ b/src/scaladoc/scala/tools/nsc/doc/Settings.scala @@ -45,7 +45,7 @@ class Settings(error: String => Unit, val printMsg: String => Unit = println(_)) val docfooter = StringSetting ( "-doc-footer", "footer", - "A footer on every Scaladoc page, by default the EPFL/Typesafe copyright notice. Can be overridden with a custom footer.", + "A footer on every Scaladoc page, by default the EPFL/Lightbend copyright notice. Can be overridden with a custom footer.", "" ) diff --git a/src/scaladoc/scala/tools/nsc/doc/html/page/Template.scala b/src/scaladoc/scala/tools/nsc/doc/html/page/Template.scala index 9daca10e63..f70bac8f83 100644 --- a/src/scaladoc/scala/tools/nsc/doc/html/page/Template.scala +++ b/src/scaladoc/scala/tools/nsc/doc/html/page/Template.scala @@ -280,7 +280,7 @@ class Template(universe: doc.Universe, generator: DiagramGenerator, tpl: DocTemp { if (Set("epfl", "EPFL").contains(tpl.universe.settings.docfooter.value)) - + else } -- cgit v1.2.3