Commit Graph

1370 Commits

Author SHA1 Message Date
Alexander Udalov 8c21ff66a4 Always treat all sources as parts of the module being compiled
If a path to the module-info.java file is passed as an argument, we
should treat all other source files passed as arguments (either as
individual source files or inside a source directory) as members of that
module. Previously we treated other source files as members of the
unnamed module, and this resulted in incorrect errors when using a
member exported with a qualification from another named module, for
example

 #KT-18598 In Fixed
2017-06-29 15:59:57 +03:00
Alexander Udalov 72f37a278c Do not add all modules from module path when compiling unnamed module
Note that javac reports a nice error in this case ("package foo is
declared in module lib, which is not in the module graph"), but we only
report "unresolved reference" because the corresponding modules are not
added to classpath roots. We should improve this in the future

 #KT-18598 In Progress
2017-06-29 15:59:57 +03:00
Alexander Udalov 2d3888c710 Do not add JDK .jar roots if the JDK is modular (9+)
Files like ant-javafx.jar, deploy.jar, java.jnlp.jar, javafx-swt.jar etc
should not be added to the classpath if JDK home points to a JDK 9
distribution
2017-06-29 15:59:57 +03:00
Alexander Udalov 03d83db660 Support -Xmodule-path and -Xadd-modules command line arguments
#KT-18598 In Progress
 #KT-18599 Fixed
2017-06-29 15:59:56 +03:00
Alexander Udalov e32880d9a3 Implement Java 9 module visibility checks
In this commit, only IDE tests are added, because we look for module
declarations in the IDE across the whole project, whereas in the
compiler we should do this on the module path only and that requires
separate work (KT-18599) which is done in the following commits.

(The change in Cache.kt is needed so that
JvmModuleAccessibilityChecker.ClassifierUsage, which is an inner class,
would be injected properly.)

 #KT-18598 In Progress
 #KT-18599 In Progress
2017-06-29 15:59:56 +03:00
Alexander Udalov 2275068c94 Introduce JavaModule, refactor module graph construction
#KT-18598 In Progress
 #KT-18599 In Progress
2017-06-29 15:59:56 +03:00
vitaly.khudobakhshov d165ea9ea7 Add expression type string to the REPL API
PR-1131
2017-06-27 11:28:40 +02:00
Alexey Andreev a0e1bde594 Allow to embed source files into JS source maps 2017-06-26 18:15:28 +03:00
Alexander Udalov fd0658e0f4 Minor, inline unneeded JvmDependenciesIndexFactory 2017-06-26 16:22:05 +03:00
Alexander Udalov 0e2e3b3e65 Cleanup KotlinCoreEnvironment and usages
Remove unused API, weaken declaration visibility, reformat
2017-06-26 16:22:05 +03:00
Alexander Udalov 999e4cda1d Compute module mappings eagerly in JvmPackagePartProvider, refactor
Previously we traversed all notLoadedRoots on each request for package
parts with the given package FQ name. Since notLoadedRoots might contain
a lot of roots (which never transition into "loadedModules" because e.g.
they are not Kotlin libraries, but just Java libraries or SDK roots with
the META-INF directory), this was potentially hurting performance. It
seems it's more optimal to compute everything eagerly once
JvmPackagePartProvider is constructed.

Another problem with the previous version of JvmPackagePartProvider was
that it did not support "updateable classpath" which is used by REPL and
kapt2, it only used the initial roots provided in the
CompilerConfiguration. In REPL specifically, we would thus fail to
resolve top-level callables from libraries which were dynamically added
to the execution classpath (via some kind of a @DependsOn annotation).
In the new code, JvmPackagePartProvider no longer depends on
CompilerConfiguration to avoid this sort of confusion, but rather relies
on the object that constructed it (KotlinCoreEnvironment in this case)
to provide the correct roots. This is also beneficial because the
computation of actual VirtualFile-based roots from the ones in the
CompilerConfiguration might get trickier with modular Java 9 roots
2017-06-26 16:22:05 +03:00
Alexander Udalov a5a78b8f91 Minor refactoring in ClasspathRootsResolver.convertClasspathRoots
Package prefix only makes sense for JavaSourceRoot content roots
2017-06-26 16:22:05 +03:00
Alexander Udalov 2424431e16 Extract ClasspathRootsResolver out of KotlinCoreEnvironment 2017-06-26 16:22:04 +03:00
Alexander Udalov 6d48b1c3fb Minor, extract MessageUtil.virtualFileToPath 2017-06-26 16:22:04 +03:00
Alexander Udalov 135f0a136e CLI: report error if the first argument for "-script" is not kts
#KT-3045 Fixed
2017-06-22 10:19:05 +03:00
Alexey Andreev 78b238a05b Report warning when two .kt files get same paths in JS source map 2017-06-20 17:40:36 +03:00
Alexey Andreev 13ab63ae09 Generate relative paths in JS source maps
Also, add CLI options to manipulate prefixes of path

See KT-4078
2017-06-20 17:40:32 +03:00
Alexander Udalov 09e4775a10 REPL: display configuration-related messages after start
Previously these messages (e.g. non-existing jar path in classpath,
invalid language version, etc.) were shown after the user exited from
the REPL
2017-06-08 12:28:07 +03:00
Alexander Udalov cbb6269391 REPL: do not report warnings when there are errors
#KT-18349 Fixed
2017-06-08 12:28:06 +03:00
Alexander Udalov ed922deb93 REPL: do not output additional newline after compiler and runtime errors 2017-06-08 12:28:05 +03:00
Alexander Udalov bd9dd90649 REPL: print newline before exit
No tests added because the only way to test this seems to be to launch a
new process and send "Ctrl+D" into it, which seems cumbersome for such
small change
2017-06-08 12:28:04 +03:00
Alexander Udalov 6f22baa0f6 REPL: improve "are all errors at EOF" detection
Also ignore whitespaces and comments that appear after the last error in
a REPL line

 #KT-15172 Fixed
2017-06-08 12:26:54 +03:00
Alexander Udalov 96bd8cb3c2 Minor, move PluginCliParser and PluginURLClassLoader to subpackage 2017-06-07 14:56:58 +03:00
Alexey Andreev 59240a4bd9 Report errors in JS source maps as compiler warnings 2017-06-07 11:13:55 +03:00
Alexander Udalov e6001f57fa Remove dependency of module 'backend' on 'backend.jvm' and 'ir.tree'
This breaks the circular dependency between 'backend' and 'backend.jvm'
2017-06-06 19:55:06 +03:00
Alexander Udalov a802e7fb71 CLI: fix non-XML rendering of argument parse error, simplify code
If the compiler is invoked through JPS, an instance of
XmlMessageRenderer is used and the output should be a valid XML.
Previously, we reported the argument parse error (and the note to try
"-help") before calling messageRenderer.renderPreamble, which resulted
in invalid XML. The same was happening for the usage printed on "-help".
Both of these problems are fixed

 #KT-14848 Fixed
2017-06-06 19:52:04 +03:00
Alexander Udalov a67382fdec Daemon: do not exit with internal error on invalid arguments
Invalid compiler arguments should lead to a compilation error, not
internal error. This has been fixed by splitting the
"parseArguments(...)" call (which does parsing + validation) in
CompileServiceImpl into two calls of parseCommandLineArguments +
validateArguments, and returning with a compilation error if the latter
did not succeed

 #KT-16057 Fixed
 #KT-14848 In Progress
2017-06-06 19:52:02 +03:00
Alexander Udalov 6a4c1b138f Remove dependency of module 'cli' on 'builtins-serializer'
This breaks the circular dependency between them
2017-06-06 14:29:27 +03:00
Alexander Udalov cc2f607be3 Remove dependency of module 'frontend.java' on 'javac-wrapper'
This breaks the circular dependency between them
2017-06-06 14:29:24 +03:00
Alexander Udalov 1df13e0bc9 Move TopDownAnalyzerFacadeForJVM to module 'cli'
It's only used in the command line compiler and in tests
2017-06-06 14:29:23 +03:00
Alexander Udalov f6c263b54d Remove dependency of module 'javac-wrapper' on 'cli' and 'cli-common'
This breaks the circular dependency between them
2017-06-06 14:29:22 +03:00
Alexander Udalov 26e3d2cf5d Use TopLevelDeclarations analysis mode in REPL
#KT-12564 Fixed
2017-06-06 14:00:45 +03:00
Dmitry Jemerov 286f82a5c5 Don't set java.awt.headless if it was set externally 2017-05-31 16:02:26 +02:00
Alexander Udalov 1572d2cf2b Improve modular JDK root module detection
According to the spec, "java.se" and every other non-"java.*" module
that exports at least one package without qualification, is a root.
Currently we only support compilation of a single unnamed module, and
apparently unnamed module should read all root modules.

 #KT-18180 Fixed
2017-05-30 17:35:25 +03:00
Alexander Udalov 5042bbe4a1 Minor refactoring in ContentRoots, JvmContentRoots and usages 2017-05-30 17:35:23 +03:00
Alexander Udalov 227c2d2c23 Minor, display multiline argument help prettier 2017-05-30 17:33:11 +03:00
Alexander Udalov a583a2f171 Move JavaModuleInfo and JavaModuleGraph to frontend.java 2017-05-26 19:38:49 +03:00
Alexey Andreev 522a56947c Add -keep command line option to JS DCE tool 2017-05-26 18:20:23 +03:00
Alexey Andreev 8a8fdf1968 Command-line tool for JS DCE 2017-05-26 18:20:17 +03:00
Alexey Andreev 9e89213d66 Prototyping DCE tool for JS 2017-05-26 18:20:15 +03:00
Mikhail Zarechenskiy 400ecd5e13 Support destructuring declarations in scripts and REPL
#KT-5620 In Progress
 #KT-15810 In Progress
2017-05-25 16:46:04 +03:00
Alexander Udalov 965b4199f4 Fix compilation against JRE 9 on JPS
Write the modular JDK (9+) path to the module.xml file passed to the
compiler from the JPS plugin. This path is then recorded in the compiler
configuration in KotlinToJVMBytecodeCompiler.configureSourceRoots. This
is needed because in JPS plugin, we pass "-no-jdk" and thus no JDK home
path was recorded in the compiler configuration in
K2JVMCompiler.setupJdkClasspathRoots. Presence of JDK home path in the
configuration is crucial for JDK 9 support (see
KotlinCoreEnvironment.Companion.createApplicationEnvironment), because
classes there can only be loaded with the special "jrt" file system, not
as .class files in .jar files

 #KT-17801 Fixed
2017-05-24 15:46:57 +03:00
Alexander Udalov 671aed252d Support single Java source files in kotlinc arguments
E.g. "kotlinc foo.kt test/Bar.java" will compile foo.kt, and
declarations from Bar.java will be accessible to Kotlin code in foo.kt.

The change in AbstractTopLevelMembersInvocationTest is needed because an
incorrect configuration was created in that test where a library jar was
also a Java source root (the compiler is never configured this way in
production), which led to an exception in
JavaCoreProjectEnvironment#addSourcesToClasspath

 #KT-17697 Fixed
2017-05-18 19:22:17 +03:00
baratynskiy 5eea3b6569 Introduce experimental -Xuse-javac compilation mode
In this mode, javac AST and Symbol files are used during
Kotlin compilation instead of PSI / binary stuff.
Later, they are reused for Java file compilation.
javac in this mode is integrated into kotlinc.
2017-05-17 17:48:17 +03:00
Denis Zharkov 692840860e Use allScope when resolving classifiers of binary classes
Otherwise it might lead to the problems when reading class files
from the source scope (e.g. a groovy file or an already compiled java file)

Note that it may be reproduced only with Maven because in JPS
and Gradle we reading source java files even when they're shouldn't be
recompiled, while in Maven we read class files in the case

 #KT-17897 Fixed
2017-05-17 14:33:23 +03:00
Pavel V. Talanov 798c80ed07 Use wrappers around java.util.* to emulate kotlin.collection.* behaviour
Backend: If kotlin class extends kotlin.collection.List
    write it as it's super interface (light class mode only)
IDE: Provide wrapper classes to java resolve
    that try to emulate backend behaviour

For example if kotlin class implements kotlin.collections.Map,
    we provide a superinterface that has abstract 'getEntries' method
    and 'entrySet' method that is considered default.
In reality all those methods are generated in the class itself.

In IDE supporting this case without hacks is not feasible performance-wise
    since kotlin.collection.* may not be an immediate supertype and we need
    to compute all supertypes just to calculate own methods of the class
2017-05-16 22:01:03 +03:00
Alexander Udalov 3f5b8b3f68 Refactor JvmDependenciesIndexImpl.search
- use nullable type "T?" instead of HandleResult consisting of the found
  value and the "should continue" flag
- inline all local functions because they don't add any value now
2017-05-15 12:17:46 +03:00
Anton Bannykh 2e9a59819a JS: support internal visibility from friend modules
Friend modules should be provided using the -Xfriend-modules flag
in the same format as -libraries. No manual configuration required for
JPS, Gradle and Maven plugins.

Friend modules could be switched off using the -Xfriend-modules-disabled
flag. Doing that will
  * prevent internal declarations from being exported,
  * values provided by -Xfriend-modules ignored,
  * raise a compilation error on attemps to use internal declarations from other modules

Fixes #KT-15135 and #KT-16568.
2017-05-04 21:44:17 +03:00
Ilya Chernikov 732367e671 Pass earlier scripts as array, removes 255-lines repl limitation
fixes #KT-10060
2017-05-03 18:11:46 +02:00
Ilya Chernikov 15ccd28e2e Switch old IDE/CLI repls to the new infrastructure
should also fix #KT-5822
2017-05-03 18:11:45 +02:00