Skip to content

izip! is just wrong #970

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

Closed
DeltaEpsilon7787 opened this issue Jul 9, 2024 · 7 comments
Closed

izip! is just wrong #970

DeltaEpsilon7787 opened this issue Jul 9, 2024 · 7 comments

Comments

@DeltaEpsilon7787
Copy link

itertools = "0.13.0"

izip!(alpha, beta, gamma, delta, epsilon)

expands into

$crate::__std_iter::IntoIterator::into_iter(alpha)
    .zip(beta)
    .zip(gamma)
    .zip(delta)
    .zip(epsilon)
    .map(|((((a, b), b), b), b)| (a, b, b, b, b))

which is obviously wrong.

@jswrenn
Copy link
Member

jswrenn commented Jul 9, 2024

Yikes, thanks for the report! Disappointed that this slipped through our CI.

@Philippe-Cholet
Copy link
Member

@DeltaEpsilon7787
Macro expansion is weird. My guess is that the compiler distinguish the four different versions of "b".

It seems to be working just fine: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=435b75b4411195ae0a4fcce78aac4ca9

Do you have an example of something going wrong?

@DeltaEpsilon7787
Copy link
Author

DeltaEpsilon7787 commented Jul 9, 2024

Looks like VSCode (and thus, rust LSP) are incorrectly determining the types of the vars in that situation.
image
Or rather, there is a disconnect in the LSP and the compiler.

To be fair, I can't blame it. What damn magic makes this work?


image


Thus, not a bug with itertools itself.

@Philippe-Cholet
Copy link
Member

Copying your example in Sublime Text, I get the same (i32, f64, f64) weirdness. rust-analyzer does not distinguish the bs as good as the compiler does.

@Philippe-Cholet Philippe-Cholet closed this as not planned Won't fix, can't repro, duplicate, stale Jul 9, 2024
@phimuemue
Copy link
Member

phimuemue commented Jul 10, 2024

Yikes, thanks for the report! Disappointed that this slipped through our CI.

Just out of curiosity: Does anybody know if our CI would have cought this? (Would dig into this myself, but lack time.)

@Philippe-Cholet
Copy link
Member

Well there is nothing to catch. But the detected weirdness appears when there are at least 3 arguments to izip (the only interesting case since a.zip(b) is good enough for 2 arguments).
We have tests with izip!(3 arguments) so yeah, we should totally know if something breaks.
And one test for izip!(4 args) apparently.

@DeltaEpsilon7787
Copy link
Author

We figured out the reason for the weirdness, so to speak. It's due to hygienic macros. The macro expanded code cannot represent the fact that those different b have different context assigned to them, so they are not, in fact, 4 variables named b, they are 4 variables that are essentially named b+[ID1], b+[ID2], b+[ID3], b+[ID4] wherein ID is an anonymous identifier constructed on every macro expansion. Kind of like variable owner aspect, which is also invisible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants