| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
原始链接: https://news.ycombinator.com/item?id=43977147
Hacker News 的讨论围绕着一篇使用图论解决编程语言问题(特别是公共子表达式消除,CSE)的文章展开。评论者指出,这种技术类似于现有的编译器优化,例如全局值编号 (GVN) 和 CSE,质疑为什么没有提及这些方法。有人担心这是在重新发明轮子,并且在识别出公共子表达式后确定计算位置的复杂性,提到了支配关系和支配树。一些人建议使用更简单的方法,例如拓扑排序。讨论还涉及将图论、范畴论和神经网络等理论概念应用于实际问题的更广泛意义,强调了学术研究和了解相关领域最新知识的价值。一位评论者幽默地建议“发布错误的解决方案”以引出有益的反馈,而另一位则强调了学术界的潜在价值。
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
No, it is ubiquitously known as CSE: common subexpression elimination.
The original DAG representation of the abstract syntax, on the other hand, exhibits substructure sharing.
> Of course, that invariant eventually changed. We added a way in the source langauge to introduce lets, which meant my algorithm was wrong.
Because you have to identify variables by more than just their symbol, due to shadowing, like De Brujn indexing and other schemes.
CSE is not particularly difficult in a functional language. Variable assignments throw a monkey wrench into it. Any terms with side effects also.
By the way, CSE can be done over intermediate representations, rather than abstract syntax. In an intermediate representation, you look for identical instructions with the same operands, not arbitrarily large expressions, while paying attention to variable liveness.
reply