These are chat archives for rust-lang/rust

27th
Oct 2017
Fra ns
@snarf95_twitter
Oct 27 2017 07:04
Interesting.. turning all collect into iterators resulted in approx 2 times slower execution for my chess ai.
Denis Lisov
@tanriol
Oct 27 2017 08:52
Sounds strange, but certainly possible...
Jonas Platte
@jplatte
Oct 27 2017 09:00
@snarf95_twitter with --release?
David Blewett
@davidblewett
Oct 27 2017 14:37
who do I talk to about getting involved? I’m a long time Python developer, but am still new to Rust. Would like to help, possibly in one of the working groups?
Jonas Platte
@jplatte
Oct 27 2017 14:38
@davidblewett Are you talking about the impl period? There's a separate channel for that: https://gitter.im/rust-impl-period/Lobby
David Blewett
@davidblewett
Oct 27 2017 14:40
thanks!
Gil
@giarve
Oct 27 2017 15:16
Hello guys, is there anything written about sharing a runtime variable among tests?
Zakarum
@omni-viral
Oct 27 2017 15:17
How to specify different default features based on platform?
Gil
@giarve
Oct 27 2017 15:18
Nope, sharing a common client to make requests
Reusing the same I mean, in each test
As tests run in parallel it seems troublesome, but perhaps passing a reference?
Zakarum
@omni-viral
Oct 27 2017 15:19
@giarve Aren't they runned in different processes?
Gil
@giarve
Oct 27 2017 15:20
Well I don't know, probably you are right because I have no idea :D
Zakarum
@omni-viral
Oct 27 2017 15:20
Sending something to someone over wire in unit-tests isn't the best you can do
It's better to create mock-server and talk with it
Gil
@giarve
Oct 27 2017 15:21
Nono, it's about sharing a variable
Like it was in the same scope
Zakarum
@omni-viral
Oct 27 2017 15:21
Why do you want to?
Tests should be independent
Each one should be valid without others
Gil
@giarve
Oct 27 2017 15:23
Oh ok thanks. Well it was about sharing a variable, but if that's the rule, I must follow it :D
Fra ns
@snarf95_twitter
Oct 27 2017 19:42
Any idea how I can make the bishop_moves_iter function compile? I've tried various stuff but with no luck so far kinda stuck atm. https://play.rust-lang.org/?gist=cffd015220eb490cc993341309925d1a&version=nightly
Jonas Platte
@jplatte
Oct 27 2017 19:53
@snarf95_twitter Are you avoiding chain? That would seem like the obvious solution here, rather than a slice / array.
Fra ns
@snarf95_twitter
Oct 27 2017 19:54
Yeah I initially used chain but it kinda reduced quality in terms of readability
Jonas Platte
@jplatte
Oct 27 2017 19:57
Hm, weren't you saying recently that you use nightly anyway? This actually seems like a perfect example of something that is quite a bit easier to write with generators than with iterator combinators.
Fra ns
@snarf95_twitter
Oct 27 2017 20:00
I’m using nightly, yes. I’m currently writing a function for each piece type that returns an impl iterator<Item=Tile>. I need flatten all these functions as a last step to get all the tile position that a player can move to.
I don’t know if yield and generators are suitable for this task
Jonas Platte
@jplatte
Oct 27 2017 20:00
Let me try..
Jonas Platte
@jplatte
Oct 27 2017 20:08
Oh, I think I misunderstood your code
Jonas Platte
@jplatte
Oct 27 2017 20:27
Wow, auto-ref can really suck some times.. This bug is making it harder to implement this thing ^^ rust-lang/rust#32871
Well not really bug, more missing feature
@snarf95_twitter It works when you throw a bunch of heap allocation at the problem ^^
(usage of the box_syntax feature could also be replace by plain old Box::new() here)
Fra ns
@snarf95_twitter
Oct 27 2017 20:32
hmm the 'static lifetime is okay here?
that's awesome, works well :) don't know about perf tho but okay. and that box_syntax really is a life saver
Jonas Platte
@jplatte
Oct 27 2017 20:34
Actually that 'static is a leftover from my experimentation
Doesn't seem to be required
Fra ns
@snarf95_twitter
Oct 27 2017 20:35
okay cool
Jonas Platte
@jplatte
Oct 27 2017 20:35
Yeah perf is probably horrible (in comparison to the perf of an ideal implementation)
Once const generics arrive (I'm working on it! :D) we might get impl<T, const N: usize> IntoIterator for [T; N] and then this can be written with one layer of indirection removed :)
Fra ns
@snarf95_twitter
Oct 27 2017 20:38
yeah that would be really nice :) box would still be needed tho right?
Jonas Platte
@jplatte
Oct 27 2017 20:39
Yup
I can't think of how to get rid of the boxing right now
Fra ns
@snarf95_twitter
Oct 27 2017 20:41
this version using chain just makes my head hurt trying to read it:
    sweep_iter(
        board,
        (1..min(8 - tr, 8 - tc)).map(move |i| Tile::new(tr + i, tc + i)),
        piece.owner,
    )
    .chain(sweep_iter(
        board,
        (1..min(8 - tr, tc + 1)).map(move |i| Tile::new(tr + i, tc - i)),
        piece.owner,
    ))
    .chain(sweep_iter(
        board,
        (1..min(tr + 1, tc + 1)).map(move |i| Tile::new(tr - i, tc - i)),
        piece.owner,
    ))
    .chain(sweep_iter(
        board,
        (1..min(tr + 1, 8 - tc)).map(move |i| Tile::new(tr - i, tc + i)),
        piece.owner,
    ))
Jonas Platte
@jplatte
Oct 27 2017 20:41
But if there is a way (there probably is) I'm pretty sure it will also get rid of the Vec
Fra ns
@snarf95_twitter
Oct 27 2017 20:42
I'm willing to sacrifice a little bit of performance to avoid this kind of code
Jonas Platte
@jplatte
Oct 27 2017 20:42
Trying to think of how to refactor it is making my head hurt too ^^
You could just write a macro..
Fra ns
@snarf95_twitter
Oct 27 2017 20:43
haha
Jonas Platte
@jplatte
Oct 27 2017 20:43
But that kind of feels like cheating :D
Fra ns
@snarf95_twitter
Oct 27 2017 20:43
I'm scared of using macros
Jonas Platte
@jplatte
Oct 27 2017 20:43
It's not actually that bad
Fra ns
@snarf95_twitter
Oct 27 2017 20:43
mainly because of bad experiences with cpp
Jonas Platte
@jplatte
Oct 27 2017 20:43
hehe, you read the source code of some c or c++ unit testing libary? :P
Fra ns
@snarf95_twitter
Oct 27 2017 20:45
nope
cant imagine it being pretty tho
Jonas Platte
@jplatte
Oct 27 2017 20:45
Some of them have macros that "parse" expressions put into them ^^
So that something like ASSERT(a > b) can print both a and b in case of assertion failure
Fra ns
@snarf95_twitter
Oct 27 2017 20:47
that's clever
but not something I want to fix if something goes bad
Jonas Platte
@jplatte
Oct 27 2017 20:47
yup and requires some really ugly cpp code ^^
David DeSimone
@DavidDeSimone
Oct 27 2017 23:20
If I've found a suspected case of bad codegen, and have a minimal reproduction, what's the best way to report it?
Jonas Platte
@jplatte
Oct 27 2017 23:24
@DavidDeSimone I think the I-slow tag would probably be a good fit, unless I'm misunderstanding what "bad codegen" means: https://github.com/rust-lang/rust/issues?q=is%3Aopen+is%3Aissue+label%3AI-slow
David DeSimone
@DavidDeSimone
Oct 27 2017 23:27
To clarify, "bad codegen" here means I have safe Rust that is causing a SEGFAULT on windows in MSYS2, but works on other platforms. I may be using the incorrect erm here. I discovered this case in rand crate and was able to create a github repo with minimal reproduction.
Jonas Platte
@jplatte
Oct 27 2017 23:27
Oh, that sounds pretty bad
David DeSimone
@DavidDeSimone
Oct 27 2017 23:28
It may be that this is actually just an FFI bug that I'm not seeing and this code is doing something not supported, but either way it's affecting the rand crate, which needs to be fixed in one way or another
Jonas Platte
@jplatte
Oct 27 2017 23:29
Honestly if it is safe Rust that can trigger undefined behaviour, just by using a common crate, sounds like you shouldn't immediately publish it to the world and contact the rand devs privately
It's kind of too late now though ^^
David DeSimone
@DavidDeSimone
Oct 27 2017 23:35
that's a good point. However as a friend just pointed out to me in private, this appears to be an error in our application logic
Jonas Platte
@jplatte
Oct 27 2017 23:35
Uhh... Okay
David DeSimone
@DavidDeSimone
Oct 27 2017 23:36
I apologize for jumping the gun a little. The problem is we were having __chkstk call ___chkstk, which we should not have been doing.
Jonas Platte
@jplatte
Oct 27 2017 23:36
Yeah I noticed that
So rand doesn't define that, you do in your application?
David DeSimone
@DavidDeSimone
Oct 27 2017 23:38
correct, this is just a false alarm
Jonas Platte
@jplatte
Oct 27 2017 23:40
So... Why did you define that in your application? ^^
David DeSimone
@DavidDeSimone
Oct 27 2017 23:43
I wasn't the person to do that, but I believe it was because we saw linker errors for __chkstk, but saw that we had ___chkstk defined in our binary, so we forwarded the call, thinking it was an msys2 quirk. I copied it in my reproduction without thinking "wait, is that actually needed?"