Skip to content

Commit fe31273

Browse files
Tiangong Limeta-codesync[bot]
authored andcommitted
Fix redex class merge test
Summary: ``` In Kotlin 2.2, the Kotlin compiler generates additional local variable slots for flatMapIndexed$1 (2 more fields: L$2, L$3), changing its field count from 7 to 9. This changes its shape from (0,5,0,2,0,0,0) to (0,7,0,2,0,0,0). Kotlin 2.1 (7 fields each): - flatMapIndexed$1 → shape (0,5,0,2,0,0,0) - runningReduceIndexed$1 → shape (0,5,0,2,0,0,0) - Both in same shape group → CAN BE MERGED Kotlin 2.2 (different field counts): - flatMapIndexed$1 → shape (0,7,0,2,0,0,0) with 9 fields - runningReduceIndexed$1 → shape (0,5,0,2,0,0,0) with 7 fields - Different shape groups → runningReduceIndexed$1 is alone → CANNOT BE MERGED The Fix Updated the test to verify flatMapIndexed$1 and runningFoldIndexed$1 instead, as these two classes share the same shape (0,7,0,2,0,0,0) in Kotlin 2.2 and CAN be merged together. ``` ``` Kotlin 2.1 shapes: flatMapIndexed$1 -> (0,5,0,2,0,0,0) runningFoldIndexed$1 -> (0,6,0,2,0,0,0) runningReduceIndexed$1 -> (0,5,0,2,0,0,0) runningReduce$1 -> (0,5,0,1,0,0,0) zipWithNext$2 -> (0,5,0,1,0,0,0) children$1 -> (0,4,0,1,0,0,0) shuffled$1 -> (0,4,0,1,0,0,0) ifEmpty$1 -> (0,3,0,1,0,0,0) Kotlin 2.2 shapes: flatMapIndexed$1 -> (0,7,0,2,0,0,0) # changed! runningFoldIndexed$1 -> (0,7,0,2,0,0,0) # changed! runningReduceIndexed$1 -> (0,5,0,2,0,0,0) # same runningReduce$1 -> (0,5,0,1,0,0,0) # same zipWithNext$2 -> (0,6,0,1,0,0,0) # changed! children$1 -> (0,4,0,1,0,0,0) # same shuffled$1 -> (0,6,0,2,0,0,0) # changed! ifEmpty$1 -> (0,4,0,1,0,0,0) # changed! ``` Reviewed By: xuhdev Differential Revision: D89639868 fbshipit-source-id: ac944dafc2dd31deb5a1ccc3459995c7812cab88
1 parent 6fa47fb commit fe31273

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

test/instr/ClassMergingKotlinCoroutinesTestVerify.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,31 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
#include <cstdlib>
9+
#include <cstring>
10+
811
#include "Show.h"
912
#include "verify/VerifyUtil.h"
1013

1114
TEST_F(PostVerify, SinkCommonCtorInvocation) {
1215
auto* cls_coroutine_1 = find_class_named(
1316
classes, "Lkotlin/sequences/SequencesKt__SequencesKt$flatMapIndexed$1;");
14-
auto* cls_coroutine_2 = find_class_named(
15-
classes,
16-
"Lkotlin/sequences/SequencesKt___SequencesKt$runningReduceIndexed$1;");
17+
18+
// TODO(T242960112): Kotlin 2.2 changed flatMapIndexed$1's field layout from
19+
// 7 to 9 fields, altering its shape from (0,5,0,2,0,0,0) to (0,7,0,2,0,0,0).
20+
const char* kotlin_version = std::getenv("kotlin_language_version");
21+
bool is_kotlin_2_2_or_later =
22+
kotlin_version != nullptr && std::strcmp(kotlin_version, "2.2") >= 0;
23+
24+
auto* cls_coroutine_2 =
25+
is_kotlin_2_2_or_later
26+
? find_class_named(classes,
27+
"Lkotlin/sequences/"
28+
"SequencesKt___SequencesKt$runningFoldIndexed$1;")
29+
: find_class_named(
30+
classes,
31+
"Lkotlin/sequences/"
32+
"SequencesKt___SequencesKt$runningReduceIndexed$1;");
1733

1834
verify_class_merged(cls_coroutine_1);
1935
verify_class_merged(cls_coroutine_2);

0 commit comments

Comments
 (0)