diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ToplevelPhases.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ToplevelPhases.kt index 7f1bf27ad99..0a513309f68 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ToplevelPhases.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ToplevelPhases.kt @@ -209,7 +209,9 @@ internal val psiToIrPhase = konanUnitPhase( moduleDescriptor, symbolTable, config.configuration.languageVersionSettings ) - val irProviderForCEnumsAndCStructs = IrProviderForCEnumAndCStructStubs(generatorContext, interopBuiltIns, symbols) + val irProviderForCEnumsAndCStructs = IrProviderForCEnumAndCStructStubs( + generatorContext, interopBuiltIns, symbols, llvmModuleSpecification::containsModule + ) // We need to run `buildAllEnumsAndStructsFrom` before `generateModuleFragment` because it adds references to symbolTable // that should be bound. modulesWithoutDCE diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/interop/IrProviderForCEnumAndCStructStubs.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/interop/IrProviderForCEnumAndCStructStubs.kt index 35df12cf8dc..87fef4e423e 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/interop/IrProviderForCEnumAndCStructStubs.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/interop/IrProviderForCEnumAndCStructStubs.kt @@ -38,11 +38,17 @@ import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter * compiler phases. * 2. It is an easier and more obvious approach. Since implementation of metadata-based * libraries generation already took too much time we take an easier approach here. + * + * [moduleFilter] -- We want to select modules that should be part of compiler's output. + * + * For example, when we generate compiler cache, + * declarations from dependencies should not be added to the current module. */ internal class IrProviderForCEnumAndCStructStubs( context: GeneratorContext, private val interopBuiltIns: InteropBuiltIns, - symbols: KonanSymbols + symbols: KonanSymbols, + private val moduleFilter: (ModuleDescriptor) -> Boolean ) : IrProvider { private val symbolTable: SymbolTable = context.symbolTable @@ -65,7 +71,7 @@ internal class IrProviderForCEnumAndCStructStubs( * of enums and structs that should be generated. */ val outputFiles: List - get() = filesMap.values.toList() + get() = filesMap.filterKeys { moduleFilter(it.module) }.values.toList() fun canHandleSymbol(symbol: IrSymbol): Boolean { if (!symbol.isPublicApi) return false