mirror of
https://github.com/astral-sh/ruff.git
synced 2026-05-06 08:56:57 -04:00
45acbd0b66
I ultimately hunted down the core issue with my previous approach to "if you give string annotation sub-AST nodes any kind of NodeIndex, a bunch of random places in the code will start thinking it's ok to store info about them, which is a problem because they all count up from index 0 which creates conflicts/crashes". Rather than trying to play whackamole I decided to create a scheme to give string annotation nodes a unique NodeIndex by shifting up the parent node's index -- so 0xAB's sub-AST nodes look like 0xAB00...0000, 0xAB00..0001, etc. This scheme avoids any collisions for any reasonable AST (most string annotations are like, a dozen sub-nodes, so they need maybe 4 or 5 bits, which would require hundreds of MB of python code to run out of bits...). As a bonus, this admits an extremely simple implementation of recording and fetching sub-AST types... they just are stored now, and you can just pass in their NodeIndex and get back actual results. * Fixes https://github.com/astral-sh/ty/issues/1640 * Fixes https://github.com/astral-sh/ty/issues/2028