Stream: t-libs/stdarch

Topic: Target-feature iterator


gnzlbg (Sep 16 2019 at 09:08, on Zulip):

@Luca Barbato so what do you need the feature iterator for ? I've managed to rebase it, but I'm not sure it is ready for merging.

gnzlbg (Sep 16 2019 at 09:08, on Zulip):

My goal was switching rustc to use the same feature-detection as libstd

Luca Barbato (Sep 16 2019 at 09:08, on Zulip):

The support for runtime disabling extension would need to map Feature to the strings provided by the env:var

gnzlbg (Sep 16 2019 at 09:08, on Zulip):

right now, we use LLVM to detect features there, and LLVM might not 100% agree with libstd on what features are available

Luca Barbato (Sep 16 2019 at 09:09, on Zulip):

The override is to disable more features so that part is fine

gnzlbg (Sep 16 2019 at 09:10, on Zulip):

hmm, so the envar would have a string of features, e.g., "avx,aes" etc. right ?

Luca Barbato (Sep 16 2019 at 09:10, on Zulip):

yes

gnzlbg (Sep 16 2019 at 09:10, on Zulip):

and where in std::detect do you want to implement the override ?

gnzlbg (Sep 16 2019 at 09:11, on Zulip):

probably not at the macro level, and probably before the dispatch to the actual feature detection for the target

Luca Barbato (Sep 16 2019 at 09:11, on Zulip):

STD_DETECT_DISABLE="avx2" my_bin would run it with avx2 off even if the system claims it is

gnzlbg (Sep 16 2019 at 09:11, on Zulip):

so that one does not have to implement it for every target

Luca Barbato (Sep 16 2019 at 09:11, on Zulip):

I refactored check_for so I can run the env check there

gnzlbg (Sep 16 2019 at 09:12, on Zulip):

ah, that what that was for, great

gnzlbg (Sep 16 2019 at 09:12, on Zulip):

yes so it makes sense

gnzlbg (Sep 16 2019 at 09:12, on Zulip):

hmm

gnzlbg (Sep 16 2019 at 09:12, on Zulip):

we probably want to read the override variable only once, cache it in a bitset

Luca Barbato (Sep 16 2019 at 09:12, on Zulip):

exactly :)

gnzlbg (Sep 16 2019 at 09:12, on Zulip):

and then only do a bit test

gnzlbg (Sep 16 2019 at 09:12, on Zulip):

so what do you need the feature iterator there for?

Luca Barbato (Sep 16 2019 at 09:13, on Zulip):

I get from the env

gnzlbg (Sep 16 2019 at 09:13, on Zulip):

do you want to dynamically create the bitset ?

Luca Barbato (Sep 16 2019 at 09:13, on Zulip):

"foo, bar, baz"

Luca Barbato (Sep 16 2019 at 09:13, on Zulip):

I split the , and then for each string I need to to map a Feature

Luca Barbato (Sep 16 2019 at 09:14, on Zulip):

and then flip off the bit in the cache

Luca Barbato (Sep 16 2019 at 09:14, on Zulip):

So I need the from_str part

Luca Barbato (Sep 16 2019 at 09:14, on Zulip):

mainly

Luca Barbato (Sep 16 2019 at 09:15, on Zulip):

then if the iterator itself needs more work it is fine

Luca Barbato (Sep 16 2019 at 09:15, on Zulip):

one discussion item if we want to make the iterator return a 3 items tuple

gnzlbg (Sep 16 2019 at 09:15, on Zulip):

ah I see (I forgot that the from_str part was already implemented)

Luca Barbato (Sep 16 2019 at 09:15, on Zulip):

with one item for the env override

Luca Barbato (Sep 16 2019 at 09:15, on Zulip):

so the program knows what is available and what is off for external reasons

gnzlbg (Sep 16 2019 at 09:16, on Zulip):

hmm, dunno

Luca Barbato (Sep 16 2019 at 09:16, on Zulip):

but its use-case is relatively fringe (a program wanting to tell the user what's is on and off)

gnzlbg (Sep 16 2019 at 09:16, on Zulip):

the point of the override it is to be able to override it

gnzlbg (Sep 16 2019 at 09:16, on Zulip):

if a program can inspect that, and ignore it, then I don't know

Luca Barbato (Sep 16 2019 at 09:17, on Zulip):

not ignore

Luca Barbato (Sep 16 2019 at 09:17, on Zulip):

basically

gnzlbg (Sep 16 2019 at 09:17, on Zulip):

also, thinking about it, no, but query the value, and do something depending on it

gnzlbg (Sep 16 2019 at 09:17, on Zulip):

I suppose that initially this does not matter, because the iterator isn't public

Luca Barbato (Sep 16 2019 at 09:18, on Zulip):

my main use-case is to debug behavior on user-machine

Luca Barbato (Sep 16 2019 at 09:18, on Zulip):

so all I need is a way for the user to turn off a feature without having to rebuild everything

gnzlbg (Sep 16 2019 at 09:18, on Zulip):

so maybe we could add that later

Luca Barbato (Sep 16 2019 at 09:18, on Zulip):

definitely

gnzlbg (Sep 16 2019 at 09:18, on Zulip):

but right now the iterator returns whether a feature is enabled, using the normal check

Luca Barbato (Sep 16 2019 at 09:18, on Zulip):

basically all I need is the from_str

gnzlbg (Sep 16 2019 at 09:19, on Zulip):

and that check will be overriden by the env

Luca Barbato (Sep 16 2019 at 09:19, on Zulip):

and it is fine

gnzlbg (Sep 16 2019 at 09:19, on Zulip):

ok

Luca Barbato (Sep 16 2019 at 09:19, on Zulip):

the iterator is good since it can be used on a --help path

gnzlbg (Sep 16 2019 at 09:19, on Zulip):

i think we can do it like this initially, and we'll see

Luca Barbato (Sep 16 2019 at 09:19, on Zulip):

so there is a mean to discover what can be turn off or on

gnzlbg (Sep 16 2019 at 09:19, on Zulip):

maybe we should add an UNSTABLE to the env variable

gnzlbg (Sep 16 2019 at 09:20, on Zulip):

to make it clear that this API is not stable

gnzlbg (Sep 16 2019 at 09:20, on Zulip):

and maybe even somehow disable it for stable Rust

Luca Barbato (Sep 16 2019 at 09:20, on Zulip):

Initially I thought of using a feature guard

Luca Barbato (Sep 16 2019 at 09:20, on Zulip):
gnzlbg (Sep 16 2019 at 09:20, on Zulip):

I also thought about having FOO="avx=off:avx512f:on" kind of syntax

Luca Barbato (Sep 16 2019 at 09:21, on Zulip):

no :)

gnzlbg (Sep 16 2019 at 09:21, on Zulip):

but disabling features is always sound

Luca Barbato (Sep 16 2019 at 09:21, on Zulip):

you can ONLY disable it

gnzlbg (Sep 16 2019 at 09:21, on Zulip):

while enabling features can exhibit UB

Luca Barbato (Sep 16 2019 at 09:21, on Zulip):

enabling a feature you do not support is a sigill

gnzlbg (Sep 16 2019 at 09:21, on Zulip):

I wonder if there is a feature that can exhibit UB when it is disabled

gnzlbg (Sep 16 2019 at 09:22, on Zulip):

either way an _UNSTABLE env var that disables features on nightly for debugging seems ok

gnzlbg (Sep 16 2019 at 09:22, on Zulip):

I'll try and see if I can get this merged today

Luca Barbato (Sep 16 2019 at 09:22, on Zulip):

great :)

Luca Barbato (Sep 16 2019 at 09:22, on Zulip):

I'll get the first draft of the code on top of it

Luca Barbato (Sep 16 2019 at 09:23, on Zulip):

and let see what people think

Luca Barbato (Sep 17 2019 at 13:43, on Zulip):

Here the first draft stdarch#808 I tested it and seems working as intended

Luca Barbato (Sep 17 2019 at 14:40, on Zulip):

I wonder if would be fine to conflate the feature with file_io

Last update: Nov 15 2019 at 10:55UTC