Skip to content

Commit

Permalink
Switch to auto generated IR tree
Browse files Browse the repository at this point in the history
  • Loading branch information
mcpiroman authored and udalov committed Jan 14, 2022
1 parent e99eb1a commit c5aa261
Show file tree
Hide file tree
Showing 145 changed files with 4,952 additions and 914 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 @@ -41,7 +41,7 @@ class ScopeValidator(
}
}

fun visitVariableAccess(element: IrElement, variable: IrValueDeclaration) {
fun visitValueAccess(element: IrElement, variable: IrValueDeclaration) {
if (variable !in this.values) {
reportError(element, "Value ${variable.render()} not accessible")
}
Expand Down Expand Up @@ -130,7 +130,7 @@ class ScopeValidator(
}

override fun visitValueAccess(expression: IrValueAccessExpression, data: Visibles) {
data.visitVariableAccess(expression, expression.symbol.owner)
data.visitValueAccess(expression, expression.symbol.owner)
super.visitValueAccess(expression, data)
}

Expand Down
Expand Up @@ -365,8 +365,8 @@ fun usefulDeclarations(
expression.symbol.owner.enqueue("raw function access")
}

override fun visitVariableAccess(expression: IrValueAccessExpression) {
super.visitVariableAccess(expression)
override fun visitValueAccess(expression: IrValueAccessExpression) {
super.visitValueAccess(expression)

expression.symbol.owner.enqueue("variable access")
}
Expand Down
Expand Up @@ -108,33 +108,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 @@ -153,7 +155,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)
}
}
@@ -0,0 +1,15 @@
/*
* 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

/**
* A non-leaf IR tree element.
* @sample org.jetbrains.kotlin.ir.generator.IrTree.abstractElement
*/
abstract class IrAbstractElement : IrElement
21 changes: 21 additions & 0 deletions compiler/ir/ir.tree/gen/org/jetbrains/kotlin/ir/IrElement.kt
@@ -0,0 +1,21 @@
/*
* 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

import org.jetbrains.kotlin.ir.IrElementBase

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

val endOffset: Int
}
15 changes: 15 additions & 0 deletions compiler/ir/ir.tree/gen/org/jetbrains/kotlin/ir/IrStatement.kt
@@ -0,0 +1,15 @@
/*
* 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

/**
* 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,31 +3,49 @@
* 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.InlineClassRepresentation
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.descriptors.SourceElement
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
import org.jetbrains.kotlin.ir.types.IrSimpleType
import org.jetbrains.kotlin.ir.types.IrType
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 isInline: 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

0 comments on commit c5aa261

Please sign in to comment.