Add long offset TRIE regnodes#24544
Conversation
The makedepend infra adds "." and ".." to the path, apparently to assist "cppstdin" functioning. However if your cc compiler is configured to be something like "ccache gcc", and you happen to have a "gcc" dev directory with a built "gcc" executable in it in a sister directory to your perl repo then the path change results in ccache finding the wrong gcc and using it for the dependency analysis, which then breaks the dependencies. The path munging doesn't make sense when the compiler is a command like this, and apparently is only there to assist 'ccpstdin' so this patch just disables the path munging when the compiler is something else.
Sometimes I use a project local cache dir. This hides it when I use it.
Replace numeric trie/Aho-Corasick opcode assumptions with explicit classification and mapping. Use IS_TRIE_AC() for debug-time trie data selection and convert TRIE and TRIEC to their Aho-Corasick forms with an explicit mapping instead of relying on opcode spacing. This hardens the regex engine against adding new trie-like regops that shift opcode numbers without being used.
The define RE_PREFER_LONG_TRIE can be used to control whether we produce LTRIE or TRIE by preference. For testing this was set to 1 to make sure the LTRIE functionality worked, but in practice we prefer 0, as it means regexp programs are a little smaller overall.
khwilliamson
left a comment
There was a problem hiding this comment.
This is far more than I was expecting. From the comments in the earlier code, I inferred that all that mattered was that the length of the current node fit in a U16, and I just wasn't seeing how to avoid looking at the total length between the first and final nodes. I didn't expect a distinct trie type for longer chains
arguably we could just get rid of it entirely, but its helpful to test
|
I haven't looked at it in detail yet, but this introduces a warning: |
|
@tonycoz - I can't reproduce that right now, but i am pretty sure i know what I did wrong. Ill push a patch shortly hopefully. |
Tony Cook has reported a case where the TRIE_DATA_SLOT_set(stclass, data_slot) warns about
The comment says it all, some compilers dont understand this code and think it will write out of bounds so we unroll the TRIE_DATA_SLOT_set() macro to allow us to resuse just the part we need here.
|
@tonycoz I think the warning is bogus, and that the code wont write out of bounds. Nevertheless I replaced the offending macro with one the compiler should be more comfortable with. |
That fixed it, though the commit message is a little misleading: the warning was from gcc 13 on linux. |
This is a second PR to address #23388, see also: 03f74bb
FWIW, this patch ended up being a bit of a rabbit hole, as make depend was silently not working for me, and hiding that the perl I was building was not always the latest or even the same code at the same time. Hence I ended up doing various secondary hacks to rule out issues that in the end came down to the unstable build process.
The general idea here however is to add LTRIE and LTRIEC as complements to TRIE and TRIEC regex engine opcodes. These handle longer jump distances correctly. In fact with this PR tries overall now use 32 bit offsets (jump tables and whatnot), but we keep the "small trie" opcode as it comes in handy when we are optimizing very small patterns.