In particular, the JVM backend inlines the bodies of lambdas into the
generated lambda subclasses and stores bound receivers in the receiver
field of CallableReference. Both are required for reflection.
This commit fixes the handling of accessors for super calls, changes the
naming scheme to avoid accessor name clashes and uses a more robust test
to determine the placement of accessors for protected static members.
Previously, the order of IrSetField statements in this lowering was
non-deterministic. This broke the inliner in the JVM backend which
expects statements to be in argument order.
It's necessary when expect class is actualized via typealias
To support it properly, we need to return AbbriviatedType instead of
SimpleTypeImpl, thus scopeFactory is not enough anymore
The most interesting part happens in SimpleType.refine, other types
either don't implement refinement at all (they return just 'this',
mainly it's some special types, like ErrorType and such) or implement
it trivially via recursion (those are "composite" types)
SimpleType.refine captures so-called refinement factory, which is essentially
an injected callback which tells how to reconstruct the type with new
(refined) memberScope.
We have to inject callback because we express quite different types with
SimpleTypeImpl, and some of them need different refinement logic.
Another possible implementation approach (more invasive one) would be
to extract those types in separate subtypes of KotlinType and implement
'refine' via overrides.
The most meaningful callbacks are injected from
'AbstractClassDescriptor.defaultType' and from 'KotlinTypeFactory'.
This is possible now because after 3a9b94235f, 0423d0f41e and
5341de253f, all top level functions/properties in sources and in
binaries have a corresponding containing facade class
This is actually either a LAMBDA or an ANONYMOUS_FUNCTION.
Not quite sure if it's really required, but some tools such as IR-based
decompiler might require this information.
Since we now generate file classes even for IR loaded from dependencies
(see 3a9b94235f) to simplify code in certain lowerings, it makes sense
to do that for all source files together before any meaningful
lowerings. The easiest way to do so is to make FileClassLowering a
module-wide phase.
ExpectDeclarationsRemoveLowering is now also a module-wide phase because
it needs to be run before FileClassLowering (to avoid producing empty
facades for files that only contain `expect` declarations)
Similarly to how it's done for callable references. This is needed for
IrTypeMapper to be able to correctly compute the name of the SAM wrapper
IrClass without resorting to the name of the underlying descriptor
(computed in CodegenAnnotatingVisitor)
This is useful to store data that must be kept when the element is
transformed, such as names of local/anonymous classes and
EnclosingMethod values on JVM which are computed before any lowerings.
For now, this is implemented very conservatively: the only field
`attributeOwnerId` which can be used in BackendContext implementation as
a key in the map