These are chat archives for rust-lang/rust

18th
Feb 2018
sken
@floreslorca
Feb 18 2018 04:46
whats cargo build --release --lib --target="x86_64-pc-windows-gnu" doing exactly? im running this from a makefile, the problem is that i need a way to download both the one mentioned before and `cargo build --release
sken
@floreslorca
Feb 18 2018 04:53
is there a way to build for win and osx/linux?
Fredrik Portström
@portstrom
Feb 18 2018 11:31
I upgraded to rustc 1.24.0 (4d90ac38c 2018-02-12) and cargo 0.25.0 (8c93e0895 2018-02-01) and I see no evidence of compilation being more incremental than it was with the previous two releases. Compilation just takes a bit longer than it used to. Is there anyway I can verify that incremental compilation is enabled?
Aleksey Kladov
@matklad
Feb 18 2018 11:33
@portstrom run cargo build -v and see if there's a -C incremental flag passed to rustc
Fredrik Portström
@portstrom
Feb 18 2018 11:35
@matklad I see the flag is there. Thanks. Too bad incremental compilation didn't do any difference in compilation time whatsoever.
Daniel Bischof
@dbischof90
Feb 18 2018 12:19
Have you performed cargo check?
Fredrik Portström
@portstrom
Feb 18 2018 12:21
@dbischof90 I haven't. Does that make a difference?
Daniel Bischof
@dbischof90
Feb 18 2018 12:23
It think it should? I followed the discussions around it end of last year.
The way I understood it was that that cargo would try to figure out what needs to be rebuilt at all
I guess @matklad will be able to tell you more about that. That was just something from the back of my head.
Fredrik Portström
@portstrom
Feb 18 2018 12:32

If anything, it made the build very slow. It used to take 60 seconds.

real    1m39.949s
user    0m30.076s
sys    0m5.020s

Interesting that it only spends 35 seconds of CPU time. I guess disk IO is taking most of the time, and incremental compilation moves even more load from the CPU to the disk. It may work better on a computer with an SSD and sufficient RAM for enormous disk buffers.

Fredrik Portström
@portstrom
Feb 18 2018 12:45

With incremental compilation turned off, I get these numbers:

real    1m13.146s
user    1m40.560s
sys    0m3.700s

The CPU does a lot more work, but compilation time is significantly shorter.

Denis Lisov
@tanriol
Feb 18 2018 12:46
@portstrom I assume your incremental build is not the initial build, but a build after that with some source changes?
Daniel Bischof
@dbischof90
Feb 18 2018 12:46
Let's see what the RWWME (rustaceans with way more experience) have to say :P
Peter Atashian
@retep998
Feb 18 2018 12:47
There are cases where incremental currently regresses performance
Fredrik Portström
@portstrom
Feb 18 2018 12:49
@tanriol I've compiled each configuration at least twice, measuring the second or third run. Between each build, the source change is one byte in a string literal.
Fredrik Portström
@portstrom
Feb 18 2018 12:59
I guess it's a tradeoff. Choose incremental compilation if the CPU is the bottleneck and you have a fast disk and unused RAM. Chose non-incremental compilation if disk access is a bottleneck but you have a fast CPU. Now I've tried on my laptop which has an HDD and 4 GB RAM. I will try tomorrow on my office computer that has an SSD and 16 GB RAM.
apiraino
@apiraino
Feb 18 2018 13:02
Hello everyone, I'm a rust-rookie in need a bit of help implementing a custom Trait for SmallVec::Array
https://play.rust-lang.org/?gist=b396dc5e478f38f28b10eb0f155650b4&version=stable
I don't understand what kind of Trait should I write (also tried a bruteforce approach, having the compiler lead me to the impl)
asking this because I'm trying to update a crate (scraper) to using the latest version of another crate (selectors) that has replaced Vec with Smallvec.
Daniel Bischof
@dbischof90
Feb 18 2018 13:19
Why do you need that?
Not saying it's a bad idea but that seems to be some solution for a highly specialized problem that you are most likely not encountering as a beginner, @apiraino
apiraino
@apiraino
Feb 18 2018 13:23
@dbischof90 you're right this stuff is a bit over my head :^) What I was trying to accomplish is updating this:
https://github.com/programble/scraper/blob/master/src/selector.rs#L16
the old version uses selectors==0.18.0 (the Servo CSS parsing lib)
I'm trying to port to selectors==0.19
Daniel Bischof
@dbischof90
Feb 18 2018 13:24
I see
apiraino
@apiraino
Feb 18 2018 13:24
and I need to modify the impl of the method parse
Daniel Bischof
@dbischof90
Feb 18 2018 13:24
What happens if you try?
parse is a method here, not part of a trait
apiraino
@apiraino
Feb 18 2018 13:27
yes (sorry). what I meant is the struct Selector in the new version should use Smallvec instead of Vec for its member selectors. because the method parse now returns a SmallVec
it's a hairy problem, that's why I wanted to start from a simpler example :)
Daniel Bischof
@dbischof90
Feb 18 2018 13:27
One problem I see is that you try to define the type inside of a trait. I don't think (although not sure here) that this is possible.
Okay
apiraino
@apiraino
Feb 18 2018 13:28
I see that type Item? Should it be implemented somehow?
Daniel Bischof
@dbischof90
Feb 18 2018 13:28
Then I'll take that back. :)
Haven't seen that.
Ah
Wait
So if the trait definition you can define "Well, there is that generic type Item that I'm gonna assume exists here.". However, when you impl XYZ for MyStruct {..., there you can then set type Item = String; as far as I see
apiraino
@apiraino
Feb 18 2018 13:32
type Item = String returns a compiler error:
error: associated type defaults are unstable (see issue #29661)
Daniel Bischof
@dbischof90
Feb 18 2018 13:33
Yes, that might work with unstable code. I don't think it does with stable (well, obviously it doesn't)
But you said that the only issue is that you now get a SmallVec back
What's the limitation? Where does your code break?
Denis Lisov
@tanriol
Feb 18 2018 13:34
@apiraino In the trait impl or in the trait definition?
apiraino
@apiraino
Feb 18 2018 13:35
@tanriol in the trait definition should suffice (if I'm not wrong), but I'm quite "blind" here and trying things :)
@dbischof90 I changed the definition of the struct Selector like this:
 pub struct Selector {                                                                                                        
     /// The CSS selectors.                                                                                                   
=    pub selectors: SmallVec<parser::Selector<Simple>>,                                                                       
 }
Daniel Bischof
@dbischof90
Feb 18 2018 13:36
Going through the provided methods of SmallVec, that doesn't look too different..
Denis Lisov
@tanriol
Feb 18 2018 13:36
@apiraino The "associated type defaults" part seems to imply that on stable you cannot specify the concrete type in the definition, only in the impl
apiraino
@apiraino
Feb 18 2018 13:37
and the compliler complaint with:
error[E0277]: the trait bound `selectors::parser::Selector<selector::Simple>: smallvec::Array` is not satisfied
  --> src/selector.rs:17:5
   |
17 |     pub selectors: SmallVec<parser::Selector<Simple>>,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `smallvec::Array` is not implemented for `selectors::parser::Selector<selector::Simple>`
   |
   = note: required by `smallvec::SmallVec`
Daniel Bischof
@dbischof90
Feb 18 2018 13:37
Ah.
apiraino
@apiraino
Feb 18 2018 13:37
which is a more generic problem that I wanted to solve on its own
(see my rust snippet on the playground)
Daniel Bischof
@dbischof90
Feb 18 2018 13:37
True, the def says pub struct SmallVec<A: Array>.
red75prime
@red75prime
Feb 18 2018 13:38
@apiraino Try replacing pub selectors: Vec<parser::Selector<Simple>>, with pub selectors: Smallvec<[parser::Selector<Simple>;8]>,
apiraino
@apiraino
Feb 18 2018 13:41
ok @red75prime the error changed :) so maybe you pushed me towards the right direction
Daniel Bischof
@dbischof90
Feb 18 2018 13:41
You only need impl Array for parser::Selector { .... Set type Item = selector::Simple.
And then you need to implement these functions for your selector. How many bytes is a Selector? That's something you would implement for the function size().
The other two look like partially unsafe code. But that should be it then.
apiraino
@apiraino
Feb 18 2018 13:44
what's the difference between implementing Array explicitely with impl Array for ... and using Smallvec<[......]> like red75prime suggested? (sorry for the lame question)
anyway, now I moved to a lifetime error, I think it's improved, I need to finish the new implementation putting a couple lifetimes where needed
Daniel Bischof
@dbischof90
Feb 18 2018 13:46
I think the normal Vec<T> has them too.
I'm not sure if the array he meant and the trait Array are necessarily the same thing. If yes, then hooray ;)
apiraino
@apiraino
Feb 18 2018 13:47
I saw the SmallVec[] synatx elsewhere so I think it's the right suggestion
Denis Lisov
@tanriol
Feb 18 2018 13:47
@apiraino SmallVec<[MyType; ExpectedLength]> is the intended way of using SmallVec
Daniel Bischof
@dbischof90
Feb 18 2018 13:48
Okay, good to know.
apiraino
@apiraino
Feb 18 2018 13:48
I could not even learn from other implementation of the new selectors == 0.19 library. Only the Servo project uses it. And that codebase is hard to follow :)
I think I'm not blocked anymore here, thank you so much for your help
great, no more errors: at least the syntax related issues should be fixed!
thanks again for your help
Michal 'vorner' Vaner
@vorner
Feb 18 2018 15:57
Hello. I'm trying to read the code of rustc. One comment looks strange ‒ Right now this only includes macro_rules! macros, and macros 2.0. ‒ what other macros exist? Are custom derives considered special case, not part of macros 2.0?
Andy Grove
@andygrove
Feb 18 2018 16:23
Morning all. I'm struggling with moving a value into a closure and wonder if someone can tell me what I am doing wrong? https://play.rust-lang.org/?gist=ffaee5906f7b539f1f496320b1519174&version=stable
The use case is that I'm trying to compile expressions into closures for runtime excecution
red75prime
@red75prime
Feb 18 2018 16:30
Ok(Box::new(move |_| Ok(lit.clone())))
Fn closures cannot modify captured environment. Ok(lit) tries to move captured lit from the closure.
Andy Grove
@andygrove
Feb 18 2018 16:31
huh, I swear I already tried that ... thanks @red75prime
right, that makes sense
red75prime
@red75prime
Feb 18 2018 16:34
The only closure you can move out of is FnOnce, BTW.