Stream: t-compiler/wg-rls-2.0

Topic: miri


Laurențiu Nicola (Apr 16 2019 at 17:16, on Zulip):

@RalfJ Is this a limitation of miri, or a bug in the program? Sorry for subscribing you, I'm not sure how else to ping you.

RalfJ (Apr 16 2019 at 17:31, on Zulip):

@Laurențiu Nicola subscribing is fine. ;) alternatively try the "general" stream; the question does not seem particularily RLS-related

RalfJ (Apr 16 2019 at 17:31, on Zulip):

to answer your question, the error means that Miri thinks this code has UB for using pointers the wrong way

RalfJ (Apr 16 2019 at 17:32, on Zulip):

those checks and the models they use are experimental, so this does not mean your program is wrong. but it is an interesting result, when Miri disallows something people expect to work we should figure out what it is.

RalfJ (Apr 16 2019 at 17:33, on Zulip):

it is hard to say more than that without a way for me to reproduce the problem. the code seems to do crazy stuff with transmutes/unions, so I wouldnt be surprised if there was something wrong in it^^

Laurențiu Nicola (Apr 16 2019 at 17:34, on Zulip):

it is related to rls :D

RalfJ (Apr 16 2019 at 17:35, on Zulip):

okay^^ I dont see the connection then ;)

Laurențiu Nicola (Apr 16 2019 at 17:35, on Zulip):

or rust-analyzer

Laurențiu Nicola (Apr 16 2019 at 17:36, on Zulip):

I tried to run some of its tests under miri

RalfJ (Apr 16 2019 at 17:39, on Zulip):

if you could minimize this to an as-small-as-possible testcase that still fails, that'd be awesome

RalfJ (Apr 16 2019 at 17:42, on Zulip):

but even if not, please report an issue at https://github.com/rust-lang/miri/ with instructions for how to reproduce the problem

Laurențiu Nicola (Apr 16 2019 at 17:43, on Zulip):

that code is way over my head

Laurențiu Nicola (Apr 16 2019 at 17:44, on Zulip):

I don't think it's a miri bug

Laurențiu Nicola (Apr 16 2019 at 17:44, on Zulip):

I'm sure @matklad will be happy to see this

matklad (Apr 16 2019 at 17:49, on Zulip):

oh yeah, I am doing completely crazy stuff in rowan, and I am totally not sure if it works.

@Laurențiu Nicola how did you get miri to work with rowan? Last time I've checked, it failed because of random numbers somewhere...

Laurențiu Nicola (Apr 16 2019 at 17:49, on Zulip):

I have this nightly

Laurențiu Nicola (Apr 16 2019 at 17:49, on Zulip):

rustc 1.35.0-nightly (aa99abeb2 2019-04-14)

matklad (Apr 16 2019 at 17:50, on Zulip):

And what command are you running?

Laurențiu Nicola (Apr 16 2019 at 17:50, on Zulip):

I installed miri with rustup, then ran ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo-miri miri test in the ra_syntax crate

Laurențiu Nicola (Apr 16 2019 at 17:50, on Zulip):

ra_assists also reports an uninitialized read somewhere

Laurențiu Nicola (Apr 16 2019 at 17:51, on Zulip):

ra_arena seems clean

Laurențiu Nicola (Apr 16 2019 at 17:53, on Zulip):

rowan's tests also pass

matklad (Apr 16 2019 at 17:53, on Zulip):

that's because rowan basically has no tests, everything is tested in rust-analyzer :D

Laurențiu Nicola (Apr 16 2019 at 17:53, on Zulip):

ah, I didn't check :D

RalfJ (Apr 16 2019 at 17:59, on Zulip):

Miri supports random numbers since very recently

RalfJ (Apr 16 2019 at 17:59, on Zulip):

you need to pass -Zmiri-seed=<some hex>

RalfJ (Apr 16 2019 at 18:00, on Zulip):

but @Laurențiu Nicola didnt seem to do that so maybe that test doesnt even need entropy?

Laurențiu Nicola (Apr 16 2019 at 18:02, on Zulip):

I don't see any rand dependency

Laurențiu Nicola (Apr 16 2019 at 18:03, on Zulip):

does it actually support the rand crate? how does that work?

matklad (Apr 16 2019 at 18:04, on Zulip):

that was a while ago, maybe I am remembering the things incorrectly.

Looking at the error, it looks like it's in the colleseum crate, which is typed-arena, but with a mutex on top

matklad (Apr 16 2019 at 18:04, on Zulip):

a-ha, reproduced the error locally

RalfJ (Apr 16 2019 at 18:05, on Zulip):

@matklad you remember correctly, entropy support in Miri was added less than a week ago^^

RalfJ (Apr 16 2019 at 18:05, on Zulip):

does it actually support the rand crate? how does that work?

you pass Miri a seed and it uses that to generate "entropy" whenever the program asks for it

Laurențiu Nicola (Apr 16 2019 at 18:07, on Zulip):

but there are a lot of ways to request entropy, how does it hook all of them?

Laurențiu Nicola (Apr 16 2019 at 18:07, on Zulip):

what does mem::transmute::<&mut T, &mut T> do?

matklad (Apr 16 2019 at 18:08, on Zulip):

@RalfJ made a relatively easy repro. This is not rust-analyzer related, the famous typed-arena crate is affected

λ git clone git@github.com:SimonSapin/rust-typed-arena.git

21:06:50|~/tmp
λ cd rust-typed-arena/

21:06:53|~/tmp/rust-typed-arena|master✓
λ ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo-miri miri test # cargo miri doesn't work for me for whatever reason
...
 constant evaluation error: stopping looking for borrow being accessed (Alias(None)) because of barrier (38549)
matklad (Apr 16 2019 at 18:08, on Zulip):

@Laurențiu Nicola it thransmutes lifetimes

Laurențiu Nicola (Apr 16 2019 at 18:09, on Zulip):

oooh

matklad (Apr 16 2019 at 18:09, on Zulip):

I guess, I'll open a bug in typed arena and CC you. The code looks reasonable to me

Laurențiu Nicola (Apr 16 2019 at 18:11, on Zulip):

yeah, I should have checked all of the deps first (:

matklad (Apr 16 2019 at 18:12, on Zulip):

typed_arena is not a dependency, collesseum is. but collesseum is a fancier typed_arena, and the same bug triggers for later

Laurențiu Nicola (Apr 16 2019 at 18:13, on Zulip):

it triggers in both of them, yup

matklad (Apr 16 2019 at 18:14, on Zulip):

@RalfJ filed https://github.com/SimonSapin/rust-typed-arena/issues/26

Laurențiu Nicola (Apr 16 2019 at 18:16, on Zulip):

there's also one in ra_assists

RalfJ (Apr 16 2019 at 18:17, on Zulip):

but there are a lot of ways to request entropy, how does it hook all of them?

it just hooks whatever rand uses on Windows and Linux. That's good enough for now ;)

RalfJ (Apr 16 2019 at 18:18, on Zulip):

RalfJ filed https://github.com/SimonSapin/rust-typed-arena/issues/26

thanks! I'll have a look once I find some time.

matklad (Apr 16 2019 at 18:23, on Zulip):

@Laurențiu Nicola @RalfJ the second error you are observing is https://github.com/servo/rust-smallvec/issues/126

Laurențiu Nicola (Apr 16 2019 at 18:40, on Zulip):

I suppose there's no way to tell miri to continue after it finds an error?

RalfJ (Apr 17 2019 at 06:21, on Zulip):

No, Miri is not able to distinguish between fatal errors and those that it could in principle ignore.

RalfJ (Apr 18 2019 at 13:29, on Zulip):

Turns out this is a somewhat deep problem that would have to be fixed in Vec::push: https://github.com/SimonSapin/rust-typed-arena/issues/26#issuecomment-484507322

matklad (Apr 18 2019 at 13:55, on Zulip):

Cool! So that means that C++ style guarantee of "no refernces/iteraros are invalidated in push if there's enough capcity" has a real, checkable code underneath it! I am absolutely amazed by how powerful miri's approach of "let's check for UB by definition" is in practice.

RalfJ (Apr 18 2019 at 14:17, on Zulip):

:)

RalfJ (Apr 18 2019 at 14:19, on Zulip):

there's "just" the caveat that you need some code that actually exhibits the problematic behavior -- basically we need people to write test cases for all sorts of things that they think should be legal unsafe interactions with types like Vec, and have them all be checked by Miri.

Last update: Nov 12 2019 at 15:30UTC