Skip to content
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

Erase integer and float variables before needs_drop calls in HIR generator analysis #103036

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Oct 14, 2022

This is kinda a follow-up to #102695, which only coincidentally fixes #102645.

This is a more proper fix, but it may be a "misuse" of the InferenceLiteralEraser and InferCtxt::resolve_numeric_literals_with_default, which was originally intended only for diagnostics. However, I do feel like this usage is legitimate. For the purposes of drop tracking, we don't care that an int/float infer variable is unresolved, since all builtin int/float types are trivially drop and copy.

Given that there may be a legitimate desire not to use InferenceLiteralEraser, that's why I split it up -- only need a review on the last commit in the stack.

r? @lcnr since you reviewed #102695, feel free to reassign.

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Oct 14, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 14, 2022
let ty = self.fcx.tcx.erase_regions(ty);
// All int/float types are trivially drop, so those infer variables can be erased
let ty = self.fcx.resolve_numeric_literals_with_default(ty);
if ty.needs_infer() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The resolve_numeric_literals_with_default probably makes this a bit more accurate, too, since integer variables no longer trigger may_need_drop for no reason.

@compiler-errors
Copy link
Member Author

@lcnr and I decided this is probably not the best way forward...

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Oct 23, 2022
…r, r=lcnr

Check `needs_infer` before `needs_drop` during HIR generator analysis

This is kinda a revival of rust-lang#103036, but with the understanding that after fallback, a generator-interior type will only have `needs_infer` true if there's an error that prevented int or float variable fallback to occur (modulo region variables, which are erased).

Therefore the best choice here is to delay a bug and skip the `needs_drop` call altogether.

r? `@lcnr` feel free to reassign though
@compiler-errors compiler-errors deleted the erase-num-vars-in-generator-analysis branch November 2, 2022 02:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ICE: index out of bounds: the len is 0 but the index is 0 -Zdrop-tracking, generators
4 participants