summaryrefslogtreecommitdiff
path: root/src/repl
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #5402 from som-snytt/issue/8040-unusedSeth Tisue2017-04-102-8/+8
|\ | | | | SI-8040 Improve unused warnings
| * SI-8040 No warn args to super, main argsSom Snytt2017-03-111-6/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | `class B(x: X) extends A(x)` uses `x` in ctor, where it is detectable as an ordinary param. `implicit class C(val s: String)` may not use `s` in extension methods, so don't warn. Don't warn required args to main method. Don't warn about synthetic isDefinedAt in anonymous functions, or about defaultCase$.
| * SI-8040 Warn unused pattern varsSom Snytt2017-03-111-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | Warn for unused `case X(x) =>` but, as an escape hatch, not for `case X(x @ _) =>`. The latter form is deemed documentary. (Named args could serve a similar purpose, `case X(x = _) =>`.) An attachment is used to mark the bound var, and the symbol position is used to correlate the identifier with the variable that is introduced. This mechanism doesn't work yet when only a single var is defined.
* | SI-10226 REPL handles paste when colorizedSom Snytt2017-03-142-5/+4
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Colorization or Colourisation tripped up REPL on paste. Prompt detection should use the plain text prompt, not the ansified prompt. Manual test since .flags doesn't like it: ``` $ ./build/pack/bin/scala -Dscala.repl.prompt="%nhello > " Welcome to Scala 2.12.2-20170314-033334-d0c2620 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_111). Type in expressions for evaluation. Or try :help. hello > 42 res0: Int = 42 hello > hello > 42 // Detected repl transcript. Paste more, or ctrl-D to finish. hello > "wtf?" // Replaying 2 commands from transcript. hello > 42 res1: Int = 42 hello > "wtf?" res2: String = wtf? hello > ```
* Revert "SI-10133 Require escaped single quote char lit"Adriaan Moors2017-02-213-22/+53
|
* SD-256 enable colored output by default on unixAntoine Gourlay2017-02-211-1/+1
| | | | | | | | | `scala.color` now has 3 states: `true`, `false` and `auto` (the default). `auto` allows colors if not on windows and if the shell is interactive (as in, both stdin and stdout are a tty). The autodetect works as expected when run via SBT too, and it can always be overriden on the CLI or via JAVA_OPTS.
* Merge pull request #5640 from optimizely/repl-import-handlerAdriaan Moors2017-02-202-15/+32
|\ | | | | SI-9881 Fix ImportHandler's reporting of importedNames and importedSymbols
| * Fix ImportHandler's reporting of importedNames and importedSymbolsHao Xia2017-01-112-15/+32
| |
* | Merge pull request #5629 from som-snytt/issue/10120-quote-errAdriaan Moors2017-02-203-53/+22
|\ \ | | | | | | SI-10133 Require escaped single quote char lit
| * | SI-10120 ReplReporter handles message indentSom Snytt2017-01-183-53/+22
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Instead of indenting source code to make messages align on output, let the reporter add indentation, only if the source is the console (and not a pastie or a loaded file). Previously, syntax errors were not indented. ``` $ skala Welcome to Scala 2.12.2-20170108-010722-939abf1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_111). Type in expressions for evaluation. Or try :help. scala> 'abc' <console>:1: error: unclosed character literal (or use " for string literal "abc") 'abc' ^ scala> :quit $ scala Welcome to Scala 2.12.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_111). Type in expressions for evaluation. Or try :help. scala> 'abc' <console>:1: error: unclosed character literal 'abc' ^ ```
* | Merge pull request #5707 from retronym/topic/java9-prepareLukas Rytz2017-02-201-1/+1
|\ \ | | | | | | More groundwork for JDK 9 support
| * | Avoid ambiguous overload on JDK 9Jason Zaugg2017-02-161-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The addition of this method in `CharBuffer` CharBuffer position(int newPosition) renders an ambiguity in: ``` scala> (b: java.nio.CharBuffer) => b.position <console>:12: error: ambiguous reference to overloaded definition, both method position in class CharBuffer of type (x$1: Int)java.nio.CharBuffer and method position in class Buffer of type ()Int match expected type ? (b: java.nio.CharBuffer) => b.position ``` Manually applying the empty params avoids this.
* | | EOL is System.lineSeparatorSom Snytt2017-02-131-3/+3
|/ / | | | | | | | | | | The old EOL is EOL. Use `println()` when feasible and obvious. Minor cleanup of surrounding code.
* | Merge pull request #5647 from som-snytt/issue/10130Adriaan Moors2017-02-071-1/+1
|\ \ | | | | | | SI-10130 Ignore extra parse warnings
| * | SI-10130 Ignore extra parse warningsSom Snytt2017-01-161-1/+1
| |/ | | | | | | | | | | Don't emit warnings when parsing to test for complete input. The warnings will show up in the templated code.
* / SI-8662 Repl completionsSom Snytt2017-01-282-56/+141
|/ | | | | | Support command completions with a completer that delegates to a colon command completer, which either completes the command or completes a filename.
* Support extra module references in the REPLJason Zaugg2016-12-122-4/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | By default, scala-compiler.jar is in the bootclasspath, which gives us a `null` when we call `classOf[IMain].getClassLoader`. That value is used as the parent class loader of the classloader that evals code in the REPL. Under JDK9, this breaks lookup of classes on the module path: ``` scala -J--add-modules=java.compiler -J--add-exports=jdk.jdeps/com.sun.tools.javap=ALL-UNNAMED Welcome to Scala 2.12.1 (Java HotSpot(TM) 64-Bit Server VM, Java 9-ea). Type in expressions for evaluation. Or try :help. scala> new com.sun.tools.javap.JavapTask(); java.lang.NoClassDefFoundError: com/sun/tools/javap/JavapTask at java.base/java.lang.Class.getDeclaredMethods0(Native Method) at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:2948) ``` A workaround is to use `-nobootcp`. This commit uses the system classloader as the parent in place of the null classloader to make this work in both cases. ``` qscala -J--add-modules=java.compiler -J--add-exports=jdk.jdeps/com.sun.tools.javap=ALL-UNNAMED Welcome to Scala 2.12.2-20161208-165912-3de1c0c (Java HotSpot(TM) 64-Bit Server VM, Java 9-ea). Type in expressions for evaluation. Or try :help. scala> new com.sun.tools.javap.JavapTask(); res0: com.sun.tools.javap.JavapTask = com.sun.tools.javap.JavapTask@1f1cddf3 scala> ``` Note that the `:javap` command still requires `-nobootcp` because code in the REPL implements an interface in a the `java.compiler` module.
* Support inlining under -Yrepl-class-based REPLJason Zaugg2016-11-281-1/+1
| | | | | | | By marking the wrapper classes as sealed, the inliner will be able to assume finality of defs introduces in the REPL without requiring the user to mark them as `final`, which is an odd thing to do in single line of REPL input.
* SI-8779 Enable inlining of code within a REPL sessionJason Zaugg2016-11-281-0/+13
| | | | | | | | | | | | | | | | | | | | | The REPL has a long running instance of Global which outputs classfiles by default to a VirtualDirectory. The inliner did not find any of these class files when compiling calls to methods defined in previous runs (ie, previous lines of input.) This commit: - Adds a hook to augment the classpath that the optimizer searches, and uses this in the REPL to add the output directory - Fixes the implementation of `findClassFile` in VirtualDirectory, which doesn't seem to have been used in anger before. I've factored out some common code into a new method on `AbstractFile`. - Fixes a similar problem getSubDir reported by Li Haoyi - Adds missing unit test coverage. This also fixes a bug in REPL autocompletion for types defined in packages >= 2 level deep (with the `:paste -raw` command). I've added a test for this case.
* Typo and spelling correctionsJanek Bogucki2016-11-112-2/+2
|
* assorted typo fixes, cleanup, updating of commentsSeth Tisue2016-10-241-1/+1
| | | | | | just in time for Halloween. "boostrap" is definitely the most adorable typo evah -- and one of the most common, too. but we don't want to scare anybody.
* No warn when discarding r.f(): r.typeSom Snytt2016-09-101-5/+1
| | | | | | | | | | The paradigm is `def add(x: X): Unit = listBuffer += x`. The value that is discarded is not new information. Also cleans up the recent tweaks to help messaging. Adds newlines in case they ask for multiple helps.
* 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