I am trying to start using the paradise macro plugin, so I have been beginning with the identity macro example from:
https://docs.scala-lang.org/overviews/macros/annotations.html
However, when I try to use the identity annotation I get
error: enable macro paradise to expand macro annotations
As you would expect if the plugin isn't loaded. However, I am following the instructions from
https://docs.scala-lang.org/overviews/macros/paradise.html
But when I invoke:
scalac -Xplugin:paradise_2.12.8-2.1.1.jar -Xshow-phases
I do not see the macroparadise phase:
phase name id description
---------- -- -----------
parser 1 parse source into ASTs, perform simple desugaring
namer 2 resolve names, attach symbols to named trees
packageobjects 3 load package objects
typer 4 the meat and potatoes: type the trees
patmat 5 translate match expressions
...
However, if I instead do
scalac -Xplugin:paradise_2.12.8-2.1.1.jar -Xplugin-list
I get
macroparadise - Empowers production Scala compiler with latest macro developments
So I really confused as to what step I'm missing here? Is there some new command-line argument I'm missing? Is using sbt required?
Related
Say I develop a package with a limited set of dependencies (for example, LinearAlgebra).
In the Unit testing part, I might need additional dependencies (for instance, CSV to load a file). I can configure that in the Project.toml all good.
Now from there and in VS Code, how can I debug the Unit tests? I tried running the "runtests.jl" in the debugger; however, it unsurprisingly complains that the CSV package is unavailable.
I could add the CSV package (as a temporary solution), but I would prefer that the debugger run with the configuration for the unit testing; how can I achieve that?
As requested, here is how it can be reproduced (it is not quite minimal, but instead I used a commonly used package as it give confidence the package is not the problem). We will use DataFrames and try to execute the debugger for its unit tests.
Make a local version of DataFrames for the purpose of developing a feature in it. I execute dev DataFrames in a new REPL.
Select the correct environment (in .julia/dev/DataFrames) through the VS-code user interface.
Execute the "proper" unit testing by executing test DataFrames at the pkg prompt. Everything should go smoothly.
Try to execute the tests directly (open the runtests.jl and use the "Run" button in vs-code). I see some errors of the type:
LoadError: ArgumentError: Package CategoricalArrays not found in current path:
- Run `import Pkg; Pkg.add("CategoricalArrays")` to install the CategoricalArrays package.
which is consistent with CategoricalArrays being present in the [extras] section of the Project.toml but not present in the [deps].
Finally, instead of the "Run" command, execute the "Run and Debug". I encounter similar errors here is the first one:
Test Summary: | Pass Total
merge | 19 19
PASSED: index.jl
FAILED: dataframe.jl
LoadError: ArgumentError: Package DataStructures not found in current path:
- Run `import Pkg; Pkg.add("DataStructures")` to install the DataStructures package.
So I can't debug the code after the part requiring the extras packages.
After all that I delete this package with the command free DataFrames at the pkg prompt.
I see the same behavior in my package.
I'm not certain I understand your question, but I think you might be looking for the TestEnv package. It allows you to activate a temporary environment containing the [extras] dependencies. The discourse announcement contains a good description of the use cases.
Your runtest.jl file should contain all necessary imports to run tests.
Hence you are expected to have in your runtests.jl file lines such as:
using YourPackageName
using CSV
# the lines with tests now go here.
This is a standard in Julia package layout. For an example have a look at any mature Julia such as DataFrames.jl (https://github.com/JuliaData/DataFrames.jl/blob/main/test/runtests.jl).
I have a file called Parser.fs with module Parser at the top of the file. It compiles. I have another module in the same directory, Main, that looks like this:
module Main
open Parser
let _ = //do stuff
I tried to compile Main.fs with $ fsharpc Main.fs (idk if there's another way to compile). The first error is module or namespace 'Parser' is not defined, all other errors are because of the fact that the functions in Parser are not in scope.
I don't know if it matters, but I did try compiling Main after Parser, and it still didn't work. What am I doing wrong?
F#, unlike Haskell, does not have separate compilation. Well, it does at the assembly level, but not at the module level. If you want both modules to be in the same assembly, you need to compile them together:
fsharpc Parser.fs Main.fs
Another difference from Haskell: order of compilation matters. If you reverse the files, it won't compile.
Alternatively, you could compile Parser into its own assembly:
fsharpc Parser.fs -o:Parser.dll
And then reference that assembly when compiling Main:
fsharpc Main.fs -r:Parser.dll
That said, I would recommend using an fsproj project file (analog of cabal file). Less headache, more control.
I have this scala code
object S extends App{
println("This is trait program")
}
When I execute scala S.scala it executes fine.
Now I want to know how can it execute code without compile and creating of class file.
Scala is a compiled language, and it needs to compile the code and the .class file is needed for execution.
Maybe you are thinking in using the REPL, where you can interactively code: https://www.scala-lang.org/documentation/getting-started.html#run-it-interactively
But, under the hood, the REPL is compiling your code, and executing the compiled .class
The command scala that you are launching is used to launch Scala REPL, and if you provide a file as an argument, it'll execute it will execute the content of the files as if it was bulk pasted in a REPL.
It's true that Scala is a compiled language, but it does not mean that a .class file is necessary. All that the Scala compiler needs to do is generate relevant JVM byte code and call JVM with that byte code. This does not mean that it explicitly has to create a .class file in directory from where you called it. It can do it all using memory and temporary storage and just call JVM with generated byte code.
If you are looking to explicitly generate class files with Scala that you can later execute by calling java manually, you should use Scala compiler CLI (command: scalac).
Please note that Scala compiler has interfaces to check and potentially compile Scala code on the fly, which is very useful for IDEs (checkout IntelliJ and Ensime).
Just call main() on the object (which inherits this method from App):
S.main(Array())
main() expects an Array[String], so you can just provide an empty array.
Scala is a compiled language in terms of source code to java bytecode transition, however some tricks may be taken to make it resemble an interpreted language. A naive implementation is that when run scala myscript.scala, it follows these steps:
scalac Myscript.scala. It generates S.class (which is the entry class that contains main method) and potentially other class files.
scala -cp . S. This runs/interprets from the main entry of the class
file. -cp . specifies the classpath; and S is the entry class without file extension .class. Note that run/interprets means interpreting (java) bytecode (rather than Scala/Java source code), which is done by JVM runtime.
Remove all the temporarily generated class files. This procedure is optional as long as the users are not aware of the temporary files (i.e., transparent to users).
That is to say, scala acts as a driver that may handle 0) initialization 1) compilation(scalac) 2) execute/run (scala) 3) cleanup.
The actual procedures may be different (e.g., due to performance concerns some files are only in memory/cached, or not generated, or not deleted, by using lower-level APIs of scala driver, etc.) but the general idea should be similar.
On Linux machines, you might find some evidences in /tmp folder. For me,
$ tree /tmp
/tmp
├── hsperfdata_hongxu
│ └── 64143
└── scala-develhongxu
├── output-redirects
│ ├── scala-compile-server-err.log
│ └── scala-compile-server-out.log
└── scalac-compile-server-port
└── 34751
4 directories, 4 files
It is also noteworthy that this way of running Scstepsala is not full-fledged. For example, package declarations are not supported.
# MyScript.scala
package hw
object S extends App {
println("Hello, world!")
}
And it emit error:
$ scala Myscript.scala
.../Myscript.scala:1: error: illegal start of definition
package hw
^
one error found
Others have also mentioned the REPL (read–eval–print loop), which is quite similar. Essentially, almost every language can have an (interactive) interpreter. Here is a text from wikipedia:
REPLs can be created to support any language. REPL support for compiled languages is usually achieved by implementing an interpreter on top of a virtual machine which provides an interface to the compiler. Examples of REPLs for compiled languages include CINT (and its successor Cling), Ch, and BeanShell
However interpreted languages (Python, Ruby, etc.) are typically superior due to their dynamic nature and runtime VMs/interpreters.
Additionally, the gap between compiled and interpreted is not that big. And you can see Scala actually has some interpreted features (at least it appears) since it makes you feel that you can execute like a script language.
Looking at http://www.scala-sbt.org/release/docs/Howto/scaladoc.html there are examples for giving scaladoc options such -groups and -implicits.
Where is the information regarding the scaladoc (2.10) options? Like a man page. I can't seem to find it, neither of docs.scala-lang.org, nor on wiki.scala-lang.org...
I don't use a Scala installation besides managed by sbt, so I really would like an online resource.
scaladoc -help gives:
Usage: scaladoc <options> <source files>
where possible scaladoc options include:
-diagrams Create inheritance diagrams for classes, traits and packages.
-diagrams-dot-path <path> The path to the dot executable used to generate the inheritance diagrams. Eg: /usr/bin/dot
-diagrams-dot-restart <n> The number of times to restart a malfunctioning dot process before disabling diagrams (default: 5)
-diagrams-dot-timeout <n> The timeout before the graphviz dot util is forcefully closed, in seconds (default: 10)
-diagrams-max-classes <n> The maximum number of superclasses or subclasses to show in a diagram
-diagrams-max-implicits <n> The maximum number of implicitly converted classes to show in a diagram
-doc-footer <footer> A footer on every ScalaDoc page, by default the EPFL/Typesafe copyright notice. Can be overridden with a custom footer.
-doc-format:<format> Selects in which format documentation is rendered (html) default:html
-doc-generator <class-name> The fully qualified name of a doclet class, which will be used to generate the documentation
-doc-no-compile <path> A directory containing sources which should be parsed, no more (e.g. AnyRef.scala)
-doc-root-content <path> The file from which the root package documentation should be imported.
-doc-source-url <url> A URL pattern used to build links to template sources; use variables, for example: ?{TPL_NAME} ('Seq'), ?{TPL_OWNER} ('scala.collection'), ?{FILE_PATH} ('scala/collection/Seq')
-doc-title <title> The overall name of the Scaladoc site
-doc-version <version> An optional version number, to be appended to the title
-expand-all-types Expand all type aliases and abstract types into full template pages. (locally this can be done with the #template annotation)
-groups Group similar functions together (based on the #group annotation)
-implicits Document members inherited by implicit conversions.
-implicits-hide:<implicit(s)> Hide the members inherited by the given comma separated, fully qualified implicit conversions. Add dot (.) to include default conversions.
-implicits-show-all Show members inherited by implicit conversions that are impossible in the default scope. (for example conversions that require Numeric[String] to be in scope)
-no-link-warnings Avoid warnings for ambiguous and incorrect links.
-no-prefixes Prevents generating prefixes in types, possibly creating ambiguous references, but significantly speeding up scaladoc.
-raw-output For each html file, create another .html.raw file containing only the text. (can be used for quickly diffing two scaladoc outputs)
-skip-packages <<package1>:...:<packageN>> A colon-delimited list of fully qualified package names that will be skipped from scaladoc.
Additional debug settings:
-diagrams-debug Show debugging information for the diagram creation process.
-implicits-debug Show debugging information for members inherited by implicit conversions.
Standard scalac options also available:
-Dproperty=value Pass -Dproperty=value directly to the runtime system.
-J<flag> Pass <flag> directly to the runtime system.
-P:<plugin>:<opt> Pass an option to a plugin
-X Print a synopsis of advanced options.
-bootclasspath <path> Override location of bootstrap class files.
-classpath <path> Specify where to find user class files.
-d <directory|jar> destination for generated classfiles.
-dependencyfile <file> Set dependency tracking file.
-deprecation Emit warning and location for usages of deprecated APIs.
-doc-external-doc:<external-doc> comma-separated list of classpath_entry_path#doc_URL pairs describing external dependencies.
-encoding <encoding> Specify character encoding used by source files.
-explaintypes Explain type errors in more detail.
-extdirs <path> Override location of installed extensions.
-external-urls:<externalUrl(s)> (deprecated) comma-separated list of package_names=doc_URL for external dependencies, where package names are ':'-separated
-feature Emit warning and location for usages of features that should be imported explicitly.
-g:<level> Set level of generated debugging info. (none,source,line,vars,notailcalls) default:vars
-help Print a synopsis of standard options
-implicits-sound-shadowing Use a sound implicit shadowing calculation. Note: this interacts badly with usecases, so only use it if you haven't defined usecase for implicitly inherited members.
-javabootclasspath <path> Override java boot classpath.
-javaextdirs <path> Override java extdirs classpath.
-language:<feature> Enable one or more language features.
-no-specialization Ignore #specialize annotations.
-nobootcp Do not use the boot classpath for the scala jars.
-nowarn Generate no warnings.
-optimise Generates faster bytecode by applying optimisations to the program
-print Print program with Scala-specific features removed.
-sourcepath <path> Specify location(s) of source files.
-target:<target> Target platform for object files. All JVM 1.5 targets are deprecated. (jvm-1.5,jvm-1.5-fjbg,jvm-1.5-asm,jvm-1.6,jvm-1.7,msil) default:jvm-1.6
-toolcp <path> Add to the runner classpath.
-unchecked Enable additional warnings where generated code depends on assumptions.
-uniqid Uniquely tag all identifiers in debugging output.
-usejavacp Utilize the java.class.path in classpath resolution.
-verbose Output messages about what the compiler is doing.
-version Print product version and exit.
#<file> A text file containing compiler arguments (options and source files)
Deprecated settings:
-make:<policy> Recompilation detection policy (all,changed,immediate,transitive,transitivenocp) default:all
deprecated: this option is unmaintained. Use sbt or an IDE for selective recompilation.
Beside from that I don't know of any other information sites. The only thing available for sure is the source code that contains all settings.
I am porting a 2.7.7 scala code base over to 2.8 and was wondering if there was a compiler option to display migration notices? I was bitten by a change in behavior for mutable sequences that had the following migration notice[1], however it doesn't display anything when I build the project ( I have deprecation and unchecked warnings enabled already)
1: #migration(2, 8,
"As of 2.8, this operation creates a new map. To add an element as a\n"+
"side effect to an existing map and return that map itself, use +=."
)
The option is: -Xmigration
Entering scalac -help will show the standard options of the Scala compiler.
Entering scalac -X will show the advanced options.
Entering scalac -Y will show the private options.
It's a extended option, -Xmigration.
~: scala -X
Usage: scala <options> <source files>
Possible advanced options include:
-Xassem-extdirs <dirs> List of directories containing assemblies, defaults to `lib'
-Xassem-name <file> Name of the output assembly (only relevant with -target:msil)
-Xassem-path <path> List of assemblies referenced by the program (only relevant with -target:msil)
-Xcheck-null Emit warning on selection of nullable reference
-Xcheckinit Add runtime checks on field accessors. Uninitialized accesses result in an exception being thrown.
-Xdisable-assertions Generate no assertions and assumptions
-Xelide-below Generate calls to #elidable-marked methods only if method priority is greater than argument.
-Xexperimental Enable experimental extensions
-Xfatal-warnings Fail the compilation if there are any warnings.
-Xfuture Turn on future language features
-Xgenerate-phase-graph <file> Generate the phase graphs (outputs .dot files) to fileX.dot
-Xlog-implicits Show more info on why some implicits are not applicable
-Xmigration Warn about constructs whose behavior may have changed between 2.7 and 2.8
-Xno-forwarders Do not generate static forwarders in mirror classes
-Xno-uescape Disables handling of \u unicode escapes
-Xnojline Do not use JLine for editing
-Xplugin-disable:<plugin> Disable a plugin
-Xplugin-list Print a synopsis of loaded plugins
-Xplugin-require:<plugin> Abort unless a plugin is available
-Xplugin:<file> Load a plugin from a file
-Xpluginsdir <path> Path to search compiler plugins
-Xprint-icode Log internal icode to *.icode files
-Xprint-pos Print tree positions (as offsets)
-Xprint-types Print tree types (debugging option)
-Xprint:<phase> Print out program after <phase> or "all"
-Xprompt Display a prompt after each error (debugging option)
-Xresident Compiler stays resident, files to compile are read from standard input
-Xscript <object> Compile as a script, wrapping the code into object.main()
-Xshow-class <class> Show class info
-Xshow-object <object> Show object info
-Xshow-phases Print a synopsis of compiler phases
-Xsource-reader <classname> Specify a custom method for reading source files
-Xsourcedir <directory> When -target:msil, the source folder structure is mirrored in output directory.
-Xwarninit Warn about possible changes in initialization semantics
-Y Print a synopsis of private options
% scala -X
Usage: scala <options> <source files>
Possible advanced options include:
...
-Xmigration Warn about constructs whose behavior may have changed between 2.7 and 2.8
...