Put $assertionDisabled field into inline-site's class

The generated code is more inline with java, and we avoid the error of
accessing package-private field outside of the package.
However, this changes semantics a bit. Now, a user should set assertion
status of inline-site's package, instead of inline function's one.
 #KT-28317: Fixed
This commit is contained in:
Ilmir Usmanov
2019-02-01 20:11:06 +03:00
parent acb83f1af1
commit 1e4b7e1ef1
25 changed files with 818 additions and 33 deletions
@@ -5,6 +5,8 @@
// IGNORE_BACKEND: JVM_IR
// TARGET_BACKEND: JVM
package test
inline fun inlineMe() {
assert(false) { "FROM INLINED" }
}
@@ -12,6 +14,8 @@ inline fun inlineMe() {
// FILE: inlineSite.kt
// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm
import test.*
class CheckerJvmAssertInlineFunctionAssertionsDisabled {
fun check() {
inlineMe()
@@ -3,6 +3,8 @@
// WITH_RUNTIME
// FULL_JDK
package test
inline fun inlineMe() {
assert(false) { "FROM INLINED" }
}
@@ -10,6 +12,8 @@ inline fun inlineMe() {
// FILE: inlineSite.kt
// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm
import test.*
class CheckerJvmAssertInlineFunctionAssertionsEnabled {
fun check() {
inlineMe()
@@ -5,6 +5,8 @@
// WITH_RUNTIME
// NO_CHECK_LAMBDA_INLINING
package test
inline fun call(c: () -> Unit) {
c()
}
@@ -12,6 +14,8 @@ inline fun call(c: () -> Unit) {
// FILE: inlineSite.kt
// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm
import test.*
interface Checker {
fun checkTrue(): Boolean
fun checkFalse(): Boolean
@@ -0,0 +1,46 @@
// TARGET_BACKEND: JVM
// FILE: inline.kt
// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm
// WITH_RUNTIME
// FULL_JDK
package test
var result = "OK"
class State {
companion object {
inline fun inlineMe() {
assert(false) { "FROM INLINED" }
}
}
}
// FILE: inlineSite.kt
// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm
import test.*
class CheckerJvmAssertInlineFunctionAssertionsEnabled {
fun check() {
State.inlineMe()
throw RuntimeException("FAIL 0")
}
}
class Dummy
fun enableAssertions(): CheckerJvmAssertInlineFunctionAssertionsEnabled {
val loader = Dummy::class.java.classLoader
loader.setDefaultAssertionStatus(true)
val c = loader.loadClass("CheckerJvmAssertInlineFunctionAssertionsEnabled")
return c.newInstance() as CheckerJvmAssertInlineFunctionAssertionsEnabled
}
fun box(): String {
var c = enableAssertions()
try {
c.check()
return "FAIL 2"
} catch (ignore: AssertionError) {}
return result
}
@@ -5,6 +5,8 @@
// WITH_RUNTIME
// NO_CHECK_LAMBDA_INLINING
package test
object CrossinlineLambdaContainer {
inline fun call(crossinline c: () -> Unit) {
val l = { c() }
@@ -15,7 +17,7 @@ object CrossinlineLambdaContainer {
// FILE: inlineSite.kt
// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm
import CrossinlineLambdaContainer.call
import test.CrossinlineLambdaContainer.call
interface Checker {
fun checkTrue(): Boolean
@@ -102,9 +104,7 @@ class ShouldBeEnabled : Checker {
fun setDesiredAssertionStatus(v: Boolean): Checker {
val loader = Checker::class.java.classLoader
loader.setClassAssertionStatus("ShouldBeEnabled", true)
loader.setClassAssertionStatus("ShouldBeDisabled", false)
loader.setClassAssertionStatus("CrossinlineLambdaContainer", v)
loader.setDefaultAssertionStatus(v)
val c = loader.loadClass(if (v) "ShouldBeEnabled" else "ShouldBeDisabled")
return c.newInstance() as Checker
}
@@ -0,0 +1,237 @@
// IGNORE_BACKEND: JVM_IR
// TARGET_BACKEND: JVM
// FILE: inline.kt
// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm
// WITH_RUNTIME
// NO_CHECK_LAMBDA_INLINING
package test
object CrossinlineLambdaContainer {
inline fun call(b: Boolean, crossinline c: () -> Unit) {
val l = {
assert(b) { "FROM INLINED" }
c()
}
l()
}
}
// FILE: inlineSite.kt
// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm
import test.CrossinlineLambdaContainer.call
interface Checker {
fun checkTrueTrue(): Boolean
fun checkTrueFalse(): Boolean
fun checkFalseTrue(): Boolean
fun checkFalseFalse(): Boolean
fun checkTrueWithMessageTrue(): Boolean
fun checkTrueWithMessageFalse(): Boolean
fun checkFalseWithMessageTrue(): Boolean
fun checkFalseWithMessageFalse(): Boolean
}
class ShouldBeDisabled : Checker {
override fun checkTrueTrue(): Boolean {
var hit = false
val l = { hit = true; true }
call(true) {
assert(l())
}
return hit
}
override fun checkTrueFalse(): Boolean {
var hit = false
val l = { hit = true; true }
call(false) {
assert(l())
}
return hit
}
override fun checkFalseTrue(): Boolean {
var hit = false
val l = { hit = true; false }
call(true) {
assert(l())
}
return hit
}
override fun checkFalseFalse(): Boolean {
var hit = false
val l = { hit = true; false }
call(false) {
assert(l())
}
return hit
}
override fun checkTrueWithMessageTrue(): Boolean {
var hit = false
val l = { hit = true; true }
call(true) {
assert(l()) { "BOOYA" }
}
return hit
}
override fun checkTrueWithMessageFalse(): Boolean {
var hit = false
val l = { hit = true; true }
call(false) {
assert(l()) { "BOOYA" }
}
return hit
}
override fun checkFalseWithMessageTrue(): Boolean {
var hit = false
val l = { hit = true; false }
call(true) {
assert(l()) { "BOOYA" }
}
return hit
}
override fun checkFalseWithMessageFalse(): Boolean {
var hit = false
val l = { hit = true; false }
call(false) {
assert(l()) { "BOOYA" }
}
return hit
}
}
class ShouldBeEnabled : Checker {
override fun checkTrueTrue(): Boolean {
var hit = false
val l = { hit = true; true }
call(true) {
assert(l())
}
return hit
}
override fun checkTrueFalse(): Boolean {
var hit = false
val l = { hit = true; true }
call(false) {
assert(l())
}
return hit
}
override fun checkFalseTrue(): Boolean {
var hit = false
val l = { hit = true; false }
call(true) {
assert(l())
}
return hit
}
override fun checkFalseFalse(): Boolean {
var hit = false
val l = { hit = true; false }
call(false) {
assert(l())
}
return hit
}
override fun checkTrueWithMessageTrue(): Boolean {
var hit = false
val l = { hit = true; true }
call(true) {
assert(l()) { "BOOYA" }
}
return hit
}
override fun checkTrueWithMessageFalse(): Boolean {
var hit = false
val l = { hit = true; true }
call(false) {
assert(l()) { "BOOYA" }
}
return hit
}
override fun checkFalseWithMessageTrue(): Boolean {
var hit = false
val l = { hit = true; false }
call(true) {
assert(l()) { "BOOYA" }
}
return hit
}
override fun checkFalseWithMessageFalse(): Boolean {
var hit = false
val l = { hit = true; false }
call(false) {
assert(l()) { "BOOYA" }
}
return hit
}
}
fun setDesiredAssertionStatus(v: Boolean): Checker {
val loader = Checker::class.java.classLoader
loader.setDefaultAssertionStatus(v)
val c = loader.loadClass(if (v) "ShouldBeEnabled" else "ShouldBeDisabled")
return c.newInstance() as Checker
}
fun box(): String {
var c = setDesiredAssertionStatus(false)
if (c.checkTrueTrue()) return "FAIL 00"
if (c.checkTrueFalse()) return "FAIL 01"
if (c.checkTrueWithMessageTrue()) return "FAIL 10"
if (c.checkTrueWithMessageFalse()) return "FAIL 11"
if (c.checkFalseTrue()) return "FAIL 20"
if (c.checkFalseFalse()) return "FAIL 21"
if (c.checkFalseWithMessageTrue()) return "FAIL 30"
if (c.checkFalseWithMessageFalse()) return "FAIL 31"
c = setDesiredAssertionStatus(true)
if (!c.checkTrueTrue()) return "FAIL 40"
try {
c.checkTrueFalse()
return "FAIL 41"
} catch (ignore: AssertionError) {
}
if (!c.checkTrueWithMessageTrue()) return "FAIL 50"
try {
c.checkTrueWithMessageFalse()
return "FAIL 51"
} catch (ignore: AssertionError) {
}
try {
c.checkFalseTrue()
return "FAIL 60"
} catch (ignore: AssertionError) {
}
try {
c.checkFalseFalse()
return "FAIL 61"
} catch (ignore: AssertionError) {
}
try {
c.checkFalseWithMessageTrue()
return "FAIL 70"
} catch (ignore: AssertionError) {
}
try {
c.checkFalseWithMessageFalse()
return "FAIL 71"
} catch (ignore: AssertionError) {
}
return "OK"
}
@@ -0,0 +1,214 @@
// IGNORE_BACKEND: JVM_IR
// TARGET_BACKEND: JVM
// FILE: inline.kt
// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm
// WITH_RUNTIME
// NO_CHECK_LAMBDA_INLINING
package test
object CrossinlineLambdaContainer {
inline fun call(b: Boolean, crossinline c: () -> Unit) {
val l = {
assert(b) { "FROM INLINED" }
c()
}
l()
}
}
// FILE: inlineSite.kt
// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm
import test.CrossinlineLambdaContainer.call
interface Checker {
fun checkTrueTrue(): Boolean
fun checkTrueFalse(): Boolean
fun checkFalseTrue(): Boolean
fun checkFalseFalse(): Boolean
fun checkTrueWithMessageTrue(): Boolean
fun checkTrueWithMessageFalse(): Boolean
fun checkFalseWithMessageTrue(): Boolean
fun checkFalseWithMessageFalse(): Boolean
}
class ShouldBeDisabled : Checker {
override fun checkTrueTrue(): Boolean {
var hit = false
val l = { hit = true; true }
call(true) {
assert(l())
}
return hit
}
override fun checkTrueFalse(): Boolean {
var hit = false
val l = { hit = true; true }
call(false) {
assert(l())
}
return hit
}
override fun checkFalseTrue(): Boolean {
var hit = false
val l = { hit = true; false }
call(true) {
assert(l())
}
return hit
}
override fun checkFalseFalse(): Boolean {
var hit = false
val l = { hit = true; false }
call(false) {
assert(l())
}
return hit
}
override fun checkTrueWithMessageTrue(): Boolean {
var hit = false
val l = { hit = true; true }
call(true) {
assert(l()) { "BOOYA" }
}
return hit
}
override fun checkTrueWithMessageFalse(): Boolean {
var hit = false
val l = { hit = true; true }
call(false) {
assert(l()) { "BOOYA" }
}
return hit
}
override fun checkFalseWithMessageTrue(): Boolean {
var hit = false
val l = { hit = true; false }
call(true) {
assert(l()) { "BOOYA" }
}
return hit
}
override fun checkFalseWithMessageFalse(): Boolean {
var hit = false
val l = { hit = true; false }
call(false) {
assert(l()) { "BOOYA" }
}
return hit
}
}
class ShouldBeEnabled : Checker {
override fun checkTrueTrue(): Boolean {
var hit = false
val l = { hit = true; true }
call(true) {
assert(l())
}
return hit
}
override fun checkTrueFalse(): Boolean {
var hit = false
val l = { hit = true; true }
call(false) {
assert(l())
}
return hit
}
override fun checkFalseTrue(): Boolean {
var hit = false
val l = { hit = true; false }
call(true) {
assert(l())
}
return hit
}
override fun checkFalseFalse(): Boolean {
var hit = false
val l = { hit = true; false }
call(false) {
assert(l())
}
return hit
}
override fun checkTrueWithMessageTrue(): Boolean {
var hit = false
val l = { hit = true; true }
call(true) {
assert(l()) { "BOOYA" }
}
return hit
}
override fun checkTrueWithMessageFalse(): Boolean {
var hit = false
val l = { hit = true; true }
call(false) {
assert(l()) { "BOOYA" }
}
return hit
}
override fun checkFalseWithMessageTrue(): Boolean {
var hit = false
val l = { hit = true; false }
call(true) {
assert(l()) { "BOOYA" }
}
return hit
}
override fun checkFalseWithMessageFalse(): Boolean {
var hit = false
val l = { hit = true; false }
call(false) {
assert(l()) { "BOOYA" }
}
return hit
}
}
fun setDesiredAssertionStatus(v: Boolean): Checker {
val loader = Checker::class.java.classLoader
loader.setDefaultAssertionStatus(false)
loader.setPackageAssertionStatus("test", v)
val c = loader.loadClass(if (v) "ShouldBeEnabled" else "ShouldBeDisabled")
return c.newInstance() as Checker
}
fun box(): String {
var c = setDesiredAssertionStatus(false)
if (c.checkTrueTrue()) return "FAIL 00"
if (c.checkTrueFalse()) return "FAIL 01"
if (c.checkTrueWithMessageTrue()) return "FAIL 10"
if (c.checkTrueWithMessageFalse()) return "FAIL 11"
if (c.checkFalseTrue()) return "FAIL 20"
if (c.checkFalseFalse()) return "FAIL 21"
if (c.checkFalseWithMessageTrue()) return "FAIL 30"
if (c.checkFalseWithMessageFalse()) return "FAIL 31"
c = setDesiredAssertionStatus(true)
if (c.checkTrueTrue()) return "FAIL 100"
if (c.checkTrueFalse()) return "FAIL 101"
if (c.checkTrueWithMessageTrue()) return "FAIL 110"
if (c.checkTrueWithMessageFalse()) return "FAIL 111"
if (c.checkFalseTrue()) return "FAIL 120"
if (c.checkFalseFalse()) return "FAIL 121"
if (c.checkFalseWithMessageTrue()) return "FAIL 130"
if (c.checkFalseWithMessageFalse()) return "FAIL 131"
return "OK"
}
@@ -0,0 +1,48 @@
// TARGET_BACKEND: JVM
// FILE: inline.kt
// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm
// WITH_RUNTIME
// FULL_JDK
package test
class A {
inline fun a() {
assert(false) { "from inlined" }
}
}
class B {
inline fun b() {
A().a()
error("FAIL 0")
}
}
// FILE: inlineSite.kt
// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm
import test.*
class Checker {
fun check() {
B().b()
error("FAIL 1")
}
}
class Dummy
fun enableAssertions(): Checker {
val loader = Dummy::class.java.classLoader
loader.setDefaultAssertionStatus(true)
val c = loader.loadClass("Checker")
return c.newInstance() as Checker
}
fun box(): String {
var c = enableAssertions()
try {
c.check()
return "FAIL 2"
} catch (ignore: AssertionError) {}
return "OK"
}