solidity icon indicating copy to clipboard operation
solidity copied to clipboard

Implementation of Lengauer-Tarjan algorithm to find dominators

Open r0qs opened this issue 2 years ago • 8 comments

This is one step towards fixing https://github.com/ethereum/solidity/issues/13721

The implementation is based on the following paper: https://www.cs.princeton.edu/courses/archive/spr03/cs423/download/dominators.pdf, see appendix B pg. 139.

r0qs avatar Jul 31 '23 14:07 r0qs

Why is it still a draft?

cameel avatar Feb 08 '24 11:02 cameel

Why is it still a draft?

Because I still need to address this comment here: https://github.com/ethereum/solidity/pull/14460#discussion_r1291601390 which will require refactor of the current code. Or we could merge it as it is now and refactor it later.

r0qs avatar Feb 22 '24 12:02 r0qs

Ah, ok. I thought it was ready and only waiting for a review and that you just forgot to mark it as such :)

Or we could merge it as it is now and refactor it later.

I mean, whether recursion depth will be an issue depends on what we end up using this algorithm for in practice. I think there's a real risk that the graphs do end up being quite large in edge cases, but I haven't actually done any calculation that would prove it. It just seems like I cannot exclude that possibility. You could try to do a very rough estimation of the worst case and if it seems that it's unlikely that it can exhaust the stack, we can also just slap a TODO on it and merge without fixing it.

We'd just have to be careful every time we use it for a new thing. Hitting the limit in some, even not so uncommon edge cases, will likely not be easy to discover in a PR because code we test with is never very large. And I don't have confidence that out external projects are comprehensive enough to hit such cases. So if we get it wrong. we'll just get bug reports when we release and people start actually using it. It won't be the end of the world - it will just crash and not do anything dangerous - but my preference is just to not end up in a situation where I have to worry about it and do things right from the start.

So overall I'd say it depends on how badly we want to merge it. If there's a hurry, TODO is good enough. Otherwise I'd rather still fix it, unless you have an estimate of max depth in our use case showing it's a non-issue.

cameel avatar Feb 22 '24 13:02 cameel

I mean, merging this and actually using it are still two things. Having an eternal PR like this based on some possible refactoring to address hypotheticals also doesn't really help ;-). So I'd say, let's just merge this and take things from there.

ekpyron avatar Feb 22 '24 20:02 ekpyron

djeva

GAMECHANGE avatar Feb 23 '24 11:02 GAMECHANGE

I'll make sure we merge it next week, but I'd still want to take another pass through it before we do. Looking at it now, I remember that there were some questionable things that I wanted to get back to after the stuff I pointed out is fixed. In the end I never did because there were always other important things, but I'll prioritize this PR now.

cameel avatar Mar 29 '24 19:03 cameel

I converted it to draft since I'm still applying the refactoring to an id-based algorithm and there are some commits that will be moved to another PRs.

r0qs avatar Jun 24 '24 17:06 r0qs

You can see how it will be used in this branch: https://github.com/ethereum/solidity/tree/dominator-yul-cfg

r0qs avatar Jun 28 '24 12:06 r0qs

By the way, maybe someone will find this useful: An Explanation of Lengauer-Tarjan Dominators Algorithm. The original paper is pretty dense and I found this one more helpful to get a general overview before digging into details.

cameel avatar Jul 13 '24 00:07 cameel