Skip to content

Commit 3ab45bf

Browse files
committed
Fix high-arity memoized functions, add .kotlin to gitignore
1 parent 1419659 commit 3ab45bf

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ session.txt
1616
*.dll
1717
*.so
1818

19+
.kotlin/
20+
1921
prep_times.txt
2022

2123
# apparently gitignore doesn't like wildcards in the middle of the file name

compiler-plugin/src/main/kotlin/Memoizer.kt

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,14 @@ class Memoizer(private val context: IrPluginContext) : IrElementTransformerVoid(
132132

133133
val statements = body.statements.toMutableList()
134134

135-
val toAdd = context.irBuiltIns.createIrBuilder(declaration.symbol).run {
136-
irIfThen(
137-
condition = irNot(irEqualsNull(irCall(mapGet).apply {
138-
dispatchReceiver = irGetField(declaration.dispatchReceiverParameter?.let(::irGet), memoizeMapField)
139-
putValueArgument(0, createKeyFor(declaration))
140-
})),
141-
thenPart = irReturn(irCall(mapGet).apply {
142-
dispatchReceiver = irGetField(declaration.dispatchReceiverParameter?.let(::irGet), memoizeMapField)
143-
putValueArgument(0, createKeyFor(declaration))
144-
})
135+
val toAdd = context.irBuiltIns.createIrBuilder(declaration.symbol).irBlock {
136+
val check = createTmpVariable(irCall(mapGet).apply {
137+
dispatchReceiver = irGetField(declaration.dispatchReceiverParameter?.let(::irGet), memoizeMapField)
138+
putValueArgument(0, createKeyFor(declaration))
139+
})
140+
+irIfThen(
141+
condition = irNot(irEqualsNull(irGet(check))),
142+
thenPart = irReturn(irGet(check))
145143
)
146144
}
147145
statements.add(0, toAdd)
@@ -172,9 +170,7 @@ class Memoizer(private val context: IrPluginContext) : IrElementTransformerVoid(
172170
putValueArgument(2, irGet(params[2]))
173171
}
174172
else -> irCall(listOf).apply {
175-
params.forEachIndexed { index, parameter ->
176-
putValueArgument(index, irGet(parameter))
177-
}
173+
putValueArgument(0, irVararg(context.irBuiltIns.anyType, params.map { irGet(it) }))
178174
}
179175
}
180176
}

0 commit comments

Comments
 (0)