Commit Graph
100 Commits
Author SHA1 Message Date
Ivan Kylchik 32057f6d10 [JVM_IR] Use createSimpleNamedCompilerPhase to create lowerings 2023-11-01 14:01:17 +00:00
Ivan Kylchik f5bb477459 [JVM_IR] Move all stickyPostconditions into single lowering
`stickyPostconditions` are such conditions that are checked
every time after applying when a new lowering finishes its execution.
Right now we are using them only in JVM, and this is a blocker
for adopting Native approach for lowering execution.

In Native we are using
`SimpleNamedCompilerPhase<in Context : LoggingContext, Input, Output>`
as the common super type for all lowerings. Here we have `Input` and
`Output` that can potentially be different and `stickyPostconditions`
don't have much sense in that case.
2023-11-01 14:01:17 +00:00
Ivan Kylchik 6a02a26db8 [Native] Move createSimpleNamedCompilerPhase into common.phaser.PhaseBuilders
This is needed to be able to reuse these functions
for other backends.
2023-11-01 14:01:17 +00:00
Ivan Kylchik 465fc9116e [IR] Drop some old lower utils that are not used anymore 2023-11-01 14:01:17 +00:00
Ivan Kylchik e827f260e7 [IR] Simplify IrProperty?.isConst check in interpreter 2023-10-25 16:43:25 +00:00
Ivan Kylchik a97c0bab0b [IR] Simplify access to IrProperty from IrCall and IrField in interpreter 2023-10-25 16:43:25 +00:00
Ivan Kylchik ad0fad5fad [FIR] Drop isStatic field from FirJavaFieldBuilder
It is not used anywhere, and it looks like the proper way to set
`isStatic` is through the `status` field.
2023-10-20 16:33:21 +00:00
Ivan Kylchik 69a888b431 [FIR] Add diag test to verify const checker in Java world
Currently, this test is not working for FIR.

#KT-57802 Fixed
2023-10-20 16:33:21 +00:00
Ivan Kylchik 4334ae9da9 [FIR] Add JvmName to the list of REQUIRED_ANNOTATIONS
We need to resolve `JvmName` as soon as possible because
it can be analyzed in `FirJavaElementFinder` to create
the correct class stub.

#KT-57802
2023-10-20 16:33:20 +00:00
Ivan Kylchik a45bb8d92b [FIR] Find the correct FIR file in Java finder for file with JvmName
#KT-57802
2023-10-20 16:33:20 +00:00
Ivan Kylchik 8c7c44f9f5 [FIR] Fix evaluation of Java properties for Char and String types
#KT-57802
2023-10-20 16:33:20 +00:00
Ivan Kylchik bf6f241d4a [FIR] Reuse transformConst method to evaluate properties in Java world
#KT-57802
2023-10-20 16:33:20 +00:00
Ivan Kylchik 4d9b4dd27f [FIR] Use lazy evaluation for FIR Java properties
This is needed to avoid recursive evaluations when we have
multiple `const val` properties in a single class or file.

#KT-57802
2023-10-20 16:33:20 +00:00
Ivan Kylchik 7935b2bdb1 [FIR] Allow to evaluate top level const properties in Java world
#KT-57802
2023-10-20 16:33:20 +00:00
Ivan Kylchik 886ef1a4b4 [FIR] Support the simple case of java field interpretation
#KT-57802
2023-10-20 16:33:20 +00:00
Ivan Kylchik 2af73c2b13 [FIR] Add FirJavaElementFinder to session's components
This change allows us to use `IrInterpreter` to evaluate Kotlin's
const properties that were called from Java world

#KT-57802
2023-10-20 16:33:20 +00:00
Ivan Kylchik fbe00b1b91 [FIR] Add Fir2IrLazyField class
This class will be used to delay const evaluation of java fields
until IR tree is built.

#KT-57802
2023-10-20 16:33:20 +00:00
Ivan Kylchik 70f195598e [FIR2IR] Don't run interpreter's preprocessors on fir2ir stage
In IR interpreter we have "preprocessors". Preprocessor is a
transformer that changes IR expressions in a way that we can
interpret them at least partially.

We have two places where interpretation is happening:
1. Right after fir2ir where we evaluate only strictly necessary
expression for `const val` and annotations.
2. In lowering for every backend where we are doing some
constant folding.

Earlier, to avoid double work, we didn't launch preprocessors
in backend if we were using K2. But this approach breaks compilation
for MPP projects where one module is compiled with K1 into klib
and the overall project is compiled with K2. On the backend side,
we are mistakenly assuming that preprocessors were launched, but they
were not.

The solution is to run preprocessors only on the backend side. If we
think about it, interpretation on fir2ir doesn't require any
preprocessing because we are working only with expressions that are
correct and must be fully evaluated.

#KT-62126 Fixed
2023-10-19 12:29:32 +00:00
Ivan Kylchik 350ee4be1d [Native] Replace consequence line and column calls with a single one 2023-10-13 08:50:47 +00:00
Ivan Kylchik 1be98b8f08 [IR] Extract some common code into AbstractIrFileEntry 2023-10-13 08:50:47 +00:00
Ivan Kylchik 6039d39546 [IR] Add new method IrFileEntry.getLineAndColumnNumbers
Calling this method instead of sequence of `getLineNumber` and
`getLineNumber` is faster because we eliminate one exess
`getLineNumber` call.
2023-10-13 08:50:47 +00:00
Ivan Kylchik a30d0aeeb0 [JVM] Replace AbstractInsnNode.getType with new util function
This change speeds up backend by approximately 0.96%.
2023-10-13 08:50:47 +00:00
Ivan Kylchik 67460962c3 [JVM] Use HashSet instead of SmartSet in MaxStackFrameSizeAndLocalsCalculator
This change speeds up backend by approximately 0.25%.
2023-10-13 08:50:47 +00:00
Ivan Kylchik 05b364a5f1 [JVM] Simplify equals method in StrictBasicValue 2023-10-13 08:50:47 +00:00
Ivan Kylchik 84a47a2298 [IR] Drop SLRUCache usages from NaiveSourceBasedFileEntryImpl
Access to `SLRUCache` is a bottleneck when we call `getLineNumber`.
We are very rarely going to access the same offset. This change
speeds up backend by approximately 0.43%.
2023-10-13 08:50:47 +00:00
Ivan Kylchik 4a07454d8d [IR] Drop excess resolveFakeOverride from EVALUATION_MODE
This change doesn't affect semantic and speeds up
backend by approximately 0.06%.
2023-10-13 08:50:47 +00:00
Ivan Kylchik 3335db0aa8 [IR] Simplify unsigned check in EVALUATION_MODE
This way we are not creating useless intermediate lists. This change
speeds up backend by approximately 0.38%.
2023-10-13 08:50:47 +00:00
Ivan Kylchik f36f37bf47 [IR] Drop isNan fun from IrInterpreterCommonChecker
It is not used anymore after 858f432807
2023-10-13 08:50:47 +00:00
Ivan Kylchik 9135e9d13d [JVM_IR] Drop reversed call from writeLocalVariablesInTable
It is better to use simple for loop. This change speeds up
backend by approximately 0.07%.
2023-10-13 08:50:47 +00:00
Ivan Kylchik 96a2da4906 [JVM] Split mergeControlFlowEdge into full and fast versions
This is needed because for `FastStackAnalyzer` we actually
will use only `fast` version, that can potentially improve overall
performance.
2023-10-12 13:04:43 +00:00
Ivan Kylchik 07c7792693 [JVM] Drop toArray call where iterator can be used 2023-10-12 13:04:43 +00:00
Ivan Kylchik 2387fe302c [JVM] Use reference comparison for objects defined in StrictBasicValue 2023-10-12 13:04:43 +00:00
Ivan Kylchik c1c04376cf [JVM] Replace open functions in FastAnalyzer with constructor args 2023-10-12 13:04:43 +00:00
Ivan Kylchik 99655cfa15 [JVM] Make newFrame constructor's parameter for FastAnalyzer 2023-10-12 13:04:43 +00:00
Ivan Kylchik cfe38470af [JVM] Use composition instead of inheritance in FixStackAnalyzer
This way we will be able to pass `createFrame` argument
directly to `FastAnalyzer`.
2023-10-12 13:04:43 +00:00
Ivan Kylchik 2327800a95 [JVM] Make BoxingInterpreter an abstract class instead of open
This way, it is a little bit easier to fit the semantics of this
class in the head.
2023-10-12 13:04:43 +00:00
Ivan Kylchik 38dd75c6c8 [JVM] Drop boxingInterpreter constructor parameter from BoxingFrame 2023-10-12 13:04:43 +00:00
Ivan Kylchik 6d57cbe23c [JVM] Reorganize positions of methods in FastAnalyzer 2023-10-12 13:04:43 +00:00
Ivan Kylchik 895afc736d [JVM] Drop I : Interpreter<V> type parameter from FastAnalyzer 2023-10-12 13:04:43 +00:00
Ivan Kylchik 87c46db3d5 [JVM] Drop getFrame and setFrame methods from FastAnalyzer 2023-10-12 13:04:43 +00:00
Ivan Kylchik f7f253d2bf [JVM] Move isTcbStart computation in FastAnalyzer 2023-10-12 13:04:43 +00:00
Ivan Kylchik 53d9b3c54f [JVM] Combine all mergeControlFlowEdge methods
This is just a refactoring commit. All fast analyzers are doing the
same thing in `mergeControlFlowEdge`, so we extract it in common
`FastAnalyzer`. The only exception is `FastStackAnalyzer`.
There was no `isMergeNode` check, but this is an optimization
that allows us to reuse a frame and not copy it.
2023-10-12 13:04:42 +00:00
Ivan Kylchik 68e4a7a318 [JVM] Combine all analyzeInstruction methods 2023-10-12 13:04:42 +00:00
Ivan Kylchik 58473b94a7 [JVM] Reuse visitNopInsn method in all Fast...Analyzer classes 2023-10-12 13:04:42 +00:00
Ivan Kylchik ed95ebc585 [JVM] Move visit...Insn methods in FastAnalyzer
They are actually the same.
2023-10-12 13:04:42 +00:00
Ivan Kylchik 7845e6bb0a [JVM] Drop visitControlFlowExceptionEdge method from FastStackAnalyzer
There is no class that overrides this method.

Also replaced `newValue` call with `newExceptionValue`. Under the hood,
`newExceptionValue` still calls `newValue` if the interpreter doesn't
redefine it. And it kind of makes sense to call `newExceptionValue`
here because we are handling try-catch block.
2023-10-12 13:04:42 +00:00
Ivan Kylchik e9019e9fb3 [JVM] Drop StoreLoadInterpreter class 2023-10-12 13:04:42 +00:00
Ivan Kylchik 364faa9506 [JVM] Drop StoreLoadValue interface 2023-10-12 13:04:42 +00:00
Ivan Kylchik 95872bd13c [JVM] Reuse findMergeNodes in FastStoreLoadAnalyzer 2023-09-14 15:02:03 +00:00
Ivan Kylchik 617e7d1a36 [JVM] Store VarInsnNode in StoreData instead of AbstractInsnNode
This way we can avoid some casts.
2023-09-14 15:02:03 +00:00
Ivan Kylchik 140ccccae3 [Minor] Drop unused method from CompositeMethodTransformer 2023-09-14 15:02:03 +00:00
Ivan Kylchik f9868f757b [JVM] Simplify StoreLoadInterpreter and StoreLoadFrame 2023-09-14 15:02:03 +00:00
Ivan Kylchik 0e9d884b0b [JVM] Slightly rewrite mergeControlFlowEdge in FastStackAnalyzer
This change is supposed to show how similar
`mergeControlFlowEdge` methods are, and maybe
we should combine them.
2023-09-14 15:02:03 +00:00
Ivan Kylchik 6f8e243f0b [JVM] Avoid inheritance from FastMethodAnalyzer
This way it is easier to analyze code.
2023-09-14 15:02:03 +00:00
Ivan Kylchik 5f27e1a6b2 [JVM] Make FixStackAnalyzer inherit FastStackAnalyzer 2023-09-14 15:02:02 +00:00
Ivan Kylchik f49f6656b9 [JVM] Move private extension methods into FixStackFrame 2023-09-14 15:02:02 +00:00
Ivan Kylchik 2c4c3a73b8 [JVM] Move initLocals method into FastAnalyzer 2023-09-14 15:02:02 +00:00
Ivan Kylchik 83c75c1edf [JVM] Unify initLocals method in Fast...Analyzer classes 2023-09-14 15:02:02 +00:00
Ivan Kylchik 02d8a62cb0 [JVM] Fully move analyze method into FastAnalyzer 2023-09-14 15:02:02 +00:00
Ivan Kylchik abe727fdd7 [JVM] Extract common code from Fast...Analyzer into analyzeInner 2023-09-14 15:02:02 +00:00
Ivan Kylchik e0dd3a33c0 [JVM] Extract unique code in Fast...Analyzer into analyzeInstruction 2023-09-14 15:02:02 +00:00
Ivan Kylchik bf53268453 [JVM] Move computeExceptionHandlers into base FastAnalyzer 2023-09-14 15:02:02 +00:00
Ivan Kylchik 98cc2c839f [JVM] Create base FastAnalyzer class for all Fast...Analyzer 2023-09-14 15:02:02 +00:00
Ivan Kylchik 7853256c02 [JVM] Drop some excess toArray calls on instructions 2023-09-14 15:02:02 +00:00
Ivan Kylchik d8e682ab30 [JVM] Drop insnsArray from Fast...Analyzer classes
We are using useless `toArray` can that we can avoid.
2023-09-14 15:02:02 +00:00
Ivan Kylchik ede6eb0b34 [IR] Print exception's class in error message from interpreter 2023-09-14 08:47:06 +00:00
Ivan Kylchik 2df5b48474 [IR] Report error from IR interpreter on field recursive initialization
#KT-59890
#KT-61802 Fixed
2023-09-14 08:47:06 +00:00
Ivan Kylchik 1843eeb16b [FIR] Drop visualizer module
This module was created to compare type resolve in K1 and K2. But
overall, these tests contain a lot of bugs, and it is quite hard
to use it.
2023-09-13 12:55:14 +00:00
Ivan Kylchik 2cd504b675 [FIR] Drop old TODO from LightTreeRawFirDeclarationBuilder
There is no description and no information that we suppose
to fix.
2023-09-13 12:55:13 +00:00
Ivan Kylchik 5d88a1f1c3 [Native] Rename Lowerings to NativeLoweringPhases
This is done to unify the way how we name file
that contains lowerings in different backends.
2023-09-11 10:04:50 +00:00
Ivan Kylchik 386d69018d [JVM] Rename JvmLower to JvmLoweringPhases
This is done to unify the way how we name file
that contains lowerings in different backends.
2023-09-11 10:04:50 +00:00
Ivan Kylchik 6048d52a97 [K2] Avoid field inlining during FIR2IR phase
Before const inlining for fields, we actually want to remember a given
field in `InlineConstTracker`. We are doing it already in const
evaluation. So we just need to ignore const inlining in
`CallAndReferenceGenerator` and delegate it to const evaluation.

#KT-60737
2023-09-07 19:12:18 +00:00
Ivan Kylchik 40c9f831e2 [Native] Drop IrUtils2 file 2023-09-05 11:21:51 +00:00
Ivan Kylchik 8142ae2579 [Native] Drop irCatch from IrUtils2 2023-09-05 11:21:51 +00:00
Ivan Kylchik c2076a0227 [Native] Move hasNonConstInitializer from IrUtils2
This function could be useful for other backends.
2023-09-05 11:21:51 +00:00
Ivan Kylchik ddde95bd78 [Native] Move irByte from IrUtils2
We already have similar functions in `ExpressionHelpers`. Makes
sense to keep them together.
2023-09-05 11:21:51 +00:00
Ivan Kylchik d62323cdf1 [Native] Move addTopLevelInitializer from IrUtils2
This function is actually used only in `InteropLowering` and it
is too specific to be included into utils.
2023-09-05 11:21:51 +00:00
Ivan Kylchik 5cd96831dc [Native] Move isRestrictedSuspendFunction from IrUtils2
This function is also helpful for JVM backend.
2023-09-05 11:21:50 +00:00
Ivan Kylchik 2657adc6dc [Native] Move addFile from IrUtils2
This function is actually used only in `BackendPhases` and it is
too specific to be included into utils.
2023-09-05 11:21:50 +00:00
Ivan Kylchik 4fb29a5e12 [Native] Drop addArguments from IrUtils2
We can simplify single usage of this function
2023-09-05 11:21:50 +00:00
Ivan Kylchik 20165dd699 [Native] Drop defaultOrNullableType from IrUtils2
We can simplify most usages of `defaultOrNullableType`
2023-09-05 11:21:50 +00:00
Ivan Kylchik 583a5496d5 [Native] Drop irCall from IrUtils2
We can reuse the same function from common `ExpressionHelpers`
2023-09-05 11:21:50 +00:00
Ivan Kylchik 5c68ea2b64 [Native] Simplify irCatch from IrUtils2 2023-09-05 11:21:50 +00:00
Ivan Kylchik 8cc4db39d2 [Native] Drop copy from IrUtils2
It is not used anywhere
2023-09-05 11:21:50 +00:00
Ivan Kylchik b3474ac730 [Native] Drop irBuilder from IrUtils2
We can reuse `createIrBuilder` function
2023-09-05 11:21:50 +00:00
Ivan Kylchik 9e750e900d [Native] Drop createField from IrUtils2
We can call `IrFieldImpl` directly, the same way it is done
for other IR declarations in `CBridgeGen` file.
2023-09-05 11:21:50 +00:00
Ivan Kylchik 7e71e778c9 [Native] Drop stub from IrUtils2
It is not used anywhere
2023-09-05 11:21:50 +00:00
Ivan Kylchik b10d330cfd [Native] Drop getContainingFile from IrUtils2
We can reuse `fileOrNull` function from common `IrUtils`
2023-09-05 11:21:50 +00:00
Ivan Kylchik a437e0378a [Native] Drop irCallOp from IrUtils2
It is not used anywhere
2023-09-05 11:21:50 +00:00
Ivan Kylchik 4376e58acb [Native] Drop createArrayOfExpression from IrUtils2
We can reuse the same function from common `IrUtils`
2023-09-05 11:21:50 +00:00
Ivan Kylchik 962172f96d [Native] Drop irSetVar from IrUtils2
We can reuse `irSet` function
2023-09-05 11:21:50 +00:00
Ivan Kylchik 9ab053a3a6 [Native] Drop substitute from IrUtils2
We can reuse the same function from common `IrTypeUtils`
2023-09-05 11:21:50 +00:00
Ivan Kylchik d0a5738499 [Native] Drop addChild from IrUtils2
We can reuse the same function from common `IrUtils`
2023-09-05 11:21:50 +00:00
Ivan Kylchik 3efe07d0cb [Native] Drop getArgumentsWithIr from IrUtils2
We can reuse the same function from common `IrUtils`
2023-09-05 11:21:49 +00:00
Ivan Kylchik abc061e17f [IR] Restore and fix ifConstVal test
It was accidentally dropped after KT-55196 fix.
2023-09-05 11:06:43 +00:00
Ivan Kylchik 2537ff94b7 [Native] Move StringTable and its builder to separate file 2023-09-05 08:35:48 +00:00
Ivan Kylchik 86b4d36b54 [Native] Make StringTable and its builder internal 2023-09-05 08:35:47 +00:00
Ivan Kylchik 70697af6b9 [Native] Move proto utils from KonanIrLinker into separate utils file 2023-09-05 08:35:47 +00:00
Ivan Kylchik 66b9c2f260 [Native] Move FORWARD_DECLARATION_ORIGIN into KonanForwardDeclarationModuleDeserializer 2023-09-05 08:35:47 +00:00
Ivan Kylchik cc906ad6d5 [Native] Move INVALID_INDEX into KonanPartialModuleDeserializer 2023-09-05 08:35:47 +00:00