[LL API] Ignore local functions in 'CodeFragmentDeclarationCollector'

In the old JVM backend, local functions were compiled as JVM classes,
so there were an instance to pass around. Today, they are compiled to
static functions in the containing class/facade, and calls to them
compile natively.
This commit is contained in:
Yan Zhulanow
2023-08-07 22:08:43 +09:00
committed by Space Team
parent 921db9f8d4
commit ee7e6b0fce
5 changed files with 7 additions and 23 deletions
@@ -85,12 +85,6 @@ public sealed class CodeFragmentCapturedValue(
get() = "this@$name" get() = "this@$name"
} }
/** Represents a captured named local function. */
public class LocalFunction(
name: Name,
isCrossingInlineBounds: Boolean,
) : CodeFragmentCapturedValue(name.asString(), isMutated = false, isCrossingInlineBounds)
/** Represents an externally provided value. */ /** Represents an externally provided value. */
public class ForeignValue( public class ForeignValue(
name: Name, name: Name,
@@ -1,6 +1,3 @@
LocalFunction[name: call; isMutated: false; displayText: call]
fun call(a: R|kotlin/Int|, b: R|kotlin/String|): R|kotlin/Unit|
R|(kotlin/Int, kotlin/String) -> kotlin/Unit|
Local[name: x; isMutated: false; displayText: x] Local[name: x; isMutated: false; displayText: x]
lval x: R|kotlin/Int| lval x: R|kotlin/Int|
R|kotlin/Int| R|kotlin/Int|
@@ -22,10 +22,11 @@ MODULE_FRAGMENT name:<Sources of main>
CONSTRUCTOR visibility:public <> () returnType:<root>.CodeFragment [primary] CONSTRUCTOR visibility:public <> () returnType:<root>.CodeFragment [primary]
BLOCK_BODY BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any' DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
FUN name:run visibility:public modality:FINAL <> (p0:kotlin.Function2<kotlin.Int, kotlin.String, kotlin.Unit>, p1:kotlin.Int, p2:kotlin.String) returnType:kotlin.Unit FUN name:run visibility:public modality:FINAL <> (p0:kotlin.Int, p1:kotlin.String) returnType:kotlin.Unit
VALUE_PARAMETER name:p0 index:0 type:kotlin.Function2<kotlin.Int, kotlin.String, kotlin.Unit> VALUE_PARAMETER name:p0 index:0 type:kotlin.Int
VALUE_PARAMETER name:p1 index:1 type:kotlin.Int VALUE_PARAMETER name:p1 index:1 type:kotlin.String
VALUE_PARAMETER name:p2 index:2 type:kotlin.String
EXPRESSION_BODY EXPRESSION_BODY
BLOCK type=kotlin.Unit origin=null BLOCK type=kotlin.Unit origin=null
GET_VAR 'p0: kotlin.Function2<kotlin.Int, kotlin.String, kotlin.Unit> declared in <root>.CodeFragment.run' type=kotlin.Function2<kotlin.Int, kotlin.String, kotlin.Unit> origin=null CALL 'local final fun call (a: kotlin.Int, b: kotlin.String): kotlin.Unit declared in <root>.test' type=kotlin.Unit origin=null
a: GET_VAR 'p0: kotlin.Int declared in <root>.CodeFragment.run' type=kotlin.Int origin=null
b: GET_VAR 'p1: kotlin.String declared in <root>.CodeFragment.run' type=kotlin.String origin=null
@@ -1,7 +1,7 @@
public final class CodeFragment { public final class CodeFragment {
// source: 'fragment.kt' // source: 'fragment.kt'
public method <init>(): void public method <init>(): void
public final static method run(p0: kotlin.jvm.functions.Function2, p1: int, p2: java.lang.String): void public final static method run(p0: int, p1: java.lang.String): void
} }
public final class LocalFunctionKt public final class LocalFunctionKt
@@ -27,14 +27,12 @@ import org.jetbrains.kotlin.fir.labelName
import org.jetbrains.kotlin.fir.references.FirSuperReference import org.jetbrains.kotlin.fir.references.FirSuperReference
import org.jetbrains.kotlin.fir.references.FirThisReference import org.jetbrains.kotlin.fir.references.FirThisReference
import org.jetbrains.kotlin.fir.references.toResolvedCallableSymbol import org.jetbrains.kotlin.fir.references.toResolvedCallableSymbol
import org.jetbrains.kotlin.fir.resolve.constructFunctionType
import org.jetbrains.kotlin.fir.resolve.defaultType import org.jetbrains.kotlin.fir.resolve.defaultType
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
import org.jetbrains.kotlin.fir.symbols.impl.* import org.jetbrains.kotlin.fir.symbols.impl.*
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
import org.jetbrains.kotlin.fir.types.FirTypeRef import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
import org.jetbrains.kotlin.fir.types.specialFunctionTypeKind
import org.jetbrains.kotlin.fir.visitors.FirDefaultVisitorVoid import org.jetbrains.kotlin.fir.visitors.FirDefaultVisitorVoid
import org.jetbrains.kotlin.name.StandardClassIds import org.jetbrains.kotlin.name.StandardClassIds
import org.jetbrains.kotlin.psi import org.jetbrains.kotlin.psi
@@ -195,12 +193,6 @@ private class CodeFragmentCapturedValueVisitor(
} }
is FirNamedFunctionSymbol -> { is FirNamedFunctionSymbol -> {
if (symbol.isLocal) { if (symbol.isLocal) {
val isCrossingInlineBounds = isCrossingInlineBounds(element, symbol)
val capturedValue = CodeFragmentCapturedValue.LocalFunction(symbol.name, isCrossingInlineBounds)
val firFunction = symbol.fir
val functionType = firFunction.constructFunctionType(firFunction.specialFunctionTypeKind(session))
val typeRef = buildResolvedTypeRef { type = functionType }
register(symbol, CodeFragmentCapturedSymbol(capturedValue, symbol, typeRef))
registerFile(symbol) registerFile(symbol)
} }
} }