summaryrefslogtreecommitdiff
path: root/src/repl/scala
Commit message (Collapse)AuthorAgeFilesLines
* Fields does bitmaps & synch for lazy vals & modulesAdriaan Moors2016-08-291-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Essentially, we fuse mixin and lazyvals into the fields phase. With fields mixing in trait members into subclasses, we have all info needed to compute bitmaps, and thus we can synthesize the synchronisation logic as well. By doing this before erasure we get better signatures, and before specialized means specialized lazy vals work now. Mixins is now almost reduced to its essence: implementing super accessors and forwarders. It still synthesizes accessors for param accessors and early init trait vals. Concretely, trait lazy vals are mixed into subclasses with the needed synchronization logic in place, as do lazy vals in classes and methods. Similarly, modules are initialized using double checked locking. Since the code to initialize a module is short, we do not emit compute methods for modules (anymore). For simplicity, local lazy vals do not get a compute method either. The strange corner case of constant-typed final lazy vals is resolved in favor of laziness, by no longer assigning a constant type to a lazy val (see widenIfNecessary in namers). If you explicitly ask for something lazy, you get laziness; with the constant-typedness implicit, it yields to the conflicting `lazy` modifier because it is explicit. Co-Authored-By: Lukas Rytz <lukas@lightbend.com> Fixes scala/scala-dev#133 Inspired by dotc, desugar a local `lazy val x = rhs` into ``` val x$lzy = new scala.runtime.LazyInt() def x(): Int = { x$lzy.synchronized { if (!x$lzy.initialized) { x$lzy.initialized = true x$lzy.value = rhs } x$lzy.value } } ``` Note that the 2.11 decoding (into a local variable and a bitmap) also creates boxes for local lazy vals, in fact two for each lazy val: ``` def f = { lazy val x = 0 x } ``` desugars to ``` public int f() { IntRef x$lzy = IntRef.zero(); VolatileByteRef bitmap$0 = VolatileByteRef.create((byte)0); return this.x$1(x$lzy, bitmap$0); } private final int x$lzycompute$1(IntRef x$lzy$1, VolatileByteRef bitmap$0$1) { C c = this; synchronized (c) { if ((byte)(bitmap$0$1.elem & 1) == 0) { x$lzy$1.elem = 0; bitmap$0$1.elem = (byte)(bitmap$0$1.elem | 1); } return x$lzy$1.elem; } } private final int x$1(IntRef x$lzy$1, VolatileByteRef bitmap$0$1) { return (byte)(bitmap$0$1.elem & 1) == 0 ? this.x$lzycompute$1(x$lzy$1, bitmap$0$1) : x$lzy$1.elem; } ``` An additional problem with the above encoding is that the `lzycompute` method synchronizes on `this`. In connection with the new lambda encoding that no longer generates anonymous classes, captured lazy vals no longer synchronize on the lambda object. The new encoding solves this problem (scala/scala-dev#133) by synchronizing on the lazy holder. Currently, we don't exploit the fact that the initialized field is `@volatile`, because it's not clear the performance is needed for local lazy vals (as they are not contended, and as soon as the VM warms up, biased locking should deal with that) Note, be very very careful when moving to double-checked locking, as this needs a different variation than the one we use for class-member lazy vals. A read of a volatile field of a class does not necessarily impart any knowledge about a "subsequent" read of another non-volatile field of the same object. A pair of volatile reads and write can be used to implement a lock, but it's not clear if the complexity is worth an unproven performance gain. (Once the performance gain is proven, let's change the encoding.) - don't explicitly init bitmap in bytecode - must apply method to () explicitly after uncurry
* Merge pull request #5306 from szeiger/issue/8576Stefan Zeiger2016-08-121-1/+1
|\ | | | | SI-8576 Minimal changes for `-Xcheckinit` compatibility
| * SI-8576 Minimal changes for `-Xcheckinit` compatibilityStefan Zeiger2016-08-121-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As explained in https://issues.scala-lang.org/browse/SI-8576, I expect serialization compatibility between builds with and without `-Xcheckinit` to be unattainable. This commit contains some minor fixes for issues discovered while running builds with `-Xcheckinit`: - Add `@SerialVersionUID` to `scala.collection.immutable.Vector`, as requested in SI-8576. Note that this does not make `Vector` serialization compatible. - Use lazy initialization for `global` in `PresentationCompilation`. It used to access the uninitialized `self` variable (which seems to be inconsequential in practice and only fails under `-Xcheckinit`). We should consider using `Externalizable` instead of `Serializable` for collections in 2.13 to make collection classes serialization compatible.
* | Merge pull request #5272 from som-snytt/issue/8829Adriaan Moors2016-08-112-0/+8
|\ \ | | | | | | SI-8829 Defaultly scala -feature -deprecation
| * | SI-8829 Let reporter customize retry messageSom Snytt2016-07-091-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | "Re-run with -deprecation" is not always appropriate. REPL gets to customize the message. The API includes the setting and its name, because reflect Settings do not have names. (!)
| * | SI-8829 Defaultly scala -feature -deprecationSom Snytt2016-07-081-0/+5
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Turn on `-feature -deprecation` in REPL if neither option is selected. ``` $ ./build/pack/bin/scala Welcome to Scala 2.12.0-20160707-105953-4e564ef (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_92). Type in expressions for evaluation. Or try :help. scala> @deprecated("","") def f = 42 f: Int scala> f toDouble <console>:13: warning: postfix operator toDouble should be enabled by making the implicit value scala.language.postfixOps visible. This can be achieved by adding the import clause 'import scala.language.postfixOps' or by setting the compiler option -language:postfixOps. See the Scaladoc for value scala.language.postfixOps for a discussion why the feature should be explicitly enabled. f toDouble ^ <console>:13: warning: method f is deprecated: f toDouble ^ res1: Double = 42.0 scala> :quit $ scala Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_92). Type in expressions for evaluation. Or try :help. scala> @deprecated("","") def f = 42 f: Int scala> f toDouble warning: there was one deprecation warning; re-run with -deprecation for details warning: there was one feature warning; re-run with -feature for details res1: Double = 42.0 ```
* / Reduce deprecations and warningsSimon Ochsenreither2016-08-021-5/+5
|/
* Merge branch '2.11.x' into 2.12.xAdriaan Moors2016-06-051-1/+4
|\
| * SI-7898 Preserve reader against subversionSom Snytt2016-06-041-1/+4
| | | | | | | | | | | | | | | | SBT tries to install its own SimpleReader (for some reason) if it needs to create its own IMain. Because Rube Goldberg needs to execute some postinit hooks, don't let SBT do that.
* | SI-9104 Autodetect raw pastageSom Snytt2016-06-022-21/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | If `-raw` is not supplied explicitly to REPL `:paste`, see if the code text starts with `package` keyword or else see if it parses to a named package (to cope with leading commentary). In that case, take it as raw. But parse only on suspect comment slash. It's only worth parsing for a package if there's a chance that package keyword is buried behind comments. Small refactors to the `paste` object.
* | Merge commit '90215ce' into merge-2.11-to-2.12-june-1Lukas Rytz2016-06-013-73/+241
|\|
| * SI-7898 Label for parsing -i sourcesLukas Rytz2016-05-241-1/+1
| | | | | | | | Text-based REPL pre-parses, so use the current label for errors.
| * SI-7898 Report paste errors improvedlySom Snytt2016-05-232-18/+27
| | | | | | | | | | | | | | | | Use a "label" for errors, so that script names are shown. Position is still wrong for scripts in REPL. Initial scripts are run with `ILoop.echo` and results printing turned off, but reporter still enabled.
| * SI-7898 Quiet REPL at startupSom Snytt2016-05-221-6/+18
| | | | | | | | Enable noisy modes only when interpreting user input.
| * SI-7898 Read user input during REPL warmupSom Snytt2016-05-202-56/+204
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The compiler is created on main thread and user input is read on an aux thread (opposite to currently). Fixes completion when `-i` is supplied. Now `-i` means pasted and new option `-I` means line-by-line. The temporary reader uses postInit to swap in the underlying reader. Completion is disabled for the temporary reader, rather than blocking while it waits for a compiler. But manically hitting tab is one way of knowing exactly when completion is live.
* | Add since arg to deprecationWarning and use itSimon Ochsenreither2016-05-291-1/+1
| |
* | Fully qualify types in REPL generated codeDale Wijnand2016-05-263-16/+18
| |
* | SI-7916: ScriptEngine supportSom Snytt2016-05-193-163/+385
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Refactor the ScriptEngine support to an adaptor atop the IMain API. Allow references to resolve to context attributes. (The attributes must be defined at compilation time, though they may resolve to updated values at evaluation time.) This means that attributes are not bound statically in REPL history. In particular, we forgo the trick of binding attributes named "name: Type" as typed values. Instead, an `x` bound in dynamic context is injected into the script as a dynamic selection `$ctx.x` where `ctx` performs the look-up in the script context. When a compiled script is re-evaluated, a new instance of the script class is created and defined symbols are rebound. The context stdout writer is handled with `Console.withOut`, with bytes decoded using the default charset. Compilation errors are thrown as ScriptException with the first reported error. This commit doesn't attempt dynamic selection from objects in context. Currently, script must cast.
* | Merge remote-tracking branch 'origin/2.11.x' into ↵Jason Zaugg2016-05-172-19/+25
|\| | | | | | | | | | | | | | | | | merge/2.11.x-to-2.12.x-20160517 Conflicts: build.sbt test/files/run/repl-javap-app.check test/files/run/repl-javap-app.scala
| * SI-9740 Repl import fix -Yrepl-class-basedSom Snytt2016-05-022-19/+25
| | | | | | | | | | | | | | Under `-Yrepl-class-based`, templating must follow the same scoping as under traditional object-based. The new test shows a typical case where two values of the same simple name must be imported in different scopes.
* | Add check to scala REPL package to improve feedback about implicits (#5159)Jens2016-05-131-4/+8
| | | | | | | | | | | | | | When the repl is started with additional compiler flags that prevent implicits being in scope (like -Yno-predef) the default message of implicits in scope using :implicits stays the same. This additional check will return the same message if predef is indeed in scope and an adjusted message if Predef is not in scope.
* | Merge pull request #5112 from lrytz/dropRecursiveClasspathJason Zaugg2016-05-052-27/+14
|\ \ | | | | | | Remove legacy recursive classpath implementation
| * | Remove abstraction layer in classpath implementationLukas Rytz2016-05-022-12/+11
| | |
| * | remove recursive classpath implementationLukas Rytz2016-04-231-16/+4
| | |
* | | Merge commit '684c314' into merge-2.11-to-2.12-apr-22Lukas Rytz2016-04-222-5/+13
|\ \ \ | |/ / |/| / | |/
| * SI-9734 Narrow type when import REPL history (#5084)som-snytt2016-04-201-1/+1
| | | | | | | | | | Under `-Yrepl-class-based`, imports from historical `$read` instances must be singleton-typed so that path-dependent types remain so.
| * SI-9735 REPL prefer standard escapes for code text (#5086)som-snytt2016-04-201-4/+12
| | | | | | | | | | When constructing code text for compilation, the REPL should prefer standard escape sequences, in case unicode escapes are disabled.
| * Apply some static code analysis recommendationsJanek Bogucki2015-11-262-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix a batch of code inspection recommendations generated by IntelliJ 14.1.5. Categories of fix, Unnecessary public modifier in interface Replace filter+size with count Replace filter+nonEmpty with exists Replace filter+headOption with find Replace `if (x != null) Some(x) else None` with Option(x) Replace getOrElse null with orNull Drop redundant semicolons Replace anon fun with PF Replace anon fun with method
* | SI-9749 REPL strip lead ws on dot continuation (#5097)som-snytt2016-04-151-7/+7
| | | | | | | | | | | | Permit leading whitespace before `.` for continued selection. This is just to handle pastes, which will typically include indented text, and not to make dot-continuation especially robust.
* | Remove references to trait impl classes, mostly in doc commentsLukas Rytz2016-04-071-2/+0
| |
* | Support :require when using the flat classpath representation.Lukas Rytz2016-03-221-2/+2
| | | | | | | | | | | | :require was re-incarnated in https://github.com/scala/scala/pull/4051, it seems to be used by the spark repl. This commit makes it work when using the flat classpath representation.
* | Enable flat classpath by defaultLukas Rytz2016-03-221-9/+25
| | | | | | | | | | | | | | Implements VirtualDirectoryFlatClassPath, which is required for the presentation compiler created for the repl's tab-completion. Various minor cleanups in the flat classpath implementation.
* | Fix some typos in `spec` documents and comments.Dongjoon Hyun2016-03-151-1/+1
| |
* | Remove unused imports and other minor cleanupsSimon Ochsenreither2015-12-1814-43/+29
| | | | | | | | | | | | | | | | | | | | - Language imports are preceding other imports - Deleted empty file: InlineErasure - Removed some unused private[parallel] methods in scala/collection/parallel/package.scala This removes hundreds of warnings when compiling with "-Xlint -Ywarn-dead-code -Ywarn-unused -Ywarn-unused-import".
* | Update some phase listsSimon Ochsenreither2015-11-251-10/+5
| |
* | Merge commit '8eb1d4c' into merge-2.11-to-2.12-nov-24Lukas Rytz2015-11-241-1/+1
|\|
| * Create shaded JLine in sbt buildStefan Zeiger2015-10-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Reusing parts of #4593, this commits adds two additional subprojects to the sbt build: - repl-jline, which is already used by the ant build, builds the part of the REPL that depends on JLine. The actual JLine depenency is moved to this project. - repl-jline-shaded uses JarJar to create a shaded version of repl-jline and jline.jar. Unlike the ant build, this setup does not use any circular dependencies. dist/mkBin puts all of quick/repl, quick/repl-jline and quick/repl-jline-shaded onto the classpath of build-sbt/quick/bin/scala. A future addition to the sbt build for building build-sbt/pack will have to put the generated classfiles into the correct JARs, mirroring the old structure.
* | Remove unneeded overrides from ReplGLobalSom Snytt2015-10-271-32/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | These seem to have been originally added as a basis for future REPL work, for instance moving away from textual code generation to using a custom typechecker to include definitions and imports from previous lines in scope. But until such work is started, lets remove the as-yet-uneeded customizations in the name of simplicity. (Original commits by Som Snytt, extended by Jason Zaugg to remove the custom typer.)
* | merge 2.11.x onto 2.12.x, Oct 16 2015Seth Tisue2015-10-162-16/+37
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | there were merge conflicts in the Eclipse config that I resolved with --ours. I invite @performantdata to submit a followup PR bringing the Eclipse stuff into a good state on 2.12.x. there was a test failure in test/junit/scala/collection/mutable/OpenHashMapTest.scala due to the 2.12 compiler emitting the field backing a private var differently (with an unmangled name). Lukas says the difference is expected, so I just updated the code in the test. there were no other merge conflicts. % git log --decorate --oneline -1 origin/2.11.x | cat ae5f0de (origin/HEAD, origin/2.11.x) Merge pull request #4791 from performantdata/issue/9508 % git log --decorate --oneline -1 origin/2.12.x | cat c99e53e (HEAD -> 2.12.x, origin/2.12.x) Merge pull request #4797 from lrytz/M3-versions % export MB=$(git merge-base 2.12.x origin/2.11.x) % echo $MB 42cafa21f3c4a08c6dd34608278f810b6ec2886f % git log --graph --oneline --decorate $MB...origin/2.11.x | cat * ae5f0de (origin/HEAD, origin/2.11.x) Merge pull request #4791 from performantdata/issue/9508 |\ | * 08dca37 (origin/pull/4791) SI-9508 fix classpaths in Eclipse configuration * | fe76232 Merge pull request #4798 from performantdata/issue/9513 |\ \ | * | 9c97a7f (origin/pull/4798) Suppress unneeded import. | * | 30d704d Document some OpenHashMap internal methods. | * | 1fb32fc SI-9513 decrement "deleted" count in OpenHashMap.put() when slot reused | |/ * | 14f875c Merge pull request #4788 from dk14/patch-1 |\ \ | * | 42acd55 (origin/pull/4788) explicitly specify insertion-order feature in docs | / * | 68ce049 Merge pull request #4771 from som-snytt/issue/9492-here |\ \ | * | f290962 (origin/pull/4771) SI-9492 Line trimming paste | * | bc3589d SI-9492 REPL paste here doc | / * | 9834fc8 Merge pull request #4610 from todesking/spec-implicits-remove-obsolete |\ \ | * | 46009b1 (origin/pull/4610) Add view/context-bound parameter ordering rule | * | 6eba305 Spec: Implicit parameters with context/view bound is allowed since 2.10 | / * | d792e35 Merge pull request #4789 from janekdb/2.11.x-param-names-predicates-operations |\ \ | |/ |/| | * b19a07e (origin/pull/4789) Rename forall, exists and find predicate and operator params. |/ * 648c7a1 Merge pull request #4790 from SethTisue/issue/9501 |\ | * 40d12f1 (origin/pull/4790) SI-9501 link README to Scala Hacker Guide * e0b5891 Merge pull request #4786 from performantdata/issue/9506 * 39acad8 (origin/pull/4786) SI-9506 suppress Scala IDE-generated files in the Eclipse project dirs * 74dc364 SI-9506 suppress Scala IDE-generated files in the Eclipse project dirs % git merge ae5f0de Auto-merging src/repl/scala/tools/nsc/interpreter/ILoop.scala Auto-merging src/library/scala/util/Either.scala Auto-merging src/library/scala/runtime/Tuple3Zipped.scala Auto-merging src/library/scala/runtime/Tuple2Zipped.scala Auto-merging src/library/scala/collection/parallel/ParIterableLike.scala Auto-merging src/library/scala/collection/immutable/ListMap.scala Auto-merging src/library/scala/collection/TraversableLike.scala Auto-merging src/eclipse/test-junit/.classpath CONFLICT (content): Merge conflict in src/eclipse/test-junit/.classpath Auto-merging src/eclipse/scaladoc/.classpath CONFLICT (content): Merge conflict in src/eclipse/scaladoc/.classpath Auto-merging src/eclipse/scala-compiler/.classpath Auto-merging src/eclipse/repl/.classpath CONFLICT (content): Merge conflict in src/eclipse/repl/.classpath Auto-merging src/eclipse/partest/.classpath CONFLICT (content): Merge conflict in src/eclipse/partest/.classpath Auto-merging src/eclipse/interactive/.classpath Auto-merging README.md Automatic merge failed; fix conflicts and then commit the result. % git checkout --ours src/eclipse/partest/.classpath % git checkout --ours src/eclipse/repl/.classpath % git checkout --ours src/eclipse/scaladoc/.classpath % git checkout --ours src/eclipse/test-junit/.classpath % git add -u % emacs test/junit/scala/collection/mutable/OpenHashMapTest.scala % git diff test/junit/scala/collection/mutable/OpenHashMapTest.scala | cat ... - val field = m.getClass.getDeclaredField("scala$collection$mutable$OpenHashMap$$deleted") + val field = m.getClass.getDeclaredField("deleted") ... % git add -u
| * SI-9492 Line trimming pasteSom Snytt2015-09-272-3/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Use `-` stripmargin character to indicate trim (i.e. remove leading indentation). `<<` looks more like shift left, but is already the standard here doc sequence. Indentation is often mangled by pasting, so trimming normalizes lines for error messages. The entire paste text was already trimmed as a whole. `-Dscala.repl.here` provides a default end string, which is unset unless specified. ``` scala> :pa <- // Entering paste mode (ctrl-D to finish) def g = 10 def f! = 27 -- // Exiting paste mode, now interpreting. <console>:2: error: '=' expected but identifier found. def f! = 27 ^ ```
| * SI-9492 REPL paste here docSom Snytt2015-09-271-16/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Simple here documentish syntax for REPL paste. This makes it easier to paste a block of script (as opposed to transcript). It also means you won't accidentally ctl-D out of the REPL and then out of SBT and then out of the terminal window. ``` scala> :paste < EOF // Entering paste mode (EOF to finish) class C { def c = 42 } EOF // Exiting paste mode, now interpreting. defined class C scala> new C().c res0: Int = 42 scala> :paste <| EOF // Entering paste mode (EOF to finish) |class D { def d = 42 } EOF // Exiting paste mode, now interpreting. defined class D scala> new D().d res1: Int = 42 scala> :quit ```
* | Merge commit 'bb3ded3' into merge-2.11-to-2.12-oct-5Lukas Rytz2015-10-051-1/+1
|\|
| * Support completion in erroneous string interpolation.Jason Zaugg2015-09-241-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In the code: ``` s"${fooo<CURSOR" ``` The parser treats `fooo` as a interpolator ID for the quote that we actually intend to end the interpolated string. Inserting a space (in addition to `__CURSOR__` that we already patch in to avoid parsing a partial identifier as a keyword), solves this problem.
* | Remove the old REPL tab completion implementationJason Zaugg2015-09-236-513/+5
| | | | | | | | | | We kept it around behind an option in 2.11.x, but we can jettison it in 2.12.x.
* | Merge commit '03aaf05' into merge-2.11-to-2.12-sep-22Lukas Rytz2015-09-229-123/+405
|\|
| * Remove used param and document positionDeltaJason Zaugg2015-09-212-3/+3
| |
| * Hide some completion candidates on the first TABJason Zaugg2015-09-091-4/+15
| | | | | | | | | | | | When `foo.<TAB>`, assume you don't want to see the inherited members from Any_ and universally applicable extension methods like `ensuring`. Hitting <TAB> a second time includes them in the results.
| * Fix completion for multi-line entriesJason Zaugg2015-09-093-16/+20
| | | | | | | | | | | | | | | | | | We need to include the previously entered lines into the code that we presentation compile. Management of this state makes the interpret method non tail recursive, so we could blow the default stack with a multi-line entry of hundreds of lines. I think thats an acceptable limitation.
| * Camel Case and JavaBean completionJason Zaugg2015-09-081-7/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is just too useful to leave on the cutting room floor. ``` scala> classOf[String].enclo<TAB> scala> classOf[String].getEnclosing getEnclosingClass getEnclosingConstructor getEnclosingMethod scala> classOf[String].simpl<TAB> scala> classOf[String].getSimpleName type X = global.TTWD<TAB> scala> type X = global.TypeTreeWithDeferredRefCheck ``` I revised the API of `matchingResults` as it was clunky to reuse the filtering on accessibility and term/type-ness while providing a custom name matcher.
| * Sort completion proposalsJason Zaugg2015-09-031-1/+1
| |