-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Consider const fn with &self
while checking liveness
#128329
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is happening here? What does the &self
receiver have anything to do with this? Why is this only being special-cased for consts?
Specifically, why isn't this a problem for pub const fn new() -> Foo
? You can also call that in a const. Why isn't this a problem outside of consts?
I feel like this suggests that there is something more fundamentally wrong with the dead code pass...
The dead code analysis for public methods is based on the assumption that we must have a value of
Because the above assumption not works well for static items.
|
For the record, this seems incredibly fragile and likely to break if we stabilize arbitrary self types in the future.
This isn't really what I'm asking. I'm asking -- why is this check only needed for |
For now, there are also methods with
Because we must use the |
The issue here is that the earlier code checked only builder methods without receivers (for reasons explained above by @mu001999). However, in #128272 someone constructed a case which wasn't covered by that analysis. In this case a builder method that did take a receiver was being called from a static context (e.g. The reason I'm limiting this only to const methods is nothing other than efficiency. Because only const methods can be called from a static context, checking others will be wasteful. |
I think you should not be special-casing things unnecessarily, since it complicates the implementation and makes it more complex to maintain. You said this is wasteful, but I don't think that this special-case on the compiler is worth taking on unless there is a good reason to (i.e. a perf run). This is especially true since the comment doesn't really demonstrate why this is important -- it's just restating what the code right below it does. I still don't think either of y'all have explained why this is specific to statics. What does a static have anything to do with this? Because it represents a value that be referenced by name before it's created? I think there are other ways of creating code that "conjures" a value without a constructor having been created, i.e. |
I am surprised that the approach here is to allow my weird code as a special case, along with the other much-less-special-but-still-special case of |
I agree with @chrisnc that all of this should probably be reverted and reworked, since then we're not pressured to put up hacky fixes in favor of getting it correct and well documented the first time 👍 |
Thanks for your inputs guys. I'll close this PR and let @mu001999 take another shot at the original analysis. |
Fixes #128272
The issue occurred because we weren't considering for liveness check builder methods that can be called from a static context (e.g.
static X: Foo = X.new()
). Now we do.