Skip to content
This repository has been archived by the owner on Aug 10, 2021. It is now read-only.

Support -Xexport-library in reverse C interop. #2740

Merged
merged 3 commits into from
Mar 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,10 @@ private fun selectExportedLibraries(
): List<String> {
val exportedLibraries = arguments.exportedLibraries?.toList().orEmpty()

return if (exportedLibraries.isNotEmpty() && outputKind != CompilerOutputKind.FRAMEWORK) {
configuration.report(STRONG_WARNING, "-Xexport-library is only supported when producing frameworks, " +
return if (exportedLibraries.isNotEmpty() && outputKind != CompilerOutputKind.FRAMEWORK &&
outputKind != CompilerOutputKind.STATIC && outputKind != CompilerOutputKind.DYNAMIC) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe fix error message below too?

configuration.report(STRONG_WARNING,
"-Xexport-library is only supported when producing frameworks or native libraries, " +
"but the compiler is producing ${outputKind.name.toLowerCase()}")

emptyList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,9 @@ internal class CAdapterGenerator(
}

override fun visitPackageViewDescriptor(descriptor: PackageViewDescriptor, ignored: Void?): Boolean {
if (descriptor.module != context.moduleDescriptor) return true
val fragments = descriptor.module.getPackage(FqName.ROOT).fragments.filter { it.module == context.moduleDescriptor }
if (descriptor.module !in moduleDescriptors) return true
val fragments = descriptor.module.getPackage(FqName.ROOT).fragments.filter {
it.module in moduleDescriptors }
visitChildren(fragments)
return true
}
Expand All @@ -605,15 +606,10 @@ internal class CAdapterGenerator(

private val seenPackageFragments = mutableSetOf<PackageFragmentDescriptor>()
private var currentPackageFragments: List<PackageFragmentDescriptor> = emptyList()
private val packageScopes = mutableMapOf<String, ExportedElementScope>()

override fun visitModuleDeclaration(descriptor: ModuleDescriptor, ignored: Void?): Boolean {
currentPackageFragments = descriptor.getPackageFragments().sortedWith(
Comparator { o1, o2 ->
o1.fqName.toString().compareTo(o2.fqName.toString())
})
seenPackageFragments.clear()
descriptor.getPackage(FqName.ROOT).accept(this, null)
return true
TODO("Shall not be called directly")
}

override fun visitTypeAliasDescriptor(descriptor: TypeAliasDescriptor, ignored: Void?): Boolean {
Expand All @@ -624,8 +620,11 @@ internal class CAdapterGenerator(
override fun visitPackageFragmentDescriptor(descriptor: PackageFragmentDescriptor, ignored: Void?): Boolean {
val fqName = descriptor.fqName
val name = if (fqName.isRoot) "root" else translateName(fqName.shortName().asString())
val packageScope = ExportedElementScope(ScopeKind.PACKAGE, name)
scopes.last().scopes += packageScope
val packageScope = packageScopes.getOrPut(name) {
val scope = ExportedElementScope(ScopeKind.PACKAGE, name)
scopes.last().scopes += scope
scope
}
scopes.push(packageScope)
visitChildren(DescriptorUtils.getAllDescriptors(descriptor.getMemberScope()))
for (currentPackageFragment in currentPackageFragments) {
Expand All @@ -639,9 +638,21 @@ internal class CAdapterGenerator(
return true
}


private val moduleDescriptors = mutableSetOf<ModuleDescriptor>()

fun generateBindings() {
scopes.push(ExportedElementScope(ScopeKind.TOP, "kotlin"))
context.moduleDescriptor.accept(this, null)
moduleDescriptors += context.moduleDescriptor
moduleDescriptors += context.getExportedDependencies()

currentPackageFragments = moduleDescriptors.flatMap { it.getPackageFragments() }.toSet().sortedWith(
Comparator { o1, o2 ->
o1.fqName.toString().compareTo(o2.fqName.toString())
})

context.moduleDescriptor.getPackage(FqName.ROOT).accept(this, null)

// TODO: add few predefined types.
listOf<KotlinType>(
// context.builtIns.anyType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ internal val psiToIrPhase = konanUnitPhase(
konanLibrary.irHeader?.let { header ->
// TODO: consider skip deserializing explicitly exported declarations for libraries.
// Now it's not valid because of all dependencies that must be computed.
val deserializationStrategy = DeserializationStrategy.EXPLICITLY_EXPORTED
val deserializationStrategy = if (getExportedDependencies().contains(dependency))
DeserializationStrategy.ALL else DeserializationStrategy.EXPLICITLY_EXPORTED
modules[konanLibrary.libraryName] = deserializer.deserializeIrModuleHeader(dependency, header, deserializationStrategy)
}
}
Expand Down