Commit Graph

109298 Commits

Author SHA1 Message Date
Marco Pennekamp b2cd29726b [LL] Rewrite CleanableSoftValueCache in terms of ConcurrentHashMap.compute
- The previous implementation of `putIfAbsent` made two calls to the
  `backingMap`: `putIfAbsent` and `replace`. This breaks atomicity at
  least in theory. Implementing the major compute operations in terms of
  `backingMap.compute` allows us to restrict the critical section to
  this single atomic `ConcurrentHashMap` operation, which is easier to
  reason about.
- Using `backingMap.compute` also improves the guarantees we can make in
  respect to `computeIfAbsent`'s computation function `f`. We can now
  guarantee that the function is called exactly once iff the `key` is
  absent, because it is only ever invoked inside `backingMap.compute`,
  which makes this guarantee itself.
- Remove `putIfAbsent`, which isn't currently used by
  `LLFirSessionCache`. It can easily be implemented using
  `computeIfAbsent` in the future.

^KT-61222
2024-02-27 16:45:52 +00:00
Marco Pennekamp 5819f4eaa2 [LL FIR] Test resolve extension disposal after modification events
- These tests simply ensure that a resolve extension is disposed after
  any kind of modification event is raised. It's not meant to test
  complex scenarios, but rather to detect when resolve extension
  disposal isn't invoked *at all*.
- I tried implementing a similar test for resolve extension disposal
  after soft reference garbage collection, but the only way to force the
  GC to collect soft references is to allocate memory until an
  out-of-memory error occurs. That is bad for the test infrastructure,
  because it might allocate A LOT of memory (depending on the max heap),
  which is problematic for running tests locally. Also, our Kotlin tests
  stop on an OOM error altogether (so additional configuration would be
  required) and the heap is dumped into a 20GB file (on my machine),
  which is again problematic for local test runs.

^KT-61222
2024-02-27 16:45:52 +00:00
Marco Pennekamp 040b7472a9 [AA] Add MODIFICATION_EVENT test directive
- This allows tests to specify which modification event they want to
  publish.
- The modification event won't be published automatically. Tests need to
  invoke `publishModificationEventByDirective` at the right time.

^KT-56288
2024-02-27 16:45:52 +00:00
Marco Pennekamp 7a5a1833e7 [AA] Implement disposable KtResolveExtensions
- This commit adds the `Disposable` interface to `KtResolveExtension`.
  Resolve extensions are disposed after their associated session has
  been invalidated, or reclaimed by the GC.
- Example use case: Opening a message bus connection with the lifetime
  of the resolve extension.

^KT-61222 fixed
2024-02-27 16:45:52 +00:00
Marco Pennekamp efb56ed30a [LL FIR] Implement disposal support for LLFirSessions
- This commit adds a `Disposable` to `LLFirSession` which lives as long
  as the session. For example, session components can now open a message
  bus connection that is automatically disposed after the session has
  been invalidated or reclaimed.
- Because `LLFirSession`s should still benefit from soft reference-based
  automatic reclamation by the GC, we have to use a soft value map with
  cleanup in `LLFirSessionCache`. It ensures that the child disposables
  are properly disposed even when the session is collected as a soft
  value.
- The session cannot be the `Disposable` itself because a valid
  disposable reference is needed to call `Disposer.dispose`. When a soft
  reference is added to a reference queue (such as the reference queue
  employed by the soft value map), its referent is already cleared.
  Hence, it's not possible to watch a softly referenced `Disposable`
  with a reference queue and also pass it to `Disposer.dispose`. This is
  why the `LLFirSessionCleaner` contains a strong reference to the
  `disposable`, because that will not keep the `LLFirSession` from being
  reclaimed, while keeping the `disposable` alive slightly longer than
  the session.

^KT-61222
2024-02-27 16:45:52 +00:00
Marco Pennekamp 35856ab58f [LL FIR] Implement CleanableSoftValueCache
- This cache implementation is useful for lifecycle management of cached
  values when we also want to allow the GC to reclaim those values which
  are unused. It ensures that the cleanup is (almost) definitely invoked
  at some point after a value has been reclaimed by the GC, and also
  invokes the same cleanup operation when the value is removed from the
  cache conventionally. This unifies the approach to cleaning up such
  elements.
  - It would be possible to have the cache ONLY perform cleanup for
    references reclaimed by the GC, but this would put the onus on the
    consumer to perform the cleanup when an element is removed from the
    cache conventionally. That comes with its own pitfalls, such as
    requiring the user to handle `clear` correctly, or not forgetting
    to perform cleanup with the old value returned by `put`.
- "Almost definitely" because the reference queue won't be processed if
  the cache becomes unused at some point. However, this is not an issue
  for the current intended use case (session invalidation and disposal)
  and can be solved by clearing the cache before it becomes entirely
  unused.
- The cache requires read and write actions for certain operations to
  simplify the implementation of `clear`.

^KT-61222
2024-02-27 16:45:51 +00:00
Artem Kobzar 3429cbd321 [K/JS] Support companion objects in external and exported declarations 2024-02-27 16:30:13 +00:00
Alexander Udalov 5cda3fba12 IR: produce new fake override for each static member
This is an addition to d4278250e6. Apparently we still need to produce
a new fake override for each inherited static member, because otherwise
we would try to determine the most specific return type, maximum
visibility, etc, all of which makes no sense for static members.

 #KT-66152 Fixed
2024-02-27 16:05:52 +00:00
Dmitriy Dolovov f204293e4d [Test] Unify work with KLIB artifact paths and dependencies
Unify functions from `JsEnvironmentConfigurator` and
`WasmEnvironmentConfigurator` that do the same logic. Make this logic
also be available for `NativeEnvironmentConfigurator`:
- get*ArtifactSimpleName()
- get*KlibArtifactPath()
- get*KlibOutputDir()
- getAllRecursiveLibrariesFor()
- getAllRecursiveDependenciesFor()
- getAllDependenciesMappingFor()
- getKlibDependencies()

This would allow to have the same logic in one place, and also
reuse it in `IrBackendFacade`s to be implemented for Native.

^KT-65117
2024-02-27 15:22:47 +00:00
Timofey Solonin 7e9e064748 Add an IT for publication of multiplatform resources in a jvm target
^KT-65540
2024-02-27 14:04:51 +00:00
Timofey Solonin 370799b4e3 Publish multiplatform resources in for jvm target
^KT-65540
2024-02-27 14:04:51 +00:00
Timofey Solonin 3dd33e5aa7 Add external APIs to publish multiplatform resources in a target
^KT-65540
2024-02-27 14:04:51 +00:00
Andrei Tyrin 4e10dcd808 [tests] Klib based signature clash improve coverage for KT-63670 2024-02-27 14:01:44 +00:00
Artem Daugel-Dauge fff5a412ec [Gradle] Xcode version too high warning
Adds new warning diagnostic that checks that selected Xcode version is not higher than latest tested with the current Kotlin version

^KT-62373 Verification Pending
2024-02-27 13:23:55 +00:00
Artem Daugel-Dauge e822375461 [Gradle] Fix CocoaPods configuration cache IT for Gradle 8.6 2024-02-27 13:23:33 +00:00
Alexander Shabalin 0882d1752d [K/N][tests] Fix path-separator handling ^KT-65977 2024-02-27 13:20:50 +00:00
Alexander Shabalin c491858a49 [K/N][tests] Add EnforcedHostTarget to atomicfu tests ^KT-65977 2024-02-27 13:20:50 +00:00
Alexander Shabalin a8fcef9cca Revert "[K/N][tests] Remove atomicfu tests from :nativeCompilerTest ^KT-65977"
This reverts commit 513f86f8fc.
2024-02-27 13:20:50 +00:00
Alexander.Likhachev 2d161723d5 [Gradle] Regenerate Gradle compiler arguments DSL
^KT-65986 Fixed
2024-02-27 13:07:18 +00:00
Alexander.Likhachev 95fd91ae16 [CLI, Gradle] Update GradleDeprecatedOption.removeAfter values
The values updated to follow the deprecation cycle "warning -> error -> removed"
^KT-65986 In Progress
2024-02-27 13:07:18 +00:00
Alexander.Likhachev d20f31e963 [CLI, Gradle] Fix GradleDeprecatedOption.removeAfter processing
The expected format was Kotlin language version (e.g. `2.0`), however the actual passed values were Kotlin release versions (e.g. `2.0.0`)
^KT-65986 In Progress
2024-02-27 13:07:18 +00:00
Alexander.Likhachev 83a9ac62ea [Gradle] Regenerate Gradle compiler arguments DSL
^KT-65986 In Progress
2024-02-27 13:07:18 +00:00
Alexander.Likhachev d40d1316d3 [CLI, Gradle] Suppress deprecation errors in generated compiler arguments DSL
^KT-65986 In Progress
2024-02-27 13:07:18 +00:00
Alexander Shabalin ac6aad1f65 [K/N][tests] Do not run objcexport-header-generator in backend.native:tests ^KTI-1571 2024-02-27 12:24:36 +00:00
Roman Efremov 23ae617ea0 Fix inaccurate report of DEPRECATED_ACCESS_TO_ENTRY_PROPERTY_FROM_ENUM
Add separate diagnostic for the case when it is reported on qualifiers.

^KT-64488
2024-02-27 11:22:35 +00:00
Roman Efremov 02b5fed389 Fix inaccurate report of DEPRECATED_ACCESS_TO_ENTRY_PROPERTY_FROM_ENUM
It can be reported not only from within the enum, but also from
top-level functions. Add separate diagnostic for such cases.

^KT-64488
2024-02-27 11:22:35 +00:00
Roman Efremov 34d87465ac [Test] Add test for Enum.entries shadowing when property is imported
This is similar to KT-64488 but without context receivers.
Warning message "access ... from within the enum" is also incorrect
here.

^KT-64488
2024-02-27 11:22:35 +00:00
cristiangarcia e83d2e31d4 Fix CompileToBitcodePlugin onlyIf to make it CC compatible
Required for KTI-1553
2024-02-27 10:32:58 +00:00
Vyacheslav Gerasimov c382b0e2b3 Build: Remove kotlin-compiler from dependencies during Idea import
#KTI-1598
2024-02-27 10:29:59 +00:00
Vyacheslav Gerasimov 8fd3166199 Build: Remove coroutines-core dependency from backend.native:tests
The dependency on kotlinx-coroutines-core seems redundant and always
overridden by another dependency.
2024-02-27 10:29:59 +00:00
Vyacheslav Gerasimov f924de5a2c Build: Remove unused dependencies on :kotlin-compiler project
#KTI-1598
2024-02-27 10:29:59 +00:00
Timofey Solonin 5ddc7b47ef Add a task to hierarchically assemble multiplatform resources
^KT-65540
2024-02-27 10:27:38 +00:00
Timofey Solonin 74628c0394 Register multiplatform publication extension
^KT-65540
2024-02-27 10:27:38 +00:00
Timofey Solonin ea0c3837a0 Add kotlin.mpp.enableResourcesPublication feature toggle
^KT-65540
2024-02-27 10:27:38 +00:00
Mikhail Glukhikh 678816f9e8 K1: introduce BUILDER_INFERENCE_STUB_PARAMETER_TYPE to prevent compiler crashes
This diagnostic is reported in rare situations when
StubTypeForBuilderInference is kept as a parameter type
of for loop or lambda. Before this commit, we had in K1
"Could not load module <error module>" from IrLinker instead.

Related to: KT-52757, KT-53109, KT-63841, KT-64066
#KT-53478 Fixed
2024-02-27 10:25:13 +00:00
Dmitriy Novozhilov 6f6e37f552 [FIR] Report about recursion in implicit types for receivers of invoke
^KT-65576 Fixed
2024-02-27 09:34:02 +00:00
Dmitriy Novozhilov 234cc5be2b [Test] Reproduce KT-65576 2024-02-27 09:34:02 +00:00
Mikhail Glukhikh 91e9fbd9bf K1: change depr. level of List.getFirst to HIDDEN but don't force it on overrides
#KT-65441 Fixed
2024-02-27 08:40:53 +00:00
Mikhail Glukhikh d870d9dcc6 K1/K2: add tests for KT-65441 current behavior 2024-02-27 08:40:52 +00:00
Nataliya.Valtman 5885514c3d Add JSON output type for build reports
#KT-65792 Fixed
2024-02-27 08:32:36 +00:00
Artem Olkov f493df42a9 [Swift Export] fix swift export full test by adding missing runtime modulemap
Merge-request: KT-MR-14627
Merged-by: Artem Olkov <artem.olkov@jetbrains.com>
2024-02-27 08:15:12 +00:00
Evgenii Mazhukin 347eedb0a0 [JPS][IC] Fix the use of Jps-dependency-graph API for lookups
All dependencies should be registered before the Backend::associate().

^KT-65429


Merge-request: KT-MR-14616
Merged-by: Evgenii Mazhukin <evgenii.mazhukin@jetbrains.com>
2024-02-27 07:42:15 +00:00
Anton Lakotka 3ff2bc403c [Gradle] Report warning when there is multiple source roots in compilation
This issue should warn users about possible problems in K2 compiler.
Because in this setup there will be no symbols visibility between
those source set roots as it used to be in K1.
There is an assumption that this case usually appears in the code
generation setup. And users might not experience any problems before.

^KT-64913 Verification Pending
2024-02-27 02:01:25 +00:00
Marco Pennekamp b5eccd63b1 [AA] Fix compilation facility "multi binary module" test module structure
- The module structure for these tests was set up backwards: We should
  keep the test module kind of the main module flexible (as it is
  configured by test configurators), but keep the module kinds of the
  binary libraries fixed.

^KT-65960
^KT-64994
2024-02-26 21:57:23 +00:00
Marco Pennekamp 4ea3de1760 [AA] Refactoring: Rename KtModuleFactory to KtTestModuleFactory
^KT-65960
2024-02-26 21:57:23 +00:00
Marco Pennekamp 3f04604187 [AA] Tests: Improve handling of dependencyPaths
- The name wasn't specific enough.
- Remove default `emptyList()` argument from `CompiledLibraryProvider`
  so that passing `dependencyBinaryRoots` isn't missed. (My changes
  didn't include it in `KtLibraryBinaryModuleFactoryBase` yet, but it
  was actually missed from `KtLibrarySourceModuleFactory` even in the
  original commit.)

^KT-65960
^KT-64994
2024-02-26 21:57:23 +00:00
Marco Pennekamp 5663521a36 [AA] Tests: Remove topological ordering from KtTestModule creation
- The test infrastructure already requires test modules to be properly
  ordered regarding dependencies, so a module A which is a dependency
  for a module B must always be ordered before B. Hence, it makes no
  sense to also order modules topologically.
- Reordering modules may cause the resulting `KtTestModule`s to be
  out-of-order with the test modules, because the topological order
  might be different from the test module order, even if the dependency
  relationship already holds in the original order.
  `KtTestModuleProjectStructure` requires the same ordering as test
  modules to ensure the same order during iteration of `KtTestModule`s.

^KT-65960
^KT-64994
2024-02-26 21:57:23 +00:00
Marco Pennekamp c7ccfcc785 [AA] Fix sealed inheritors provider for binary libraries in Standalone tests
- Since binary libraries don't carry decompiled files anymore, the
  static declaration provider doesn't index binary libraries in the
  Standalone mode, where we don't use stub-based deserialization. This
  led `LLSealedInheritorsProviderFactoryForTests` to fail in Standalone
  mode for sealed classes from binary libraries, as this provider is now
  populated from the declaration provider's index (see the previous
  commit). Luckily, class-based deserialization sets
  `sealedInheritorsAttr`, so we can simply use this attribute.

^KT-65960
2024-02-26 21:57:23 +00:00
Marco Pennekamp e62038f5f3 [AA] Tests: Rewrite sealed class inheritors collection to use the declaration provider
- Now that binary libraries are decompiled to stubs instead of PSI
  files, we cannot collect sealed inheritors from `KtFile`s anymore.
  Since all `KtFile`s and binary library stubs are both indexed by the
  declaration provider, we can collect inheritors from its index
  instead.
- Invalidating all sessions at the end of `prepareSealedClassInheritors`
  fixes some improper resolve phases in lazy resolution test data. While
  the previous implementation requested an uncached resolve session, it
  didn't account for sessions of dependencies still being cached.

^KT-65960
2024-02-26 21:57:23 +00:00
Marco Pennekamp 47afd37596 [AA] IDE mode tests: Build and index stubs for binary libraries
- Instead of indexing binary library declarations from decompiled PSI,
  the static declaration provider now builds and indexes stubs. As noted
  in KT-65960, this brings IDE mode tests much more in line with
  decompiled stubs indexing in the IDE. It should allow us to catch
  issues with the stub-based deserialized symbol provider outside of IDE
  tests.
- In the Standalone mode, we can skip stub-indexing completely, as we
  provide FIR symbols via class-based deserialization. This also extends
  to shared binary roots.

^KT-65960 fixed
2024-02-26 21:57:23 +00:00