Commit Graph

82931 Commits

Author SHA1 Message Date
Ivan Kylchik 0cc866a2fb Support Enum class as intrinsic in ir interpreter
Methods of Enum class don't have bodies, so must be treated as
intrinsics
2021-06-07 15:35:08 +03:00
Ivan Kylchik e5617ede7e Add Throwable class into interpreter builtins map
Methods of Throwable class doesn't have bodies using FIR, so they must
be handled as builtins
2021-06-07 15:35:07 +03:00
Ivan Kylchik 8234c9cec1 Add toString function with nullable receiver into builtins map
On JVM we don't have body for this function, so we must process it as
intrinsic or builtin
2021-06-07 15:35:06 +03:00
Ivan Kylchik 7882fdf232 Simplify logic of checking that IrGetField can be interpreted 2021-06-07 15:35:04 +03:00
Ivan Kylchik ca1932b3a5 Set proper fir type for deserialized annotation's arguments 2021-06-07 15:35:03 +03:00
Ivan Kylchik b3fa7b25cf Optimize Utils.kt by removing unused functions 2021-06-07 15:35:02 +03:00
Ivan Kylchik 877832ef8c Optimize some methods of CallStack and Frame 2021-06-07 15:35:01 +03:00
Ivan Kylchik e0438d1123 Implement better workflow of interpretation with callable reference 2021-06-07 15:34:59 +03:00
Ivan Kylchik 9a8e0f3fb3 Add new builtins methods for some interfaces into IrBuiltInsMapGenerated
This change allow us to skip looking for override when evaluate call
for some primitive.
2021-06-07 15:34:58 +03:00
Ivan Kylchik b4463b948c Rewrite unfoldValueParameters to take into account recursive calls
The workflow of evaluation value arguments is now like this:
1. Calculate not null arguments
2. Add them into intermediate stack
3. Calculate defaults for those parameters that have no argument
This flow allow us to avoid early addition of variable onto stack.
2021-06-07 15:34:57 +03:00
Ivan Kylchik 6411d09579 Rewrite wrap function to take into account function name
This is needed to understand whenever arrays must be unwrapped or not.
For now, in case of kotlin.Array.set and kotlin.Pair.<init> calls it is
considered to remain arrays as Primitive class to save their irType
info.
2021-06-07 15:34:55 +03:00
Ivan Kylchik 04b36ff19e Make interpreted functions implicitly return Unit as result 2021-06-07 15:34:54 +03:00
Ivan Kylchik 0e8ca12499 Add callback to methods of CallInterceptor to specify default behaviour 2021-06-07 15:34:53 +03:00
Ivan Kylchik 285929ad07 Add new intercept method in CallInterceptor for proxy 2021-06-07 15:34:52 +03:00
Ivan Kylchik 25d01099d8 Add CallInterceptor interface and implement its default realization
CallInterceptor will handle calls, constructor calls, getting enum
entries and objects. It will make a decision for interpreter: this call
must be handled as intrinsic or it must be interpreted.
2021-06-07 15:34:50 +03:00
Ivan Kylchik c8b268a789 Refactor entire IrInterpreter to achieve better code quality 2021-06-07 15:34:49 +03:00
Ivan Kylchik 3294af5e49 Get correct irClass from class reference in case of reified parameter 2021-06-07 15:34:47 +03:00
Ivan Kylchik fe99b235d3 Implement more precise control flow in ir interpreter
"More precise" in terms of the number of passing tests.
In this case ControlStructures test block was used.
2021-06-07 15:34:46 +03:00
Ivan Kylchik c3ad319c13 Implement correct processing for receivers of IrFunctionReference 2021-06-07 15:34:44 +03:00
Ivan Kylchik a73173e480 Fix interpretation of arguments with default value 2021-06-07 15:34:43 +03:00
Ivan Kylchik 38f4e6e8bf Implement interpretation of assert method 2021-06-07 15:34:42 +03:00
Ivan Kylchik 8617809528 Rename expression value parameter to declaration 2021-06-07 15:34:40 +03:00
Alexander Udalov e6254b51e1 Rewrite generator for IrBuiltInsMapGenerated
Similarly to 742fef9042 with OperationsMapGenerated, use optimized
`when` over strings instead of lambdas because lambdas lead to a lot of
bytecode.

The change in `IrConst.toPrimitive` is needed because for operations
like `Byte.plus(Int)` the IrConst instance would have the IR type for
kotlin.Byte, but the actual runtime value of type Int
(java.lang.Integer), which would lead to CCE from
`interpretBinaryFunction`. Previously it didn't fail because of
unchecked cast before calling the lambda, which allowed a value of
runtime type java.lang.Integer to sneak through to the lambda parameter
and be "unboxed" to the correct type via the `(... as Number).toByte()`
conversion which backend generates.

The main benefit of this change is that it reduces the size of the
proguarded compiler jar by ~0.69%.
2021-06-07 15:34:39 +03:00
Ivan Kylchik ac7a1c7762 Add new intrinsic handler for sourceLocation function 2021-06-07 15:34:38 +03:00
Ivan Kylchik 7fe776fe10 Simplify work with stack by adding additional newFrame method 2021-06-07 15:34:37 +03:00
Ivan Kylchik d578aa0ec5 Pass irFile in interpreter method in IrConstTransformer 2021-06-07 15:34:35 +03:00
Ivan Kylchik ec16c40bf4 Save right entry point for expression 2021-06-07 15:34:34 +03:00
Ivan Kylchik 9d9ab498aa Remove typeArguments field in State interface 2021-06-07 15:34:33 +03:00
Ivan Kylchik a10d88924f Simplify getIrFunctionByIrCall method in KFunctionState
Removed check of invoke symbols equality. Without this check it is
possible to store init functions in KFunctionState
2021-06-07 15:34:32 +03:00
Ivan Kylchik 3d1d86e9cb Change call method of KProperty1Proxy to invoke corresponding accessors 2021-06-07 15:34:30 +03:00
Ivan Kylchik 64d5cea337 Implement getter and setter for KPropertyProxy 2021-06-07 15:34:29 +03:00
Ivan Kylchik f89b75e387 Implement interpretation of KParameter interface 2021-06-07 15:34:28 +03:00
Ivan Kylchik a4edddaa6e Extract all reflection state classes into separate files 2021-06-07 15:34:26 +03:00
Ivan Kylchik aa321f2333 Move ReflectionState.kt into separate package "reflection" 2021-06-07 15:34:25 +03:00
Ivan Kylchik 5a95e5b45f Implement interpretation for KType and KTypeParameter 2021-06-07 15:34:24 +03:00
Ivan Kylchik 88b5b5f702 Implement interpretation of KVisibility class
For now it is interpreted as Wrapper, but maybe further it will be
converted to Common
2021-06-07 15:34:23 +03:00
Ivan Kylchik 40bf4fafc9 Implement basic interpretation of IrClassReference 2021-06-07 15:34:22 +03:00
Ivan Kylchik 002804941f Replace Lambda state with KFunctionState 2021-06-07 15:34:21 +03:00
Ivan Kylchik 749200d518 Fix constructor call checker
Forget to check constructor for availability of compile time annotation
2021-06-07 15:34:19 +03:00
Ivan Kylchik 41ea1525d1 Implement basic interpretation for KProperty 2021-06-07 15:34:18 +03:00
Ivan Kylchik c3d0438405 Allow to interpret property reference 2021-06-07 15:34:16 +03:00
Ivan Kylchik ac858f760a Forbid vararg flattening in place there array was expected 2021-06-07 15:34:15 +03:00
Ivan Kylchik 8b2706aaee Change interpretConstructor method to be able to init object single time 2021-06-07 15:34:13 +03:00
Ivan Kylchik 903e883809 Add additional type arguments to stack from super types 2021-06-07 15:34:12 +03:00
Ivan Kylchik a9d686b9f9 Add outer object to stack when interpreting constructor of inner class 2021-06-07 15:34:11 +03:00
Ivan Kylchik b570d3f7fd Fix interpreter error related to recreating Unit object 2021-06-07 15:34:09 +03:00
Ivan Kylchik b98f680d65 Fix interpreter error related to incorrect work of get value for objects 2021-06-07 15:34:08 +03:00
Ivan Kylchik d931e2eead Implement simple proxy for non interface structures like kotlin.Pair 2021-06-07 15:34:07 +03:00
Ivan Kylchik 1e5096294e Implement proxy for custom interfaces 2021-06-07 15:34:06 +03:00
Ivan Kylchik 96a090f2ab Implement LambdaProxy class 2021-06-07 15:34:04 +03:00