Skip to content

Commit

Permalink
Merge branch 'release-v0.7.17' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
sfackler committed Oct 5, 2016
2 parents 6f5575c + 21ecf72 commit e073dd2
Show file tree
Hide file tree
Showing 18 changed files with 131 additions and 31 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ rust:
- 1.6.0
script:
- (test $TRAVIS_RUST_VERSION != "nightly" || (cd phf_macros && cargo test))
- (test $TRAVIS_RUST_VERSION != "nightly" || (cd phf_macros && cargo test --features unicase_support))
- (test $TRAVIS_RUST_VERSION != "nightly" || (cd phf_macros && cargo test --features stats))
- (test $TRAVIS_RUST_VERSION != "nightly" || (cd phf_macros && cargo bench))
- (test $TRAVIS_RUST_VERSION != "nightly" || (cd phf_shared && cargo build --features core))
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Rust-PHF

[![Build Status](https://travis-ci.org/sfackler/rust-phf.png?branch=master)](https://travis-ci.org/sfackler/rust-phf) [![Latest Version](https://img.shields.io/crates/v/phf.svg)](https://crates.io/crates/phf)

[Documentation](https://sfackler.github.io/rust-phf/doc/v0.7.16/phf)
[Documentation](https://sfackler.github.io/rust-phf/doc/v0.7.17/phf)

Rust-PHF is a library to generate efficient lookup tables at compile time using
[perfect hash functions](http://en.wikipedia.org/wiki/Perfect_hash_function).
Expand Down
6 changes: 3 additions & 3 deletions phf/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "phf"
authors = ["Steven Fackler <sfackler@gmail.com>"]
version = "0.7.16"
version = "0.7.17"
license = "MIT"
description = "Runtime support for perfect hash function data structures"
repository = "https://github.com/sfackler/rust-phf"
documentation = "https://sfackler.github.io/rust-phf/doc/v0.7.16/phf"
documentation = "https://sfackler.github.io/rust-phf/doc/v0.7.17/phf"

[lib]
name = "phf"
Expand All @@ -17,4 +17,4 @@ core = ["phf_shared/core"]
unicase = ["phf_shared/unicase"]

[dependencies]
phf_shared = { version = "=0.7.16", path = "../phf_shared" }
phf_shared = { version = "=0.7.17", path = "../phf_shared" }
2 changes: 1 addition & 1 deletion phf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! PHF data structures can be generated via the syntax extensions in the
//! `phf_macros` crate or via code generation in the `phf_codegen` crate. See
//! the documentation of those crates for more details.
#![doc(html_root_url="https://sfackler.github.io/rust-phf/doc/v0.7.16")]
#![doc(html_root_url="https://sfackler.github.io/rust-phf/doc/v0.7.17")]
#![warn(missing_docs)]
#![cfg_attr(feature = "core", no_std)]

Expand Down
8 changes: 4 additions & 4 deletions phf_builder/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "phf_builder"
version = "0.7.16"
version = "0.7.17"
authors = ["Steven Fackler <sfackler@gmail.com>"]
license = "MIT"
description = "Runtime creation of perfect hash function data structures"
repository = "https://github.com/sfackler/rust-phf"
documentation = "https://sfackler.github.io/rust-phf/doc/v0.7.16/phf_builder"
documentation = "https://sfackler.github.io/rust-phf/doc/v0.7.17/phf_builder"

[dependencies]
phf = { version = "=0.7.16", path = "../phf" }
phf_generator = { version = "=0.7.16", path = "../phf_generator" }
phf = { version = "=0.7.17", path = "../phf" }
phf_generator = { version = "=0.7.17", path = "../phf_generator" }
2 changes: 1 addition & 1 deletion phf_builder/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![doc(html_root_url="http://sfackler.github.io/rust-phf/doc/v0.7.16")]
#![doc(html_root_url="http://sfackler.github.io/rust-phf/doc/v0.7.17")]
extern crate phf;
extern crate phf_generator;

Expand Down
8 changes: 4 additions & 4 deletions phf_codegen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[package]
name = "phf_codegen"
authors = ["Steven Fackler <sfackler@gmail.com>"]
version = "0.7.16"
version = "0.7.17"
license = "MIT"
description = "Codegen library for PHF types"
repository = "https://github.com/sfackler/rust-phf"
documentation = "https://sfackler.github.io/rust-phf/doc/v0.7.16/phf_codegen"
documentation = "https://sfackler.github.io/rust-phf/doc/v0.7.17/phf_codegen"

[dependencies.phf_generator]
path = "../phf_generator"
version = "=0.7.16"
version = "=0.7.17"

[dependencies.phf_shared]
path = "../phf_shared"
version = "=0.7.16"
version = "=0.7.17"
2 changes: 1 addition & 1 deletion phf_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
//! builder.entry("world", "2");
//! // ...
//! ```
#![doc(html_root_url="http://sfackler.github.io/rust-phf/doc/v0.7.16")]
#![doc(html_root_url="http://sfackler.github.io/rust-phf/doc/v0.7.17")]
extern crate phf_shared;
extern crate phf_generator;

Expand Down
6 changes: 3 additions & 3 deletions phf_generator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[package]
name = "phf_generator"
authors = ["Steven Fackler <sfackler@gmail.com>"]
version = "0.7.16"
version = "0.7.17"
license = "MIT"
description = "PHF generation logic"
repository = "https://github.com/sfackler/rust-phf"
documentation = "https://sfackler.github.io/rust-phf/doc/v0.7.16/phf_generator"
documentation = "https://sfackler.github.io/rust-phf/doc/v0.7.17/phf_generator"

[dependencies]
rand = "0.3"

[dependencies.phf_shared]
path = "../phf_shared"
version = "=0.7.16"
version = "=0.7.17"
2 changes: 1 addition & 1 deletion phf_generator/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![doc(html_root_url="http://sfackler.github.io/rust-phf/doc/v0.7.16")]
#![doc(html_root_url="http://sfackler.github.io/rust-phf/doc/v0.7.17")]
extern crate phf_shared;
extern crate rand;

Expand Down
18 changes: 13 additions & 5 deletions phf_macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "phf_macros"
authors = ["Steven Fackler <sfackler@gmail.com>"]
version = "0.7.16"
version = "0.7.17"
license = "MIT"
description = "Compiler plugin for perfect hash function data structures"
repository = "https://github.com/sfackler/rust-phf"
documentation = "https://sfackler.github.io/rust-phf/doc/v0.7.16/phf_macros"
documentation = "https://sfackler.github.io/rust-phf/doc/v0.7.17/phf_macros"

[lib]
name = "phf_macros"
Expand All @@ -15,19 +15,27 @@ test = false

[features]
stats = ["time"]
unicase_support = ["unicase", "phf_shared/unicase"]

[dependencies.phf_generator]
path = "../phf_generator"
version = "=0.7.16"
version = "=0.7.17"

[dependencies.phf_shared]
path = "../phf_shared"
version = "=0.7.16"
version = "=0.7.17"

[dependencies.time]
version = "0.1"
optional = true

[dependencies.unicase]
version = "1.4"
optional = true

[dev-dependencies.phf]
path = "../phf"
version = "=0.7.16"
version = "=0.7.17"

[dev-dependencies.compiletest_rs]
version = "0.2"
32 changes: 29 additions & 3 deletions phf_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
//! }
//! # fn main() {}
//! ```
#![doc(html_root_url="http://sfackler.github.io/rust-phf/doc/v0.7.16")]
#![doc(html_root_url="http://sfackler.github.io/rust-phf/doc/v0.7.17")]
#![feature(plugin_registrar, quote, rustc_private)]

extern crate syntax;
Expand All @@ -39,6 +39,8 @@ extern crate time;
extern crate rustc_plugin;
extern crate phf_shared;
extern crate phf_generator;
#[cfg(feature = "unicase_support")]
extern crate unicase;

use std::collections::HashMap;
use std::collections::hash_map::Entry::{Occupied, Vacant};
Expand All @@ -55,6 +57,8 @@ use syntax::ptr::P;
use rustc_plugin::Registry;
use phf_generator::HashState;
use std::env;
#[cfg(feature = "unicase_support")]
use unicase::UniCase;

use util::{Entry, Key};
use util::{create_map, create_set, create_ordered_map, create_ordered_set};
Expand Down Expand Up @@ -282,8 +286,30 @@ fn parse_key(cx: &mut ExtCtxt, e: &Expr) -> Option<Key> {
None
}
}
#[cfg(feature = "unicase_support")]
ExprKind::Call(ref f, ref args) => {
if let ExprKind::Path(_, ref path) = f.node {
if path.segments.last().unwrap().identifier.name.as_str() == "UniCase" {
if args.len() == 1 {
if let ExprKind::Lit(ref lit) = args.first().unwrap().node {
if let ast::LitKind::Str(ref s, _) = lit.node {
return Some(Key::UniCase(UniCase(s.to_string())));
} else {
cx.span_err(e.span, "only a str literal is allowed in UniCase");
return None;
}
}
} else {
cx.span_err(e.span, "only one str literal is allowed in UniCase");
return None;
}
}
}
cx.span_err(e.span, "only UniCase is allowed besides literals");
None
},
_ => {
cx.span_err(e.span, "expected a literal");
cx.span_err(e.span, "expected a literal (or a UniCase if the unicase_support feature is enabled)");
None
}
}
Expand All @@ -301,7 +327,7 @@ fn adjust_key(cx: &mut ExtCtxt, e: P<Expr>) -> P<Expr> {
};
if coerce_as_slice {
let u8_type = cx.ty_path(cx.path_ident(e.span, cx.ident_of("u8")));
let array_type = cx.ty(e.span, TyKind::Vec(u8_type));
let array_type = cx.ty(e.span, TyKind::Slice(u8_type));
let slice_type = cx.ty_rptr(e.span, array_type, None, Mutability::Immutable);
cx.expr_cast(e.span, e, slice_type)
} else {
Expand Down
6 changes: 6 additions & 0 deletions phf_macros/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub enum Key {
U64(u64),
I64(i64),
Bool(bool),
#[cfg(feature = "unicase_support")]
UniCase(::unicase::UniCase<String>),
}

impl Hash for Key {
Expand All @@ -42,6 +44,8 @@ impl Hash for Key {
Key::U64(b) => b.hash(state),
Key::I64(b) => b.hash(state),
Key::Bool(b) => b.hash(state),
#[cfg(feature = "unicase_support")]
Key::UniCase(ref u) => u.hash(state),
}
}
}
Expand All @@ -61,6 +65,8 @@ impl PhfHash for Key {
Key::U64(b) => b.phf_hash(state),
Key::I64(b) => b.phf_hash(state),
Key::Bool(b) => b.phf_hash(state),
#[cfg(feature = "unicase_support")]
Key::UniCase(ref u) => u.phf_hash(state),
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions phf_macros/tests/compile-fail-unicase/equivalent-keys.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![feature(plugin)]
#![plugin(phf_macros)]

extern crate phf;
extern crate unicase;

static MAP: phf::Map<UniCase<&'static str>, isize> = phf_map!( //~ ERROR duplicate key UniCase("FOO")
UniCase("FOO") => 42, //~ NOTE one occurrence here
UniCase("foo") => 42, //~ NOTE one occurrence here
);
21 changes: 21 additions & 0 deletions phf_macros/tests/compiletest.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
extern crate compiletest_rs as compiletest;

use std::path::PathBuf;

#[allow(dead_code)]
fn run_mode(directory: &'static str, mode: &'static str) {
let mut config = compiletest::default_config();
let cfg_mode = mode.parse().ok().expect("Invalid mode");

config.mode = cfg_mode;
config.target_rustcflags = Some("-L target/debug/deps".to_owned());
config.src_base = PathBuf::from(format!("tests/{}", directory));

compiletest::run_tests(&config);
}

#[cfg(feature = "unicase_support")]
#[test]
fn compile_test_unicase() {
run_mode("compile-fail-unicase", "compile-fail");
}
28 changes: 28 additions & 0 deletions phf_macros/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#![plugin(phf_macros)]

extern crate phf;
#[cfg(feature = "unicase_support")]
extern crate unicase;

mod map {
use std::collections::{HashMap, HashSet};
Expand Down Expand Up @@ -231,6 +233,32 @@ mod map {
assert_eq!(&10, v)
}
}

#[cfg(feature = "unicase_support")]
#[test]
fn test_unicase() {
use unicase::UniCase;
static MAP: phf::Map<UniCase<&'static str>, isize> = phf_map!(
UniCase("FOO") => 10,
UniCase("Bar") => 11,
);
assert!(Some(&10) == MAP.get(&UniCase("FOo")));
assert!(Some(&11) == MAP.get(&UniCase("bar")));
assert_eq!(None, MAP.get(&UniCase("asdf")));
}

#[cfg(feature = "unicase_support")]
#[test]
fn test_unicase_alt() {
use unicase;
static MAP: phf::Map<unicase::UniCase<&'static str>, isize> = phf_map!(
unicase::UniCase("FOO") => 10,
unicase::UniCase("Bar") => 11,
);
assert!(Some(&10) == MAP.get(&unicase::UniCase("FOo")));
assert!(Some(&11) == MAP.get(&unicase::UniCase("bar")));
assert_eq!(None, MAP.get(&unicase::UniCase("asdf")));
}
}

mod set {
Expand Down
6 changes: 3 additions & 3 deletions phf_shared/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "phf_shared"
authors = ["Steven Fackler <sfackler@gmail.com>"]
version = "0.7.16"
version = "0.7.17"
license = "MIT"
description = "Support code shared by PHF libraries"
repository = "https://github.com/sfackler/rust-phf"
documentation = "https://sfackler.github.io/rust-phf/doc/v0.7.16/phf_shared"
documentation = "https://sfackler.github.io/rust-phf/doc/v0.7.17/phf_shared"

[lib]
name = "phf_shared"
Expand All @@ -16,4 +16,4 @@ test = false
core = []

[dependencies]
unicase = { version = "1.1", optional = true }
unicase = { version = "1.4", optional = true }
2 changes: 1 addition & 1 deletion phf_shared/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![doc(html_root_url="http://sfackler.github.io/rust-phf/doc/v0.7.16")]
#![doc(html_root_url="http://sfackler.github.io/rust-phf/doc/v0.7.17")]
#![cfg_attr(feature = "core", no_std)]
#[cfg(not(feature = "core"))]
extern crate std as core;
Expand Down

0 comments on commit e073dd2

Please sign in to comment.