Commit Graph

105 Commits

Author SHA1 Message Date
Sergej Jaskiewicz be1d8e2894 [IR] Delete deprecated IrFactory methods
We no longer care about binary compatibility wrt the Compose IDE plugin,
see the comment in KTIJ-26314.

^KTIJ-26314 Fixed
2024-02-21 12:03:40 +00:00
Pavel Kunyavskiy 7e3e9aafa4 [IR] Add kdoc for IrExternalPackageFragment 2024-02-13 17:30:53 +00:00
Alexander.Likhachev 60080e8bb8 [Build] Remove redundant trove4j compileOnly dependencies
^KTI-1135 In Progress
2024-01-10 11:29:25 +00:00
Sergej Jaskiewicz f844a86057 [utils] Introduce the bind function and use it throughout 2023-12-13 10:04:45 +00:00
Sergej Jaskiewicz 1bed6a063f [SIR] Add SirTransformerVoid class
This is convenient for cases when the transformer has no context to pass
to each method
2023-12-12 14:27:57 +00:00
Sergej Jaskiewicz 80c9eae409 [tree generators] Factor out common transformer printing logic 2023-12-12 14:27:57 +00:00
Wojciech Litewka ef53bd9548 [IR generator] Add missing isChild = false
Those fields were effectively marked as child elements after refactor.
However, because of the current (to possibly be changed) configuration,
the generator did not write accept methods for them.
2023-12-11 10:48:43 +00:00
Sergej Jaskiewicz 8d1907e2f5 [FIR/IR generator] Introduce the common entry point for tree generators
This reduces code duplication.
2023-12-05 20:30:22 +00:00
Sergej Jaskiewicz 19ff050eae [FIR/IR generator] Move usedTypes to AbstractElement, rename it 2023-12-05 20:30:22 +00:00
Sergej Jaskiewicz e4078d163b [IR generator] Move each visitor printer into its own file 2023-12-05 20:30:22 +00:00
Sergej Jaskiewicz 0c0f7f9899 [FIR/IR generator] Rename files with printers: use printer class's names 2023-12-05 20:30:22 +00:00
Sergej Jaskiewicz d0f87f9aba [FIR/IR generator] Rename field's needAcceptAndTransform to isChild
This better describes the semantics.
2023-12-05 11:41:02 +00:00
Sergej Jaskiewicz f3016e1dcb [FIR generator] Avoid FIR-specific code in AbstractBuilderPrinter 2023-12-01 12:06:06 +00:00
Sergej Jaskiewicz 91b5a71f1a [FIR generator] Extract the Implementation class to a common module
We want to use it to generate implementation classes for other
trees, just like we already do with elements (see `AbstractElement`).
2023-12-01 12:06:06 +00:00
Sergej Jaskiewicz 11d203d0a7 [IR] Add a kDoc for IrStringConcatenation 2023-11-29 14:52:04 +00:00
Sergej Jaskiewicz 2f98b4310a [IR] Add a kDoc for IrAnonymousInitializer 2023-11-29 14:52:04 +00:00
Sergej Jaskiewicz de502301ed [IR] Add a kDoc for IrRawFunctionReference 2023-11-29 14:52:04 +00:00
Sergej Jaskiewicz 7bd4de65f8 [IR generator] Deduplicate field copying logic 2023-11-28 16:24:40 +00:00
Sergej Jaskiewicz 5f04bc8a27 [IR generator] Simplify computation of walkable children
Don't require to specify them explicitly via `isChild` in IR generator,
instead test the field type whether it is an element.
2023-11-28 16:24:40 +00:00
Sergej Jaskiewicz ad4e97154f [FIR/IR generator] Factor out allFields to AbstractElement 2023-11-28 16:24:40 +00:00
Sergej Jaskiewicz 38ee477ab4 [FIR/IR generator] Make AbstractField generic over itself
This will make some code more type-safe.
2023-11-28 16:24:40 +00:00
Sergej Jaskiewicz c6eb7d6c21 [FIR/IR generator] Factor out walkableChildren and transformableChildren 2023-11-28 16:24:40 +00:00
Sergej Jaskiewicz 0465c6d0ee [FIR/IR generator] Make InterfaceAndAbstractClassConfigurator open 2023-11-28 16:24:40 +00:00
Sergej Jaskiewicz 4307e76f15 [FIR/IR generator] Remove visitSuperTypeByDefault from visitor printers
This property is FIR-specific, no need to use it in the generic printer.
2023-11-24 17:29:58 +00:00
Sergej Jaskiewicz a5b5492b2d [IR generator] Simplify configuration of visitor parents
Don't specify a visitor parent manually for each IR node,
use an algorithm instead.
2023-11-24 17:29:58 +00:00
Sergej Jaskiewicz 62d32471e1 [FIR generator] Extract BaseTransformerTypeFinder into the common module
We want to use it in other tree generators.
2023-11-24 17:29:58 +00:00
Sergej Jaskiewicz 8eefb210f9 [FIR/IR generator] Introduce the shared Model class 2023-11-22 15:10:16 +00:00
Sergej Jaskiewicz 9a11208e67 [FIR/IR generator] Extract visitFunctionName to AbstractElement 2023-11-22 15:10:16 +00:00
Sergej Jaskiewicz 8ba42a7ff2 [IR generator] Use Element#typeName i/o Element#name where needed
This slightly reduces repetition.
2023-11-22 15:10:16 +00:00
Sergej Jaskiewicz 6ac4cd5973 [IR generator] Get rid of the config model
In the IR generator, we had a so-called `ConfigModel` with classes like
`ElementConfig` and `FieldConfig` that we deal with during
tree configuration in `IrTree.kt`, and another kind of model called
just `Model` that included the `Element` and `Field` classes
correspondingly. Those were used for actual code generation.
After configuration, `ConfigModel` was transformed to `Model` and
then the code generation was performed using `Model`.

This architecture is overly complicated and results in massive code
duplication. Most `ElementConfig` and `FieldConfig` properties had
exactly the same counterparts in `Element` in `Field` classes.

So, if you wanted to add a new feature to the tree generator, you had to
add a property to both `ConfigModel` and `Model`.

Turns out we can do just fine with only one kind of model.
2023-11-22 15:10:16 +00:00
Sergej Jaskiewicz fab63e38aa [FIR/IR generator] Reduce duplication when printing curly-braced blocks 2023-11-21 01:15:10 +00:00
Sergej Jaskiewicz 18ed85c26e [IR generator] Auto-generate IrElementTransformerVoid 2023-11-21 01:15:10 +00:00
Sergej Jaskiewicz 02c12ae26f [FIR generator] Write kDocs for accept & transform methods in FirElement 2023-11-09 13:30:25 +00:00
Sergej Jaskiewicz ed28923282 [IR generator] Don't use kotlinpoet for auto-generating IR tree classes
KT-61970 Fixed
KT-61703 Fixed
2023-11-09 13:30:25 +00:00
Sergej Jaskiewicz bca35c0015 [FIR/IR generator] Add default arguments to TypeVariable constructor 2023-11-09 13:30:25 +00:00
Sergej Jaskiewicz a84277782a [IR generator] Don't use kotlinpoet for auto-generating IrFactory
KT-61970
2023-11-06 09:47:22 +00:00
Sergej Jaskiewicz c5f519f7c7 [FIR/IR generator] Commonize visitor printing logic
This is a step towards commonizing the code generator between
FIR and IR: KT-61970

Also, don't use kotlinpoet for generating IR visitors (KT-61703)
2023-11-02 23:05:18 +00:00
Sergej Jaskiewicz 7b7bcb8ffa [FIR/IR generator] Introduce ImportCollector
This class enables printing the import list in generated files
in a smarter way.

Also, refactor `Importable` interface hierarchy, namely, don't inherit
`TypeRef` from `Importable`, since we have types like `TypeRef.Star`
which are not really importable.

Replace the `Importable#typeWithArguments` property with
the `TypeRef#render` method to utilize `ImportCollector` while rendering
types.
2023-10-26 17:33:59 +00:00
Dmitriy Novozhilov fb8bf19091 [IR] Rename IrSymbolInternals to UnsafeDuringIrConstructionAPI
The new name more precisely describes the meaning of this opt-int
2023-10-25 11:32:46 +00:00
Dmitriy Novozhilov c8b7dbd352 [IR] Add optIn to IrDeclarationContainer.declarations
Accessing list of declaration may trigger lazy declaration list computation for lazy class,
   which requires computation of fake-overrides for this class. So it's unsafe to access it
   before IR for all sources is built (because fake-overrides of lazy classes may depend on
   declaration of source classes, e.g. for java source classes)

So this OptIn is needed to carefully handle all cases of .declarations access in FIR2IR
2023-10-24 15:35:05 +00:00
Sergej Jaskiewicz 9eacdb3314 [FIR generator] Print builder property name in generated classes' KDocs
Just like we do when generating the IR tree
2023-10-24 10:29:43 +00:00
Sergej Jaskiewicz fa20e401f8 [IR generator] Rename kdoc -> kDoc property in FieldConfig 2023-10-24 10:29:43 +00:00
Sergej Jaskiewicz 7e7f4811bd [FIR/IR generator] Add kDoc property to AbstractElement & AbstractField 2023-10-24 10:29:43 +00:00
Sergej Jaskiewicz f2bb988e68 [FIR/IR generator] Replace getTypeWithArguments with a property
The `notNull` of that method was never used.
2023-10-20 10:49:20 +00:00
Sergej Jaskiewicz de4e39906c [FIR/IR generator] Use TypeRef for working with types in fields
- Don't inherit `AbstractField` from `Importable`, because it really
  is not
- Remove the `arguments` and `nullable` properties from `AbstractField`.
  Both properties can be derived from the field's `typeRef`.
- Make `AbstractField`'s `typeRef` property of type
  `TypeRefWithNullability` instead of just `TypeRef`, because fields
  can always be nullable.
2023-10-20 10:49:20 +00:00
Sergej Jaskiewicz 75b509c185 [FIR/IR generator] Share visitor-related properties between FIR & IR 2023-10-20 06:41:12 +00:00
Sergej Jaskiewicz 04c5ac0eb6 [FIR/IR generator] Factor out adding pure abstract element as parent 2023-10-19 12:00:25 +00:00
Sergej Jaskiewicz 5798021e4b [FIR/IR generator] Refactor element parents
- Move `elementParents` and `otherParents` properties
  to `AbstractElement`
- Use `elementParents` instead of `parentRefs` where needed
2023-10-19 12:00:25 +00:00
Pavel Kunyavskiy ad5831acc6 [IR] Add a method to get ModuleDescriptor from IrPackageFragment
Ideally, instead of this method, there should be a link
to IrModuleFragment. Unfortunately, it would require to big refactoring,
as some of IrPackageFragment implementations doesn't have any
IrModuleFragment inside, and are not located inside any
IrModuleFragment.

So for now, we just implement and use everywhere a single way of
getting the module descriptor, which respects a IrModuleFragment
link if it exists, and fallbacks to descriptor-based method
if it doesn't.

^KT-62623
2023-10-19 10:16:44 +00:00
Sergej Jaskiewicz 417aa236fb [FIR/IR generator] Factor out printing the preamble in generated files 2023-10-18 18:42:40 +00:00