-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inliner can remove side effects from objects #4765
Comments
The known issue is https://github.com/lampepfl/dotty/blob/c3469da3538546cd8d7311da932f68b76737b909/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala#L416-L459, but I don't think that's the code involved here. |
See also scala/scala-dev#112 |
Uh, the prefix will be invoked, but not if it's idempotent — the comment disagrees with the code and it seems the comment's right. @milessabin asks in #4763:
I hadn't realized, but that's an option in https://github.com/lampepfl/dotty/blob/c3469da3538546cd8d7311da932f68b76737b909/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala#L416-L459, which says
When we talked about this code this Monday in the meeting, we didn't change this code because our purity checker is still too weak. Furthermore, there's a micro-purity checking (being extended), and references to an object are marked as idempotent; that is, we know it's safe to replace |
I think we should leave this as is for the moment. The problem is that, without a good purity analysis of objects we end up referring to way too many objects. The inliner's job is to produce fast code, and it can't do that if we fix this issue. I believe the correct approach is to come up with a better purity analysis of objects. #4710 is a start. If we have that, we can switch to |
I'm sorry but no. The inliner's primary job is to produce correct code. Under that constraint, it should make it as fast as possible. But disregarding correctness because it's annoying to produce fast code is a terrible mistake. If you want to do that, you need to change the language specification to relax the rules of object initialization. |
Noticed while discussing #4763, haven't found in the tracker. Might be a known bug (related to what @allanrenucci noticed recently with constant folding accepting idempotent rather than pure methods), but we should have an issue for this.
EDIT: the issue is that
println("object init");
is dropped.The text was updated successfully, but these errors were encountered: