-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expect/actual support in klibs under -Xklib-mpp
- Loading branch information
1 parent
218d7c3
commit dc8240c
Showing
49 changed files
with
2,623 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
...iler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ExpectDependencyGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package org.jetbrains.kotlin.psi2ir.generators | ||
|
||
import org.jetbrains.kotlin.descriptors.* | ||
import org.jetbrains.kotlin.ir.IrElement | ||
import org.jetbrains.kotlin.ir.declarations.* | ||
import org.jetbrains.kotlin.ir.symbols.IrSymbol | ||
import org.jetbrains.kotlin.ir.types.classOrNull | ||
import org.jetbrains.kotlin.ir.util.SymbolTable | ||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid | ||
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid | ||
import org.jetbrains.kotlin.ir.visitors.acceptVoid | ||
import org.jetbrains.kotlin.resolve.multiplatform.findExpects | ||
|
||
// Need to create unbound symbols for expects corresponding to actuals of the currently compiled module. | ||
// This is neccessary because there is no explicit links between expects and actuals | ||
// neither in descriptors nor in IR. | ||
fun referenceExpectsForUsedActuals(expectDescriptorToSymbol: MutableMap<DeclarationDescriptor, IrSymbol>, symbolTable: SymbolTable, irModule: IrModuleFragment) { | ||
irModule.acceptVoid(object : IrElementVisitorVoid { | ||
|
||
private fun <T> T.forEachExpect(body: (DeclarationDescriptor) -> Unit) where T: IrDeclaration { | ||
this.descriptor.findExpects().forEach { | ||
body(it) | ||
} | ||
} | ||
|
||
override fun visitElement(element: IrElement) { | ||
element.acceptChildrenVoid(this) | ||
} | ||
override fun visitClass(declaration: IrClass) { | ||
declaration.forEachExpect { | ||
val symbol = symbolTable.referenceClass(it as ClassDescriptor) | ||
expectDescriptorToSymbol.put(it, symbol); | ||
it.constructors.forEach { | ||
expectDescriptorToSymbol.put(it, symbolTable.referenceConstructor(it as ClassConstructorDescriptor)) | ||
} | ||
} | ||
super.visitDeclaration(declaration) | ||
} | ||
override fun visitSimpleFunction(declaration: IrSimpleFunction) { | ||
declaration.forEachExpect { | ||
val symbol = symbolTable.referenceSimpleFunction(it as FunctionDescriptor); | ||
expectDescriptorToSymbol.put(it, symbol); | ||
} | ||
super.visitDeclaration(declaration) | ||
} | ||
override fun visitConstructor(declaration: IrConstructor) { | ||
declaration.forEachExpect { | ||
val symbol = symbolTable.referenceConstructor(it as ClassConstructorDescriptor) | ||
expectDescriptorToSymbol.put(it, symbol); | ||
|
||
} | ||
super.visitDeclaration(declaration) | ||
} | ||
override fun visitProperty(declaration: IrProperty) { | ||
declaration.forEachExpect { | ||
val symbol = symbolTable.referenceProperty(it as PropertyDescriptor) | ||
expectDescriptorToSymbol.put(it, symbol); | ||
} | ||
super.visitDeclaration(declaration) | ||
} | ||
override fun visitEnumEntry(declaration: IrEnumEntry) { | ||
declaration.forEachExpect { | ||
val symbol = symbolTable.referenceEnumEntry(it as ClassDescriptor) | ||
expectDescriptorToSymbol.put(it, symbol); | ||
|
||
} | ||
super.visitDeclaration(declaration) | ||
} | ||
override fun visitTypeAlias(declaration: IrTypeAlias) { | ||
// Force actual type alias right hand side deserialization. | ||
if (declaration.isActual) { | ||
declaration.expandedType.classOrNull?.descriptor?.let { symbolTable.referenceClass(it) } | ||
} | ||
|
||
declaration.forEachExpect { | ||
val symbol = when (it) { | ||
is ClassDescriptor -> symbolTable.referenceClass(it) | ||
else -> error("Unexpected expect for actual type alias: $it") | ||
} | ||
expectDescriptorToSymbol.put(it, symbol); | ||
|
||
} | ||
super.visitDeclaration(declaration) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/symbols/IrDelegatingSymbol.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.jetbrains.kotlin.ir.symbols | ||
|
||
import org.jetbrains.kotlin.descriptors.* | ||
import org.jetbrains.kotlin.ir.declarations.* | ||
import org.jetbrains.kotlin.ir.util.UniqId | ||
|
||
abstract class IrDelegatingSymbol<S: IrBindableSymbol<D, B>, B: IrSymbolOwner, D: DeclarationDescriptor>(var delegate: S) | ||
: IrBindableSymbol<D, B> { | ||
override val owner: B get() = delegate.owner | ||
override val descriptor: D get() = delegate.descriptor | ||
override val isBound: Boolean get() = delegate.isBound | ||
override var uniqId: UniqId | ||
get() = delegate.uniqId | ||
set(value: UniqId) { delegate.uniqId = value } | ||
|
||
override fun bind(owner: B) = delegate.bind(owner) | ||
override fun hashCode() = delegate.hashCode() | ||
override fun equals(other: Any?): Boolean { | ||
if (this === other) return true | ||
if (this === delegate) return true | ||
return false | ||
} | ||
} | ||
|
||
class IrDelegatingClassSymbolImpl(delegate: IrClassSymbol) : | ||
IrClassSymbol, IrDelegatingSymbol<IrClassSymbol, IrClass, ClassDescriptor>(delegate) | ||
|
||
class IrDelegatingEnumEntrySymbolImpl(delegate: IrEnumEntrySymbol) : | ||
IrEnumEntrySymbol, IrDelegatingSymbol<IrEnumEntrySymbol, IrEnumEntry, ClassDescriptor>(delegate) | ||
|
||
class IrDelegatingSimpleFunctionSymbolImpl(delegate: IrSimpleFunctionSymbol) : | ||
IrSimpleFunctionSymbol, IrDelegatingSymbol<IrSimpleFunctionSymbol, IrSimpleFunction, FunctionDescriptor>(delegate) | ||
|
||
class IrDelegatingConstructorSymbolImpl(delegate: IrConstructorSymbol) : | ||
IrConstructorSymbol, IrDelegatingSymbol<IrConstructorSymbol, IrConstructor, ClassConstructorDescriptor>(delegate) | ||
|
||
class IrDelegatingPropertySymbolImpl(delegate: IrPropertySymbol) : | ||
IrPropertySymbol, IrDelegatingSymbol<IrPropertySymbol, IrProperty, PropertyDescriptor>(delegate) | ||
|
||
class IrDelegatingTypeAliasSymbolImpl(delegate: IrTypeAliasSymbol) : | ||
IrTypeAliasSymbol, IrDelegatingSymbol<IrTypeAliasSymbol, IrTypeAlias, TypeAliasDescriptor>(delegate) | ||
|
||
fun wrapInDelegatedSymbol(delegate: IrSymbol) = when(delegate) { | ||
is IrClassSymbol -> IrDelegatingClassSymbolImpl(delegate) | ||
is IrEnumEntrySymbol -> IrDelegatingEnumEntrySymbolImpl(delegate) | ||
is IrSimpleFunctionSymbol -> IrDelegatingSimpleFunctionSymbolImpl(delegate) | ||
is IrConstructorSymbol -> IrDelegatingConstructorSymbolImpl(delegate) | ||
is IrPropertySymbol -> IrDelegatingPropertySymbolImpl(delegate) | ||
is IrTypeAliasSymbol -> IrDelegatingTypeAliasSymbolImpl(delegate) | ||
else -> error("Unexpected symbol to delegate to: $delegate") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.