Improved const evaluation for ZST checks.#401
Improved const evaluation for ZST checks.#401ErisianArchitect wants to merge 3 commits intoservo:v2from
Conversation
|
Really interesting! One concern I have is that nothing prevents using unrelated types for the TaggedLen methods that are now generic. Would it make more sense for TaggedLen to be generic and contain a PhantomData member to constrain it and reduce the need for manual type annotations? |
|
I thought about doing that with the PhantomData. There's no reason it couldn't be done. |
|
I moved Edit: Oh, I almost forgot. The reason I originally didn't use PhantomData was because it interfered with the derived Clone and Copy implementations, so I had to implement those manually. |
jdm
left a comment
There was a problem hiding this comment.
Thanks! I think the result of these changes is much clearer.
|
Really not sure what to do about the mysterious failure in the miri build, unfortunately. |
Yeah, I'm not either, but maybe removing those unnecessary |
|
I'll try that in #402. |
|
Well, it says something about outdated JSON and recommends using cargo clean. I don't think running cargo clean would work, anyway, because the CI is running a fresh version every time. Maybe try updating serde? |
|
It should already use the latest version of Serde, since there's no Cargo.lock file pinning it. |
#!/usr/bin/bash
set -ex
# Clean out our target dir, which may have artifacts compiled by a version of
# rust different from the one we're about to download.
cargo clean
# Install and run the latest version of nightly where miri built successfully.
# Taken from: https://github.com/rust-lang/miri#running-miri-on-ci
MIRI_NIGHTLY=nightly-$(curl -s https://rust-lang.github.io/rustup-components-history/x86_64-unknown-linux-gnu/miri)
echo "Installing latest nightly with Miri: $MIRI_NIGHTLY"
rustup default "$MIRI_NIGHTLY"
rustup component add miri
cargo miri setup
cargo miri test --verbose
# This should probably be cargo clean right here
cargo miri test --verbose --all-featuresMiri is run twice in a row with no |
|
I added cargo clean to the miri script. I don't know if that will fix the problem, but it's worth a try. |
I was reading through the source code, and I noticed the usage of
is_zst()as a condition in some if statements. Rust does not guarantee that const functions will be evaluated at compile time, so the compiler may not perform dead code elimination on these if statements. I removed theis_zstfunctions from type implementations, and instead added a generic parameter toTaggedLenfunctions and forcedis_zstto be evaluated at compile time. This should guarantee dead code elimination in some cases.Edit: Sorry, I forgot to mention, I also replaced the
is_zstfunction with a const in some places. Maybe one or two. Yet again, for dead code elimination.