Commit Graph

460 Commits

Author SHA1 Message Date
Alexander Likhachev 5cae57cf28 [IC] Flush incremental caches on close
#KT-53168 Fixed
2022-07-14 12:55:30 +00:00
Aleksei.Cherepanov 0950205a47 [IC] Add test for lookups flushing
#KT-53168
2022-07-14 12:55:29 +00:00
Alexander Likhachev 18560db373 [IC] Remove unused variable declaration
Previously it was introduced to make `when` exhaustive, but now all the `when` operators on enums are exhaustive
2022-07-13 19:40:47 +00:00
Mikhail Glukhikh 7bbd8d3b95 FIR2IR entry points: don't create JvmDescriptorMangler if not needed 2022-07-13 13:11:49 +00:00
Andrey Uskov 5ba3053e00 [IC] Do not report recompilation of non-existing files 2022-07-12 05:53:10 +00:00
Andrey Uskov 0b7244280f Disable expect-actual tests for fir
FIR currently does not support MPP, thus IC tests involving expect-
actuals, should be disabled.
2022-07-12 05:53:10 +00:00
Andrey Uskov 318d955d64 [IC] Add tests for sealed classes (KT-45474) 2022-07-12 05:53:09 +00:00
Andrey Uskov 21e762458e [IC] Fixed IC for when expressions involving sealed interfaces
#KT-45474 Fixed
2022-07-12 05:53:09 +00:00
Mikhail Glukhikh 45eb9238b3 Fir2IrClassifierStorage: don't calculate signature in registerClass 2022-07-06 10:02:09 +00:00
Hung Nguyen 46c769deb6 [IC] Fix fallback logic in IncrementalCompilerRunner
The current logic works as follows:
- Try either incremental compilation or non-incremental compilation
- If the above (or any of its surrounding work) fails, fall back to
  non-incremental compilation

This means we may perform non-incremental compilation twice.

This commit will fix that logic so that we fall back to non-incremental
compilation only if *incremental compilation* fails.

A nice consequence of this change is that it also resolves the critical
bugs described at KT-52669 (which occur because the current logic is
flawed).

#KT-52669 Fixed
2022-06-28 12:47:11 +00:00
Alexander Udalov ec9d929532 Remove dependency of fir2ir:jvm-backend on backend.jvm.entrypoint
Extract JvmIrDeserializer(Impl), similarly to the existing
JvmIrSerializer(Impl). Remove `allowErrorNodes` which is always false
anyway.
2022-06-13 12:35:51 +00:00
Hung Nguyen 08e6eb07c1 [New IC] Reduce memory usage of classpath snapshot cache
- Remove soft references that are too old.
 - Compute memory usage based on Runtime.totalMemory() instead of
   Runtime.maxMemory() as the latter is not reliable.
 - Remove debug logs that haven't proved to be useful.
 - Collect metrics on the number of cache hits (in addition to cache
   misses).

#KT-52329 In Progress

[New IC] Reduce memory usage of classpath snapshot cache

Use object interning for commonly shared objects. These include:
  - supertypes of classes
  - package names of classes

One experiment showed that with the above optimization, memory usage was
reduced from 660 MB down to 280 MB (+ 4 MB for the interning pool).

More aggressive object interning didn't reduce memory usage much
further, but would increase interning overhead and code complexity, so
we didn't do this to more objects.

Note that this commit optimizes the size of classpath snapshots in
memory, not their serialized data on disk. (I attempted the latter,
but the size was only reduced from 160 MB down to 130 MB, while the code
complexity became much higher as multiple interning pools would need to
be stored to disk and later loaded from disk, each per classpath entry
snapshot or shrunk classpath snapshot.)

#KT-52329 Fixed
2022-05-25 12:59:20 +03:00
Georgy Bronnikov ffe1615e9c Fir: simplify IrBuiltInsOverFir 2022-05-19 12:02:42 +02:00
Georgy Bronnikov e0c175bb50 Fir2Ir: remove symbolTable as separate component from FirResult
It's already in components.
2022-05-19 12:02:41 +02:00
Georgy Bronnikov 13d4d60afa Fir2Ir: pass Fir2IrExtensions to backend 2022-05-19 12:02:41 +02:00
nataliya.valtman dcdd1cd14e KT-49780 Do not clean outputs after cache corruption 2022-05-17 08:47:23 +00:00
Simon Ogorodnik 58885a1b07 KT-52217 Rename 'use-fir' to 'use-k2', update message 2022-04-28 15:42:42 +00:00
Hung Nguyen 9eb3c7ed76 [New IC] Optimize Java class snapshotting with ASM ClassWriter
To snapshot a Java class (+ its fields and methods), previously we used
Gson to serialize a class field/method to a string via reflection, and
hash that string.

We now use an ASM ClassWriter to write a placeholder class containing
the field/method of interest and hash the bytecode of that class.

One experiment showed that this new approach is ~10 times faster than
the previous approach (140s down to 16s when snapshotting 600 jars).

Test: Updated expectation files for JavaClassSnapshotterTest unit tests
      + Existing integration tests to prevent regression

^KT-52141 In Progress
2022-04-27 15:26:26 +00:00
Hung Nguyen 6d3e679a59 Implement cache eviction for classpath snapshot cache
Implement an in-memory cache that uses a combination of strong
references and `SoftReference`s so that it adapts to memory
availability.

Cache eviction is currently performed after loading a classpath snapshot
(this can be changed later if necessary).

Evicted cache entries' values will be converted from strong references
into `SoftReference`s so that they can still be used for as long as the
JVM allows them.

There are 2 types of cache eviction:
  - Least recently used: Oldest entries will be evicted
  - Memory usage limit: If memory is limited, all entries will be
    evicted

Test: Added InMemoryCacheWithEvictionTest unit test

^KT-51978 In Progress
2022-04-21 17:34:01 +00:00
Ilya Chernikov c4a29651b0 FIR IC: fix test with behavior different from non-tight cycle variants 2022-03-30 08:34:51 +00:00
Ilya Chernikov f2ddac3ece IC: Adopt IC compilation for case then runCompiler adds some dirty files
as it is the case for Fir IC compilation.
2022-03-30 08:34:44 +00:00
Ilya Chernikov 03cbfea737 FIR LT: Introduce source file abstraction, carry it from parsing to IR
along with source lines mapping, allows to "emulate" usage of the
PSI files which allows to extract source file and line mapping info
on every stage from source element.
It makes sense to use this mapping for the error reporting too.
2022-03-30 08:34:30 +00:00
Ilya Chernikov 973273c6c6 FIR CLI: count lines/files and report events to perfman 2022-03-30 08:33:11 +00:00
Ilya Chernikov f89765eb33 Make JDK classpath roots configuration explicit...
instead of relying on the "configuration files" parameter.
(in the process of migration from KotlinCoreEnvironment).
2022-03-30 08:32:56 +00:00
Ilya Chernikov 5abdf93d3b IC: Add IC test with fix on rename file with only class inside
"fails" on JS and JPS tests - the IC logic there is less precise.
2022-03-30 08:32:17 +00:00
Ilya Chernikov 3220900abe FIR: add tests for IC with LT and new CLI pipeline 2022-03-30 08:32:10 +00:00
Ilya Chernikov a239f02a30 Add cli argumens for FIR "tight" IC and LightTree usage 2022-03-30 08:32:03 +00:00
Ilya Chernikov 9e32188938 FIR LT: add syntax error reporting to LT2Fir
use it in the new pipeline
2022-03-30 08:31:56 +00:00
Ilya Chernikov 275135a1b2 FIR: extend cli pipeline with incremental compilation logic
use it in the IncrementalCompilationRunner
2022-03-30 08:31:10 +00:00
Hung Nguyen bd8f49c5d6 KT-45777: Count cache misses when loading classpath snapshot
to get more insights into the build performance of that step.

^KT-45777 In Progress
2022-03-29 11:36:41 +00:00
Hung Nguyen f23e66a6e2 KT-45777: Replace EmptyICReporter with DoNothingICReporter
to be more consistent (every *Reporter has a DoNothing*Reporter).

^KT-45777 In Progress
2022-03-29 11:36:41 +00:00
Hung Nguyen d70dbf3146 KT-45777: Add debug log messages for classpath snapshot feature
Also clean up classpath snapshot shrinking a bit to make it clearer.

^KT-45777 In Progress
2022-03-29 11:36:40 +00:00
nataliya.valtman c38dd1c004 Fix unstable testIncrementalCompilationAfterCacheHit test 2022-03-14 20:08:14 +03:00
Ilya Chernikov aa0386276d Fix FIR incremental compilation failure with inlines and lambdas
#KT-51546 fixed
2022-03-14 13:37:50 +03:00
Hung Nguyen 5f1cf34c79 KT-45777: Take coarse-grained snapshots of external libraries
to reduce the size of the snapshots.

- Track metrics for Gradle classpath snapshot artifact transform
- Format size metrics so it's more readable

^KT-45777 In Progress
2022-03-11 17:44:25 +01:00
Hung Nguyen aaef41cf64 KT-45777: Clean up handling around LookupSymbols and ProgramSymbols
Make it clearer and more efficient.

^KT-45777 In Progress
2022-03-07 19:05:09 +03:00
Hung Nguyen d2193f3873 KT-45777: Allow 2 levels of granularity when tracking changes
1. CLASS_LEVEL: allows tracking whether a .class file has changed
     without tracking what specific parts of the .class file (e.g.,
     fields or methods) have changed.

  2. CLASS_MEMBER_LEVEL: allows tracking not only whether a .class file
     has changed but also what specific parts of the .class file (e.g.,
     fields or methods) have changed.

 The idea is that for better performance we will use CLASS_LEVEL for
 classpath entries that are usually unchanged, and CLASS_MEMBER_LEVEL
 for classpath entries that are frequently changed. We'll work out the
 specifics in a following commit after some measurements.

Support running kotlinc on Windows in ClasspathSnapshotTestCommon
Also add tests for different Kotlin class kinds.
Add unit tests for CLASS_LEVEL snapshotting and diffing

Test: Updated ClasspathSnapshotterTest + ClasspathChangesComputerTest
Add ClasspathChangesComputerTest.testMixedClassSnapshotGranularities
2022-02-17 10:46:19 +03:00
Hung Nguyen 39b7c6e326 KT-34862: Clean up tests for incremental compilation after cache hit
Make sure that:
  - Compilation with -Pkotlin.incremental.useClasspathSnapshot=true or
    -Dkotlin.incremental.classpath.snapshot.enabled=true is incremental
    after cache hit.
  - Default compilation (using build history files) is non-incremental
    after cache hit.

Also unify the related tests into
BuildCacheRelocationIT.testKotlinIncrementalCompilation*. We don't need
corresponding tests in BuildCacheIT because BuildCacheRelocationIT
already covers it.
2022-02-15 14:05:58 +03:00
nataliya.valtman d4d5c701fe Make statistic more readable 2022-02-11 17:23:38 +03:00
Hung Nguyen d018031cbf KT-45777: Clean up build cache tests for incremental compilation
- Clean up BuildCacheRelocationIT.testKotlinIncrementalCompilation
 - Delete BuildCacheIT.testKotlinCompileIncrementalBuildWithoutRelocation
   as it is already covered by the test in BuildCacheRelocationIT
 - Add BuildCacheRelocationIT.testKotlinIncrementalCompilation_withClasspathSnapshot
- Updated BuildCacheRelocationIT.testKotlinIncrementalCompilation_withClasspathSnapshot
2022-02-08 18:07:38 +03:00
Hung Nguyen 1cb509d529 KT-45777: Remove proto-based approach to compute Java class snapshots
as the ASM-based approach is better, and we have switched to the
ASM-based approach for a while now.
2022-02-01 12:41:53 +03:00
Hung Nguyen 37c6b1c2dc KT-45777: Track build time in nanoseconds instead of milliseconds
to ensure precision (otherwise, rounding errors to milliseconds may
add up and cause unexplainable gaps in the running time).

We can still use milliseconds in the final report after all the precise
sub-build-times have been aggregated.
2022-01-31 19:50:03 +03:00
Nikita Bobko ca716fd226 Regenerate tests 2022-01-12 15:25:16 +01:00
Andrey Uskov 2adc851f1b Don't use global state for keeping incremental compilation state
Previously IC state was stored in System properties. As result parallel
compilation might cause incorrect state of IC, what led to corruption
of kotlin_module files. Now IC state is stored via CompilerArguments
and CompilerConfiguration
#KT-46038 Fixed
2022-01-12 13:37:46 +03:00
Hung Nguyen 78f10d9142 KT-45777: Keep only package facades whose members are looked up
to reduce the size of the shrunk classpath snapshot further.
2021-12-25 00:20:31 +03:00
Hung Nguyen 9b96dbe2d2 KT-45777: Parse classes only once with ASM
to get both constants and inline functions.

Also add BasicClassInfo to ClassFileWithContents to simplify the code.
2021-12-24 18:31:49 +03:00
Hung Nguyen 9a995af0df KT-44741: Improve handling of constants defined in companion objects 2021-12-24 18:31:49 +03:00
Hung Nguyen a900f2b66d KT-45777: Reorganize unit test data for classpath snapshot feature
to make it easier to add more tests in the next commits.

- Add unit tests for constants and inline functions

Also add tests for different kinds of Kotlin classes: CLASS,
FILE_FACADE, MULTIFILE_CLASS.

-Add unit test for nested classes

Also remove the existing integration test for nested classes to keep the
integration tests focused on the key scenarios while unit tests will
cover the corner cases.

Ignore inline functions that are private
2021-12-24 18:31:49 +03:00
Vyacheslav Gerasimov f7a9065b75 Build: Use intellij maven repo instead of downloaded IDEA
#KTI-82
2021-12-16 21:48:23 +03:00
Vyacheslav Gerasimov bc2f0936bd Build: Rename commonDep -> commonDependency 2021-12-16 21:48:19 +03:00