(This was originally an update of the previous post, but I feel that editing a 7-day old post is a bit unfair and I know that some people don't like it, so now it's separate):
Or... perhaps I should take that back. I just tried to generate a very basic IDNA mapping table in Swift:
internal enum IDNAMappingStatus {
case valid
case ignored
case mapped
case deviation
case disallowed
case disallowed_STD3_valid
case disallowed_STD3_mapped
}
internal let idna_mapping_data: [(codePoints: ClosedRange<UInt32>, status: IDNAMappingStatus, mapping: [UInt32]?)] = [
(0x0...0x2C, IDNAMappingStatus.disallowed_STD3_valid, nil),
(0x2D...0x2E, IDNAMappingStatus.valid, nil),
(0x2F...0x2F, IDNAMappingStatus.disallowed_STD3_valid, nil),
(0x30...0x39, IDNAMappingStatus.valid, nil),
(0x3A...0x40, IDNAMappingStatus.disallowed_STD3_valid, nil),
(0x41...0x41, IDNAMappingStatus.mapped, [0x61]),
(0x42...0x42, IDNAMappingStatus.mapped, [0x62]),
(0x43...0x43, IDNAMappingStatus.mapped, [0x63]),
(0x44...0x44, IDNAMappingStatus.mapped, [0x64]),
<snip>
(0xB8...0xB8, IDNAMappingStatus.disallowed_STD3_mapped, [0x20, 0x327]),
(0xB9...0xB9, IDNAMappingStatus.mapped, [0x31]),
(0xBA...0xBA, IDNAMappingStatus.mapped, [0x6F]),
(0xBB...0xBB, IDNAMappingStatus.valid, nil),
(0xBC...0xBC, IDNAMappingStatus.mapped, [0x31, 0x2044, 0x34]),
(0xBD...0xBD, IDNAMappingStatus.mapped, [0x31, 0x2044, 0x32]),
(0xBE...0xBE, IDNAMappingStatus.mapped, [0x33, 0x2044, 0x34]),
(0xBF...0xBF, IDNAMappingStatus.valid, nil),
(0xC0...0xC0, IDNAMappingStatus.mapped, [0xE0]),
(0xC1...0xC1, IDNAMappingStatus.mapped, [0xE1]),
(0xC2...0xC2, IDNAMappingStatus.mapped, [0xE2]),
<snip>
]
Obviously it could be optimised a lot - this is just straight from the data files, with no considerations about faster representations for contiguous ranges or splitting off the "mapping" (replacement) scalars.
But even so, it's enough to make me doubt it'll be realistic to ship any time soon. Even if I replace the Array with a scalar, it takes >75GB memory for a debug build of this thing (I also tried a nightly; same). At that point, questions about static initialisation are kind of academic. There's no way this can ship.
Removing the table and building again, I see a couple of instances of swift-frontend spin up, each of which take 60-100MB of memory and are gone in a flash as the project is built. With the table? It eats the universe.
There are 8908 entries in the table, which is a lot... but also not that much. I don't really think that's a proportionate level of memory use, to be honest.
I think we just need to admit that Swift can't do this kind of thing, and since C can do it, and we can interop with C, there's probably not a huge appetite to fix it (at least, the reaction to this thread doesn't suggest there is). It means that libraries who want to be pure Swift and showcase what the language can do are left in a bit of an embarrassing spot though. It's hard to claim that Swift is suitable for systems programming when we can't handle this kind of task.