Stream: t-compiler/const-eval

Topic: getcwd shim


Christian Poveda (Sep 18 2019 at 15:25, on Zulip):

I've been implementing the getcwd shim for miri and I have a few questions about it

Christian Poveda (Sep 18 2019 at 15:26, on Zulip):

My implementation uses std::env::current_dir, which is the standard library wrapper for getcwd basically.

Christian Poveda (Sep 18 2019 at 15:28, on Zulip):

However, the manipulation of the PathBuf returned by current_dir is platform specific. On windows you can transform that into a Vec<u16> and on linux (And hopefully macos) you transform it into a Vec<u8>. How should I handle this? should I go full cfg! on this?

oli (Sep 18 2019 at 15:37, on Zulip):

oh windows _getcwd should also return an ascii string. there's _wgetcwd for wide strings, so you could pathbuf.display().to_string().bytes() and write those bytes I guess?

Christian Poveda (Sep 18 2019 at 15:38, on Zulip):

I think it would be a little bit irresponsible for me to implement the windows part without testing it or abusing CI :P

Christian Poveda (Sep 18 2019 at 15:39, on Zulip):

is it there any chance that a PathBuf might not be "displayable"?

oli (Sep 18 2019 at 15:41, on Zulip):

it may be lossy if the path is not real utf8 I think

oli (Sep 18 2019 at 15:41, on Zulip):

idk, do a best effort thing and we'll wait for someone to complain?

Christian Poveda (Sep 18 2019 at 15:47, on Zulip):

Ok I'm going to put a FIXME into the display thing, the std docs aren't clear enough. Apparently display only fails if you lack permissions to see the path metadata

Christian Poveda (Sep 18 2019 at 16:11, on Zulip):

I added a comment about that little detail but it works

Christian Poveda (Sep 18 2019 at 16:12, on Zulip):

so... the next question is, how to test it? We cannot count on anything about the current directory.

oli (Sep 18 2019 at 17:35, on Zulip):

yes we can, the last part must be "miri"

oli (Sep 18 2019 at 17:35, on Zulip):

(I think)

oli (Sep 18 2019 at 17:35, on Zulip):

oh

oli (Sep 18 2019 at 17:35, on Zulip):

hmm

oli (Sep 18 2019 at 17:35, on Zulip):

we can't cd

Christian Poveda (Sep 18 2019 at 18:17, on Zulip):

why miri?

Christian Poveda (Sep 18 2019 at 18:17, on Zulip):

i mean you can clone it into any directory name, right?

Christian Poveda (Sep 18 2019 at 18:54, on Zulip):

:facepalm: i closed the PR by accident, can you reopen it? or should I do another one

RalfJ (Sep 18 2019 at 21:02, on Zulip):

:facepalm: i closed the PR by accident, can you reopen it? or should I do another one

you closed and force-pushed. a capital sin, according to GH. now I can't reopen.

RalfJ (Sep 18 2019 at 21:02, on Zulip):

but if you force-push the old commit back in, we cold reopen.

Christian Poveda (Sep 18 2019 at 21:02, on Zulip):

I'm going to change my religion

Christian Poveda (Sep 18 2019 at 21:03, on Zulip):

"rust-lang:master is up to date with all commits from christianpoveda:getcwd-shim" what the hell is going on?

RalfJ (Sep 18 2019 at 21:03, on Zulip):

so... the next question is, how to test it? We cannot count on anything about the current directory.

you could, like, .join("tests") and test if a compiletest.rs exists, or so? well hm that's another API that's not implemented

RalfJ (Sep 18 2019 at 21:04, on Zulip):

"rust-lang:master is up to date with all commits from christianpoveda:getcwd-shim" what the hell is going on?

it says so quite clearly? you need to force-push the old thing back into it

RalfJ (Sep 18 2019 at 21:04, on Zulip):

the one that was there when you closed the PR

RalfJ (Sep 18 2019 at 21:04, on Zulip):

I guess test it by just calling the function. at least then we know it doesn't ICE or so...

Christian Poveda (Sep 18 2019 at 21:04, on Zulip):

wait but... I don't have the old thing

Christian Poveda (Sep 18 2019 at 21:05, on Zulip):

I guess test it by just calling the function. at least then we know it doesn't ICE or so...

ok

RalfJ (Sep 18 2019 at 21:05, on Zulip):

of course you do. git doesnt lose anything.

Christian Poveda (Sep 18 2019 at 21:05, on Zulip):

Ok let me stack-overflow it

RalfJ (Sep 18 2019 at 21:05, on Zulip):

git push christianpoveda ba1fe3e:refs/heads/getcwd-shim -f

RalfJ (Sep 18 2019 at 21:05, on Zulip):

or so

RalfJ (Sep 18 2019 at 21:08, on Zulip):

anyway, I am falling asleep. g'night.

Christian Poveda (Sep 18 2019 at 21:09, on Zulip):

So it literally has the old commit somewhere... nice, thank you

Christian Poveda (Sep 18 2019 at 21:09, on Zulip):

have a good night

Christian Poveda (Sep 19 2019 at 15:09, on Zulip):

I added a test that just calls get_current_dir and unwraps it

Christian Poveda (Sep 19 2019 at 15:13, on Zulip):

Oh wait, this should only work if isolation is disabled, right?

Christian Poveda (Sep 19 2019 at 15:17, on Zulip):

What should happen here? i suppose one option would be to just error if getcwd is used when isolation is on, other option would be to return a null pointer which is that happens when getcwd according to the manual.

Christian Poveda (Sep 19 2019 at 15:31, on Zulip):

I think the first option is less obscure if someone tries to use getcwd with isolation

Last update: Nov 15 2019 at 20:05UTC