From b2efb322c44c336a7d88f8e5425c469d8f2dcdc6 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sat, 25 Apr 2026 16:53:43 +0300 Subject: [PATCH] cgen: more optimizations --- vlib/builtin/grapheme.v | 2152 +------------------------------------- vlib/v/builder/builder.v | 15 + vlib/v/gen/c/cgen.v | 26 +- vlib/v/gen/c/fn.v | 56 +- vlib/v/gen/c/utils.v | 133 ++- 5 files changed, 192 insertions(+), 2190 deletions(-) diff --git a/vlib/builtin/grapheme.v b/vlib/builtin/grapheme.v index be494fd5b..9ad9881dc 100644 --- a/vlib/builtin/grapheme.v +++ b/vlib/builtin/grapheme.v @@ -21,2124 +21,50 @@ enum GraphemeBreakProperty { zwj } -const grapheme_control_ranges = [ - u32(0x0000), - 0x0009, - 0x000B, - 0x000C, - 0x000E, - 0x001F, - 0x007F, - 0x009F, - 0x00AD, - 0x00AD, - 0x061C, - 0x061C, - 0x180E, - 0x180E, - 0x200B, - 0x200B, - 0x200E, - 0x200F, - 0x2028, - 0x2028, - 0x2029, - 0x2029, - 0x202A, - 0x202E, - 0x2060, - 0x2064, - 0x2065, - 0x2065, - 0x2066, - 0x206F, - 0xFEFF, - 0xFEFF, - 0xFFF0, - 0xFFF8, - 0xFFF9, - 0xFFFB, - 0x13430, - 0x13438, - 0x1BCA0, - 0x1BCA3, - 0x1D173, - 0x1D17A, - 0xE0000, - 0xE0000, - 0xE0001, - 0xE0001, - 0xE0002, - 0xE001F, - 0xE0080, - 0xE00FF, - 0xE01F0, - 0xE0FFF, -]! +const grapheme_control_ranges = '00000000090000000b0000000c0000000e0000001f0000007f0000009f000000ad000000ad0000001c0600001c0600000e1800000e1800000b2000000b2000000e2000000f200000282000002820000029200000292000002a2000002e20000060200000642000006520000065200000662000006f200000fffe0000fffe0000f0ff0000f8ff0000f9ff0000fbff00003034010038340100a0bc0100a3bc010073d101007ad1010000000e0000000e0001000e0001000e0002000e001f000e0080000e00ff000e00f0010e00ff0f0e00' -const grapheme_extend_ranges = [ - u32(0x0300), - 0x036F, - 0x0483, - 0x0487, - 0x0488, - 0x0489, - 0x0591, - 0x05BD, - 0x05BF, - 0x05BF, - 0x05C1, - 0x05C2, - 0x05C4, - 0x05C5, - 0x05C7, - 0x05C7, - 0x0610, - 0x061A, - 0x064B, - 0x065F, - 0x0670, - 0x0670, - 0x06D6, - 0x06DC, - 0x06DF, - 0x06E4, - 0x06E7, - 0x06E8, - 0x06EA, - 0x06ED, - 0x0711, - 0x0711, - 0x0730, - 0x074A, - 0x07A6, - 0x07B0, - 0x07EB, - 0x07F3, - 0x07FD, - 0x07FD, - 0x0816, - 0x0819, - 0x081B, - 0x0823, - 0x0825, - 0x0827, - 0x0829, - 0x082D, - 0x0859, - 0x085B, - 0x08D3, - 0x08E1, - 0x08E3, - 0x0902, - 0x093A, - 0x093A, - 0x093C, - 0x093C, - 0x0941, - 0x0948, - 0x094D, - 0x094D, - 0x0951, - 0x0957, - 0x0962, - 0x0963, - 0x0981, - 0x0981, - 0x09BC, - 0x09BC, - 0x09BE, - 0x09BE, - 0x09C1, - 0x09C4, - 0x09CD, - 0x09CD, - 0x09D7, - 0x09D7, - 0x09E2, - 0x09E3, - 0x09FE, - 0x09FE, - 0x0A01, - 0x0A02, - 0x0A3C, - 0x0A3C, - 0x0A41, - 0x0A42, - 0x0A47, - 0x0A48, - 0x0A4B, - 0x0A4D, - 0x0A51, - 0x0A51, - 0x0A70, - 0x0A71, - 0x0A75, - 0x0A75, - 0x0A81, - 0x0A82, - 0x0ABC, - 0x0ABC, - 0x0AC1, - 0x0AC5, - 0x0AC7, - 0x0AC8, - 0x0ACD, - 0x0ACD, - 0x0AE2, - 0x0AE3, - 0x0AFA, - 0x0AFF, - 0x0B01, - 0x0B01, - 0x0B3C, - 0x0B3C, - 0x0B3E, - 0x0B3E, - 0x0B3F, - 0x0B3F, - 0x0B41, - 0x0B44, - 0x0B4D, - 0x0B4D, - 0x0B55, - 0x0B56, - 0x0B57, - 0x0B57, - 0x0B62, - 0x0B63, - 0x0B82, - 0x0B82, - 0x0BBE, - 0x0BBE, - 0x0BC0, - 0x0BC0, - 0x0BCD, - 0x0BCD, - 0x0BD7, - 0x0BD7, - 0x0C00, - 0x0C00, - 0x0C04, - 0x0C04, - 0x0C3E, - 0x0C40, - 0x0C46, - 0x0C48, - 0x0C4A, - 0x0C4D, - 0x0C55, - 0x0C56, - 0x0C62, - 0x0C63, - 0x0C81, - 0x0C81, - 0x0CBC, - 0x0CBC, - 0x0CBF, - 0x0CBF, - 0x0CC2, - 0x0CC2, - 0x0CC6, - 0x0CC6, - 0x0CCC, - 0x0CCD, - 0x0CD5, - 0x0CD6, - 0x0CE2, - 0x0CE3, - 0x0D00, - 0x0D01, - 0x0D3B, - 0x0D3C, - 0x0D3E, - 0x0D3E, - 0x0D41, - 0x0D44, - 0x0D4D, - 0x0D4D, - 0x0D57, - 0x0D57, - 0x0D62, - 0x0D63, - 0x0D81, - 0x0D81, - 0x0DCA, - 0x0DCA, - 0x0DCF, - 0x0DCF, - 0x0DD2, - 0x0DD4, - 0x0DD6, - 0x0DD6, - 0x0DDF, - 0x0DDF, - 0x0E31, - 0x0E31, - 0x0E34, - 0x0E3A, - 0x0E47, - 0x0E4E, - 0x0EB1, - 0x0EB1, - 0x0EB4, - 0x0EBC, - 0x0EC8, - 0x0ECD, - 0x0F18, - 0x0F19, - 0x0F35, - 0x0F35, - 0x0F37, - 0x0F37, - 0x0F39, - 0x0F39, - 0x0F71, - 0x0F7E, - 0x0F80, - 0x0F84, - 0x0F86, - 0x0F87, - 0x0F8D, - 0x0F97, - 0x0F99, - 0x0FBC, - 0x0FC6, - 0x0FC6, - 0x102D, - 0x1030, - 0x1032, - 0x1037, - 0x1039, - 0x103A, - 0x103D, - 0x103E, - 0x1058, - 0x1059, - 0x105E, - 0x1060, - 0x1071, - 0x1074, - 0x1082, - 0x1082, - 0x1085, - 0x1086, - 0x108D, - 0x108D, - 0x109D, - 0x109D, - 0x135D, - 0x135F, - 0x1712, - 0x1714, - 0x1732, - 0x1734, - 0x1752, - 0x1753, - 0x1772, - 0x1773, - 0x17B4, - 0x17B5, - 0x17B7, - 0x17BD, - 0x17C6, - 0x17C6, - 0x17C9, - 0x17D3, - 0x17DD, - 0x17DD, - 0x180B, - 0x180D, - 0x1885, - 0x1886, - 0x18A9, - 0x18A9, - 0x1920, - 0x1922, - 0x1927, - 0x1928, - 0x1932, - 0x1932, - 0x1939, - 0x193B, - 0x1A17, - 0x1A18, - 0x1A1B, - 0x1A1B, - 0x1A56, - 0x1A56, - 0x1A58, - 0x1A5E, - 0x1A60, - 0x1A60, - 0x1A62, - 0x1A62, - 0x1A65, - 0x1A6C, - 0x1A73, - 0x1A7C, - 0x1A7F, - 0x1A7F, - 0x1AB0, - 0x1ABD, - 0x1ABE, - 0x1ABE, - 0x1ABF, - 0x1AC0, - 0x1B00, - 0x1B03, - 0x1B34, - 0x1B34, - 0x1B35, - 0x1B35, - 0x1B36, - 0x1B3A, - 0x1B3C, - 0x1B3C, - 0x1B42, - 0x1B42, - 0x1B6B, - 0x1B73, - 0x1B80, - 0x1B81, - 0x1BA2, - 0x1BA5, - 0x1BA8, - 0x1BA9, - 0x1BAB, - 0x1BAD, - 0x1BE6, - 0x1BE6, - 0x1BE8, - 0x1BE9, - 0x1BED, - 0x1BED, - 0x1BEF, - 0x1BF1, - 0x1C2C, - 0x1C33, - 0x1C36, - 0x1C37, - 0x1CD0, - 0x1CD2, - 0x1CD4, - 0x1CE0, - 0x1CE2, - 0x1CE8, - 0x1CED, - 0x1CED, - 0x1CF4, - 0x1CF4, - 0x1CF8, - 0x1CF9, - 0x1DC0, - 0x1DF9, - 0x1DFB, - 0x1DFF, - 0x200C, - 0x200C, - 0x20D0, - 0x20DC, - 0x20DD, - 0x20E0, - 0x20E1, - 0x20E1, - 0x20E2, - 0x20E4, - 0x20E5, - 0x20F0, - 0x2CEF, - 0x2CF1, - 0x2D7F, - 0x2D7F, - 0x2DE0, - 0x2DFF, - 0x302A, - 0x302D, - 0x302E, - 0x302F, - 0x3099, - 0x309A, - 0xA66F, - 0xA66F, - 0xA670, - 0xA672, - 0xA674, - 0xA67D, - 0xA69E, - 0xA69F, - 0xA6F0, - 0xA6F1, - 0xA802, - 0xA802, - 0xA806, - 0xA806, - 0xA80B, - 0xA80B, - 0xA825, - 0xA826, - 0xA82C, - 0xA82C, - 0xA8C4, - 0xA8C5, - 0xA8E0, - 0xA8F1, - 0xA8FF, - 0xA8FF, - 0xA926, - 0xA92D, - 0xA947, - 0xA951, - 0xA980, - 0xA982, - 0xA9B3, - 0xA9B3, - 0xA9B6, - 0xA9B9, - 0xA9BC, - 0xA9BD, - 0xA9E5, - 0xA9E5, - 0xAA29, - 0xAA2E, - 0xAA31, - 0xAA32, - 0xAA35, - 0xAA36, - 0xAA43, - 0xAA43, - 0xAA4C, - 0xAA4C, - 0xAA7C, - 0xAA7C, - 0xAAB0, - 0xAAB0, - 0xAAB2, - 0xAAB4, - 0xAAB7, - 0xAAB8, - 0xAABE, - 0xAABF, - 0xAAC1, - 0xAAC1, - 0xAAEC, - 0xAAED, - 0xAAF6, - 0xAAF6, - 0xABE5, - 0xABE5, - 0xABE8, - 0xABE8, - 0xABED, - 0xABED, - 0xFB1E, - 0xFB1E, - 0xFE00, - 0xFE0F, - 0xFE20, - 0xFE2F, - 0xFF9E, - 0xFF9F, - 0x101FD, - 0x101FD, - 0x102E0, - 0x102E0, - 0x10376, - 0x1037A, - 0x10A01, - 0x10A03, - 0x10A05, - 0x10A06, - 0x10A0C, - 0x10A0F, - 0x10A38, - 0x10A3A, - 0x10A3F, - 0x10A3F, - 0x10AE5, - 0x10AE6, - 0x10D24, - 0x10D27, - 0x10EAB, - 0x10EAC, - 0x10F46, - 0x10F50, - 0x11001, - 0x11001, - 0x11038, - 0x11046, - 0x1107F, - 0x11081, - 0x110B3, - 0x110B6, - 0x110B9, - 0x110BA, - 0x11100, - 0x11102, - 0x11127, - 0x1112B, - 0x1112D, - 0x11134, - 0x11173, - 0x11173, - 0x11180, - 0x11181, - 0x111B6, - 0x111BE, - 0x111C9, - 0x111CC, - 0x111CF, - 0x111CF, - 0x1122F, - 0x11231, - 0x11234, - 0x11234, - 0x11236, - 0x11237, - 0x1123E, - 0x1123E, - 0x112DF, - 0x112DF, - 0x112E3, - 0x112EA, - 0x11300, - 0x11301, - 0x1133B, - 0x1133C, - 0x1133E, - 0x1133E, - 0x11340, - 0x11340, - 0x11357, - 0x11357, - 0x11366, - 0x1136C, - 0x11370, - 0x11374, - 0x11438, - 0x1143F, - 0x11442, - 0x11444, - 0x11446, - 0x11446, - 0x1145E, - 0x1145E, - 0x114B0, - 0x114B0, - 0x114B3, - 0x114B8, - 0x114BA, - 0x114BA, - 0x114BD, - 0x114BD, - 0x114BF, - 0x114C0, - 0x114C2, - 0x114C3, - 0x115AF, - 0x115AF, - 0x115B2, - 0x115B5, - 0x115BC, - 0x115BD, - 0x115BF, - 0x115C0, - 0x115DC, - 0x115DD, - 0x11633, - 0x1163A, - 0x1163D, - 0x1163D, - 0x1163F, - 0x11640, - 0x116AB, - 0x116AB, - 0x116AD, - 0x116AD, - 0x116B0, - 0x116B5, - 0x116B7, - 0x116B7, - 0x1171D, - 0x1171F, - 0x11722, - 0x11725, - 0x11727, - 0x1172B, - 0x1182F, - 0x11837, - 0x11839, - 0x1183A, - 0x11930, - 0x11930, - 0x1193B, - 0x1193C, - 0x1193E, - 0x1193E, - 0x11943, - 0x11943, - 0x119D4, - 0x119D7, - 0x119DA, - 0x119DB, - 0x119E0, - 0x119E0, - 0x11A01, - 0x11A0A, - 0x11A33, - 0x11A38, - 0x11A3B, - 0x11A3E, - 0x11A47, - 0x11A47, - 0x11A51, - 0x11A56, - 0x11A59, - 0x11A5B, - 0x11A8A, - 0x11A96, - 0x11A98, - 0x11A99, - 0x11C30, - 0x11C36, - 0x11C38, - 0x11C3D, - 0x11C3F, - 0x11C3F, - 0x11C92, - 0x11CA7, - 0x11CAA, - 0x11CB0, - 0x11CB2, - 0x11CB3, - 0x11CB5, - 0x11CB6, - 0x11D31, - 0x11D36, - 0x11D3A, - 0x11D3A, - 0x11D3C, - 0x11D3D, - 0x11D3F, - 0x11D45, - 0x11D47, - 0x11D47, - 0x11D90, - 0x11D91, - 0x11D95, - 0x11D95, - 0x11D97, - 0x11D97, - 0x11EF3, - 0x11EF4, - 0x16AF0, - 0x16AF4, - 0x16B30, - 0x16B36, - 0x16F4F, - 0x16F4F, - 0x16F8F, - 0x16F92, - 0x16FE4, - 0x16FE4, - 0x1BC9D, - 0x1BC9E, - 0x1D165, - 0x1D165, - 0x1D167, - 0x1D169, - 0x1D16E, - 0x1D172, - 0x1D17B, - 0x1D182, - 0x1D185, - 0x1D18B, - 0x1D1AA, - 0x1D1AD, - 0x1D242, - 0x1D244, - 0x1DA00, - 0x1DA36, - 0x1DA3B, - 0x1DA6C, - 0x1DA75, - 0x1DA75, - 0x1DA84, - 0x1DA84, - 0x1DA9B, - 0x1DA9F, - 0x1DAA1, - 0x1DAAF, - 0x1E000, - 0x1E006, - 0x1E008, - 0x1E018, - 0x1E01B, - 0x1E021, - 0x1E023, - 0x1E024, - 0x1E026, - 0x1E02A, - 0x1E130, - 0x1E136, - 0x1E2EC, - 0x1E2EF, - 0x1E8D0, - 0x1E8D6, - 0x1E944, - 0x1E94A, - 0x1F3FB, - 0x1F3FF, - 0xE0020, - 0xE007F, - 0xE0100, - 0xE01EF, -]! +const grapheme_extend_ranges = + '000300006f0300008304000087040000880400008904000091050000bd050000bf050000bf050000c1050000c2050000c4050000c5050000c7050000c7050000100600001a0600004b0600005f0600007006000070060000d6060000dc060000df060000e4060000e7060000e8060000ea060000ed0600001107000011070000300700004a070000a6070000b0070000eb070000f3070000fd070000fd07000016080000190800001b080000230800002508000027080000290800002d080000590800005b080000d3080000e1080000e3080000020900003a0900003a0900003c0900003c09000041090000480900004d0900004d090000510900005709000062090000630900008109000081090000bc090000bc090000be090000be090000c1090000c4090000cd090000cd090000d7090000d7090000e2090000e3090000fe090000fe090000010a0000020a00003c0a00003c0a0000410a0000420a0000470a0000480a00004b0a00004d0a0000510a0000510a0000700a0000710a0000750a0000750a0000810a0000820a0000bc0a0000bc0a0000c10a0000c50a0000c70a0000c80a0000cd0a0000cd0a0000e20a0000e30a0000fa0a0000ff0a0000010b0000010b00003c0b00003c0b00003e0b00003e0b00003f0b00003f0b0000410b0000440b00004d0b00004d0b0000550b0000560b0000570b0000570b0000620b0000630b0000820b0000820b0000be0b0000be0b0000c00b0000c00b0000cd0b0000cd0b0000d70b0000d70b0000000c0000000c0000040c0000040c00003e0c0000400c0000460c0000480c00004a0c00004d0c0000550c0000560c0000620c0000630c0000810c0000810c0000bc0c0000bc0c0000bf0c0000bf0c0000c20c0000c20c0000c60c0000c60c0000cc0c0000cd0c0000d50c0000d60c0000e20c0000e30c0000000d0000010d00003b0d00003c0d00003e0d00003e0d0000410d0000440d00004d0d00004d0d0000570d0000570d0000620d0000630d0000810d0000810d0000ca0d0000ca0d0000cf0d0000cf0d0000d20d0000d40d0000d60d0000d60d0000df0d0000df0d0000310e0000310e0000340e00003a0e0000470e00004e0e0000b10e0000b10e0000b40e0000bc0e0000c80e0000cd0e0000180f0000190f0000350f0000350f0000370f0000370f0000390f0000390f0000710f00007e0f0000800f0000840f0000860f0000870f00008d0f0000970f0000990f0000bc0f0000c60f0000c60f00002d100000301000003210000037100000391000003a1000003d1000003e10000058100000591000005e100000601000007110000074100000821000008210000085100000861000008d1000008d1000009d1000009d1000005d1300005f1300001217000014170000321700003417000052170000531700007217000073170000b4170000b5170000b7170000bd170000c6170000c6170000c9170000d3170000dd170000dd1700000b1800000d1800008518000086180000a9180000a9180000201900002219000027190000281900003219000032190000391900003b190000171a0000181a00001b1a00001b1a0000561a0000561a0000581a00005e1a0000601a0000601a0000621a0000621a0000651a00006c1a0000731a00007c1a00007f1a00007f1a0000b01a0000bd1a0000be1a0000be1a0000bf1a0000c01a0000001b0000031b0000341b0000341b0000351b0000351b0000361b00003a1b00003c1b00003c1b0000421b0000421b00006b1b0000731b0000801b0000811b0000a21b0000a51b0000a81b0000a91b0000ab1b0000ad1b0000e61b0000e61b0000e81b0000e91b0000ed1b0000ed1b0000ef1b0000f11b00002c1c0000331c0000361c0000371c0000d01c0000d21c0000d41c0000e01c0000e21c0000e81c0000ed1c0000ed1c0000f41c0000f41c0000f81c0000f91c0000c01d0000f91d0000fb1d0000ff1d00000c2000000c200000d0200000dc200000dd200000e0200000e1200000e1200000e2200000e4200000e5200000f0200000ef2c0000f12c00007f2d00007f2d0000e02d0000ff2d00002a3000002d3000002e3000002f300000993000009a3000006fa600006fa60000' + + '70a6000072a6000074a600007da600009ea600009fa60000f0a60000f1a6000002a8000002a8000006a8000006a800000ba800000ba8000025a8000026a800002ca800002ca80000c4a80000c5a80000e0a80000f1a80000ffa80000ffa8000026a900002da9000047a9000051a9000080a9000082a90000b3a90000b3a90000b6a90000b9a90000bca90000bda90000e5a90000e5a9000029aa00002eaa000031aa000032aa000035aa000036aa000043aa000043aa00004caa00004caa00007caa00007caa0000b0aa0000b0aa0000b2aa0000b4aa0000b7aa0000b8aa0000beaa0000bfaa0000c1aa0000c1aa0000ecaa0000edaa0000f6aa0000f6aa0000e5ab0000e5ab0000e8ab0000e8ab0000edab0000edab00001efb00001efb000000fe00000ffe000020fe00002ffe00009eff00009fff0000fd010100fd010100e0020100e0020100760301007a030100010a0100030a0100050a0100060a01000c0a01000f0a0100380a01003a0a01003f0a01003f0a0100e50a0100e60a0100240d0100270d0100ab0e0100ac0e0100460f0100500f0100011001000110010038100100461001007f10010081100100b3100100b6100100b9100100ba1001000011010002110100271101002b1101002d1101003411010073110100731101008011010081110100b6110100be110100c9110100cc110100cf110100cf1101002f12010031120100341201003412010036120100371201003e1201003e120100df120100df120100e3120100ea12010000130100011301003b1301003c1301003e1301003e13010040130100401301005713010057130100661301006c1301007013010074130100381401003f140100421401004414010046140100461401005e1401005e140100b0140100b0140100b3140100b8140100ba140100ba140100bd140100bd140100bf140100c0140100c2140100c3140100af150100af150100b2150100b5150100bc150100bd150100bf150100c0150100dc150100dd150100331601003a1601003d1601003d1601003f16010040160100ab160100ab160100ad160100ad160100b0160100b5160100b7160100b71601001d1701001f1701002217010025170100271701002b1701002f18010037180100391801003a18010030190100301901003b1901003c1901003e1901003e1901004319010043190100d4190100d7190100da190100db190100e0190100e0190100011a01000a1a0100331a0100381a01003b1a01003e1a0100471a0100471a0100511a0100561a0100591a01005b1a01008a1a0100961a0100981a0100991a0100301c0100361c0100381c01003d1c01003f1c01003f1c0100921c0100a71c0100aa1c0100b01c0100b21c0100b31c0100b51c0100b61c0100311d0100361d01003a1d01003a1d01003c1d01003d1d01003f1d0100451d0100471d0100471d0100901d0100911d0100951d0100951d0100971d0100971d0100f31e0100f41e0100f06a0100f46a0100306b0100366b01004f6f01004f6f01008f6f0100926f0100e46f0100e46f01009dbc01009ebc010065d1010065d1010067d1010069d101006ed1010072d101007bd1010082d1010085d101008bd10100aad10100add1010042d2010044d2010000da010036da01003bda01006cda010075da010075da010084da010084da01009bda01009fda0100a1da0100afda010000e0010006e0010008e0010018e001001be0010021e0010023e0010024e0010026e001002ae0010030e1010036e10100ece20100efe20100d0e80100d6e8010044e901004ae90100fbf30100fff3010020000e007f000e0000010e00ef010e00' -const grapheme_spacing_mark_ranges = [ - u32(0x0903), - 0x0903, - 0x093B, - 0x093B, - 0x093E, - 0x0940, - 0x0949, - 0x094C, - 0x094E, - 0x094F, - 0x0982, - 0x0983, - 0x09BF, - 0x09C0, - 0x09C7, - 0x09C8, - 0x09CB, - 0x09CC, - 0x0A03, - 0x0A03, - 0x0A3E, - 0x0A40, - 0x0A83, - 0x0A83, - 0x0ABE, - 0x0AC0, - 0x0AC9, - 0x0AC9, - 0x0ACB, - 0x0ACC, - 0x0B02, - 0x0B03, - 0x0B40, - 0x0B40, - 0x0B47, - 0x0B48, - 0x0B4B, - 0x0B4C, - 0x0BBF, - 0x0BBF, - 0x0BC1, - 0x0BC2, - 0x0BC6, - 0x0BC8, - 0x0BCA, - 0x0BCC, - 0x0C01, - 0x0C03, - 0x0C41, - 0x0C44, - 0x0C82, - 0x0C83, - 0x0CBE, - 0x0CBE, - 0x0CC0, - 0x0CC1, - 0x0CC3, - 0x0CC4, - 0x0CC7, - 0x0CC8, - 0x0CCA, - 0x0CCB, - 0x0D02, - 0x0D03, - 0x0D3F, - 0x0D40, - 0x0D46, - 0x0D48, - 0x0D4A, - 0x0D4C, - 0x0D82, - 0x0D83, - 0x0DD0, - 0x0DD1, - 0x0DD8, - 0x0DDE, - 0x0DF2, - 0x0DF3, - 0x0E33, - 0x0E33, - 0x0EB3, - 0x0EB3, - 0x0F3E, - 0x0F3F, - 0x0F7F, - 0x0F7F, - 0x1031, - 0x1031, - 0x103B, - 0x103C, - 0x1056, - 0x1057, - 0x1084, - 0x1084, - 0x17B6, - 0x17B6, - 0x17BE, - 0x17C5, - 0x17C7, - 0x17C8, - 0x1923, - 0x1926, - 0x1929, - 0x192B, - 0x1930, - 0x1931, - 0x1933, - 0x1938, - 0x1A19, - 0x1A1A, - 0x1A55, - 0x1A55, - 0x1A57, - 0x1A57, - 0x1A6D, - 0x1A72, - 0x1B04, - 0x1B04, - 0x1B3B, - 0x1B3B, - 0x1B3D, - 0x1B41, - 0x1B43, - 0x1B44, - 0x1B82, - 0x1B82, - 0x1BA1, - 0x1BA1, - 0x1BA6, - 0x1BA7, - 0x1BAA, - 0x1BAA, - 0x1BE7, - 0x1BE7, - 0x1BEA, - 0x1BEC, - 0x1BEE, - 0x1BEE, - 0x1BF2, - 0x1BF3, - 0x1C24, - 0x1C2B, - 0x1C34, - 0x1C35, - 0x1CE1, - 0x1CE1, - 0x1CF7, - 0x1CF7, - 0xA823, - 0xA824, - 0xA827, - 0xA827, - 0xA880, - 0xA881, - 0xA8B4, - 0xA8C3, - 0xA952, - 0xA953, - 0xA983, - 0xA983, - 0xA9B4, - 0xA9B5, - 0xA9BA, - 0xA9BB, - 0xA9BE, - 0xA9C0, - 0xAA2F, - 0xAA30, - 0xAA33, - 0xAA34, - 0xAA4D, - 0xAA4D, - 0xAAEB, - 0xAAEB, - 0xAAEE, - 0xAAEF, - 0xAAF5, - 0xAAF5, - 0xABE3, - 0xABE4, - 0xABE6, - 0xABE7, - 0xABE9, - 0xABEA, - 0xABEC, - 0xABEC, - 0x11000, - 0x11000, - 0x11002, - 0x11002, - 0x11082, - 0x11082, - 0x110B0, - 0x110B2, - 0x110B7, - 0x110B8, - 0x1112C, - 0x1112C, - 0x11145, - 0x11146, - 0x11182, - 0x11182, - 0x111B3, - 0x111B5, - 0x111BF, - 0x111C0, - 0x111CE, - 0x111CE, - 0x1122C, - 0x1122E, - 0x11232, - 0x11233, - 0x11235, - 0x11235, - 0x112E0, - 0x112E2, - 0x11302, - 0x11303, - 0x1133F, - 0x1133F, - 0x11341, - 0x11344, - 0x11347, - 0x11348, - 0x1134B, - 0x1134D, - 0x11362, - 0x11363, - 0x11435, - 0x11437, - 0x11440, - 0x11441, - 0x11445, - 0x11445, - 0x114B1, - 0x114B2, - 0x114B9, - 0x114B9, - 0x114BB, - 0x114BC, - 0x114BE, - 0x114BE, - 0x114C1, - 0x114C1, - 0x115B0, - 0x115B1, - 0x115B8, - 0x115BB, - 0x115BE, - 0x115BE, - 0x11630, - 0x11632, - 0x1163B, - 0x1163C, - 0x1163E, - 0x1163E, - 0x116AC, - 0x116AC, - 0x116AE, - 0x116AF, - 0x116B6, - 0x116B6, - 0x11720, - 0x11721, - 0x11726, - 0x11726, - 0x1182C, - 0x1182E, - 0x11838, - 0x11838, - 0x11931, - 0x11935, - 0x11937, - 0x11938, - 0x1193D, - 0x1193D, - 0x11940, - 0x11940, - 0x11942, - 0x11942, - 0x119D1, - 0x119D3, - 0x119DC, - 0x119DF, - 0x119E4, - 0x119E4, - 0x11A39, - 0x11A39, - 0x11A57, - 0x11A58, - 0x11A97, - 0x11A97, - 0x11C2F, - 0x11C2F, - 0x11C3E, - 0x11C3E, - 0x11CA9, - 0x11CA9, - 0x11CB1, - 0x11CB1, - 0x11CB4, - 0x11CB4, - 0x11D8A, - 0x11D8E, - 0x11D93, - 0x11D94, - 0x11D96, - 0x11D96, - 0x11EF5, - 0x11EF6, - 0x16F51, - 0x16F87, - 0x16FF0, - 0x16FF1, - 0x1D166, - 0x1D166, - 0x1D16D, - 0x1D16D, -]! +const grapheme_spacing_mark_ranges = '03090000030900003b0900003b0900003e09000040090000490900004c0900004e0900004f0900008209000083090000bf090000c0090000c7090000c8090000cb090000cc090000030a0000030a00003e0a0000400a0000830a0000830a0000be0a0000c00a0000c90a0000c90a0000cb0a0000cc0a0000020b0000030b0000400b0000400b0000470b0000480b00004b0b00004c0b0000bf0b0000bf0b0000c10b0000c20b0000c60b0000c80b0000ca0b0000cc0b0000010c0000030c0000410c0000440c0000820c0000830c0000be0c0000be0c0000c00c0000c10c0000c30c0000c40c0000c70c0000c80c0000ca0c0000cb0c0000020d0000030d00003f0d0000400d0000460d0000480d00004a0d00004c0d0000820d0000830d0000d00d0000d10d0000d80d0000de0d0000f20d0000f30d0000330e0000330e0000b30e0000b30e00003e0f00003f0f00007f0f00007f0f000031100000311000003b1000003c10000056100000571000008410000084100000b6170000b6170000be170000c5170000c7170000c81700002319000026190000291900002b19000030190000311900003319000038190000191a00001a1a0000551a0000551a0000571a0000571a00006d1a0000721a0000041b0000041b00003b1b00003b1b00003d1b0000411b0000431b0000441b0000821b0000821b0000a11b0000a11b0000a61b0000a71b0000aa1b0000aa1b0000e71b0000e71b0000ea1b0000ec1b0000ee1b0000ee1b0000f21b0000f31b0000241c00002b1c0000341c0000351c0000e11c0000e11c0000f71c0000f71c000023a8000024a8000027a8000027a8000080a8000081a80000b4a80000c3a8000052a9000053a9000083a9000083a90000b4a90000b5a90000baa90000bba90000bea90000c0a900002faa000030aa000033aa000034aa00004daa00004daa0000ebaa0000ebaa0000eeaa0000efaa0000f5aa0000f5aa0000e3ab0000e4ab0000e6ab0000e7ab0000e9ab0000eaab0000ecab0000ecab0000001001000010010002100100021001008210010082100100b0100100b2100100b7100100b81001002c1101002c11010045110100461101008211010082110100b3110100b5110100bf110100c0110100ce110100ce1101002c1201002e12010032120100331201003512010035120100e0120100e212010002130100031301003f1301003f130100411301004413010047130100481301004b1301004d1301006213010063130100351401003714010040140100411401004514010045140100b1140100b2140100b9140100b9140100bb140100bc140100be140100be140100c1140100c1140100b0150100b1150100b8150100bb150100be150100be15010030160100321601003b1601003c1601003e1601003e160100ac160100ac160100ae160100af160100b6160100b6160100201701002117010026170100261701002c1801002e1801003818010038180100311901003519010037190100381901003d1901003d19010040190100401901004219010042190100d1190100d3190100dc190100df190100e4190100e4190100391a0100391a0100571a0100581a0100971a0100971a01002f1c01002f1c01003e1c01003e1c0100a91c0100a91c0100b11c0100b11c0100b41c0100b41c01008a1d01008e1d0100931d0100941d0100961d0100961d0100f51e0100f61e0100516f0100876f0100f06f0100f16f010066d1010066d101006dd101006dd10100' -const grapheme_prepend_ranges = [ - u32(0x0600), - 0x0605, - 0x06DD, - 0x06DD, - 0x070F, - 0x070F, - 0x08E2, - 0x08E2, - 0x0D4E, - 0x0D4E, - 0x110BD, - 0x110BD, - 0x110CD, - 0x110CD, - 0x111C2, - 0x111C3, - 0x1193F, - 0x1193F, - 0x11941, - 0x11941, - 0x11A3A, - 0x11A3A, - 0x11A84, - 0x11A89, - 0x11D46, - 0x11D46, -]! +const grapheme_prepend_ranges = '0006000005060000dd060000dd0600000f0700000f070000e2080000e20800004e0d00004e0d0000bd100100bd100100cd100100cd100100c2110100c31101003f1901003f19010041190100411901003a1a01003a1a0100841a0100891a0100461d0100461d0100' -const grapheme_extended_pictographic_ranges = [ - u32(0x00A9), - 0x00A9, - 0x00AE, - 0x00AE, - 0x203C, - 0x203C, - 0x2049, - 0x2049, - 0x2122, - 0x2122, - 0x2139, - 0x2139, - 0x2194, - 0x2199, - 0x21A9, - 0x21AA, - 0x231A, - 0x231B, - 0x2328, - 0x2328, - 0x2388, - 0x2388, - 0x23CF, - 0x23CF, - 0x23E9, - 0x23EC, - 0x23ED, - 0x23EE, - 0x23EF, - 0x23EF, - 0x23F0, - 0x23F0, - 0x23F1, - 0x23F2, - 0x23F3, - 0x23F3, - 0x23F8, - 0x23FA, - 0x24C2, - 0x24C2, - 0x25AA, - 0x25AB, - 0x25B6, - 0x25B6, - 0x25C0, - 0x25C0, - 0x25FB, - 0x25FE, - 0x2600, - 0x2601, - 0x2602, - 0x2603, - 0x2604, - 0x2604, - 0x2605, - 0x2605, - 0x2607, - 0x260D, - 0x260E, - 0x260E, - 0x260F, - 0x2610, - 0x2611, - 0x2611, - 0x2612, - 0x2612, - 0x2614, - 0x2615, - 0x2616, - 0x2617, - 0x2618, - 0x2618, - 0x2619, - 0x261C, - 0x261D, - 0x261D, - 0x261E, - 0x261F, - 0x2620, - 0x2620, - 0x2621, - 0x2621, - 0x2622, - 0x2623, - 0x2624, - 0x2625, - 0x2626, - 0x2626, - 0x2627, - 0x2629, - 0x262A, - 0x262A, - 0x262B, - 0x262D, - 0x262E, - 0x262E, - 0x262F, - 0x262F, - 0x2630, - 0x2637, - 0x2638, - 0x2639, - 0x263A, - 0x263A, - 0x263B, - 0x263F, - 0x2640, - 0x2640, - 0x2641, - 0x2641, - 0x2642, - 0x2642, - 0x2643, - 0x2647, - 0x2648, - 0x2653, - 0x2654, - 0x265E, - 0x265F, - 0x265F, - 0x2660, - 0x2660, - 0x2661, - 0x2662, - 0x2663, - 0x2663, - 0x2664, - 0x2664, - 0x2665, - 0x2666, - 0x2667, - 0x2667, - 0x2668, - 0x2668, - 0x2669, - 0x267A, - 0x267B, - 0x267B, - 0x267C, - 0x267D, - 0x267E, - 0x267E, - 0x267F, - 0x267F, - 0x2680, - 0x2685, - 0x2690, - 0x2691, - 0x2692, - 0x2692, - 0x2693, - 0x2693, - 0x2694, - 0x2694, - 0x2695, - 0x2695, - 0x2696, - 0x2697, - 0x2698, - 0x2698, - 0x2699, - 0x2699, - 0x269A, - 0x269A, - 0x269B, - 0x269C, - 0x269D, - 0x269F, - 0x26A0, - 0x26A1, - 0x26A2, - 0x26A6, - 0x26A7, - 0x26A7, - 0x26A8, - 0x26A9, - 0x26AA, - 0x26AB, - 0x26AC, - 0x26AF, - 0x26B0, - 0x26B1, - 0x26B2, - 0x26BC, - 0x26BD, - 0x26BE, - 0x26BF, - 0x26C3, - 0x26C4, - 0x26C5, - 0x26C6, - 0x26C7, - 0x26C8, - 0x26C8, - 0x26C9, - 0x26CD, - 0x26CE, - 0x26CE, - 0x26CF, - 0x26CF, - 0x26D0, - 0x26D0, - 0x26D1, - 0x26D1, - 0x26D2, - 0x26D2, - 0x26D3, - 0x26D3, - 0x26D4, - 0x26D4, - 0x26D5, - 0x26E8, - 0x26E9, - 0x26E9, - 0x26EA, - 0x26EA, - 0x26EB, - 0x26EF, - 0x26F0, - 0x26F1, - 0x26F2, - 0x26F3, - 0x26F4, - 0x26F4, - 0x26F5, - 0x26F5, - 0x26F6, - 0x26F6, - 0x26F7, - 0x26F9, - 0x26FA, - 0x26FA, - 0x26FB, - 0x26FC, - 0x26FD, - 0x26FD, - 0x26FE, - 0x2701, - 0x2702, - 0x2702, - 0x2703, - 0x2704, - 0x2705, - 0x2705, - 0x2708, - 0x270C, - 0x270D, - 0x270D, - 0x270E, - 0x270E, - 0x270F, - 0x270F, - 0x2710, - 0x2711, - 0x2712, - 0x2712, - 0x2714, - 0x2714, - 0x2716, - 0x2716, - 0x271D, - 0x271D, - 0x2721, - 0x2721, - 0x2728, - 0x2728, - 0x2733, - 0x2734, - 0x2744, - 0x2744, - 0x2747, - 0x2747, - 0x274C, - 0x274C, - 0x274E, - 0x274E, - 0x2753, - 0x2755, - 0x2757, - 0x2757, - 0x2763, - 0x2763, - 0x2764, - 0x2764, - 0x2765, - 0x2767, - 0x2795, - 0x2797, - 0x27A1, - 0x27A1, - 0x27B0, - 0x27B0, - 0x27BF, - 0x27BF, - 0x2934, - 0x2935, - 0x2B05, - 0x2B07, - 0x2B1B, - 0x2B1C, - 0x2B50, - 0x2B50, - 0x2B55, - 0x2B55, - 0x3030, - 0x3030, - 0x303D, - 0x303D, - 0x3297, - 0x3297, - 0x3299, - 0x3299, - 0x1F000, - 0x1F003, - 0x1F004, - 0x1F004, - 0x1F005, - 0x1F0CE, - 0x1F0CF, - 0x1F0CF, - 0x1F0D0, - 0x1F0FF, - 0x1F10D, - 0x1F10F, - 0x1F12F, - 0x1F12F, - 0x1F16C, - 0x1F16F, - 0x1F170, - 0x1F171, - 0x1F17E, - 0x1F17F, - 0x1F18E, - 0x1F18E, - 0x1F191, - 0x1F19A, - 0x1F1AD, - 0x1F1E5, - 0x1F201, - 0x1F202, - 0x1F203, - 0x1F20F, - 0x1F21A, - 0x1F21A, - 0x1F22F, - 0x1F22F, - 0x1F232, - 0x1F23A, - 0x1F23C, - 0x1F23F, - 0x1F249, - 0x1F24F, - 0x1F250, - 0x1F251, - 0x1F252, - 0x1F2FF, - 0x1F300, - 0x1F30C, - 0x1F30D, - 0x1F30E, - 0x1F30F, - 0x1F30F, - 0x1F310, - 0x1F310, - 0x1F311, - 0x1F311, - 0x1F312, - 0x1F312, - 0x1F313, - 0x1F315, - 0x1F316, - 0x1F318, - 0x1F319, - 0x1F319, - 0x1F31A, - 0x1F31A, - 0x1F31B, - 0x1F31B, - 0x1F31C, - 0x1F31C, - 0x1F31D, - 0x1F31E, - 0x1F31F, - 0x1F320, - 0x1F321, - 0x1F321, - 0x1F322, - 0x1F323, - 0x1F324, - 0x1F32C, - 0x1F32D, - 0x1F32F, - 0x1F330, - 0x1F331, - 0x1F332, - 0x1F333, - 0x1F334, - 0x1F335, - 0x1F336, - 0x1F336, - 0x1F337, - 0x1F34A, - 0x1F34B, - 0x1F34B, - 0x1F34C, - 0x1F34F, - 0x1F350, - 0x1F350, - 0x1F351, - 0x1F37B, - 0x1F37C, - 0x1F37C, - 0x1F37D, - 0x1F37D, - 0x1F37E, - 0x1F37F, - 0x1F380, - 0x1F393, - 0x1F394, - 0x1F395, - 0x1F396, - 0x1F397, - 0x1F398, - 0x1F398, - 0x1F399, - 0x1F39B, - 0x1F39C, - 0x1F39D, - 0x1F39E, - 0x1F39F, - 0x1F3A0, - 0x1F3C4, - 0x1F3C5, - 0x1F3C5, - 0x1F3C6, - 0x1F3C6, - 0x1F3C7, - 0x1F3C7, - 0x1F3C8, - 0x1F3C8, - 0x1F3C9, - 0x1F3C9, - 0x1F3CA, - 0x1F3CA, - 0x1F3CB, - 0x1F3CE, - 0x1F3CF, - 0x1F3D3, - 0x1F3D4, - 0x1F3DF, - 0x1F3E0, - 0x1F3E3, - 0x1F3E4, - 0x1F3E4, - 0x1F3E5, - 0x1F3F0, - 0x1F3F1, - 0x1F3F2, - 0x1F3F3, - 0x1F3F3, - 0x1F3F4, - 0x1F3F4, - 0x1F3F5, - 0x1F3F5, - 0x1F3F6, - 0x1F3F6, - 0x1F3F7, - 0x1F3F7, - 0x1F3F8, - 0x1F3FA, - 0x1F400, - 0x1F407, - 0x1F408, - 0x1F408, - 0x1F409, - 0x1F40B, - 0x1F40C, - 0x1F40E, - 0x1F40F, - 0x1F410, - 0x1F411, - 0x1F412, - 0x1F413, - 0x1F413, - 0x1F414, - 0x1F414, - 0x1F415, - 0x1F415, - 0x1F416, - 0x1F416, - 0x1F417, - 0x1F429, - 0x1F42A, - 0x1F42A, - 0x1F42B, - 0x1F43E, - 0x1F43F, - 0x1F43F, - 0x1F440, - 0x1F440, - 0x1F441, - 0x1F441, - 0x1F442, - 0x1F464, - 0x1F465, - 0x1F465, - 0x1F466, - 0x1F46B, - 0x1F46C, - 0x1F46D, - 0x1F46E, - 0x1F4AC, - 0x1F4AD, - 0x1F4AD, - 0x1F4AE, - 0x1F4B5, - 0x1F4B6, - 0x1F4B7, - 0x1F4B8, - 0x1F4EB, - 0x1F4EC, - 0x1F4ED, - 0x1F4EE, - 0x1F4EE, - 0x1F4EF, - 0x1F4EF, - 0x1F4F0, - 0x1F4F4, - 0x1F4F5, - 0x1F4F5, - 0x1F4F6, - 0x1F4F7, - 0x1F4F8, - 0x1F4F8, - 0x1F4F9, - 0x1F4FC, - 0x1F4FD, - 0x1F4FD, - 0x1F4FE, - 0x1F4FE, - 0x1F4FF, - 0x1F502, - 0x1F503, - 0x1F503, - 0x1F504, - 0x1F507, - 0x1F508, - 0x1F508, - 0x1F509, - 0x1F509, - 0x1F50A, - 0x1F514, - 0x1F515, - 0x1F515, - 0x1F516, - 0x1F52B, - 0x1F52C, - 0x1F52D, - 0x1F52E, - 0x1F53D, - 0x1F546, - 0x1F548, - 0x1F549, - 0x1F54A, - 0x1F54B, - 0x1F54E, - 0x1F54F, - 0x1F54F, - 0x1F550, - 0x1F55B, - 0x1F55C, - 0x1F567, - 0x1F568, - 0x1F56E, - 0x1F56F, - 0x1F570, - 0x1F571, - 0x1F572, - 0x1F573, - 0x1F579, - 0x1F57A, - 0x1F57A, - 0x1F57B, - 0x1F586, - 0x1F587, - 0x1F587, - 0x1F588, - 0x1F589, - 0x1F58A, - 0x1F58D, - 0x1F58E, - 0x1F58F, - 0x1F590, - 0x1F590, - 0x1F591, - 0x1F594, - 0x1F595, - 0x1F596, - 0x1F597, - 0x1F5A3, - 0x1F5A4, - 0x1F5A4, - 0x1F5A5, - 0x1F5A5, - 0x1F5A6, - 0x1F5A7, - 0x1F5A8, - 0x1F5A8, - 0x1F5A9, - 0x1F5B0, - 0x1F5B1, - 0x1F5B2, - 0x1F5B3, - 0x1F5BB, - 0x1F5BC, - 0x1F5BC, - 0x1F5BD, - 0x1F5C1, - 0x1F5C2, - 0x1F5C4, - 0x1F5C5, - 0x1F5D0, - 0x1F5D1, - 0x1F5D3, - 0x1F5D4, - 0x1F5DB, - 0x1F5DC, - 0x1F5DE, - 0x1F5DF, - 0x1F5E0, - 0x1F5E1, - 0x1F5E1, - 0x1F5E2, - 0x1F5E2, - 0x1F5E3, - 0x1F5E3, - 0x1F5E4, - 0x1F5E7, - 0x1F5E8, - 0x1F5E8, - 0x1F5E9, - 0x1F5EE, - 0x1F5EF, - 0x1F5EF, - 0x1F5F0, - 0x1F5F2, - 0x1F5F3, - 0x1F5F3, - 0x1F5F4, - 0x1F5F9, - 0x1F5FA, - 0x1F5FA, - 0x1F5FB, - 0x1F5FF, - 0x1F600, - 0x1F600, - 0x1F601, - 0x1F606, - 0x1F607, - 0x1F608, - 0x1F609, - 0x1F60D, - 0x1F60E, - 0x1F60E, - 0x1F60F, - 0x1F60F, - 0x1F610, - 0x1F610, - 0x1F611, - 0x1F611, - 0x1F612, - 0x1F614, - 0x1F615, - 0x1F615, - 0x1F616, - 0x1F616, - 0x1F617, - 0x1F617, - 0x1F618, - 0x1F618, - 0x1F619, - 0x1F619, - 0x1F61A, - 0x1F61A, - 0x1F61B, - 0x1F61B, - 0x1F61C, - 0x1F61E, - 0x1F61F, - 0x1F61F, - 0x1F620, - 0x1F625, - 0x1F626, - 0x1F627, - 0x1F628, - 0x1F62B, - 0x1F62C, - 0x1F62C, - 0x1F62D, - 0x1F62D, - 0x1F62E, - 0x1F62F, - 0x1F630, - 0x1F633, - 0x1F634, - 0x1F634, - 0x1F635, - 0x1F635, - 0x1F636, - 0x1F636, - 0x1F637, - 0x1F640, - 0x1F641, - 0x1F644, - 0x1F645, - 0x1F64F, - 0x1F680, - 0x1F680, - 0x1F681, - 0x1F682, - 0x1F683, - 0x1F685, - 0x1F686, - 0x1F686, - 0x1F687, - 0x1F687, - 0x1F688, - 0x1F688, - 0x1F689, - 0x1F689, - 0x1F68A, - 0x1F68B, - 0x1F68C, - 0x1F68C, - 0x1F68D, - 0x1F68D, - 0x1F68E, - 0x1F68E, - 0x1F68F, - 0x1F68F, - 0x1F690, - 0x1F690, - 0x1F691, - 0x1F693, - 0x1F694, - 0x1F694, - 0x1F695, - 0x1F695, - 0x1F696, - 0x1F696, - 0x1F697, - 0x1F697, - 0x1F698, - 0x1F698, - 0x1F699, - 0x1F69A, - 0x1F69B, - 0x1F6A1, - 0x1F6A2, - 0x1F6A2, - 0x1F6A3, - 0x1F6A3, - 0x1F6A4, - 0x1F6A5, - 0x1F6A6, - 0x1F6A6, - 0x1F6A7, - 0x1F6AD, - 0x1F6AE, - 0x1F6B1, - 0x1F6B2, - 0x1F6B2, - 0x1F6B3, - 0x1F6B5, - 0x1F6B6, - 0x1F6B6, - 0x1F6B7, - 0x1F6B8, - 0x1F6B9, - 0x1F6BE, - 0x1F6BF, - 0x1F6BF, - 0x1F6C0, - 0x1F6C0, - 0x1F6C1, - 0x1F6C5, - 0x1F6C6, - 0x1F6CA, - 0x1F6CB, - 0x1F6CB, - 0x1F6CC, - 0x1F6CC, - 0x1F6CD, - 0x1F6CF, - 0x1F6D0, - 0x1F6D0, - 0x1F6D1, - 0x1F6D2, - 0x1F6D3, - 0x1F6D4, - 0x1F6D5, - 0x1F6D5, - 0x1F6D6, - 0x1F6D7, - 0x1F6D8, - 0x1F6DF, - 0x1F6E0, - 0x1F6E5, - 0x1F6E6, - 0x1F6E8, - 0x1F6E9, - 0x1F6E9, - 0x1F6EA, - 0x1F6EA, - 0x1F6EB, - 0x1F6EC, - 0x1F6ED, - 0x1F6EF, - 0x1F6F0, - 0x1F6F0, - 0x1F6F1, - 0x1F6F2, - 0x1F6F3, - 0x1F6F3, - 0x1F6F4, - 0x1F6F6, - 0x1F6F7, - 0x1F6F8, - 0x1F6F9, - 0x1F6F9, - 0x1F6FA, - 0x1F6FA, - 0x1F6FB, - 0x1F6FC, - 0x1F6FD, - 0x1F6FF, - 0x1F774, - 0x1F77F, - 0x1F7D5, - 0x1F7DF, - 0x1F7E0, - 0x1F7EB, - 0x1F7EC, - 0x1F7FF, - 0x1F80C, - 0x1F80F, - 0x1F848, - 0x1F84F, - 0x1F85A, - 0x1F85F, - 0x1F888, - 0x1F88F, - 0x1F8AE, - 0x1F8FF, - 0x1F90C, - 0x1F90C, - 0x1F90D, - 0x1F90F, - 0x1F910, - 0x1F918, - 0x1F919, - 0x1F91E, - 0x1F91F, - 0x1F91F, - 0x1F920, - 0x1F927, - 0x1F928, - 0x1F92F, - 0x1F930, - 0x1F930, - 0x1F931, - 0x1F932, - 0x1F933, - 0x1F93A, - 0x1F93C, - 0x1F93E, - 0x1F93F, - 0x1F93F, - 0x1F940, - 0x1F945, - 0x1F947, - 0x1F94B, - 0x1F94C, - 0x1F94C, - 0x1F94D, - 0x1F94F, - 0x1F950, - 0x1F95E, - 0x1F95F, - 0x1F96B, - 0x1F96C, - 0x1F970, - 0x1F971, - 0x1F971, - 0x1F972, - 0x1F972, - 0x1F973, - 0x1F976, - 0x1F977, - 0x1F978, - 0x1F979, - 0x1F979, - 0x1F97A, - 0x1F97A, - 0x1F97B, - 0x1F97B, - 0x1F97C, - 0x1F97F, - 0x1F980, - 0x1F984, - 0x1F985, - 0x1F991, - 0x1F992, - 0x1F997, - 0x1F998, - 0x1F9A2, - 0x1F9A3, - 0x1F9A4, - 0x1F9A5, - 0x1F9AA, - 0x1F9AB, - 0x1F9AD, - 0x1F9AE, - 0x1F9AF, - 0x1F9B0, - 0x1F9B9, - 0x1F9BA, - 0x1F9BF, - 0x1F9C0, - 0x1F9C0, - 0x1F9C1, - 0x1F9C2, - 0x1F9C3, - 0x1F9CA, - 0x1F9CB, - 0x1F9CB, - 0x1F9CC, - 0x1F9CC, - 0x1F9CD, - 0x1F9CF, - 0x1F9D0, - 0x1F9E6, - 0x1F9E7, - 0x1F9FF, - 0x1FA00, - 0x1FA6F, - 0x1FA70, - 0x1FA73, - 0x1FA74, - 0x1FA74, - 0x1FA75, - 0x1FA77, - 0x1FA78, - 0x1FA7A, - 0x1FA7B, - 0x1FA7F, - 0x1FA80, - 0x1FA82, - 0x1FA83, - 0x1FA86, - 0x1FA87, - 0x1FA8F, - 0x1FA90, - 0x1FA95, - 0x1FA96, - 0x1FAA8, - 0x1FAA9, - 0x1FAAF, - 0x1FAB0, - 0x1FAB6, - 0x1FAB7, - 0x1FABF, - 0x1FAC0, - 0x1FAC2, - 0x1FAC3, - 0x1FACF, - 0x1FAD0, - 0x1FAD6, - 0x1FAD7, - 0x1FAFF, - 0x1FC00, - 0x1FFFD, -]! +const grapheme_extended_pictographic_ranges = + 'a9000000a9000000ae000000ae0000003c2000003c2000004920000049200000222100002221000039210000392100009421000099210000a9210000aa2100001a2300001b23000028230000282300008823000088230000cf230000cf230000e9230000ec230000ed230000ee230000ef230000ef230000f0230000f0230000f1230000f2230000f3230000f3230000f8230000fa230000c2240000c2240000aa250000ab250000b6250000b6250000c0250000c0250000fb250000fe2500000026000001260000022600000326000004260000042600000526000005260000072600000d2600000e2600000e2600000f2600001026000011260000112600001226000012260000142600001526000016260000172600001826000018260000192600001c2600001d2600001d2600001e2600001f2600002026000020260000212600002126000022260000232600002426000025260000262600002626000027260000292600002a2600002a2600002b2600002d2600002e2600002e2600002f2600002f260000302600003726000038260000392600003a2600003a2600003b2600003f26000040260000402600004126000041260000422600004226000043260000472600004826000053260000542600005e2600005f2600005f2600006026000060260000612600006226000063260000632600006426000064260000652600006626000067260000672600006826000068260000692600007a2600007b2600007b2600007c2600007d2600007e2600007e2600007f2600007f2600008026000085260000902600009126000092260000922600009326000093260000942600009426000095260000952600009626000097260000982600009826000099260000992600009a2600009a2600009b2600009c2600009d2600009f260000a0260000a1260000a2260000a6260000a7260000a7260000a8260000a9260000aa260000ab260000ac260000af260000b0260000b1260000b2260000bc260000bd260000be260000bf260000c3260000c4260000c5260000c6260000c7260000c8260000c8260000c9260000cd260000ce260000ce260000cf260000cf260000d0260000d0260000d1260000d1260000d2260000d2260000d3260000d3260000d4260000d4260000d5260000e8260000e9260000e9260000ea260000ea260000eb260000ef260000f0260000f1260000f2260000f3260000f4260000f4260000f5260000f5260000f6260000f6260000f7260000f9260000fa260000fa260000fb260000fc260000fd260000fd260000fe26000001270000022700000227000003270000042700000527000005270000082700000c2700000d2700000d2700000e2700000e2700000f2700000f27000010270000112700001227000012270000142700001427000016270000162700001d2700001d270000212700002127000028270000282700003327000034270000442700004427000047270000472700004c2700004c2700004e2700004e270000532700005527000057270000572700006327000063270000642700006427000065270000672700009527000097270000a1270000a1270000b0270000b0270000bf270000bf2700003429000035290000052b0000072b00001b2b00001c2b0000502b0000502b0000552b0000552b000030300000303000003d3000003d3000009732000097320000993200009932000000f0010003f0010004f0010004f0010005f00100cef00100cff00100cff00100d0f00100fff001000df101000ff101002ff101002ff101006cf101006ff1010070f1010071f101007ef101007ff101008ef101008ef1010091f101009af10100adf10100e5f1010001f2010002f2010003f201000ff201001af201001af201002ff201002ff2010032f201003af201003cf201003ff2010049f201004ff2010050f2010051f2010052f20100fff2010000f301000cf301000df301000ef301000ff301000ff3010010f3010010f3010011f3010011f3010012f3010012f3010013f3010015f3010016f3010018f3010019f3010019f301001af301001af301001bf301001bf301001cf301001cf301001df301001ef301001ff3010020f30100' + + '21f3010021f3010022f3010023f3010024f301002cf301002df301002ff3010030f3010031f3010032f3010033f3010034f3010035f3010036f3010036f3010037f301004af301004bf301004bf301004cf301004ff3010050f3010050f3010051f301007bf301007cf301007cf301007df301007df301007ef301007ff3010080f3010093f3010094f3010095f3010096f3010097f3010098f3010098f3010099f301009bf301009cf301009df301009ef301009ff30100a0f30100c4f30100c5f30100c5f30100c6f30100c6f30100c7f30100c7f30100c8f30100c8f30100c9f30100c9f30100caf30100caf30100cbf30100cef30100cff30100d3f30100d4f30100dff30100e0f30100e3f30100e4f30100e4f30100e5f30100f0f30100f1f30100f2f30100f3f30100f3f30100f4f30100f4f30100f5f30100f5f30100f6f30100f6f30100f7f30100f7f30100f8f30100faf3010000f4010007f4010008f4010008f4010009f401000bf401000cf401000ef401000ff4010010f4010011f4010012f4010013f4010013f4010014f4010014f4010015f4010015f4010016f4010016f4010017f4010029f401002af401002af401002bf401003ef401003ff401003ff4010040f4010040f4010041f4010041f4010042f4010064f4010065f4010065f4010066f401006bf401006cf401006df401006ef40100acf40100adf40100adf40100aef40100b5f40100b6f40100b7f40100b8f40100ebf40100ecf40100edf40100eef40100eef40100eff40100eff40100f0f40100f4f40100f5f40100f5f40100f6f40100f7f40100f8f40100f8f40100f9f40100fcf40100fdf40100fdf40100fef40100fef40100fff4010002f5010003f5010003f5010004f5010007f5010008f5010008f5010009f5010009f501000af5010014f5010015f5010015f5010016f501002bf501002cf501002df501002ef501003df5010046f5010048f5010049f501004af501004bf501004ef501004ff501004ff5010050f501005bf501005cf5010067f5010068f501006ef501006ff5010070f5010071f5010072f5010073f5010079f501007af501007af501007bf5010086f5010087f5010087f5010088f5010089f501008af501008df501008ef501008ff5010090f5010090f5010091f5010094f5010095f5010096f5010097f50100a3f50100a4f50100a4f50100a5f50100a5f50100a6f50100a7f50100a8f50100a8f50100a9f50100b0f50100b1f50100b2f50100b3f50100bbf50100bcf50100bcf50100bdf50100c1f50100c2f50100c4f50100c5f50100d0f50100d1f50100d3f50100d4f50100dbf50100dcf50100def50100dff50100e0f50100e1f50100e1f50100e2f50100e2f50100e3f50100e3f50100e4f50100e7f50100e8f50100e8f50100e9f50100eef50100eff50100eff50100f0f50100f2f50100f3f50100f3f50100f4f50100f9f50100faf50100faf50100fbf50100fff5010000f6010000f6010001f6010006f6010007f6010008f6010009f601000df601000ef601000ef601000ff601000ff6010010f6010010f6010011f6010011f6010012f6010014f6010015f6010015f6010016f6010016f6010017f6010017f6010018f6010018f6010019f6010019f601001af601001af601001bf601001bf601001cf601001ef601001ff601001ff6010020f6010025f6010026f6010027f6010028f601002bf601002cf601002cf601002df601002df601002ef601002ff6010030f6010033f6010034f6010034f6010035f6010035f6010036f6010036f6010037f6010040f6010041f6010044f6010045f601004ff6010080f6010080f6010081f6010082f6010083f6010085f6010086f6010086f6010087f6010087f6010088f6010088f6010089f6010089f601008af601008bf601008cf601008cf601008df601008df601008ef601008ef601008ff601008ff6010090f6010090f6010091f6010093f6010094f6010094f6010095f6010095f6010096f6010096f6010097f6010097f6010098f6010098f6010099f601009af601009bf60100a1f60100a2f60100a2f60100a3f60100a3f60100a4f60100a5f60100a6f60100a6f60100a7f60100adf60100' + + 'aef60100b1f60100b2f60100b2f60100b3f60100b5f60100b6f60100b6f60100b7f60100b8f60100b9f60100bef60100bff60100bff60100c0f60100c0f60100c1f60100c5f60100c6f60100caf60100cbf60100cbf60100ccf60100ccf60100cdf60100cff60100d0f60100d0f60100d1f60100d2f60100d3f60100d4f60100d5f60100d5f60100d6f60100d7f60100d8f60100dff60100e0f60100e5f60100e6f60100e8f60100e9f60100e9f60100eaf60100eaf60100ebf60100ecf60100edf60100eff60100f0f60100f0f60100f1f60100f2f60100f3f60100f3f60100f4f60100f6f60100f7f60100f8f60100f9f60100f9f60100faf60100faf60100fbf60100fcf60100fdf60100fff6010074f701007ff70100d5f70100dff70100e0f70100ebf70100ecf70100fff701000cf801000ff8010048f801004ff801005af801005ff8010088f801008ff80100aef80100fff801000cf901000cf901000df901000ff9010010f9010018f9010019f901001ef901001ff901001ff9010020f9010027f9010028f901002ff9010030f9010030f9010031f9010032f9010033f901003af901003cf901003ef901003ff901003ff9010040f9010045f9010047f901004bf901004cf901004cf901004df901004ff9010050f901005ef901005ff901006bf901006cf9010070f9010071f9010071f9010072f9010072f9010073f9010076f9010077f9010078f9010079f9010079f901007af901007af901007bf901007bf901007cf901007ff9010080f9010084f9010085f9010091f9010092f9010097f9010098f90100a2f90100a3f90100a4f90100a5f90100aaf90100abf90100adf90100aef90100aff90100b0f90100b9f90100baf90100bff90100c0f90100c0f90100c1f90100c2f90100c3f90100caf90100cbf90100cbf90100ccf90100ccf90100cdf90100cff90100d0f90100e6f90100e7f90100fff9010000fa01006ffa010070fa010073fa010074fa010074fa010075fa010077fa010078fa01007afa01007bfa01007ffa010080fa010082fa010083fa010086fa010087fa01008ffa010090fa010095fa010096fa0100a8fa0100a9fa0100affa0100b0fa0100b6fa0100b7fa0100bffa0100c0fa0100c2fa0100c3fa0100cffa0100d0fa0100d6fa0100d7fa0100fffa010000fc0100fdff0100' @[inline] -fn in_grapheme_ranges(r rune, ranges []u32) bool { +fn grapheme_hex_nibble(c u8) u32 { + return if c <= `9` { u32(c - `0`) } else { u32((c | 0x20) - `a` + 10) } +} + +@[inline] +fn grapheme_hex_byte(ranges string, i int) u32 { + return (grapheme_hex_nibble(ranges[i]) << 4) | grapheme_hex_nibble(ranges[i + 1]) +} + +@[inline] +fn grapheme_range_value(ranges string, value_idx int) u32 { + i := value_idx * 8 + b0 := grapheme_hex_byte(ranges, i) + b1 := grapheme_hex_byte(ranges, i + 2) + b2 := grapheme_hex_byte(ranges, i + 4) + b3 := grapheme_hex_byte(ranges, i + 6) + return b0 | (b1 << 8) | (b2 << 16) | (b3 << 24) +} + +@[inline] +fn in_grapheme_ranges(r rune, ranges string) bool { target := u32(r) mut low := 0 - mut high := ranges.len / 2 + mut high := ranges.len / 16 for low < high { mid := low + (high - low) / 2 - lo := ranges[mid * 2] - hi := ranges[mid * 2 + 1] + lo := grapheme_range_value(ranges, mid * 2) + hi := grapheme_range_value(ranges, mid * 2 + 1) if target < lo { high = mid } else if target > hi { @@ -2176,16 +102,16 @@ fn grapheme_break_property(r rune) GraphemeBreakProperty { if (r >= 0x11a8 && r <= 0x11ff) || (r >= 0xd7cb && r <= 0xd7fb) { return .t } - if in_grapheme_ranges(r, grapheme_control_ranges[..]) { + if in_grapheme_ranges(r, grapheme_control_ranges) { return .control } - if in_grapheme_ranges(r, grapheme_extend_ranges[..]) { + if in_grapheme_ranges(r, grapheme_extend_ranges) { return .extend } - if in_grapheme_ranges(r, grapheme_spacing_mark_ranges[..]) { + if in_grapheme_ranges(r, grapheme_spacing_mark_ranges) { return .spacing_mark } - if in_grapheme_ranges(r, grapheme_prepend_ranges[..]) { + if in_grapheme_ranges(r, grapheme_prepend_ranges) { return .prepend } return .other @@ -2193,7 +119,7 @@ fn grapheme_break_property(r rune) GraphemeBreakProperty { @[inline] fn is_extended_pictographic(r rune) bool { - return in_grapheme_ranges(r, grapheme_extended_pictographic_ranges[..]) + return in_grapheme_ranges(r, grapheme_extended_pictographic_ranges) } struct GraphemeState { diff --git a/vlib/v/builder/builder.v b/vlib/v/builder/builder.v index 1ca8ab479..f7ad7bd33 100644 --- a/vlib/v/builder/builder.v +++ b/vlib/v/builder/builder.v @@ -441,6 +441,18 @@ fn register_used_import(mut file ast.File, alias string) { } } +fn file_needs_c_function_call_import_scan(file &ast.File) bool { + for import_m in file.imports { + alias := import_m.alias + if (alias.len == 1 && alias[0] == `_`) || alias in file.used_imports + || alias in file.auto_imports { + continue + } + return true + } + return false +} + fn (mut b Builder) collect_used_c_function_calls(file &ast.File) map[string]bool { mut collector := CFunctionCallCollector{ names: map[string]bool{} @@ -451,6 +463,9 @@ fn (mut b Builder) collect_used_c_function_calls(file &ast.File) map[string]bool fn (mut b Builder) mark_imports_used_by_c_function_calls() { for mut file in b.parsed_files { + if !file_needs_c_function_call_import_scan(file) { + continue + } used_c_calls := b.collect_used_c_function_calls(file) if used_c_calls.len == 0 { continue diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index d2ac61892..8ebf5ea1f 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -84,6 +84,7 @@ mut: table &ast.Table = unsafe { nil } styp_cache map[ast.Type]string no_eq_method_types map[ast.Type]bool // types that does not need to call its auto eq methods for optimization + generic_parts_cache []i8 // type idx -> 0 unknown, 1 false, 2 true unique_file_path_hash u64 // a hash of file.path, used for making auxiliary fn generation unique (like `compare_xyz`) fn_decl &ast.FnDecl = unsafe { nil } // pointer to the FnDecl we are currently inside otherwise 0 last_fn_c_name string @@ -400,6 +401,7 @@ pub fn gen(files []&ast.File, mut table ast.Table, pref_ &pref.Preferences) GenO has_debugger: 'v.debug' in table.modules reflection_strings: &reflection_strings generated_map_key_fns: map[ast.Type]bool{} + generic_parts_cache: []i8{len: table.type_symbols.len} } global_g.type_resolver = type_resolver.TypeResolver.new(table, global_g) @@ -1037,6 +1039,7 @@ fn cgen_process_one_file_cb(mut p pool.PoolProcessor, idx int, wid int) voidptr has_debugger: 'v.debug' in global_g.table.modules reflection_strings: global_g.reflection_strings generated_map_key_fns: map[ast.Type]bool{} + generic_parts_cache: []i8{len: global_g.table.type_symbols.len} } g.type_resolver = type_resolver.TypeResolver.new(global_g.table, g) g.comptime = &g.type_resolver.info @@ -1534,7 +1537,7 @@ fn (mut g Gen) base_type(_t ast.Type) string { return styp } -fn (g &Gen) can_write_interface_typesymbol_declaration(sym ast.TypeSymbol) bool { +fn (mut g Gen) can_write_interface_typesymbol_declaration(sym ast.TypeSymbol) bool { if sym.info !is ast.Interface { return false } @@ -1642,16 +1645,33 @@ fn (mut g Gen) option_type_name(t ast.Type) (string, string) { return styp, base } -fn (g &Gen) type_has_unresolved_generic_parts(typ ast.Type) bool { +fn (mut g Gen) type_has_unresolved_generic_parts(typ ast.Type) bool { if typ == 0 { return false } if typ.has_flag(.generic) { return true } - if typ.idx() <= ast.nil_type_idx { + idx := typ.idx() + if idx <= ast.nil_type_idx { return false } + if idx < g.generic_parts_cache.len { + cached := g.generic_parts_cache[idx] + if cached != 0 { + return cached == 2 + } + } else if idx < g.table.type_symbols.len { + g.generic_parts_cache << []i8{len: idx - g.generic_parts_cache.len + 1} + } + resolved := g.type_has_unresolved_generic_parts_uncached(typ) + if idx < g.generic_parts_cache.len { + g.generic_parts_cache[idx] = if resolved { i8(2) } else { i8(1) } + } + return resolved +} + +fn (mut g Gen) type_has_unresolved_generic_parts_uncached(typ ast.Type) bool { sym := g.table.sym(typ) if sym.kind == .placeholder || (sym.kind == .any && !sym.is_builtin()) { return true diff --git a/vlib/v/gen/c/fn.v b/vlib/v/gen/c/fn.v index 7d497a3b6..c27af8846 100644 --- a/vlib/v/gen/c/fn.v +++ b/vlib/v/gen/c/fn.v @@ -3316,7 +3316,7 @@ fn (mut g Gen) resolved_generic_call_arg_type(arg ast.CallArg) ast.Type { return g.unwrap_generic(g.recheck_concrete_type(arg_type)) } -fn (g &Gen) generic_param_infer_type(param ast.Param) ast.Type { +fn (mut g Gen) generic_param_infer_type(param ast.Param) ast.Type { if param.orig_typ != 0 && (param.orig_typ.has_flag(.generic) || g.type_has_unresolved_generic_parts(param.orig_typ)) { return param.orig_typ @@ -3803,11 +3803,11 @@ fn (mut g Gen) resolve_active_call_concrete_type(typ ast.Type) ast.Type { } fn (mut g Gen) call_args_with_context(node ast.CallExpr, generic_names []string, concrete_types []ast.Type) { - old_generic_names := g.active_call_generic_names.clone() - old_concrete_types := g.active_call_concrete_types.clone() + old_generic_names := g.active_call_generic_names + old_concrete_types := g.active_call_concrete_types if generic_names.len > 0 && generic_names.len == concrete_types.len { - g.active_call_generic_names = generic_names.clone() - g.active_call_concrete_types = concrete_types.clone() + g.active_call_generic_names = generic_names + g.active_call_concrete_types = concrete_types } else { g.active_call_generic_names = []string{} g.active_call_concrete_types = []ast.Type{} @@ -6245,26 +6245,19 @@ fn (mut g Gen) call_args(node ast.CallExpr) { } if i < expected_types.len { if param := g.call_arg_param(node, i) { - concrete_param_type := - g.resolve_active_call_concrete_type(param.typ.set_flag(.generic)) - if concrete_param_type != 0 && concrete_param_type != expected_types[i] - && !concrete_param_type.has_flag(.generic) - && !g.type_has_unresolved_generic_parts(concrete_param_type) - && ((expected_types[i] == 0 || expected_types[i].has_flag(.generic) - || g.type_has_unresolved_generic_parts(expected_types[i])) - || node.concrete_types.len > 0 || g.cur_concrete_types.len > 0) { - expected_types[i] = concrete_param_type - } - should_refresh_expected_type := - (param.typ.has_flag(.generic) || g.type_has_unresolved_generic_parts(param.typ)) - && ((expected_types[i] == 0 || expected_types[i].has_flag(.generic) - || g.type_has_unresolved_generic_parts(expected_types[i])) - || (g.cur_fn != unsafe { nil } && g.cur_concrete_types.len > 0)) - if should_refresh_expected_type { + param_needs_generic_resolution := g.type_needs_generic_resolution(param.typ) + || g.has_active_call_generic_context() + expected_needs_generic_resolution := expected_types[i] == 0 + || g.type_needs_generic_resolution(expected_types[i]) + if param_needs_generic_resolution || expected_needs_generic_resolution + || node.concrete_types.len > 0 || g.cur_concrete_types.len > 0 { resolved_expected_type := g.resolve_active_call_concrete_type(param.typ.set_flag(.generic)) - if resolved_expected_type != 0 && !resolved_expected_type.has_flag(.generic) - && !g.type_has_unresolved_generic_parts(resolved_expected_type) { + if resolved_expected_type != 0 && resolved_expected_type != expected_types[i] + && !g.type_needs_generic_resolution(resolved_expected_type) + && (expected_needs_generic_resolution + || node.concrete_types.len > 0 + || g.cur_concrete_types.len > 0) { expected_types[i] = g.unwrap_generic(g.recheck_concrete_type(resolved_expected_type)) } @@ -6626,10 +6619,10 @@ fn (mut g Gen) ref_or_deref_arg_ex(arg ast.CallArg, expected_type_ ast.Type, lan } else { g.unwrap_generic(arg.typ) } + in_generic_context := g.has_current_generic_context() if arg.expr is ast.Ident { - needs_resolved_ident_type := arg_typ == 0 || arg_typ.has_flag(.generic) - || g.type_has_unresolved_generic_parts(arg_typ) - || (arg.expr.obj is ast.Var + needs_resolved_ident_type := arg_typ == 0 + || g.type_needs_generic_resolution(arg_typ) || (arg.expr.obj is ast.Var && (arg.expr.obj.ct_type_var in [.generic_param, .generic_var] || arg.expr.obj.is_inherited)) if needs_resolved_ident_type { @@ -6654,12 +6647,15 @@ fn (mut g Gen) ref_or_deref_arg_ex(arg ast.CallArg, expected_type_ ast.Type, lan } needs_resolved_expr_type := arg.expr is ast.SelectorExpr || arg.expr is ast.IndexExpr || arg.expr is ast.ComptimeSelector - || (arg.expr is ast.Ident && g.cur_fn != unsafe { nil } && g.cur_concrete_types.len > 0) + || (arg.expr is ast.Ident && in_generic_context && (arg_typ == 0 + || g.type_needs_generic_resolution(arg_typ) || (arg.expr.obj is ast.Var + && (arg.expr.obj.ct_type_var != .no_comptime || arg.expr.obj.generic_typ != 0 + || arg.expr.obj.is_inherited || arg.expr.obj.smartcasts.len > 0 + || arg.expr.obj.is_unwrapped)))) if needs_resolved_expr_type { resolved_arg_typ := g.resolved_expr_type(arg.expr, arg_typ) - if resolved_arg_typ != 0 && (arg_typ == 0 || arg_typ.has_flag(.generic) - || g.type_has_unresolved_generic_parts(arg_typ) - || (g.cur_fn != unsafe { nil } && g.cur_concrete_types.len > 0) + if resolved_arg_typ != 0 && (arg_typ == 0 || g.type_needs_generic_resolution(arg_typ) + || in_generic_context || g.unwrap_generic(resolved_arg_typ) != g.unwrap_generic(arg_typ)) { arg_typ = g.unwrap_generic(g.recheck_concrete_type(resolved_arg_typ)) } diff --git a/vlib/v/gen/c/utils.v b/vlib/v/gen/c/utils.v index f617d606f..70fda9354 100644 --- a/vlib/v/gen/c/utils.v +++ b/vlib/v/gen/c/utils.v @@ -10,44 +10,33 @@ fn (mut g Gen) unwrap_generic(typ ast.Type) ast.Type { if resolved_typ == 0 { resolved_typ = typ } - if resolved_typ.has_flag(.generic) || g.type_has_unresolved_generic_parts(resolved_typ) { - // NOTE: `convert_generic_type` should not mutate the table. - // - // It mutates if the generic type is for example `[]T` and the concrete - // type is an array type that has not been registered yet. - // - // This should have already happened in the checker, since it also calls - // `convert_generic_type`. `g.table` is made non-mut to make sure - // no one else can accidentally mutates the table. - current_generic_names := g.current_fn_generic_names() - if current_generic_names.len > 0 && current_generic_names.len == g.cur_concrete_types.len { - if t_typ := g.table.convert_generic_type(resolved_typ, current_generic_names, - g.cur_concrete_types) - { - return t_typ - } - } else if g.inside_struct_init { - if g.cur_struct_init_typ != 0 { - sym := g.table.sym(g.cur_struct_init_typ) - if sym.info is ast.Struct { - if sym.info.generic_types.len > 0 { - generic_names := sym.info.generic_types.map(g.table.sym(it).name) - mut concrete_types := sym.info.concrete_types.clone() - if concrete_types.len == 0 && sym.generic_types.len == generic_names.len - && sym.generic_types != sym.info.generic_types { - concrete_types = sym.generic_types.clone() - } - if t_typ := g.table.convert_generic_type(resolved_typ, generic_names, - concrete_types) - { - return t_typ - } - } - } - } - } else if resolved_typ != 0 && g.table.sym(resolved_typ).kind == .struct { - // resolve selector `a.foo` where `a` is struct[T] on non generic function - sym := g.table.sym(resolved_typ) + if !resolved_typ.has_flag(.generic) { + resolved_idx := resolved_typ.idx() + if resolved_idx <= ast.nil_type_idx + || (resolved_idx < g.generic_parts_cache.len + && g.generic_parts_cache[resolved_idx] == 1) + || !g.type_has_unresolved_generic_parts(resolved_typ) { + return resolved_typ + } + } + // NOTE: `convert_generic_type` should not mutate the table. + // + // It mutates if the generic type is for example `[]T` and the concrete + // type is an array type that has not been registered yet. + // + // This should have already happened in the checker, since it also calls + // `convert_generic_type`. `g.table` is made non-mut to make sure + // no one else can accidentally mutates the table. + current_generic_names := g.current_fn_generic_names() + if current_generic_names.len > 0 && current_generic_names.len == g.cur_concrete_types.len { + if t_typ := g.table.convert_generic_type(resolved_typ, current_generic_names, + g.cur_concrete_types) + { + return t_typ + } + } else if g.inside_struct_init { + if g.cur_struct_init_typ != 0 { + sym := g.table.sym(g.cur_struct_init_typ) if sym.info is ast.Struct { if sym.info.generic_types.len > 0 { generic_names := sym.info.generic_types.map(g.table.sym(it).name) @@ -61,15 +50,35 @@ fn (mut g Gen) unwrap_generic(typ ast.Type) ast.Type { { return t_typ } + } + } + } + } else if resolved_typ != 0 && g.table.sym(resolved_typ).kind == .struct { + // resolve selector `a.foo` where `a` is struct[T] on non generic function + sym := g.table.sym(resolved_typ) + if sym.info is ast.Struct { + if sym.info.generic_types.len > 0 { + generic_names := sym.info.generic_types.map(g.table.sym(it).name) + mut concrete_types := sym.info.concrete_types.clone() + if concrete_types.len == 0 && sym.generic_types.len == generic_names.len + && sym.generic_types != sym.info.generic_types { + concrete_types = sym.generic_types.clone() + } + if t_typ := g.table.convert_generic_type(resolved_typ, generic_names, + concrete_types) + { + return t_typ + } - if t_typ := g.table.convert_generic_type(resolved_typ, generic_names, - g.cur_concrete_types) - { - return t_typ - } + if t_typ := g.table.convert_generic_type(resolved_typ, generic_names, + g.cur_concrete_types) + { + return t_typ } } } + } + if typ.has_flag(.generic) { if t_typ := g.type_resolver.resolve_bound_generic_type(typ) { return t_typ } @@ -204,6 +213,14 @@ fn (mut g Gen) recheck_concrete_type(typ ast.Type) ast.Type { if typ == 0 { return typ } + if g.cur_fn == unsafe { nil } || g.cur_concrete_types.len == 0 { + return typ + } + idx := typ.idx() + if idx <= ast.nil_type_idx || (!typ.has_flag(.generic) && idx < g.generic_parts_cache.len + && g.generic_parts_cache[idx] == 1) { + return typ + } sym := g.table.sym(typ) match sym.info { ast.Struct, ast.Interface, ast.SumType { @@ -231,7 +248,7 @@ fn (mut g Gen) recheck_concrete_type(typ ast.Type) ast.Type { if generic_names.len == 0 || generic_names.len != g.cur_concrete_types.len { return typ } - concrete_types := g.cur_concrete_types.clone() + concrete_types := g.cur_concrete_types if resolved_typ := g.table.convert_generic_type(typ, generic_names, concrete_types) { return resolved_typ } @@ -243,6 +260,34 @@ fn (mut g Gen) recheck_concrete_type(typ ast.Type) ast.Type { return typ } +@[inline] +fn (g &Gen) has_current_generic_context() bool { + return g.cur_fn != unsafe { nil } && g.cur_concrete_types.len > 0 +} + +@[inline] +fn (mut g Gen) type_needs_generic_resolution(typ ast.Type) bool { + if typ == 0 { + return false + } + if typ.has_flag(.generic) { + return true + } + if typ.idx() <= ast.nil_type_idx { + return false + } + if (g.cur_fn == unsafe { nil } || g.cur_concrete_types.len == 0) + && !g.has_active_call_generic_context() { + return false + } + idx := typ.idx() + if idx <= ast.nil_type_idx + || (idx < g.generic_parts_cache.len && g.generic_parts_cache[idx] == 1) { + return false + } + return g.type_has_unresolved_generic_parts(typ) +} + // is_expr_smartcast_to_sumtype checks if expr is a smartcast variable/field // whose original type is the given sumtype. This is used to prevent sumtype // variant unwrapping when passing a smartcast expression to a function -- 2.39.5