Skip to content

Commit

Permalink
Switch to auto generated IR tree
Browse files Browse the repository at this point in the history
Co-authored-by: Alexander Udalov <alexander.udalov@jetbrains.com>
  • Loading branch information
mcpiroman and udalov committed May 5, 2022
1 parent dde4c7f commit 2319d78
Show file tree
Hide file tree
Showing 137 changed files with 4,591 additions and 714 deletions.
21 changes: 21 additions & 0 deletions .idea/runConfigurations/Generate_IR_tree.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -110,33 +110,35 @@ class ScriptGenerator(declarationGenerator: DeclarationGenerator) : DeclarationG
makeParameter(it.thisAsReceiverParameter, IrDeclarationOrigin.SCRIPT_IMPLICIT_RECEIVER, parametersIndex++)
}

irScript.providedProperties = descriptor.scriptProvidedProperties.zip(descriptor.scriptProvidedPropertiesParameters)
.map { (providedProperty, parameter) ->
// TODO: initializer
// TODO: do not keep direct links
val type = providedProperty.type.toIrType()
val valueParameter = context.symbolTable.declareValueParameter(
descriptor.scriptProvidedProperties.zip(descriptor.scriptProvidedPropertiesParameters) { providedProperty, parameter ->
// TODO: initializer
// TODO: do not keep direct links
val type = providedProperty.type.toIrType()
val valueParameter = context.symbolTable.declareValueParameter(
UNDEFINED_OFFSET, UNDEFINED_OFFSET,
IrDeclarationOrigin.SCRIPT_PROVIDED_PROPERTY, parameter, type
) { symbol ->
context.irFactory.createValueParameter(
UNDEFINED_OFFSET, UNDEFINED_OFFSET,
IrDeclarationOrigin.SCRIPT_PROVIDED_PROPERTY, parameter, type
) { symbol ->
context.irFactory.createValueParameter(
UNDEFINED_OFFSET, UNDEFINED_OFFSET,
IrDeclarationOrigin.SCRIPT_PROVIDED_PROPERTY, symbol, descriptor.name,
parametersIndex, type, null, isCrossinline = false, isNoinline = false, isHidden = false, isAssignable = false
).also { it.parent = irScript }
}
parametersIndex++
val irProperty =
PropertyGenerator(declarationGenerator).generateSyntheticProperty(
ktScript,
providedProperty,
valueParameter,
generateSyntheticAccessors = true
)
irProperty.origin = IrDeclarationOrigin.SCRIPT_PROVIDED_PROPERTY
irScript.statements += irProperty
valueParameter to irProperty.symbol
IrDeclarationOrigin.SCRIPT_PROVIDED_PROPERTY, symbol, descriptor.name,
parametersIndex, type, null, isCrossinline = false, isNoinline = false, isHidden = false, isAssignable = false
).also { it.parent = irScript }
}
parametersIndex++
val irProperty =
PropertyGenerator(declarationGenerator).generateSyntheticProperty(
ktScript,
providedProperty,
valueParameter,
generateSyntheticAccessors = true
)
irProperty.origin = IrDeclarationOrigin.SCRIPT_PROVIDED_PROPERTY
irScript.statements += irProperty
valueParameter to irProperty.symbol
}.unzip().let { (params, props) ->
irScript.providedProperties = props
irScript.providedPropertiesParameters = params
}

irScript.constructor = with(IrFunctionBuilder().apply {
isPrimary = true
Expand All @@ -155,7 +157,7 @@ class ScriptGenerator(declarationGenerator: DeclarationGenerator) : DeclarationG
addIfNotNull(irScript.earlierScriptsParameter)
addAll(irScript.explicitCallParameters)
addAll(irScript.implicitReceiversParameters)
irScript.providedProperties.forEach { add(it.first) }
addAll(irScript.providedPropertiesParameters)
}
irConstructor.parent = irScript
irConstructor.metadata = DescriptorMetadataSource.Function(descriptor.unsubstitutedPrimaryConstructor)
Expand Down
51 changes: 50 additions & 1 deletion compiler/ir/ir.tree/build.gradle.kts
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.ideaExt.idea

plugins {
kotlin("jvm")
id("jps-compatible")
Expand All @@ -10,10 +12,57 @@ dependencies {
implementation(project(":compiler:util"))
implementation(project(":compiler:config"))

compileOnly(project("tree-generator")) // Provided, so that IDEA can recognize references to this module in KDoc.
compileOnly(intellijCore())
}

sourceSets {
"main" { projectDefault() }
"main" {
projectDefault()
this.java.srcDir("gen")
}
"test" {}
}

val generatorClasspath by configurations.creating

dependencies {
generatorClasspath(project("tree-generator"))
}

val generationRoot = projectDir.resolve("gen")

val generateTree by tasks.registering(NoDebugJavaExec::class) {

val generatorRoot = "$projectDir/tree-generator/src/"

val generatorConfigurationFiles = fileTree(generatorRoot) {
include("**/*.kt")
}

inputs.files(generatorConfigurationFiles)
outputs.dirs(generationRoot)

args(generationRoot)
workingDir = rootDir
classpath = generatorClasspath
main = "org.jetbrains.kotlin.ir.generator.MainKt"
systemProperties["line.separator"] = "\n"
}

val compileKotlin by tasks

compileKotlin.dependsOn(generateTree)

tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinCompile<*>> {
kotlinOptions {
freeCompilerArgs += "-Xinline-classes"
}
}

if (kotlinBuildProperties.isInJpsBuildIdeaSync) {
apply(plugin = "idea")
idea {
this.module.generatedSourceDirs.add(generationRoot)
}
}
Expand Up @@ -3,11 +3,18 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

//This file was generated automatically
//DO NOT MODIFY IT MANUALLY

package org.jetbrains.kotlin.ir

import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor

/**
* A non-leaf IR tree element.
* @sample org.jetbrains.kotlin.ir.generator.IrTree.rootElement
*/
interface IrElement {
val startOffset: Int

Expand Down
Expand Up @@ -3,6 +3,13 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

//This file was generated automatically
//DO NOT MODIFY IT MANUALLY

package org.jetbrains.kotlin.ir

/**
* A non-leaf IR tree element.
* @sample org.jetbrains.kotlin.ir.generator.IrTree.statement
*/
interface IrStatement : IrElement
Expand Up @@ -3,6 +3,9 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

//This file was generated automatically
//DO NOT MODIFY IT MANUALLY

package org.jetbrains.kotlin.ir.declarations

import org.jetbrains.kotlin.descriptors.ClassDescriptor
Expand All @@ -12,9 +15,14 @@ import org.jetbrains.kotlin.ir.symbols.IrAnonymousInitializerSymbol
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor

/**
* A leaf IR tree element.
* @sample org.jetbrains.kotlin.ir.generator.IrTree.anonymousInitializer
*/
abstract class IrAnonymousInitializer : IrDeclarationBase() {
@ObsoleteDescriptorBasedAPI
abstract override val descriptor: ClassDescriptor // TODO special descriptor for anonymous initializer blocks
abstract override val descriptor: ClassDescriptor

abstract override val symbol: IrAnonymousInitializerSymbol

abstract val isStatic: Boolean
Expand Down
@@ -0,0 +1,19 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

//This file was generated automatically
//DO NOT MODIFY IT MANUALLY

package org.jetbrains.kotlin.ir.declarations

import org.jetbrains.kotlin.ir.IrElement

/**
* A non-leaf IR tree element.
* @sample org.jetbrains.kotlin.ir.generator.IrTree.attributeContainer
*/
interface IrAttributeContainer : IrElement {
var attributeOwnerId: IrAttributeContainer
}
Expand Up @@ -3,9 +3,16 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

//This file was generated automatically
//DO NOT MODIFY IT MANUALLY

package org.jetbrains.kotlin.ir.declarations

import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.descriptors.SourceElement
import org.jetbrains.kotlin.descriptors.ValueClassRepresentation
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
import org.jetbrains.kotlin.ir.types.IrSimpleType
Expand All @@ -15,21 +22,32 @@ import org.jetbrains.kotlin.ir.util.transformInPlace
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor

abstract class IrClass :
IrDeclarationBase(), IrPossiblyExternalDeclaration, IrDeclarationWithVisibility,
IrDeclarationContainer, IrTypeParametersContainer, IrAttributeContainer, IrMetadataSourceOwner {

/**
* A leaf IR tree element.
* @sample org.jetbrains.kotlin.ir.generator.IrTree.class
*/
abstract class IrClass : IrDeclarationBase(), IrPossiblyExternalDeclaration,
IrDeclarationWithVisibility, IrTypeParametersContainer, IrDeclarationContainer,
IrAttributeContainer, IrMetadataSourceOwner {
@ObsoleteDescriptorBasedAPI
abstract override val descriptor: ClassDescriptor

abstract override val symbol: IrClassSymbol

abstract val kind: ClassKind

abstract var modality: Modality

abstract val isCompanion: Boolean

abstract val isInner: Boolean

abstract val isData: Boolean

abstract val isValue: Boolean

abstract val isExpect: Boolean

abstract val isFun: Boolean

abstract val source: SourceElement
Expand Down
Expand Up @@ -3,16 +3,24 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

//This file was generated automatically
//DO NOT MODIFY IT MANUALLY

package org.jetbrains.kotlin.ir.declarations

import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor

/**
* A leaf IR tree element.
* @sample org.jetbrains.kotlin.ir.generator.IrTree.constructor
*/
abstract class IrConstructor : IrFunction() {
@ObsoleteDescriptorBasedAPI
abstract override val descriptor: ClassConstructorDescriptor

abstract override val symbol: IrConstructorSymbol

abstract val isPrimary: Boolean
Expand Down
Expand Up @@ -3,12 +3,19 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

//This file was generated automatically
//DO NOT MODIFY IT MANUALLY

package org.jetbrains.kotlin.ir.declarations

import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI

/**
* A non-leaf IR tree element.
* @sample org.jetbrains.kotlin.ir.generator.IrTree.declaration
*/
interface IrDeclaration : IrStatement, IrSymbolOwner, IrMutableAnnotationContainer {
@ObsoleteDescriptorBasedAPI
val descriptor: DeclarationDescriptor
Expand Down
@@ -1,10 +1,17 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

//This file was generated automatically
//DO NOT MODIFY IT MANUALLY

package org.jetbrains.kotlin.ir.declarations

import org.jetbrains.kotlin.ir.IrElementBase

/**
* A non-leaf IR tree element.
* @sample org.jetbrains.kotlin.ir.generator.IrTree.declarationBase
*/
abstract class IrDeclarationBase : IrElementBase(), IrDeclaration
Expand Up @@ -3,8 +3,16 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

//This file was generated automatically
//DO NOT MODIFY IT MANUALLY

package org.jetbrains.kotlin.ir.declarations


/**
* A non-leaf IR tree element.
* @sample org.jetbrains.kotlin.ir.generator.IrTree.declarationContainer
*/
interface IrDeclarationContainer : IrDeclarationParent {
val declarations: MutableList<IrDeclaration>
}
@@ -1,10 +1,17 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

//This file was generated automatically
//DO NOT MODIFY IT MANUALLY

package org.jetbrains.kotlin.ir.declarations

import org.jetbrains.kotlin.ir.IrElement

/**
* A non-leaf IR tree element.
* @sample org.jetbrains.kotlin.ir.generator.IrTree.declarationParent
*/
interface IrDeclarationParent : IrElement

0 comments on commit 2319d78

Please sign in to comment.