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

Hygiene for 3 kinds of args #15425

Merged
merged 13 commits into from
Jul 5, 2014
8 changes: 4 additions & 4 deletions src/librustc/middle/trans/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,9 +796,9 @@ fn extract_vec_elems<'a>(
// matches should fit that sort of pattern or NONE (however, some of the
// matches may be wildcards like _ or identifiers).
macro_rules! any_pat (
($m:expr, $pattern:pat) => (
($m:expr, $col:expr, $pattern:pat) => (
($m).iter().any(|br| {
match br.pats.get(col).node {
match br.pats.get($col).node {
$pattern => true,
_ => false
}
Expand All @@ -807,11 +807,11 @@ macro_rules! any_pat (
)

fn any_uniq_pat(m: &[Match], col: uint) -> bool {
any_pat!(m, ast::PatBox(_))
any_pat!(m, col, ast::PatBox(_))
}

fn any_region_pat(m: &[Match], col: uint) -> bool {
any_pat!(m, ast::PatRegion(_))
any_pat!(m, col, ast::PatRegion(_))
}

fn any_irrefutable_adt_pat(bcx: &Block, m: &[Match], col: uint) -> bool {
Expand Down
17 changes: 9 additions & 8 deletions src/libstd/io/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,14 +508,15 @@ mod bench {
use prelude::*;
use self::test::Bencher;

// why is this a macro? wouldn't an inlined function work just as well?
macro_rules! u64_from_be_bytes_bench_impl(
($size:expr, $stride:expr, $start_index:expr) =>
($b:expr, $size:expr, $stride:expr, $start_index:expr) =>
({
use super::u64_from_be_bytes;

let data = Vec::from_fn($stride*100+$start_index, |i| i as u8);
let mut sum = 0u64;
b.iter(|| {
$b.iter(|| {
let mut i = $start_index;
while i < data.len() {
sum += u64_from_be_bytes(data.as_slice(), i, $size);
Expand All @@ -527,31 +528,31 @@ mod bench {

#[bench]
fn u64_from_be_bytes_4_aligned(b: &mut Bencher) {
u64_from_be_bytes_bench_impl!(4, 4, 0);
u64_from_be_bytes_bench_impl!(b, 4, 4, 0);
}

#[bench]
fn u64_from_be_bytes_4_unaligned(b: &mut Bencher) {
u64_from_be_bytes_bench_impl!(4, 4, 1);
u64_from_be_bytes_bench_impl!(b, 4, 4, 1);
}

#[bench]
fn u64_from_be_bytes_7_aligned(b: &mut Bencher) {
u64_from_be_bytes_bench_impl!(7, 8, 0);
u64_from_be_bytes_bench_impl!(b, 7, 8, 0);
}

#[bench]
fn u64_from_be_bytes_7_unaligned(b: &mut Bencher) {
u64_from_be_bytes_bench_impl!(7, 8, 1);
u64_from_be_bytes_bench_impl!(b, 7, 8, 1);
}

#[bench]
fn u64_from_be_bytes_8_aligned(b: &mut Bencher) {
u64_from_be_bytes_bench_impl!(8, 8, 0);
u64_from_be_bytes_bench_impl!(b, 8, 8, 0);
}

#[bench]
fn u64_from_be_bytes_8_unaligned(b: &mut Bencher) {
u64_from_be_bytes_bench_impl!(8, 8, 1);
u64_from_be_bytes_bench_impl!(b, 8, 8, 1);
}
}
22 changes: 15 additions & 7 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ pub struct TyParam {
pub span: Span
}

/// Represents lifetimes and type parameters attached to a declaration
/// of a function, enum, trait, etc.
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
pub struct Generics {
pub lifetimes: Vec<Lifetime>,
Expand Down Expand Up @@ -288,7 +290,7 @@ pub enum Pat_ {
PatWild,
PatWildMulti,
// A PatIdent may either be a new bound variable,
// or a nullary enum (in which case the second field
// or a nullary enum (in which case the third field
// is None).
// In the nullary enum case, the parser can't determine
// which it is. The resolver determines this, and
Expand Down Expand Up @@ -453,10 +455,10 @@ pub enum Expr_ {
ExprCast(Gc<Expr>, P<Ty>),
ExprIf(Gc<Expr>, P<Block>, Option<Gc<Expr>>),
ExprWhile(Gc<Expr>, P<Block>),
// FIXME #6993: change to Option<Name>
// FIXME #6993: change to Option<Name> ... or not, if these are hygienic.
ExprForLoop(Gc<Pat>, Gc<Expr>, P<Block>, Option<Ident>),
// Conditionless loop (can be exited with break, cont, or ret)
// FIXME #6993: change to Option<Name>
// FIXME #6993: change to Option<Name> ... or not, if these are hygienic.
ExprLoop(P<Block>, Option<Ident>),
ExprMatch(Gc<Expr>, Vec<Arm>),
ExprFnBlock(P<FnDecl>, P<Block>),
Expand All @@ -468,9 +470,8 @@ pub enum Expr_ {
ExprField(Gc<Expr>, SpannedIdent, Vec<P<Ty>>),
ExprIndex(Gc<Expr>, Gc<Expr>),

/// Expression that looks like a "name". For example,
/// `std::slice::from_elem::<uint>` is an ExprPath that's the "name" part
/// of a function call.
/// Variable reference, possibly containing `::` and/or
/// type parameters, e.g. foo::bar::<baz>
ExprPath(Path),

ExprAddrOf(Mutability, Gc<Expr>),
Expand Down Expand Up @@ -643,6 +644,8 @@ pub struct TypeField {
pub span: Span,
}

/// Represents a required method in a trait declaration,
/// one without a default implementation
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
pub struct TypeMethod {
pub ident: Ident,
Expand All @@ -656,6 +659,8 @@ pub struct TypeMethod {
pub vis: Visibility,
}

/// Represents a method declaration in a trait declaration, possibly
/// including a default implementation
// A trait method is either required (meaning it doesn't have an
// implementation, just a signature) or provided (meaning it has a default
// implementation).
Expand Down Expand Up @@ -741,6 +746,7 @@ impl fmt::Show for Onceness {
}
}

/// Represents the type of a closure
#[deriving(PartialEq, Eq, Encodable, Decodable, Hash)]
pub struct ClosureTy {
pub lifetimes: Vec<Lifetime>,
Expand Down Expand Up @@ -809,6 +815,7 @@ pub struct InlineAsm {
pub dialect: AsmDialect
}

/// represents an argument in a function header
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
pub struct Arg {
pub ty: P<Ty>,
Expand Down Expand Up @@ -836,7 +843,7 @@ impl Arg {
}
}

// represents the header (not the body) of a function declaration
/// represents the header (not the body) of a function declaration
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
pub struct FnDecl {
pub inputs: Vec<Arg>,
Expand Down Expand Up @@ -1107,6 +1114,7 @@ pub enum Item_ {
ItemTy(P<Ty>, Generics),
ItemEnum(EnumDef, Generics),
ItemStruct(Gc<StructDef>, Generics),
/// Represents a Trait Declaration
ItemTrait(Generics, Sized, Vec<TraitRef> , Vec<TraitMethod> ),
ItemImpl(Generics,
Option<TraitRef>, // (optional) trait this impl implements
Expand Down
6 changes: 2 additions & 4 deletions src/libsyntax/ext/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use parse::parser;
use parse::token;
use parse::token::{InternedString, intern, str_to_ident};
use util::small_vector::SmallVector;
use ext::mtwt;

use std::collections::HashMap;
use std::gc::{Gc, GC};
Expand Down Expand Up @@ -273,7 +274,7 @@ pub struct BlockInfo {
// should macros escape from this scope?
pub macros_escape: bool,
// what are the pending renames?
pub pending_renames: RenameList,
pub pending_renames: mtwt::RenameList,
}

impl BlockInfo {
Expand All @@ -285,9 +286,6 @@ impl BlockInfo {
}
}

// a list of ident->name renamings
pub type RenameList = Vec<(ast::Ident, Name)>;

// The base map of methods for expanding syntax extension
// AST nodes into full ASTs
pub fn syntax_expander_table() -> SyntaxEnv {
Expand Down
Loading