This commit is contained in:
Igor Chevdar
2020-09-16 18:38:10 +05:00
parent 2c821351df
commit 06f2ef17be
4 changed files with 86 additions and 3 deletions
@@ -211,13 +211,25 @@ internal val escapeAnalysisPhase = makeKonanModuleOpPhase(
op = { context, _ ->
val entryPoint = context.ir.symbols.entryPoint?.owner
val externalModulesDFG = ExternalModulesDFG(emptyList(), emptyMap(), emptyMap(), emptyMap())
val nonDevirtualizedCallSitesUnfoldFactor =
if (entryPoint != null) {
// For a final program it can be safely assumed that what classes we see is what we got,
// so can take those. In theory we can always unfold call sites using type hierarchy, but
// the analysis might converge much, much slower, so take only reasonably small for now.
5
}
else {
// Can't tolerate any non-devirtualized call site for a library.
// TODO: What about private virtual functions?
// Note: 0 is also bad - this means that there're no inheritors in the current source set,
// but there might be some provided by the users of the library being produced.
-1
}
val callGraph = CallGraphBuilder(
context, context.moduleDFG!!,
externalModulesDFG,
context.devirtualizationAnalysisResult!!,
// Can't tolerate any non-devirtualized call site for a library.
// TODO: What about private virtual functions?
nonDevirtualizedCallSitesUnfoldFactor = if (entryPoint == null) 0 else 5
nonDevirtualizedCallSitesUnfoldFactor
).build()
EscapeAnalysis.computeLifetimes(
context, context.moduleDFG!!, externalModulesDFG, callGraph, context.lifetimes
@@ -532,6 +532,26 @@ __attribute__((swift_name("Kt39206Kt")))
+ (int32_t)myFunc __attribute__((swift_name("myFunc()"))) __attribute__((deprecated("Don't call this\nPlease")));
@end;
__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("Ckt41907")))
@interface KtCkt41907 : KtBase
- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer));
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
@end;
__attribute__((swift_name("Ikt41907")))
@protocol KtIkt41907
@required
- (void)fooC:(KtCkt41907 *)c __attribute__((swift_name("foo(c:)")));
@end;
__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("Kt41907Kt")))
@interface KtKt41907Kt : KtBase
+ (void)escapeCC:(KtCkt41907 *)c __attribute__((swift_name("escapeC(c:)")));
+ (void)testKt41907O:(id<KtIkt41907>)o __attribute__((swift_name("testKt41907(o:)")));
@end;
__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("LibraryKt")))
@interface KtLibraryKt : KtBase
@@ -0,0 +1,27 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package kt41907
class Ckt41907
interface Ikt41907 {
fun foo(c: Ckt41907)
}
private class Bkt41907 {
var c: Ckt41907? = null
}
private val b = Bkt41907()
fun escapeC(c: Ckt41907) {
b.c = c
}
fun testKt41907(o: Ikt41907) {
val c = Ckt41907()
o.foo(c)
}
@@ -0,0 +1,24 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
import Kt
class Ikt41907Impl : Ikt41907 {
func foo(c: Ckt41907) {
Kt41907Kt.escapeC(c: c)
}
}
private func test1() {
Kt41907Kt.testKt41907(o: Ikt41907Impl())
}
class Kt41907Tests : SimpleTestProvider {
override init() {
super.init()
test("Test1", test1)
}
}