Skip to content
Permalink
Browse files

Fix more clippy errros and add docs (#52)

* More clippy and docs
* Better names for pipelines
  • Loading branch information
Licenser authored and sunnygleason committed Oct 3, 2019
1 parent 0a8f144 commit b4b9b850b98cbe8a8732f7c840908fb96ff4e95c
@@ -7,8 +7,22 @@ platform:
steps:
- name: test
image: rust:1
environment:
RUSTFLAGS: '-C target-cpu=native'
CODECOV_TOKEN:
from_secret: CODECOV_TOKEN
commands:
- rustup default nightly
- rustup update
- cargo clean && cargo +nightly build --verbose --all --features neon
- cargo +nightly test --verbose --all --features neon
# - cargo +nightly install cargo-clippy -f
# - cargo +nightly clippy --verbose --all --features neon
# - cargo +nightly install cargo-tarpaulin -f
# - cargo +nightly tarpaulin -v --out Xml
#- name: coverage
# image: plugins/codecov
# settings:
# token: $CODECOV_TOKEN
# files:
# - '*.xml'
@@ -1,4 +1,4 @@
name: Rust
name: Rust (tests)

on: [push]

@@ -13,6 +13,9 @@ jobs:
- ubuntu-latest
- windows-latest
- macOS-latest
rustflags:
- '-C target-cpu=native'
- '-C target-cpu=native -C target-feature=-avx2'
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v1
@@ -21,6 +24,10 @@ jobs:
toolchain: ${{ matrix.rust }}
override: true
- name: Build
env:
RUSTFLAGS: ${{ matrix.rustflags }}
run: cargo build --verbose
- name: Run tests
env:
RUSTFLAGS: ${{ matrix.rustflags }}
run: cargo test --verbose
@@ -1,9 +1,14 @@
name: Rust
name: Rust (sanity checks)

on: [push]

jobs:
clippy_check:
strategy:
matrix:
rustflags:
- '-C target-cpu=native'
- '-C target-cpu=native -C target-feature=-avx2'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
@@ -16,30 +21,17 @@ jobs:
- name: Install clippy
run: rustup component add clippy
- uses: actions-rs/clippy-check@v1
env:
RUSTFLAGS: ${{ matrix.rustflags }}
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all
tarpaulin-avx:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Install deps
run: sudo apt-get update && sudo apt-get install -y libssl-dev pkg-config cmake zlib1g-dev
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
- name: install tarpaulin
run: cargo install cargo-tarpaulin -f
- name: run tarpaulin
env:
RUSTFLAGS: '-C target-cpu=native'
run: cargo tarpaulin -v --out Xml
- uses: codecov/codecov-action@v1.0.2
with:
token: ${{secrets.CODECOV_TOKEN}} #required
file: ./cobertura.xml
tarpaulin-sse:
tarpaulin:
strategy:
matrix:
rustflags:
- '-C target-cpu=native'
- '-C target-cpu=native -C target-feature=-avx2'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
@@ -53,12 +45,12 @@ jobs:
run: cargo install cargo-tarpaulin -f
- name: run tarpaulin
env:
RUSTFLAGS: '-C target-cpu=native -C target-feature=-avx2'
RUSTFLAGS: ${{ matrix.rustflags }}
run: cargo tarpaulin -v --out Xml
- uses: codecov/codecov-action@v1.0.2
with:
token: ${{secrets.CODECOV_TOKEN}} #required
file: ./cobertura.xml
file: ./cobertura.xml
# tarpaulin-neon:
# runs-on: ubuntu-latest
# steps:
@@ -73,7 +73,7 @@ macro_rules! bench_file {
});
c.bench(
stringify!($name),
b.throughput(|data| Throughput::Bytes(data.len() as u32)),
b.throughput(|data| Throughput::Bytes(data.len() as u64)),
);
}
};
@@ -5,10 +5,9 @@ use std::arch::x86_64::*;

use std::mem;

pub use crate::avx2::utf8check::*;
pub use crate::error::{Error, ErrorType};
pub use crate::stringparse::*;
pub use crate::Deserializer;
use crate::stringparse::*;
use crate::Deserializer;
pub use crate::Result;

impl<'de> Deserializer<'de> {
@@ -228,7 +228,7 @@ fn avxcheck_overlong(
}
}

pub struct AvxProcessedUtfBytes {
pub(crate) struct AvxProcessedUtfBytes {
rawbytes: __m256i,
high_nibbles: __m256i,
pub carried_continuations: __m256i,
@@ -257,7 +257,7 @@ fn avx_count_nibbles(bytes: __m256i, answer: &mut AvxProcessedUtfBytes) {
// check whether the current bytes are valid UTF-8
// at the end of the function, previous gets updated
#[cfg_attr(not(feature = "no-inline"), inline)]
pub fn avxcheck_utf8_bytes(
pub(crate) fn avxcheck_utf8_bytes(
current_bytes: __m256i,
previous: &AvxProcessedUtfBytes,
has_error: &mut __m256i,
@@ -1,65 +1,109 @@
use std::fmt;

/// Error types encountered while parsing
#[derive(Debug, PartialEq)]
pub enum ErrorType {
/// The key of a map isn't a string
BadKeyType,
/// The data ended early
EarlyEnd,
/// Expected an array
ExpectedArray,
/// Expected a `,` in an array
ExpectedArrayComma,
/// expected an boolean
ExpectedBoolean,
/// Expected an enum
ExpectedEnum,
/// Expected a float
ExpectedFloat,
/// Expected an integer
ExpectedInteger,
/// Expected a map
ExpectedMap,
/// Expected an `:` to seperate key and value in an object
ExpectedObjectColon,
/// Expected a `,` in an object
ExpectedMapComma,
/// Expected the object to end
ExpectedMapEnd,
/// Expected a null
ExpectedNull,
/// Expected a number
ExpectedNumber,
/// Expected a signed number
ExpectedSigned,
/// Expected a string
ExpectedString,
/// Expected an unsigned number
ExpectedUnsigned,
/// Internal error
InternalError,
/// Invalid escape sequence
InvalidEscape,
/// Invalid exponent in a floating point number
InvalidExponent,
/// Invalid number
InvalidNumber,
/// Inbalid UTF8 codepoint
InvalidUTF8,
/// Invalid Unicode escape sequence
InvalidUnicodeEscape,
/// Inbalid Unicode codepoint
InvlaidUnicodeCodepoint,
/// Object Key isn't a string
KeyMustBeAString,
/// Non structural character
NoStructure,
/// Parser Erropr
Parser,
/// Early End Of File
EOF,
/// Generic serde error
Serde(String),
/// Generic syntax error
Syntax,
/// Training characters
TrailingCharacters,
/// Unexpected character
UnexpectedCharacter,
/// Unexpected end
UnexpectedEnd,
/// Unterminated string
UnterminatedString,
/// Expected Array elements
ExpectedArrayContent,
/// Expected Object elements
ExpectedObjectContent,
/// Expected Object Key
ExpectedObjectKey,
/// Overflow of a limited buffer
Overflow,
}

/// Parser error
#[derive(Debug, PartialEq)]
pub struct Error {
/// Strucutral the error was encountered at
structural: usize,
/// Byte index it was encountered at
index: usize,
/// Current character
character: char,
/// Tyep of error
error: ErrorType,
}

impl Error {
pub fn new(structural: usize, index: usize, character: char, error: ErrorType) -> Self {
pub(crate) fn new(structural: usize, index: usize, character: char, error: ErrorType) -> Self {
Self {
structural,
index,
character,
error,
}
}
pub fn generic(t: ErrorType) -> Self {
pub(crate) fn generic(t: ErrorType) -> Self {
Self {
structural: 0,
index: 0,
@@ -28,6 +28,7 @@
// We might want to revisit inline_always
allow(clippy::module_name_repetitions, clippy::inline_always)
)]
#![deny(missing_docs)]

//! simdjson-rs is a rust port of the simejson c++ library. It follows
//! most of the design closely with a few exceptions to make it better
@@ -100,7 +101,9 @@

#[cfg(feature = "serde_impl")]
extern crate serde as serde_ext;

#[cfg(feature = "serde_impl")]
/// serde related helper functions
pub mod serde;

mod charutils;
@@ -142,6 +145,7 @@ pub use crate::neon::deser::*;
use crate::neon::stage1::SIMDJSON_PADDING;

mod stage2;
/// simd-json JSON-DOM value
pub mod value;

use crate::numberparse::Number;
@@ -152,9 +156,10 @@ use std::str;
pub use crate::error::{Error, ErrorType};
pub use crate::value::*;

/// simd-json Result type
pub type Result<T> = std::result::Result<T, Error>;

pub struct Deserializer<'de> {
pub(crate) struct Deserializer<'de> {
// This string starts with the input data and characters are truncated off
// the beginning as data is parsed.
input: &'de mut [u8],
@@ -293,9 +298,11 @@ impl<'de> Deserializer<'de> {

#[cfg(test)]
mod tests {
#![allow(clippy::unnecessary_operation, clippy::non_ascii_literal)]
use super::serde::from_slice;
use super::{
owned::to_value, owned::Map, owned::Value, to_borrowed_value, to_owned_value, Deserializer,
owned::to_value, owned::Object, owned::Value, to_borrowed_value, to_owned_value,
Deserializer,
};
use halfbrown::HashMap;
use proptest::prelude::*;
@@ -692,7 +699,10 @@ mod tests {
assert_eq!(v_simd, v_serde);
assert_eq!(
to_value(&mut d1),
Ok(Value::Array(vec![Value::Object(Map::new()), Value::Null]))
Ok(Value::Array(vec![
Value::Object(Object::new()),
Value::Null
]))
);
}

@@ -824,7 +834,7 @@ mod tests {
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("");
let v_simd: serde_json::Value = from_slice(&mut d).expect("");
assert_eq!(v_simd, v_serde);
let mut h = Map::new();
let mut h = Object::new();
h.insert("snot".into(), Value::from("badger"));
assert_eq!(to_value(&mut d1), Ok(Value::Object(h)));
}
@@ -838,7 +848,7 @@ mod tests {
let v_serde: serde_json::Value = serde_json::from_slice(d).expect("");
let v_simd: serde_json::Value = from_slice(&mut d).expect("");
assert_eq!(v_simd, v_serde);
let mut h = Map::new();
let mut h = Object::new();
h.insert("snot".into(), Value::from("badger"));
h.insert("badger".into(), Value::from("snot"));
assert_eq!(to_value(&mut d1), Ok(Value::Object(h)));
@@ -1078,7 +1088,7 @@ mod tests {
// Is this a real issue worth improving?
#[test]
fn silly_float1() {
let v = Value::from(3.0901448042322017e305);
let v = Value::from(3.090_144_804_232_201_7e305);
let s = v.encode();
dbg!(&s);
let mut bytes = s.as_bytes().to_vec();
@@ -1089,7 +1099,7 @@ mod tests {
#[test]
#[ignore]
fn silly_float2() {
let v = Value::from(-6.990585694841803e305);
let v = Value::from(-6.990_585_694_841_803e305);
let s = v.encode();
dbg!(&s);
let mut bytes = s.as_bytes().to_vec();
@@ -1157,8 +1167,8 @@ mod tests {
fn prop_json_encode_decode(val in arb_json_value()) {
let mut encoded: Vec<u8> = Vec::new();
let _ = val.write(&mut encoded);
println!("{}", String::from_utf8(encoded.clone()).unwrap());
let res = to_owned_value(&mut encoded).unwrap();
println!("{}", String::from_utf8_lossy(&encoded.clone()));
let res = to_owned_value(&mut encoded).expect("can't convert");
assert_eq!(val, res);
}

@@ -1188,7 +1198,7 @@ mod tests {
let v_simd_borrowed = to_borrowed_value(d3);
dbg!(&v_simd_borrowed);
assert!(v_simd_borrowed.is_ok());
assert_eq!(v_simd_owned.unwrap(), super::OwnedValue::from(v_simd_borrowed.unwrap()));
assert_eq!(v_simd_owned.expect("simd-error"), super::OwnedValue::from(v_simd_borrowed.expect("simd-error")));
}

}

0 comments on commit b4b9b85

Please sign in to comment.
You can’t perform that action at this time.