FIR2IR: get rid of "creates list under the hood" warnings

This commit is contained in:
Mikhail Glukhikh
2020-02-11 14:37:05 +03:00
parent fe5dd4dba1
commit df07b77271
2 changed files with 35 additions and 35 deletions
@@ -140,16 +140,18 @@ class Fir2IrDeclarationStorage(
leaveScope(descriptor) leaveScope(descriptor)
} }
private fun IrTypeParametersContainer.setTypeParameters(owner: FirTypeParametersOwner) {
typeParameters = owner.typeParameters.mapIndexed { index, typeParameter ->
getIrTypeParameter(typeParameter, index).apply { parent = this@setTypeParameters }
}
}
private fun IrClass.declareSupertypesAndTypeParameters(klass: FirClass<*>): IrClass { private fun IrClass.declareSupertypesAndTypeParameters(klass: FirClass<*>): IrClass {
for (superTypeRef in klass.superTypeRefs) { superTypes = klass.superTypeRefs.map { superTypeRef ->
superTypes += superTypeRef.toIrType(session, this@Fir2IrDeclarationStorage) superTypeRef.toIrType(session, this@Fir2IrDeclarationStorage)
} }
if (klass is FirRegularClass) { if (klass is FirRegularClass) {
for ((index, typeParameter) in klass.typeParameters.withIndex()) { setTypeParameters(klass)
typeParameters += getIrTypeParameter(typeParameter, index).apply {
parent = this@declareSupertypesAndTypeParameters
}
}
} }
return this return this
} }
@@ -320,19 +322,21 @@ class Fir2IrDeclarationStorage(
private fun <T : IrFunction> T.declareDefaultSetterParameter(type: IrType): T { private fun <T : IrFunction> T.declareDefaultSetterParameter(type: IrType): T {
val parent = this val parent = this
val descriptor = WrappedValueParameterDescriptor() val descriptor = WrappedValueParameterDescriptor()
valueParameters += irSymbolTable.declareValueParameter( valueParameters = listOf(
startOffset, endOffset, origin, descriptor, type irSymbolTable.declareValueParameter(
) { symbol -> startOffset, endOffset, origin, descriptor, type
IrValueParameterImpl( ) { symbol ->
startOffset, endOffset, IrDeclarationOrigin.DEFINED, symbol, IrValueParameterImpl(
Name.special("<set-?>"), 0, type, startOffset, endOffset, IrDeclarationOrigin.DEFINED, symbol,
varargElementType = null, Name.special("<set-?>"), 0, type,
isCrossinline = false, isNoinline = false varargElementType = null,
).apply { isCrossinline = false, isNoinline = false
this.parent = parent ).apply {
descriptor.bind(this) this.parent = parent
descriptor.bind(this)
}
} }
} )
return this return this
} }
@@ -342,16 +346,14 @@ class Fir2IrDeclarationStorage(
val type = function.valueParameters.first().returnTypeRef.toIrType(session, this@Fir2IrDeclarationStorage) val type = function.valueParameters.first().returnTypeRef.toIrType(session, this@Fir2IrDeclarationStorage)
declareDefaultSetterParameter(type) declareDefaultSetterParameter(type)
} else if (function != null) { } else if (function != null) {
for ((index, valueParameter) in function.valueParameters.withIndex()) { valueParameters = function.valueParameters.mapIndexed { index, valueParameter ->
valueParameters += createAndSaveIrParameter(valueParameter, index).apply { this.parent = parent } createAndSaveIrParameter(valueParameter, index).apply { this.parent = parent }
} }
} }
if (function !is FirConstructor) { if (function !is FirConstructor) {
val thisOrigin = IrDeclarationOrigin.DEFINED val thisOrigin = IrDeclarationOrigin.DEFINED
if (function is FirSimpleFunction) { if (function is FirSimpleFunction) {
for ((index, typeParameter) in function.typeParameters.withIndex()) { setTypeParameters(function)
typeParameters += getIrTypeParameter(typeParameter, index).apply { this.parent = parent }
}
} }
val receiverTypeRef = function?.receiverTypeRef val receiverTypeRef = function?.receiverTypeRef
if (receiverTypeRef != null) { if (receiverTypeRef != null) {
@@ -163,9 +163,8 @@ class Fir2IrVisitor(
declarations += irDeclaration declarations += irDeclaration
} }
file.annotations.forEach { annotations = file.annotations.mapNotNull {
val irCall = it.accept(this@Fir2IrVisitor, data) as? IrConstructorCall ?: return@forEach it.accept(this@Fir2IrVisitor, data) as? IrConstructorCall
annotations += irCall
} }
} }
} }
@@ -305,9 +304,8 @@ class Fir2IrVisitor(
} }
} }
addFakeOverrides(klass, processedCallableNames) addFakeOverrides(klass, processedCallableNames)
klass.annotations.forEach { annotations = klass.annotations.mapNotNull {
val irCall = it.accept(this@Fir2IrVisitor, null) as? IrConstructorCall ?: return@forEach it.accept(this@Fir2IrVisitor, null) as? IrConstructorCall
annotations += irCall
} }
} }
if (irPrimaryConstructor != null) { if (irPrimaryConstructor != null) {
@@ -377,7 +375,7 @@ class Fir2IrVisitor(
if (firOverriddenSymbol != null && this is IrSimpleFunction && firFunctionSymbol != null) { if (firOverriddenSymbol != null && this is IrSimpleFunction && firFunctionSymbol != null) {
val overriddenSymbol = declarationStorage.getIrFunctionSymbol(firOverriddenSymbol) val overriddenSymbol = declarationStorage.getIrFunctionSymbol(firOverriddenSymbol)
if (overriddenSymbol is IrSimpleFunctionSymbol) { if (overriddenSymbol is IrSimpleFunctionSymbol) {
overriddenSymbols += overriddenSymbol overriddenSymbols = listOf(overriddenSymbol)
} }
} }
var body = firFunction?.body?.convertToIrBlockBody() var body = firFunction?.body?.convertToIrBlockBody()
@@ -581,18 +579,18 @@ class Fir2IrVisitor(
property.getter, this, propertyType, property.getter is FirDefaultPropertyGetter, property.getter == null property.getter, this, propertyType, property.getter is FirDefaultPropertyGetter, property.getter == null
) )
getter?.apply { getter?.apply {
overriddenProperty?.owner?.getter?.symbol?.let { overriddenSymbols += it } overriddenProperty?.owner?.getter?.symbol?.let { overriddenSymbols = listOf(it) }
} }
if (property.isVar) { if (property.isVar) {
setter?.setPropertyAccessorContent( setter?.setPropertyAccessorContent(
property.setter, this, propertyType, property.setter is FirDefaultPropertySetter, property.setter == null property.setter, this, propertyType, property.setter is FirDefaultPropertySetter, property.setter == null
) )
setter?.apply { setter?.apply {
overriddenProperty?.owner?.setter?.symbol?.let { overriddenSymbols += it } overriddenProperty?.owner?.setter?.symbol?.let { overriddenSymbols = listOf(it) }
} }
} }
property.annotations.forEach { annotations = property.annotations.mapNotNull {
annotations += it.accept(this@Fir2IrVisitor, null) as IrConstructorCall it.accept(this@Fir2IrVisitor, null) as? IrConstructorCall
} }
declarationStorage.leaveScope(descriptor) declarationStorage.leaveScope(descriptor)
return this return this