Kotlin / multik

Multidimensional array library for Kotlin
https://kotlin.github.io/multik/
Apache License 2.0
646 stars 39 forks source link

Multik Incompatible with Jacoco #77

Closed ccjernigan closed 2 years ago

ccjernigan commented 2 years ago

STEPS TO REPRODUCE

  1. Configure a Kotlin Multiplatform application with a JVM target, Jacoco 0.8.7 for test coverage (reproduces with Kover or the Gradle scripting below), and the multik-jvm dependency.

    apply(plugin = "java-library")
    apply(plugin = "jacoco")
    
    configure<JacocoPluginExtension> {
        val jacocoVersion: String by project
        toolVersion = jacocoVersion
    }
    
    afterEvaluate {
        tasks.withType<JacocoReport>().configureEach {
            classDirectories.setFrom(
                fileTree("${buildDir}/classes/kotlin/jvm/") {
                    exclude("**/*Test*.*", "**/*Fixture*.*")
                }
            )
    
            sourceDirectories.setFrom(
                // This could be better if it dynamically got the source directories, e.g. more along the lines of
                // kotlin.sourceSets["commonMain"].kotlin.sourceDirectories,
                // kotlin.sourceSets["jvmMain"].kotlin.sourceDirectories
                listOf("src/commonMain/kotlin", "src/jvmMain/kotlin")
            )
            executionData.setFrom("${buildDir}/jacoco/jvmTest.exec")
        }
    }
  2. Create a test case that exercises some aspect of Multik, e.g.

    @Test
    fun epic_fail() {
        val top = mk.ndarray(doubleArrayOf(1.0, 2.0, 3.0, 4.0, 5.0))
        val bottom = mk.ndarray(doubleArrayOf(6.0, 7.0, 8.0, 9.0, 10.0))
    
        val matrix = mk.stack(top, bottom)
    
        mk.linalg.inv(matrix)
    }
  3. Run the tests

RESULTS Expected Tests should run regardless of whether coverage is enabled.

Actual Tests fail with a VerifyError

java.lang.VerifyError: Inconsistent stackmap frames at branch target 247
Exception Details:
  Location:
    org/jetbrains/kotlinx/multik/api/CreateNDArrayKt.linspace$default(Lorg/jetbrains/kotlinx/multik/api/Multik;DDIILjava/lang/Object;)Lorg/jetbrains/kotlinx/multik/ndarray/data/NDArray; @247: iload
  Reason:
    Type integer (current frame, locals[9]) is not assignable to double (stack map, locals[9])
  Current Frame:
    bci: @157
    flags: { }
    locals: { 'org/jetbrains/kotlinx/multik/api/Multik', double, double_2nd, double, double_2nd, integer, integer, double, double_2nd, integer, double, double_2nd, top, 'org/jetbrains/kotlinx/multik/api/Multik', integer, integer, integer, 'org/jetbrains/kotlinx/multik/api/Multik', double, double_2nd, integer }
    stack: { integer, integer }
  Stackmap Frame:
    bci: @247
    flags: { }
    locals: { 'org/jetbrains/kotlinx/multik/api/Multik', double, double_2nd, double, double_2nd, integer, integer, double, double_2nd, double, double_2nd, top, 'org/jetbrains/kotlinx/multik/api/Multik', integer, integer, integer, 'org/jetbrains/kotlinx/multik/api/Multik', double, double_2nd, integer }
    stack: { }
  Bytecode:
    0000000: b804 6f3a 0815 0607 7e9a 000d 1908 1106
    0000010: e904 54a7 000e 1032 3605 1908 1106 ea04
    0000020: 542a 1211 b800 1703 3606 1505 9e00 0e04
    0000030: 1908 1106 eb04 54a7 000b 0319 0811 06ec
    0000040: 0454 3607 0336 0903 360a 1507 9a00 2903
    0000050: 360b 1303 b019 0811 06ed 0454 3a0a bb00
    0000060: 6459 190a b600 65b7 0068 c000 6a19 0811
    0000070: 06ee 0454 bf15 0587 0f67 3907 2927 6739
    0000080: 0a2a 3a0d 0336 0e04 360f 0336 1019 0d3a
    0000090: 1115 0f87 3912 0336 1415 0e15 05a2 005a
    00000a0: 1812 0e97 9e00 0e04 1908 1106 ef04 54a7
    00000b0: 000b 0319 0811 06f0 0454 3615 0336 1603
    00000c0: 3617 1515 9900 0d19 0811 06f1 0454 a700
    00000d0: 9103 3618 1303 6519 0811 06f2 0454 3a17
    00000e0: bb00 6459 1917 b600 65b7 0068 c000 6a19
    00000f0: 0811 06f3 0454 bf15 0e15 05a3 000d 1908
    0000100: 1106 f404 54a7 005a 1812 0e98 9c00 0e04
    0000110: 1908 1106 f504 54a7 000b 0319 0811 06f6
    0000120: 0454 3615 0336 1603 3617 1515 9900 0d19
    0000130: 0811 06f7 0454 a700 2903 3618 1303 6719
    0000140: 0811 06f8 0454 3a17 bb00 6459 1917 b600
    0000150: 65b7 0068 c000 6a19 0811 06f9 0454 bf15
    0000160: 0587 150e 8767 1812 6f39 1903 3618 1819
    0000170: b803 6d8e 3615 1908 1106 fa04 54b2 006f
    0000180: 3a17 1295 b800 273a 1803 361b 1918 3a1c
    0000190: 1908 1106 fb04 5419 1cb2 0077 b800 27b8
    00001a0: 002d 9900 10b2 007b 1908 1106 fc04 54a7
    00001b0: 00d7 191c b200 7eb8 0027 b800 2d99 0010
    00001c0: b200 8119 0811 06fd 0454 a700 bc19 1cb2
    00001d0: 0084 b800 27b8 002d 9900 10b2 0087 1908
    00001e0: 1106 fe04 54a7 00a1 191c b200 8ab8 0027
    00001f0: b800 2d99 0010 b200 8d19 0811 06ff 0454
    0000200: a700 8619 1cb2 0090 b800 27b8 002d 9900
    0000210: 10b2 0093 1908 1107 0004 54a7 006b 191c
    0000220: b200 96b8 0027 b800 2d99 0010 b200 9919
    0000230: 0811 0701 0454 a700 5019 1c12 9bb8 0027
    0000240: b800 2d99 0010 b200 9e19 0811 0702 0454
    0000250: a700 3619 1c12 a0b8 0027 b800 2d99 0010
    0000260: b200 a319 0811 0703 0454 a700 1cbb 00a5
    0000270: 5912 a719 18b8 00ad b800 b1b7 00b2 1908
    0000280: 1107 0404 54bf 003a 1604 bc0a 3a18 1918
    0000290: 0315 154f 1918 3a17 1908 1107 0504 5415
    00002a0: 1519 16b8 00c3 3a1b 0336 1c03 361d 191b
    00002b0: c002 0c3a 1e03 361f 150e 8739 2019 0811
    00002c0: 0706 0454 191e b603 733a 2219 22b6 0378
    00002d0: 3623 1922 b603 7b36 2415 2315 24a4 000d
    00002e0: 1908 1107 0704 54a7 0128 1908 1107 0804
    00002f0: 5415 2336 2584 2301 1908 1107 0904 5419
    0000300: 1e15 2518 2039 2603 3628 1295 b800 273a
    0000310: 2919 0811 070a 0454 1929 b200 77b8 0027
    0000320: b800 2d99 0014 1826 8e91 b801 2119 0811
    0000330: 070b 0454 a700 ab19 29b2 007e b800 27b8
    0000340: 002d 9900 1418 268e 93b8 0124 1908 1107
    0000350: 0c04 54a7 008c 1929 b200 84b8 0027 b800
    0000360: 2d99 0013 1826 8eb8 0127 1908 1107 0d04
    0000370: 54a7 006e 1929 b200 8ab8 0027 b800 2d99
    0000380: 0013 1826 8fb8 012a 1908 1107 0e04 54a7
    0000390: 0050 1929 b200 90b8 0027 b800 2d99 0013
    00003a0: 1826 90b8 012d 1908 1107 0f04 54a7 0032
    00003b0: 1929 b200 96b8 0027 b800 2d99 0012 1826
    00003c0: b801 3019 0811 0710 0454 a700 15bb 037d
    00003d0: 5913 037f b703 8019 0811 0711 0454 bfc0
    00003e0: 0095 c003 6f00 1908 1107 1204 54b6 0210
    00003f0: 1820 1812 6339 2015 2515 249f 000d 1908
    0000400: 1107 1304 54a7 feec 1908 1107 1404 5400
    0000410: 191b c002 0c3a 1819 0811 0715 0454 bb00
    0000420: c559 1918 c000 c703 1917 01b2 0031 c000
    0000430: 2101 102a 01b7 00ca 003a 0c15 0504 a300
    0000440: 0d19 0811 0716 0454 a700 2518 0a18 076f
    0000450: 390d 1908 1107 1704 5419 0cc0 015c 180d
    0000460: b801 30b8 03b6 1908 1107 1804 5419 0cc0
    0000470: 015c 27b8 0130 b803 b919 0811 0719 0454
    0000480: 190c c001 5c19 0cb6 03ba 0464 29b8 0130
    0000490: b803 be19 0c3a 0d03 360e 1908 1107 1a04
    00004a0: 54b2 006f 3a0f 0712 71b8 001f 1303 6fb8
    00004b0: 0027 3a10 0336 1119 103a 1219 0811 071b
    00004c0: 0454 1912 b200 77b8 0027 b800 2d99 0010
    00004d0: b200 7b19 0811 071c 0454 a700 d719 12b2
    00004e0: 007e b800 27b8 002d 9900 10b2 0081 1908
    00004f0: 1107 1d04 54a7 00bc 1912 b200 84b8 0027
    0000500: b800 2d99 0010 b200 8719 0811 071e 0454
    0000510: a700 a119 12b2 008a b800 27b8 002d 9900
    0000520: 10b2 008d 1908 1107 1f04 54a7 0086 1912
    0000530: b200 90b8 0027 b800 2d99 0010 b200 9319
    0000540: 0811 0720 0454 a700 6b19 12b2 0096 b800
    0000550: 27b8 002d 9900 10b2 0099 1908 1107 2104
    0000560: 54a7 0050 1912 129b b800 27b8 002d 9900
    0000570: 10b2 009e 1908 1107 2204 54a7 0036 1912
    0000580: 12a0 b800 27b8 002d 9900 10b2 00a3 1908
    0000590: 1107 2304 54a7 001c bb00 a559 12a7 1910
    00005a0: b800 adb8 00b1 b700 b219 0811 0724 0454
    00005b0: bf00 3a13 1908 1107 2504 5419 0d19 13b6
    00005c0: 03c2 1908 1107 2604 54b0               
  Stackmap Table:
    append_frame(@22,Object[#1137])
    same_frame(@33)
    same_frame(@58)
    same_locals_1_stack_item_frame(@66,Integer)
    full_frame(@117,{Object[#231],Double,Double,Integer,Integer,Integer,Object[#1137],Integer,Integer},{})
    full_frame(@178,{Object[#231],Double,Double,Integer,Integer,Double,Double,Top,Object[#231],Integer,Integer,Integer,Object[#231],Double,Integer},{})
    same_locals_1_stack_item_frame(@186,Integer)
    append_frame(@209,Integer,Integer,Integer)
    chop_frame(@247,3)
    same_frame(@264)
    same_frame(@282)
    same_locals_1_stack_item_frame(@290,Integer)
    append_frame(@313,Integer,Integer,Integer)
    chop_frame(@351,3)
    full_frame(@434,{Object[#231],Double,Double,Integer,Integer,Double,Double,Top,Object[#231],Integer,Integer,Integer,Object[#231],Double,Integer,Integer,Top,Object[#236],Object[#234],Double,Integer,Object[#234]},{})
    same_frame(@461)
    same_frame(@488)
    same_frame(@515)
    same_frame(@542)
    same_frame(@569)
    same_frame(@595)
    same_frame(@621)
    same_locals_1_stack_item_frame(@646,Object[#108])
    full_frame(@746,{Object[#231],Double,Double,Integer,Integer,Double,Double,Top,Object[#231],Integer,Integer,Integer,Object[#231],Double,Integer,Integer,Object[#108],Object[#232],Object[#232],Double,Object[#524],Integer,Integer,Object[#524],Integer,Double,Object[#885],Integer,Integer},{})
    same_frame(@753)
    full_frame(@823,{Object[#231],Double,Double,Integer,Integer,Double,Double,Top,Object[#231],Integer,Integer,Integer,Object[#231],Double,Integer,Integer,Object[#108],Object[#232],Object[#232],Double,Object[#524],Integer,Integer,Object[#524],Integer,Double,Object[#885],Integer,Integer,Integer,Double,Integer,Object[#234]},{Object[#524],Integer})
    full_frame(@854,{Object[#231],Double,Double,Integer,Integer,Double,Double,Top,Object[#231],Integer,Integer,Integer,Object[#231],Double,Integer,Integer,Object[#108],Object[#232],Object[#232],Double,Object[#524],Integer,Integer,Object[#524],Integer,Double,Object[#885],Integer,Integer,Integer,Double,Integer,Object[#234]},{Object[#524],Integer})
    full_frame(@884,{Object[#231],Double,Double,Integer,Integer,Double,Double,Top,Object[#231],Integer,Integer,Integer,Object[#231],Double,Integer,Integer,Object[#108],Object[#232],Object[#232],Double,Object[#524],Integer,Integer,Object[#524],Integer,Double,Object[#885],Integer,Integer,Integer,Double,Integer,Object[#234]},{Object[#524],Integer})
    full_frame(@914,{Object[#231],Double,Double,Integer,Integer,Double,Double,Top,Object[#231],Integer,Integer,Integer,Object[#231],Double,Integer,Integer,Object[#108],Object[#232],Object[#232],Double,Object[#524],Integer,Integer,Object[#524],Integer,Double,Object[#885],Integer,Integer,Integer,Double,Integer,Object[#234]},{Object[#524],Integer})
    full_frame(@944,{Object[#231],Double,Double,Integer,Integer,Double,Double,Top,Object[#231],Integer,Integer,Integer,Object[#231],Double,Integer,Integer,Object[#108],Object[#232],Object[#232],Double,Object[#524],Integer,Integer,Object[#524],Integer,Double,Object[#885],Integer,Integer,Integer,Double,Integer,Object[#234]},{Object[#524],Integer})
    full_frame(@973,{Object[#231],Double,Double,Integer,Integer,Double,Double,Top,Object[#231],Integer,Integer,Integer,Object[#231],Double,Integer,Integer,Object[#108],Object[#232],Object[#232],Double,Object[#524],Integer,Integer,Object[#524],Integer,Double,Object[#885],Integer,Integer,Integer,Double,Integer,Object[#234]},{Object[#524],Integer})
    full_frame(@991,{Object[#231],Double,Double,Integer,Integer,Double,Double,Top,Object[#231],Integer,Integer,Integer,Object[#231],Double,Integer,Integer,Object[#108],Object[#232],Object[#232],Double,Object[#524],Integer,Integer,Object[#524],Integer,Double,Object[#885],Integer,Integer,Integer,Double,Integer,Object[#234]},{Object[#524],Integer,Object[#4]})
    same_frame(@1032)
    full_frame(@1039,{Object[#231],Double,Double,Integer,Integer,Double,Double,Top,Object[#231],Integer,Integer,Integer,Object[#231],Double,Integer,Integer,Object[#108],Object[#232],Object[#232],Double,Object[#524],Integer,Integer,Object[#524],Integer,Double,Object[#885],Integer,Integer},{})
    full_frame(@1099,{Object[#231],Double,Double,Integer,Integer,Double,Double,Object[#197],Object[#231],Integer,Integer,Integer,Object[#231],Double,Integer,Integer,Object[#108],Object[#232],Object[#524],Double,Object[#524],Integer,Integer,Object[#524],Integer,Double,Object[#885],Integer,Integer},{})
    full_frame(@1133,{Object[#231],Double,Double,Integer,Integer,Double,Double,Object[#197],Top,Top,Integer,Integer,Object[#231],Double,Integer,Integer,Object[#108],Object[#232],Object[#524],Double,Object[#524],Integer,Integer,Object[#524],Integer,Double,Object[#885],Integer,Integer},{})
    full_frame(@1245,{Object[#231],Double,Double,Integer,Integer,Double,Double,Object[#197],Object[#197],Integer,Object[#236],Object[#234],Integer,Object[#234],Top,Integer,Integer,Object[#108],Object[#232],Object[#524],Double,Object[#524],Integer,Integer,Object[#524],Integer,Double,Object[#885],Integer,Integer},{})
    same_frame(@1272)
    same_frame(@1299)
    same_frame(@1326)
    same_frame(@1353)
    same_frame(@1380)
    same_frame(@1406)
    same_frame(@1432)
    same_locals_1_stack_item_frame(@1457,Object[#108])
koodzi commented 2 years ago

See issue https://github.com/Kotlin/multik/issues/28 there is also a "workaround".

devcrocod commented 2 years ago

Yes, this is a known issue in kotlin.

Also, you can try a new plugin - kover.