Drop assertDetached, unneeded ceremony.

This commit is contained in:
Dmitry Petrov
2016-09-12 10:15:49 +03:00
committed by Dmitry Petrov
parent 00093ac901
commit aee2a58385
36 changed files with 2 additions and 81 deletions
@@ -16,17 +16,12 @@
package org.jetbrains.kotlin.psi2ir.intermediate
import org.jetbrains.kotlin.ir.assertDetached
import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.util.render
import org.jetbrains.kotlin.psi2ir.generators.CallGenerator
import org.jetbrains.kotlin.types.KotlinType
class OnceExpressionValue(val irExpression: IrExpression) : IntermediateValue {
init {
irExpression.assertDetached()
}
private var instantiated = false
override fun load(): IrExpression {
@@ -65,14 +65,6 @@ inline fun <T : IrElement> T.replaceWith(transformation: (T) -> IrElement) {
}
}
fun IrElement.assertChild(child: IrElement) {
assert(getChild(child.slot) == child) { "$this: Invalid child: $child" }
}
fun IrElement.assertDetached() {
assert(parent == null && slot == DETACHED_SLOT) { "$this: should be detached" }
}
fun IrElement.throwNoSuchSlot(slot: Int): Nothing =
throw AssertionError("${this.render()}: no such slot $slot")
@@ -34,7 +34,6 @@ class IrAnonymousInitializerImpl(
override var body: IrBlockBody
get() = bodyImpl!!
set(value) {
value.assertDetached()
bodyImpl?.detach()
bodyImpl = value
value.setTreeLocation(this, ANONYMOUS_INITIALIZER_BODY_SLOT)
@@ -33,7 +33,6 @@ class IrClassImpl(
override val members: MutableList<IrDeclaration> = ArrayList()
fun addMember(member: IrDeclaration) {
member.assertDetached()
member.setTreeLocation(this, members.size)
members.add(member)
}
@@ -43,7 +42,6 @@ class IrClassImpl(
override fun replaceChild(slot: Int, newChild: IrElement) {
newChild.assertDetached()
members.getOrNull(slot)?.detach() ?: throwNoSuchSlot(slot)
members[slot] = newChild.assertCast()
newChild.setTreeLocation(this, slot)
@@ -43,7 +43,6 @@ class IrDelegatedPropertyImpl(
override var delegate: IrSimpleProperty
get() = delegateImpl!!
set(value) {
value.assertDetached()
delegateImpl?.detach()
delegateImpl = value
value.setTreeLocation(this, DELEGATE_SLOT)
@@ -32,7 +32,6 @@ class IrEnumEntryImpl(
) : IrDeclarationBase(startOffset, endOffset, origin), IrEnumEntry {
override var correspondingClass: IrClass? = null
set(value) {
value?.assertDetached()
field?.detach()
field = value
value?.setTreeLocation(this, ENUM_ENTRY_CLASS_SLOT)
@@ -42,7 +41,6 @@ class IrEnumEntryImpl(
override var initializerExpression: IrExpression
get() = initializerExpressionImpl!!
set(value) {
value.assertDetached()
initializerExpressionImpl?.detach()
initializerExpressionImpl = value
value.setTreeLocation(this, ENUM_ENTRY_INITIALIZER_SLOT)
@@ -39,7 +39,6 @@ class IrFileImpl(
override val declarations: MutableList<IrDeclaration> = ArrayList()
fun addDeclaration(declaration: IrDeclaration) {
declaration.assertDetached()
declaration.setTreeLocation(this, declarations.size)
declarations.add(declaration)
}
@@ -48,7 +47,6 @@ class IrFileImpl(
declarations.getOrNull(slot)
override fun replaceChild(slot: Int, newChild: IrElement) {
newChild.assertDetached()
declarations.getOrNull(slot)?.detach() ?: throwNoSuchSlot(slot)
declarations[slot] = newChild.assertCast()
newChild.setTreeLocation(this, slot)
@@ -17,7 +17,6 @@
package org.jetbrains.kotlin.ir.declarations.impl
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.ir.assertDetached
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrFunction
import org.jetbrains.kotlin.ir.detach
@@ -36,7 +35,6 @@ abstract class IrFunctionBase(
defaults[parameter]
override fun putDefault(parameter: ValueParameterDescriptor, expressionBody: IrExpressionBody) {
expressionBody.assertDetached()
defaults[parameter]?.detach()
defaults[parameter] = expressionBody
expressionBody.setTreeLocation(this, parameter.index)
@@ -39,7 +39,6 @@ abstract class IrGeneralFunctionBase(
final override var body: IrBody? = null
set(newValue) {
newValue?.assertDetached()
field?.detach()
field = newValue
newValue?.setTreeLocation(this, FUNCTION_BODY_SLOT)
@@ -45,7 +45,6 @@ class IrLocalDelegatedPropertyImpl(
override var delegate: IrVariable
get() = delegateImpl!!
set(value) {
value.assertDetached()
delegateImpl?.detach()
delegateImpl = value
value.setTreeLocation(this, DELEGATE_SLOT)
@@ -55,7 +54,6 @@ class IrLocalDelegatedPropertyImpl(
override var getter: IrLocalPropertyAccessor
get() = getterImpl!!
set(value) {
value.assertDetached()
getterImpl?.detach()
getterImpl = value
value.setTreeLocation(this, PROPERTY_GETTER_SLOT)
@@ -63,7 +61,6 @@ class IrLocalDelegatedPropertyImpl(
override var setter: IrLocalPropertyAccessor? = null
set(value) {
value?.assertDetached()
field?.detach()
field = value
value?.setTreeLocation(this, PROPERTY_SETTER_SLOT)
@@ -17,13 +17,10 @@
package org.jetbrains.kotlin.ir.declarations.impl
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.assertDetached
import org.jetbrains.kotlin.ir.*
import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
import org.jetbrains.kotlin.ir.detach
import org.jetbrains.kotlin.ir.throwNoSuchSlot
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
import java.util.*
@@ -38,13 +35,11 @@ class IrModuleFragmentImpl(
override val files: MutableList<IrFile> = ArrayList()
fun addFile(file: IrFile) {
file.assertDetached()
file.setTreeLocation(this, files.size)
files.add(file)
}
fun addAll(newFiles: List<IrFile>) {
newFiles.forEach { it.assertDetached() }
val originalSize = files.size
files.addAll(newFiles)
newFiles.forEachIndexed { i, irFile -> irFile.setTreeLocation(this, originalSize + i) }
@@ -54,8 +49,8 @@ class IrModuleFragmentImpl(
files.getOrNull(slot)
override fun replaceChild(slot: Int, newChild: IrElement) {
newChild.assertDetached()
files.getOrNull(slot)?.detach() ?: throwNoSuchSlot(slot)
files[slot] = newChild.assertCast()
}
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
@@ -32,7 +32,6 @@ abstract class IrPropertyBase(
) : IrDeclarationBase(startOffset, endOffset, origin), IrProperty {
override var getter: IrPropertyGetter? = null
set(newGetter) {
newGetter?.assertDetached()
field?.detach()
field = newGetter
newGetter?.setTreeLocation(this, PROPERTY_GETTER_SLOT)
@@ -40,7 +39,6 @@ abstract class IrPropertyBase(
override var setter: IrPropertySetter? = null
set(newSetter) {
newSetter?.assertDetached()
field?.detach()
field = newSetter
newSetter?.setTreeLocation(this, PROPERTY_SETTER_SLOT)
@@ -32,7 +32,6 @@ class IrSimplePropertyImpl(
) : IrPropertyBase(startOffset, endOffset, origin, descriptor), IrSimpleProperty {
override var initializer: IrBody? = valueInitializer
set(value) {
value?.assertDetached()
field?.detach()
field = value
value?.setTreeLocation(this, INITIALIZER_SLOT)
@@ -42,7 +42,6 @@ class IrVariableImpl(
override var initializer: IrExpression? = null
set(value) {
value?.assertDetached()
field?.detach()
field = value
value?.setTreeLocation(this, INITIALIZER_SLOT)
@@ -34,7 +34,6 @@ abstract class IrBackingFieldExpressionBase(
) : IrDeclarationReferenceBase<PropertyDescriptor>(startOffset, endOffset, type, descriptor), IrBackingFieldExpression {
override final var receiver: IrExpression? = null
set(value) {
value?.assertDetached()
field?.detach()
field = value
value?.setTreeLocation(this, BACKING_FIELD_RECEIVER_SLOT)
@@ -25,7 +25,6 @@ class IrBlockBodyImpl(startOffset: Int, endOffset: Int) : IrElementBase(startOff
override val statements: MutableList<IrStatement> = ArrayList()
fun addStatement(statement: IrStatement) {
statement.assertDetached()
statement.setTreeLocation(this, statements.size)
statements.add(statement)
}
@@ -36,7 +35,6 @@ class IrBlockBodyImpl(startOffset: Int, endOffset: Int) : IrElementBase(startOff
override fun replaceChild(slot: Int, newChild: IrElement) {
if (slot < 0 || slot >= statements.size) throwNoSuchSlot(slot)
newChild.assertDetached()
statements[slot].detach()
statements[slot] = newChild.assertCast()
newChild.setTreeLocation(this, slot)
@@ -27,13 +27,11 @@ abstract class IrContainerExpressionBase(startOffset: Int, endOffset: Int, type:
override val statements: MutableList<IrStatement> = ArrayList(2)
fun addStatement(statement: IrStatement) {
statement.assertDetached()
statement.setTreeLocation(this, statements.size)
statements.add(statement)
}
fun addAll(newStatements: List<IrStatement>) {
newStatements.forEach { it.assertDetached() }
val originalSize = this.statements.size
this.statements.addAll(newStatements)
newStatements.forEachIndexed { i, irStatement ->
@@ -47,7 +45,6 @@ abstract class IrContainerExpressionBase(startOffset: Int, endOffset: Int, type:
override fun replaceChild(slot: Int, newChild: IrElement) {
if (slot < 0 || slot >= statements.size) throwNoSuchSlot(slot)
newChild.assertDetached()
statements[slot].detach()
statements[slot] = newChild.assertCast()
newChild.setTreeLocation(this, slot)
@@ -31,7 +31,6 @@ class IrErrorCallExpressionImpl(
) : IrExpressionBase(startOffset, endOffset, type), IrErrorCallExpression {
override var explicitReceiver: IrExpression? = null
set(value) {
value?.assertDetached()
field?.detach()
field = value
value?.setTreeLocation(this, DISPATCH_RECEIVER_SLOT)
@@ -40,7 +39,6 @@ class IrErrorCallExpressionImpl(
override val arguments: MutableList<IrExpression> = SmartList()
fun addArgument(argument: IrExpression) {
argument.assertDetached()
argument.setTreeLocation(this, arguments.size)
arguments.add(argument)
}
@@ -60,7 +58,6 @@ class IrErrorCallExpressionImpl(
override fun replaceChild(slot: Int, newChild: IrElement) {
if (slot < 0 || slot >= arguments.size) throwNoSuchSlot(slot)
newChild.assertDetached()
arguments[slot].detach()
arguments[slot] = newChild.assertCast()
newChild.setTreeLocation(this, slot)
@@ -30,7 +30,6 @@ class IrExpressionBodyImpl(startOffset: Int, endOffset: Int) : IrElementBase(sta
override var expression: IrExpression
get() = expressionImpl!!
set(newValue) {
newValue.assertDetached()
expressionImpl?.detach()
expressionImpl = newValue
newValue.setTreeLocation(this, CHILD_EXPRESSION_SLOT)
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.ir.expressions.impl
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.assertCast
import org.jetbrains.kotlin.ir.assertDetached
import org.jetbrains.kotlin.ir.detach
import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.expressions.IrGeneralCall
@@ -44,7 +43,6 @@ abstract class IrGeneralCallBase(
if (index >= argumentsByParameterIndex.size) {
throw AssertionError("$this: No such argument slot: $index")
}
valueArgument?.assertDetached()
argumentsByParameterIndex[index]?.detach()
argumentsByParameterIndex[index] = valueArgument
valueArgument?.setTreeLocation(this, index)
@@ -32,7 +32,6 @@ class IrGetClassImpl(startOffset: Int, endOffset: Int, type: KotlinType) : IrExp
override var argument: IrExpression
get() = argumentImpl!!
set(value) {
value.assertDetached()
argumentImpl?.detach()
argumentImpl = value
value.setTreeLocation(this, CHILD_EXPRESSION_SLOT)
@@ -20,7 +20,6 @@ import org.jetbrains.kotlin.ir.*
import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.expressions.IrOperator
import org.jetbrains.kotlin.ir.expressions.IrWhen
import org.jetbrains.kotlin.ir.expressions.impl.IrExpressionBase
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
import org.jetbrains.kotlin.types.KotlinType
@@ -56,7 +55,6 @@ class IrIfThenElseImpl(
var condition: IrExpression
get() = conditionImpl!!
set(value) {
value.assertDetached()
value.detach()
conditionImpl = value
value.setTreeLocation(this, IF_CONDITION_SLOT)
@@ -66,7 +64,6 @@ class IrIfThenElseImpl(
var thenBranch: IrExpression
get() = thenBranchImpl!!
set(value) {
value.assertDetached()
value.detach()
thenBranchImpl = value
value.setTreeLocation(this, IF_THEN_SLOT)
@@ -74,7 +71,6 @@ class IrIfThenElseImpl(
override var elseBranch: IrExpression? = null
set(value) {
value?.assertDetached()
value?.detach()
field = value
value?.setTreeLocation(this, IF_ELSE_SLOT)
@@ -89,7 +85,6 @@ class IrIfThenElseImpl(
}
override fun replaceChild(slot: Int, newChild: IrElement) {
newChild.assertDetached()
when (slot) {
IF_CONDITION_SLOT ->
condition = newChild.assertCast()
@@ -35,7 +35,6 @@ abstract class IrLoopBase(
override var condition: IrExpression
get() = conditionImpl!!
set(value) {
value.assertDetached()
conditionImpl?.detach()
conditionImpl = value
value.setTreeLocation(this, LOOP_CONDITION_SLOT)
@@ -43,7 +42,6 @@ abstract class IrLoopBase(
override var body: IrExpression? = null
set(value) {
value?.assertDetached()
field?.detach()
field = value
value?.setTreeLocation(this, LOOP_BODY_SLOT)
@@ -30,7 +30,6 @@ abstract class IrMemberAccessExpressionBase(
) : IrExpressionBase(startOffset, endOffset, type), IrMemberAccessExpression {
override var dispatchReceiver: IrExpression? = null
set(newReceiver) {
newReceiver?.assertDetached()
field?.detach()
field = newReceiver
newReceiver?.setTreeLocation(this, DISPATCH_RECEIVER_SLOT)
@@ -38,7 +37,6 @@ abstract class IrMemberAccessExpressionBase(
override var extensionReceiver: IrExpression? = null
set(newReceiver) {
newReceiver?.assertDetached()
field?.detach()
field = newReceiver
newReceiver?.setTreeLocation(this, EXTENSION_RECEIVER_SLOT)
@@ -93,7 +93,6 @@ class IrUnaryPrimitiveImpl private constructor(
var argument: IrExpression
get() = argumentImpl!!
set(value) {
value.assertDetached()
argumentImpl?.detach()
argumentImpl = value
value.setTreeLocation(this, ARGUMENT0_SLOT)
@@ -139,7 +138,6 @@ class IrBinaryPrimitiveImpl(
var argument0: IrExpression
get() = argument0Impl!!
set(value) {
value.assertDetached()
argument0Impl?.detach()
argument0Impl = value
value.setTreeLocation(this, ARGUMENT0_SLOT)
@@ -149,7 +147,6 @@ class IrBinaryPrimitiveImpl(
var argument1: IrExpression
get() = argument1Impl!!
set(value) {
value.assertDetached()
argument1Impl?.detach()
argument1Impl = value
value.setTreeLocation(this, ARGUMENT1_SLOT)
@@ -98,7 +98,6 @@ class IrSetterCallImpl(
override fun putArgument(index: Int, valueArgument: IrExpression?) {
if (index != SETTER_ARGUMENT_INDEX) return
argumentImpl?.detach()
valueArgument?.assertDetached()
argumentImpl = valueArgument
valueArgument?.setTreeLocation(this, SETTER_ARGUMENT_INDEX)
}
@@ -42,7 +42,6 @@ class IrReturnImpl(
override var value: IrExpression? = null
set(newValue) {
newValue?.assertDetached()
field?.detach()
field = newValue
newValue?.setTreeLocation(this, CHILD_EXPRESSION_SLOT)
@@ -50,7 +50,6 @@ class IrSetBackingFieldImpl(
override var value: IrExpression
get() = valueImpl!!
set(value) {
value.assertDetached()
valueImpl?.detach()
valueImpl = value
value.setTreeLocation(this, CHILD_EXPRESSION_SLOT)
@@ -45,7 +45,6 @@ class IrSetVariableImpl(
override var value: IrExpression
get() = valueImpl!!
set(value) {
value.assertDetached()
valueImpl?.detach()
valueImpl = value
value.setTreeLocation(this, ARGUMENT0_SLOT)
@@ -33,7 +33,6 @@ class IrSpreadElementImpl(
override var expression: IrExpression
get() = expressionImpl!!
set(value) {
value.assertDetached()
expressionImpl?.detach()
expressionImpl = value
value.setTreeLocation(this, CHILD_EXPRESSION_SLOT)
@@ -32,7 +32,6 @@ class IrStringConcatenationImpl(
override val arguments: MutableList<IrExpression> = ArrayList()
override fun addArgument(argument: IrExpression) {
argument.assertDetached()
argument.setTreeLocation(this, arguments.size)
arguments.add(argument)
}
@@ -43,7 +42,6 @@ class IrStringConcatenationImpl(
override fun replaceChild(slot: Int, newChild: IrElement) {
if (slot < 0 || slot >= arguments.size) throwNoSuchSlot(slot)
newChild.assertDetached()
arguments[slot].detach()
arguments[slot] = newChild.assertCast()
newChild.setTreeLocation(this, slot)
@@ -41,7 +41,6 @@ class IrThrowImpl(
override var value: IrExpression
get() = valueImpl!!
set(newValue) {
newValue.assertDetached()
valueImpl?.detach()
valueImpl = newValue
newValue.setTreeLocation(this, CHILD_EXPRESSION_SLOT)
@@ -34,7 +34,6 @@ class IrTryCatchImpl(
override var tryResult: IrExpression
get() = tryResultImpl!!
set(value) {
value.assertDetached()
tryResultImpl?.detach()
tryResultImpl = value
value.setTreeLocation(this, TRY_RESULT_SLOT)
@@ -46,7 +45,6 @@ class IrTryCatchImpl(
override val catchClausesCount: Int get() = catchClauseResults.size
fun addCatchClause(parameter: VariableDescriptor, result: IrExpression) {
result.assertDetached()
result.setTreeLocation(this, catchClausesCount)
catchClauseParameters.add(parameter)
catchClauseResults.add(result)
@@ -60,7 +58,6 @@ class IrTryCatchImpl(
override var finallyExpression: IrExpression? = null
set(value) {
value?.assertDetached()
field?.detach()
field = value
value?.setTreeLocation(this, FINALLY_EXPRESSION_SLOT)
@@ -46,7 +46,6 @@ class IrTypeOperatorCallImpl(
override var argument: IrExpression
get() = argumentImpl!!
set(value) {
value.assertDetached()
argumentImpl?.detach()
argumentImpl = value
value.setTreeLocation(this, ARGUMENT0_SLOT)
@@ -33,7 +33,6 @@ class IrVarargImpl(
override val elements: MutableList<IrVarargElement> = SmartList()
fun addElement(varargElement: IrVarargElement) {
varargElement.assertDetached()
varargElement.setTreeLocation(this, elements.size)
elements.add(varargElement)
}
@@ -44,7 +43,6 @@ class IrVarargImpl(
override fun replaceChild(slot: Int, newChild: IrElement) {
if (slot < 0 || slot >= elements.size) throwNoSuchSlot(slot)
newChild.assertDetached()
elements[slot].detach()
elements[slot] = newChild.assertCast()
newChild.setTreeLocation(this, slot)
@@ -34,8 +34,6 @@ class IrWhenImpl(
private val branchParts = ArrayList<IrExpression>()
fun addBranch(condition: IrExpression, result: IrExpression) {
condition.assertDetached()
result.assertDetached()
condition.setTreeLocation(this, branchParts.size)
branchParts.add(condition)
result.setTreeLocation(this, branchParts.size)
@@ -44,7 +42,6 @@ class IrWhenImpl(
override var elseBranch: IrExpression? = null
set(value) {
value?.assertDetached()
value?.detach()
field = value
value?.setTreeLocation(this, IF_ELSE_SLOT)
@@ -61,7 +58,6 @@ class IrWhenImpl(
when (slot) {
IF_ELSE_SLOT -> elseBranch = newChild.assertCast()
in branchParts.indices -> {
newChild.assertDetached()
branchParts[slot].detach()
branchParts[slot] = newChild.assertCast()
newChild.setTreeLocation(this, slot)