scalac(1)

πŸ“¦
version 2.11.12 Β· 2 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ NAME ✨

okay so bestie, this is the manual page for scalac β€” the compiler for the Scala 2 language. she lives under USER COMMANDS, and she is that girl. πŸ’…

πŸ¦‹ SYNOPSIS πŸ¦‹

scalac  [ <options> ] <source files>

🌸 PARAMETERS 🌸

  • <options> β€” command line options. peep OPTIONS below, bestie.
  • <source files> β€” one or more source files to be compiled (such as MyClass.scala). yes, she can take multiple. πŸ’–

πŸŽ€ DESCRIPTION πŸŽ€

The scalac tool reads class and object definitions, written in the Scala programming language, and compiles them into bytecode class files. no cap, that's the whole job.

By default, the compiler puts each class file in the same directory as its source file. You can specify a separate destination directory with -d (see OPTIONS, below). lowkey iconic.

πŸ‘‘ OPTIONS πŸ‘‘

The compiler has a set of standard options that are supported on the current development environment and will be supported in future releases. An additional set of non-standard options are specific to the current virtual machine implementation and are subject to change in the future. Non-standard options begin with -X. periodt.

πŸ’– Standard Options πŸ’–

  • -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 (where to find the standard built-in classes, such as "scala.List").
  • -classpath <path> β€” Specify where to find user class files (on Unix-based systems a colon-separated list of paths, on Windows-based systems, a semicolon-separated list of paths). This does not override the built-in ("boot") search path.

The default class path is the current directory. Setting the CLASSPATH variable or using the -classpath command-line option overrides that default, so if you want to include the current directory in the search path, you must include "." in the new settings. do not forget the dot, bestie, I am begging. πŸ’€

  • -d <directory|jar> β€” Specify where to place generated class files.
  • -deprecation β€” Emit warning and location for usages of deprecated APIs.

Available since Scala version 2.2.1.

  • -encoding <encoding> β€” Specify character encoding used by source files.

The default value is platform-specific (Linux: "UTF8", Windows: "Cp1252"). Executing the following code in the Scala interpreter will return the default value on your system:

scala> new java.io.InputStreamReader(System.in).getEncoding
  • -explaintypes β€” Explain type errors in more detail.
  • -extdirs <dirs> β€” Override location of installed extensions.
  • -feature β€” Emit warning and location for usages of features that should be imported explicitly.
  • -g:{none,source,line,vars,notailcalls} β€” controls debug info:
    • "none" generates no debugging info,
    • "source" generates only the source file attribute,
    • "line" generates source and line number information,
    • "vars" generates source, line number and local variable information,
    • "notailcalls" generates all of the above and will not perform tail call optimization.
  • -help β€” Print a synopsis of standard options.
  • -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 jar files.
  • -nowarn β€” Generate no warnings.
  • -optimise β€” Generates faster bytecode by applying optimisations to the program.
  • -print β€” Print program with all Scala-specific features removed.
  • -sourcepath <path> β€” Specify location(s) of source files.
  • -target:{jvm-1.5,jvm-1.6,jvm-1.7,jvm-1.8} β€” choose target JVM:
    • "jvm-1.5" target JVM 1.5 (deprecated),
    • "jvm-1.6" target JVM 1.6 (default),
    • "jvm-1.7" target JVM 1.7,
    • "jvm-1.8" target JVM 1.8,
  • -toolcp <path> β€” Add to the runner classpath.
  • -unchecked β€” Enable detailed unchecked (erasure) warnings.

Non variable type-arguments in type patterns are unchecked since they are eliminated by erasure.

Available since Scala version 2.3.0.

  • -uniqid β€” Uniquely tag all identifiers in debugging output.
  • -usejavacp β€” Utilize the java.class.path in classpath resolution.
  • -usemanifestcp β€” Utilize the manifest 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).

πŸ”₯ Advanced Options πŸ”₯

  • -Xcheckinit β€” Wrap field accessors to throw an exception on uninitialized access.
  • -Xdev β€” Enable warnings for developers working on the Scala compiler.
  • -Xdisable-assertions β€” Generate no assertions and assumptions.
  • -Xelide-below <n> β€” Calls to @elidable methods are omitted if method priority is lower than argument.
  • -Xexperimental β€” Enable experimental extensions.
  • -Xfatal-warnings β€” Fail the compilation if there are any warnings.
  • -Xfull-lubs β€” Retain pre 2.10 behavior of less aggressive truncation of least upper bounds.
  • -Xfuture β€” Turn on future language features.
  • -Xgenerate-phase-graph <file> β€” Generate the phase graphs (outputs .dot files) to fileX.dot.
  • -Xlint β€” Enable recommended additional warnings.
  • -Xlog-free-terms β€” Print a message when reification creates a free term.
  • -Xlog-free-types β€” Print a message when reification resorts to generating a free type.
  • -Xlog-implicit-conversions β€” Print a message whenever an implicit conversion is inserted.
  • -Xlog-implicits β€” Show more detail on why some implicits are not applicable.
  • -Xlog-reflective-calls β€” Print a message when a reflective method call is generated.
  • -Xmacro-settings:<option> β€” Custom settings for macros.
  • -Xmain-class <path> β€” Class for manifest's Main-Class entry (only useful with -d <jar>).
  • -Xmax-classfile-name <n> β€” Maximum filename length for generated classes.
  • -Xmigration:<version> β€” Warn about constructs whose behavior may have changed since<version>.
  • -Xno-forwarders β€” Do not generate static forwarders in mirror classes.
  • -Xno-patmat-analysis β€” Don't perform exhaustivity/unreachability analysis. Also, ignore @switch annotation.
  • -Xno-uescape β€” Disable handling of \u unicode escapes.
  • -Xnojline β€” Do not use JLine for editing.
  • -Xplugin:<paths> β€” Load a plugin from each classpath.
  • -Xplugin-disable:<plugin> β€” Disable plugins by name.
  • -Xplugin-list β€” Print a synopsis of loaded plugins.
  • -Xplugin-require:<plugin> β€” Abort if a named plugin is not loaded.
  • -Xpluginsdir <path> β€” Path to search for plugin archives.
  • -Xprint:<phases> β€” Print out program after <phases> (see below).
  • -Xprint-icode[:<phases>] β€” Log internal icode to *.icode files after <phases> (default: icode).
  • -Xprint-pos β€” Print tree positions, as offsets.
  • -Xprint-types β€” Print tree types (debugging option).
  • -Xprompt β€” Display a prompt after each error (debugging option).
  • -Xresident β€” Compiler stays resident, files to compile are read from standard input.
  • -Xscript <object> β€” Treat the source file as a script and wrap it in a main method.
  • -Xshow-class <class> β€” Show internal representation of class.
  • -Xshow-object <object> β€” Show internal representation of object.
  • -Xshow-phases β€” Print a synopsis of compiler phases.
  • -Xsource:<version> β€” Treat compiler input as Scala source for the specified version, see SI-8126.
  • -Xsource-reader <classname> β€” Specify a custom method for reading source files.
  • -Xstrict-inference β€” Don't infer known-unsound types.
  • -Xverify β€” Verify generic signatures in generated bytecode (asm backend only).
  • -Xxml:{coalescing} β€” Configure XML parsing.

"coalescing" convert PCData to Text and coalesce sibling nodes (default in 2.11).

  • -Y β€” Print a synopsis of private options.

🌈 Compilation Phases 🌈

  • parser β€” parse source into ASTs, perform simple desugaring.
  • namer β€” resolve names, attach symbols to named trees.
  • packageobjects β€” load package objects.
  • typer β€” the meat and potatoes: type the trees.
  • patmat β€” translate match expressions.
  • superaccessors β€” add super accessors in traits and nested classes.
  • extmethods β€” add extension methods for inline classes.
  • pickler β€” serialize symbol tables.
  • refchecks β€” reference/override checking, translate nested objects.
  • selectiveanf β€” ANF pre-transform for @cps (CPS plugin).
  • selectivecps β€” @cps-driven transform of selectiveanf assignments (CPS plugin).
  • uncurry β€” uncurry, translate function values to anonymous classes.
  • tailcalls β€” replace tail calls by jumps.
  • specialize β€” @specialized-driven class and method specialization.
  • explicitouter β€” this refs to outer pointers, translate patterns.
  • erasure β€” erase types, add interfaces for traits.
  • posterasure β€” clean up erased inline classes.
  • lazyvals β€” allocate bitmaps, translate lazy vals into lazified defs.
  • lambdalift β€” move nested functions to top level.
  • constructors β€” move field definitions into constructors.
  • flatten β€” eliminate inner classes.
  • mixin β€” mixin composition.
  • cleanup β€” platform-specific cleanups, generate reflective calls.
  • delambdafy β€” remove lambdas.
  • icode β€” generate portable intermediate code.
  • inliner β€” optimization: do inlining.
  • inlineHandlers β€” optimization: inline exception handlers.
  • closelim β€” optimization: eliminate uncalled closures.
  • constopt β€” optimization: optimize null and other constants.
  • dce β€” optimization: eliminate dead code.
  • jvm β€” generate JVM bytecode.
  • terminal β€” the last phase in the compiler chain.
  • all β€” matches all phases.

🌸 ENVIRONMENT 🌸

okay bestie, before we get into the environment vars, just know that these are the lil knobs and dials that control how scalac actually runs the JVM underneath. super important, lowkey underrated. let's go πŸ’…

  • JAVACMD β€” this one tells everything which java command to use when it runs your Scala code. and get this β€” you can put arguments right in there too! spaces, quotation marks, all of it? it just gets passed straight to the shell for expansion. so like, whatever you'd type in a shell, it'll figure out. slay. ✨
  • JAVA_HOME β€” points at the JDK/JRE home directory. this is where it goes looking for the java command... unless you already set JAVACMD, in which case that one wins. so JAVA_HOME is the backup plan, the understudy, the girl who steps in when the main character isn't there. 🫢
  • JAVA_OPTS β€” the options you wanna pass to the java command that JAVACMD points to. this is where you get to flex. for real, if you're on Java 1.5 or newer you can set up the JVM's memory usage like this:
JAVA_OPTS="-Xmx512M -Xms16M -Xss16M"

✨ EXAMPLES ✨

bestie these are the receipts, the actual copy-paste-able goodness. go wild:

Compile a Scala program to the current directory

scalac HelloWorld

Compile a Scala program to the destination directory classes

scalac -d classes HelloWorld.scala

Compile a Scala program using a user-defined java command

env JAVACMD=/usr/local/bin/cacao scalac -d classes
HelloWorld.scala

Compile all Scala files found in the source directory src to the destination directory classes

scalac -d classes src/*.scala
notice that last one uses src/*.scala and not just src/ β€” the shell's doing the globbing, not scalac, iykyk. 🐚

πŸ’€ EXIT STATUS πŸ’€

okay so here's the vibe check on how scalac tells you if it ate or not:

scalac returns a zero exit status if it succeeds to compile the specified input files. (yes, the original says "exist status," we're all just gonna hold hands and move past it πŸ™ˆ). and if it fails? non zero comes back at you. no in-between, no ambiguity, it's giving very decisive. πŸ’…


πŸ‘‘ AUTHOR πŸ‘‘

Written by Martin Odersky and other members of the Scala team. iconic behavior fr fr, the literal founding fathers of the language. we stan. 🌈


πŸ› REPORTING BUGS πŸ›

found something cursed? Report bugs to https://issues.scala-lang.org/. do it, bestie, the maintainers wanna know. 🫢


This is open-source software, available to you under a BSD-like license. See accompanying "copyright" or "LICENSE" file for copying conditions.

and this part is serious so I'm saying it straight: There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. like, none. zero. not a crumb. 😭


πŸ¦‹ SEE ALSO πŸ¦‹


that's the whole page bestie, you made it to the end, main character energy only. this was version 1.0, dated March 2012, and it's the scalac(1) page β€” go forth and compile something gorgeous. periodt. πŸ’–βœ¨

πŸ“¦ where this page comes from