Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unresolved name next in macro expansion #3007

Closed
eholk opened this issue Jul 24, 2012 · 2 comments
Closed

Unresolved name next in macro expansion #3007

eholk opened this issue Jul 24, 2012 · 2 comments
Labels
A-syntaxext Area: Syntax extensions
Milestone

Comments

@eholk
Copy link
Contributor

eholk commented Jul 24, 2012

// Compare bounded and unbounded protocol performance.

// xfail-pretty

use std;

import pipes::{spawn_service, recv};
import std::time::precise_time_s;

proto! pingpong {
    ping: send {
        ping -> pong
    }

    pong: recv {
        pong -> ping
    }
}

proto! pingpong_unbounded {
    ping: send {
        ping -> pong
    }

    pong: recv {
        pong -> ping
    }

    you_will_never_catch_me: send {
        never_ever_ever -> you_will_never_catch_me
    }
}

// This stuff should go in libcore::pipes
macro_rules! move {
    { $x:expr } => { unsafe { let y <- *ptr::addr_of($x); y } }
}

macro_rules! follow {
    { 
        $($message:path($($x: ident),+) -> $next:ident $e:expr)+
    } => (
        |m| alt move(m) {
          $(some($message($($x,)* next)) {
            let $next = move!{next};
            $e })+
          _ { fail }
        }
    );

    { 
        $($message:path -> $next:ident $e:expr)+
    } => (
        |m| alt move(m) {
            $(some($message(next)) {
                let $next = move!{next};
                $e })+
                _ { fail }
        } 
    )
}

fn switch<T: send, Tb: send, U>(+endp: pipes::recv_packet_buffered<T, Tb>,
                      f: fn(+option<T>) -> U) -> U {
    f(pipes::try_recv(endp))
}

fn move<T>(-x: T) -> T { x }

// Here's the benchmark

fn bounded(count: uint) {
    import pingpong::*;

    let mut ch = do spawn_service(init) |ch| {
        let mut count = count;
        let mut ch = ch;
        while count > 0 {
            ch = switch(ch, follow! {
                ping -> next { server::pong(next) }
            });

            count -= 1;
        }
    };

    let mut count = count;
    while count > 0 {
        let ch_ = client::ping(ch);

        ch = switch(ch_, follow! {
            pong -> next { next }
        });

        count -= 1;
    }
}

fn unbounded(count: uint) {
    import pingpong_unbounded::*;

    let mut ch = do spawn_service(init) |ch| {
        let mut count = count;
        let mut ch = ch;
        while count > 0 {
            ch = switch(ch, follow! {
                ping -> next { server::pong(next) }
            });

            count -= 1;
        }
    };

    let mut count = count;
    while count > 0 {
        let ch_ = client::ping(ch);

        ch = switch(ch_, follow! {
            pong -> next { next }
        });

        count -= 1;
    }
}

fn timeit(f: fn()) -> float {
    let start = precise_time_s();
    f();
    let stop = precise_time_s();
    stop - start
}

fn main() {
    let count = 1000000;
    let bounded = do timeit { bounded(count) };
    let unbounded = do timeit { unbounded(count) };

    io::println(#fmt("count: %?\n", count));
    io::println(#fmt("bounded:   %? s\t(%? μs/message)",
                     bounded, bounded * 1000000. / (count as float)));
    io::println(#fmt("unbounded: %? s\t(%? μs/message)",
                     unbounded, unbounded * 1000000. / (count as float)));

    io::println(#fmt("\n\
                      bounded is %?%% faster",
                     (unbounded - bounded) / bounded * 100.));
}

Pretty printing and recompiling fixes the problem.

@ghost ghost assigned paulstansifer Jul 24, 2012
@paulstansifer
Copy link
Contributor

The resolution of patterns is doing something really strange here.

When --pretty expanded, this works as expected.

@ghost ghost assigned eholk Aug 6, 2012
@eholk eholk closed this as completed in 517ad98 Aug 6, 2012
@eholk
Copy link
Contributor Author

eholk commented Aug 6, 2012

I fixed this. We will probably need to replace calls to is_ident with is_ident_or_path in some other places as well, but we'll wait until bugs crop up before we do that.

@eholk eholk removed their assignment Jun 16, 2014
RalfJung pushed a commit to RalfJung/rust that referenced this issue Aug 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-syntaxext Area: Syntax extensions
Projects
None yet
Development

No branches or pull requests

2 participants