Merge branch 'release/v0.3.2' into stable2
This commit is contained in:
commit
b61ca07056
18
CHANGELOG.md
18
CHANGELOG.md
|
@ -1,3 +1,21 @@
|
|||
<a name="v0.3.2"></a>
|
||||
## [v0.3.2](https://github.com/Kogia-sima/sailfish/compare/v0.3.1...v0.3.2) (2021-03-29)
|
||||
|
||||
## Fix
|
||||
|
||||
* Avoid sable/nightly mismatch error caused by proc-macro2 crate
|
||||
|
||||
<a name="v0.3.1"></a>
|
||||
## [v0.3.1](https://github.com/Kogia-sima/sailfish/compare/v0.3.0...v0.3.1) (2021-01-23)
|
||||
|
||||
## New Features
|
||||
|
||||
* Allow unsized types for filters
|
||||
|
||||
## Fix
|
||||
|
||||
* Workaround for incorrect cargo fingerprints
|
||||
|
||||
<a name="v0.3.0"></a>
|
||||
## [v0.3.0](https://github.com/Kogia-sima/sailfish/compare/v0.2.2...v0.3.0) (2020-12-20)
|
||||
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "ansi_term"
|
||||
version = "0.11.0"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
|
||||
checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
@ -32,10 +32,10 @@ dependencies = [
|
|||
]
|
||||
|
||||
[[package]]
|
||||
name = "difference"
|
||||
version = "2.0.0"
|
||||
name = "diff"
|
||||
version = "0.1.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198"
|
||||
checksum = "0e25ea47919b1560c4e3b7fe0aaab9becf5b84a10325ddf7db0f0ba5e1026499"
|
||||
|
||||
[[package]]
|
||||
name = "filetime"
|
||||
|
@ -66,7 +66,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "integration-tests"
|
||||
version = "0.3.1"
|
||||
version = "0.3.2"
|
||||
dependencies = [
|
||||
"pretty_assertions",
|
||||
"sailfish",
|
||||
|
@ -84,9 +84,9 @@ checksum = "b8b7a7c0c47db5545ed3fef7468ee7bb5b74691498139e4b3f6a20685dc6dd8e"
|
|||
|
||||
[[package]]
|
||||
name = "itoap"
|
||||
version = "0.1.0"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e804a5759b475f44377998918a7e3be9da3767056f5e77751ef7803893db0e9"
|
||||
checksum = "9028f49264629065d057f340a86acb84867925865f73bbf8d47b4d149a7e88b8"
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
|
@ -123,13 +123,13 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "pretty_assertions"
|
||||
version = "0.6.1"
|
||||
version = "0.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f81e1644e1b54f5a68959a29aa86cde704219254669da328ecfdf6a1f09d427"
|
||||
checksum = "f297542c27a7df8d45de2b0e620308ab883ad232d06c14b76ac3e144bda50184"
|
||||
dependencies = [
|
||||
"ansi_term",
|
||||
"ctor",
|
||||
"difference",
|
||||
"diff",
|
||||
"output_vt100",
|
||||
]
|
||||
|
||||
|
@ -168,7 +168,7 @@ checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
|
|||
|
||||
[[package]]
|
||||
name = "sailfish"
|
||||
version = "0.3.1"
|
||||
version = "0.3.2"
|
||||
dependencies = [
|
||||
"itoap",
|
||||
"ryu",
|
||||
|
@ -180,7 +180,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "sailfish-compiler"
|
||||
version = "0.3.1"
|
||||
version = "0.3.2"
|
||||
dependencies = [
|
||||
"filetime",
|
||||
"home",
|
||||
|
@ -194,7 +194,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "sailfish-macros"
|
||||
version = "0.3.1"
|
||||
version = "0.3.2"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"sailfish-compiler",
|
||||
|
|
|
@ -32,7 +32,7 @@ Dependencies:
|
|||
|
||||
```toml
|
||||
[dependencies]
|
||||
sailfish = "0.3.1"
|
||||
sailfish = "0.3.2"
|
||||
```
|
||||
|
||||
Template file (templates/hello.stpl):
|
||||
|
|
|
@ -4,7 +4,7 @@ In order to use sailfish templates, you have add two dependencies in your `Cargo
|
|||
|
||||
``` toml
|
||||
[dependencies]
|
||||
sailfish = "0.3.1"
|
||||
sailfish = "0.3.2"
|
||||
```
|
||||
|
||||
## Feature Flags
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "sailfish-examples"
|
||||
version = "0.3.1"
|
||||
version = "0.3.2"
|
||||
authors = ["Ryohei Machida <orcinus4627@gmail.com>"]
|
||||
edition = "2018"
|
||||
publish = false
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "sailfish-compiler"
|
||||
version = "0.3.1"
|
||||
version = "0.3.2"
|
||||
authors = ["Ryohei Machida <orcinus4627@gmail.com>"]
|
||||
description = "Really fast, intuitive template engine for Rust"
|
||||
homepage = "https://github.com/Kogia-sima/sailfish"
|
||||
|
@ -39,4 +39,4 @@ default-features = false
|
|||
features = ["span-locations"]
|
||||
|
||||
[dev-dependencies]
|
||||
pretty_assertions = "0.6.1"
|
||||
pretty_assertions = "0.7.1"
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
use crate::error::*;
|
||||
use syn::visit_mut::VisitMut;
|
||||
use syn::Block;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Analyzer {}
|
||||
|
||||
impl Analyzer {
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn analyze(&self, ast: &mut Block) -> Result<(), Error> {
|
||||
let mut child = AnalyzerImpl { error: None };
|
||||
child.visit_block_mut(ast);
|
||||
|
||||
if let Some(e) = child.error {
|
||||
Err(e)
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct AnalyzerImpl {
|
||||
error: Option<Error>,
|
||||
}
|
||||
|
||||
impl VisitMut for AnalyzerImpl {
|
||||
// write code here
|
||||
}
|
|
@ -5,6 +5,7 @@ use std::path::{Path, PathBuf};
|
|||
use std::sync::Arc;
|
||||
use syn::Block;
|
||||
|
||||
use crate::analyzer::Analyzer;
|
||||
use crate::config::Config;
|
||||
use crate::error::*;
|
||||
use crate::optimizer::Optimizer;
|
||||
|
@ -57,6 +58,7 @@ impl Compiler {
|
|||
});
|
||||
|
||||
let resolver = Resolver::new().include_handler(include_handler);
|
||||
let analyzer = Analyzer::new();
|
||||
let optimizer = Optimizer::new().rm_whitespace(self.config.rm_whitespace);
|
||||
|
||||
let compile_file = |input: &Path,
|
||||
|
@ -68,6 +70,7 @@ impl Compiler {
|
|||
let r = resolver.resolve(&*input, &mut tsource.ast)?;
|
||||
report.deps = r.deps;
|
||||
|
||||
analyzer.analyze(&mut tsource.ast)?;
|
||||
optimizer.optimize(&mut tsource.ast);
|
||||
|
||||
if let Some(parent) = output.parent() {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#[macro_use]
|
||||
mod error;
|
||||
|
||||
mod analyzer;
|
||||
mod compiler;
|
||||
mod config;
|
||||
mod optimizer;
|
||||
|
|
|
@ -130,7 +130,29 @@ fn compile(
|
|||
output_file: &Path,
|
||||
config: Config,
|
||||
) -> Result<CompilationReport, Error> {
|
||||
struct FallbackScope {}
|
||||
|
||||
impl FallbackScope {
|
||||
fn new() -> Self {
|
||||
// SAFETY:
|
||||
// Any token or span constructed after `proc_macro2::fallback::force()` must
|
||||
// not outlive after `unforce()` because it causes span mismatch error. In
|
||||
// this case, we must ensure that `compile_file` does not return any token or
|
||||
// span.
|
||||
proc_macro2::fallback::force();
|
||||
FallbackScope {}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for FallbackScope {
|
||||
fn drop(&mut self) {
|
||||
proc_macro2::fallback::unforce();
|
||||
}
|
||||
}
|
||||
|
||||
let compiler = Compiler::with_config(config);
|
||||
|
||||
let _scope = FallbackScope::new();
|
||||
compiler.compile_file(input_file, &*output_file)
|
||||
}
|
||||
|
||||
|
|
|
@ -227,7 +227,6 @@ impl SourceBuilder {
|
|||
|
||||
pub fn finalize(mut self) -> Result<TranslatedSource, Error> {
|
||||
self.source.push_str("\n}");
|
||||
proc_macro2::fallback::force();
|
||||
match syn::parse_str::<Block>(&*self.source) {
|
||||
Ok(ast) => Ok(TranslatedSource {
|
||||
ast,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "sailfish-macros"
|
||||
version = "0.3.1"
|
||||
version = "0.3.2"
|
||||
authors = ["Ryohei Machida <orcinus4627@gmail.com>"]
|
||||
description = "Really fast, intuitive template engine for Rust"
|
||||
homepage = "https://github.com/Kogia-sima/sailfish"
|
||||
|
@ -30,6 +30,6 @@ proc-macro2 = "1.0.11"
|
|||
|
||||
[dependencies.sailfish-compiler]
|
||||
path = "../sailfish-compiler"
|
||||
version = "0.3.1"
|
||||
version = "0.3.2"
|
||||
default-features = false
|
||||
features = ["procmacro"]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "fuzzing-tests"
|
||||
version = "0.3.1"
|
||||
version = "0.3.2"
|
||||
authors = ["Ryohei Machida <orcinus4627@gmail.com>"]
|
||||
edition = "2018"
|
||||
publish = false
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "integration-tests"
|
||||
version = "0.3.1"
|
||||
version = "0.3.2"
|
||||
authors = ["Kogia-sima <orcinus4627@gmail.com>"]
|
||||
edition = "2018"
|
||||
publish = false
|
||||
|
@ -13,4 +13,4 @@ serde_json = "1.0.53"
|
|||
|
||||
[dev-dependencies]
|
||||
trybuild = "1.0.28"
|
||||
pretty_assertions = "0.6.1"
|
||||
pretty_assertions = "0.7.1"
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
use sailfish::TemplateOnce;
|
||||
use sailfish_macros::TemplateOnce;
|
||||
|
||||
#[derive(TemplateOnce)]
|
||||
#[template(path = "empty.stpl")]
|
||||
struct ExistTemplate;
|
||||
|
||||
#[derive(TemplateOnce)]
|
||||
#[template(path = "not_exist.stpl")]
|
||||
struct NotExistTemplate {
|
||||
var: usize
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("{}", ExistTemplate.render_once().unwrap());
|
||||
println!("{}", NotExistTemplate { var: 1996 }.render_once().unwrap());
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
error: Template file "not_exist.stpl" not found
|
||||
--> $DIR/template_not_found.rs:9:19
|
||||
|
|
||||
9 | #[template(path = "not_exist.stpl")]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0599]: no method named `render_once` found for struct `NotExistTemplate` in the current scope
|
||||
--> $DIR/template_not_found.rs:16:51
|
||||
|
|
||||
10 | struct NotExistTemplate {
|
||||
| ----------------------- method `render_once` not found for this
|
||||
...
|
||||
16 | println!("{}", NotExistTemplate { var: 1996 }.render_once().unwrap());
|
||||
| ^^^^^^^^^^^ method not found in `NotExistTemplate`
|
||||
|
|
||||
= help: items from traits can only be used if the trait is implemented and in scope
|
||||
= note: the following trait defines an item `render_once`, perhaps you need to implement it:
|
||||
candidate #1: `TemplateOnce`
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "sailfish"
|
||||
version = "0.3.1"
|
||||
version = "0.3.2"
|
||||
authors = ["Ryohei Machida <orcinus4627@gmail.com>"]
|
||||
description = "Really fast, intuitive template engine for Rust"
|
||||
homepage = "https://github.com/Kogia-sima/sailfish"
|
||||
|
@ -22,14 +22,14 @@ json = ["serde", "serde_json"]
|
|||
perf-inline = []
|
||||
|
||||
[dependencies]
|
||||
itoap = "0.1.0"
|
||||
itoap = "1.0.1"
|
||||
ryu = "1.0.4"
|
||||
serde = { version = "1.0.111", optional = true }
|
||||
serde_json = { version = "1.0.53", optional = true }
|
||||
|
||||
[dependencies.sailfish-macros]
|
||||
path = "../sailfish-macros"
|
||||
version = "0.3.1"
|
||||
version = "0.3.2"
|
||||
optional = true
|
||||
|
||||
[build-dependencies]
|
||||
|
|
|
@ -136,12 +136,12 @@ impl Buffer {
|
|||
pub fn push_str(&mut self, data: &str) {
|
||||
let size = data.len();
|
||||
|
||||
// NOTE: Since there's no guarantee that the maximum slice size won't overflow
|
||||
// isize::MAX, we must call `reserve()` instead of `reserve_small()`. See
|
||||
// https://github.com/rust-lang/rust/pull/79930#issuecomment-747135498 for more
|
||||
// details.
|
||||
self.reserve(size);
|
||||
unsafe {
|
||||
// SAFETY: this operation won't overflow because slice cannot exceeds
|
||||
// isize::MAX bytes.
|
||||
// https://doc.rust-lang.org/reference/behavior-considered-undefined.html
|
||||
self.reserve_small(size);
|
||||
|
||||
let p = self.data.add(self.len);
|
||||
std::ptr::copy_nonoverlapping(data.as_ptr(), p, size);
|
||||
self.len += size;
|
||||
|
@ -162,7 +162,6 @@ impl Buffer {
|
|||
}
|
||||
|
||||
#[cfg_attr(feature = "perf-inline", inline)]
|
||||
#[cold]
|
||||
fn reserve_internal(&mut self, size: usize) {
|
||||
debug_assert!(size <= std::isize::MAX as usize);
|
||||
|
||||
|
|
|
@ -89,6 +89,7 @@ pub(super) unsafe fn escape_small(feed: &str, mut buf: *mut u8) -> usize {
|
|||
buf as usize - buf_begin as usize
|
||||
}
|
||||
|
||||
#[cfg(any(target_arch = "x86_64", target_arch = "x86", target_arch = "aarch64"))]
|
||||
#[inline]
|
||||
pub(super) unsafe fn push_escaped_str(value: &str, buffer: &mut Buffer) {
|
||||
buffer.reserve_small(value.len());
|
||||
|
@ -105,3 +106,9 @@ pub(super) unsafe fn push_escaped_str(value: &str, buffer: &mut Buffer) {
|
|||
|
||||
buffer._set_len(buffer.len() + value.len());
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_arch = "x86_64", target_arch = "x86", target_arch = "aarch64")))]
|
||||
#[inline]
|
||||
pub(super) unsafe fn push_escaped_str(value: &str, buffer: &mut Buffer) {
|
||||
buffer.push_str(value);
|
||||
}
|
||||
|
|
|
@ -38,8 +38,10 @@ macro_rules! unlikely {
|
|||
};
|
||||
}
|
||||
|
||||
/// memcpy implementation based on glibc (https://github.molgen.mpg.de/git-mirror/glibc/blob/master/sysdeps/x86_64/multiarch/memcpy-avx-unaligned.S)
|
||||
/// Custom memcpy implementation is faster on some platforms
|
||||
/// implementation based on glibc (https://github.molgen.mpg.de/git-mirror/glibc/blob/master/sysdeps/x86_64/multiarch/memcpy-avx-unaligned.S)
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
#[cfg(any(target_arch = "x86_64", target_arch = "x86", target_arch = "aarch64"))]
|
||||
pub unsafe fn memcpy_16(src: *const u8, dst: *mut u8, len: usize) {
|
||||
debug_assert!(len <= 16);
|
||||
let len_u8 = len as u8;
|
||||
|
@ -66,3 +68,10 @@ pub unsafe fn memcpy_16(src: *const u8, dst: *mut u8, len: usize) {
|
|||
*dst = *src;
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(any(
|
||||
target_arch = "x86_64",
|
||||
target_arch = "x86",
|
||||
target_arch = "aarch64"
|
||||
)))]
|
||||
pub use ptr::copy_nonoverlapping as memcpy_16;
|
||||
|
|
|
@ -3,8 +3,8 @@ unlet b:current_syntax
|
|||
|
||||
syn include @rustSyntax syntax/rust.vim
|
||||
|
||||
syn region sailfishCodeBlock contained matchgroup=sailfishTag start=/<%/ keepend end=/%>/ contains=@rustSyntax
|
||||
syn region sailfishBufferBlock contained matchgroup=sailfishTag start=/<%=/ keepend end=/%>/ contains=@rustSyntax
|
||||
syn region sailfishCodeBlock matchgroup=sailfishTag start=/<%/ keepend end=/%>/ contains=@rustSyntax
|
||||
syn region sailfishBufferBlock matchgroup=sailfishTag start=/<%=/ keepend end=/%>/ contains=@rustSyntax
|
||||
syn region sailfishCommentBlock start=/<%#/ end=/%>/
|
||||
|
||||
" Redefine htmlTag so that it can contain jspExpr
|
||||
|
|
Loading…
Reference in New Issue