2382 Commits

Author SHA1 Message Date
Guillaume Gomez
00f9c7068d
Merge pull request #448 from Kijewski/pr-int-base
derive: don't suppress fatal errors in integer parsing
2025-05-19 13:07:37 +02:00
René Kijewski
359da68fa0 derive: don't suppress fatal errors in integer parsing 2025-05-19 11:59:37 +02:00
Guillaume Gomez
df2e35063f
Merge pull request #441 from Kijewski/pr-dependencies
Update dependencies
2025-05-19 11:31:29 +02:00
René Kijewski
e99f612391 Drive-by fixes 2025-05-18 23:06:42 +02:00
René Kijewski
75dd2c92f3 Update dependencies
* Update version-incompatible dependencies in examples.
* Update version-incompatible dev-dependencies.
* Replaced deprecated `criterion::black_box`.
* Add `features = "simd"` to `winnow`. This adds a transitive
  dependency to `memchr`, on which we already depend on directly.
2025-05-18 23:06:41 +02:00
René Kijewski
3e5562dc7c
derive: prefix more generated variables with __askama (#444)
* _did_loop → __askama_did_loop

* _iter → __askama_iter

* bool → askama::helpers::core::primitive::bool

* _loop_item → __askama_item
2025-05-18 23:05:18 +02:00
René Kijewski
3775f4e3a3 Use unicode-ident to determine what is an identifier
Resolves <https://github.com/askama-rs/askama/issues/442>.

The performance is actually slightly better than before. `unicode-ident`
is highly optimized and jump free.

One test from a fuzzer outcome had to be deleted, because it contained
identifiers that weren't actually identifiers. There is still a test
that tests the same problem, but every identifier is simply `x`. In
another fuzzed test a character [`U+E0049`] was removed.

[`U+E0049`]: https://en.wikipedia.org/w/index.php?oldid=1278382889

<details>
<summary>Benchmark results</summary>

```text
$ cd askama_parser && cargo bench

librustdoc/all          time:   [184.47 µs 185.30 µs 186.08 µs]
                        thrpt:  [75.887 MiB/s 76.207 MiB/s 76.548 MiB/s]
                 change:
                        time:   [−1.4364% −0.9672% −0.4738%] (p = 0.00 < 0.05)
                        thrpt:  [+0.4761% +0.9767% +1.4573%]
                        Change within noise threshold.

librustdoc/item_info    time:   [3.3880 µs 3.3892 µs 3.3906 µs]
                        thrpt:  [46.409 MiB/s 46.428 MiB/s 46.445 MiB/s]
                 change:
                        time:   [−3.8735% −3.5927% −3.2949%] (p = 0.00 < 0.05)
                        thrpt:  [+3.4071% +3.7266% +4.0296%]
                        Performance has improved.

librustdoc/item_union   time:   [20.052 µs 20.087 µs 20.126 µs]
                        thrpt:  [49.044 MiB/s 49.140 MiB/s 49.224 MiB/s]
                 change:
                        time:   [−2.2419% −1.8647% −1.5113%] (p = 0.00 < 0.05)
                        thrpt:  [+1.5345% +1.9002% +2.2933%]
                        Performance has improved.

librustdoc/page         time:   [85.828 µs 86.157 µs 86.518 µs]
                        thrpt:  [71.571 MiB/s 71.871 MiB/s 72.147 MiB/s]
                 change:
                        time:   [−1.2728% −0.7668% −0.2512%] (p = 0.00 < 0.05)
                        thrpt:  [+0.2518% +0.7727% +1.2892%]
                        Change within noise threshold.

librustdoc/print_item   time:   [10.065 µs 10.101 µs 10.138 µs]
                        thrpt:  [93.132 MiB/s 93.469 MiB/s 93.806 MiB/s]
                 change:
                        time:   [−3.3793% −2.8352% −2.3267%] (p = 0.00 < 0.05)
                        thrpt:  [+2.3821% +2.9180% +3.4975%]
                        Performance has improved.

librustdoc/short_item_info
                        time:   [9.0741 µs 9.1018 µs 9.1377 µs]
                        thrpt:  [99.148 MiB/s 99.540 MiB/s 99.843 MiB/s]
                 change:
                        time:   [−4.7480% −4.2335% −3.7763%] (p = 0.00 < 0.05)
                        thrpt:  [+3.9245% +4.4207% +4.9847%]
                        Performance has improved.

librustdoc/sidebar      time:   [21.468 µs 21.555 µs 21.648 µs]
                        thrpt:  [57.004 MiB/s 57.252 MiB/s 57.482 MiB/s]
                 change:
                        time:   [−3.7641% −3.0465% −2.4191%] (p = 0.00 < 0.05)
                        thrpt:  [+2.4791% +3.1423% +3.9114%]
                        Performance has improved.

librustdoc/source       time:   [7.9602 µs 7.9780 µs 7.9929 µs]
                        thrpt:  [92.230 MiB/s 92.403 MiB/s 92.609 MiB/s]
                 change:
                        time:   [−1.6386% −1.0684% −0.5875%] (p = 0.00 < 0.05)
                        thrpt:  [+0.5910% +1.0799% +1.6659%]
                        Change within noise threshold.

librustdoc/type_layout_size
                        time:   [4.7821 µs 4.7915 µs 4.8017 µs]
                        thrpt:  [56.406 MiB/s 56.526 MiB/s 56.637 MiB/s]
                 change:
                        time:   [−1.9743% −1.4867% −1.0153%] (p = 0.00 < 0.05)
                        thrpt:  [+1.0257% +1.5091% +2.0141%]
                        Performance has improved.

librustdoc/type_layout  time:   [15.022 µs 15.051 µs 15.076 µs]
                        thrpt:  [178.57 MiB/s 178.88 MiB/s 179.22 MiB/s]
                 change:
                        time:   [−1.5028% −1.0358% −0.5705%] (p = 0.00 < 0.05)
                        thrpt:  [+0.5738% +1.0466% +1.5257%]
                        Change within noise threshold.
```
</details>
2025-05-18 23:04:47 +02:00
Guillaume Gomez
37101cb95d
Merge pull request #440 from Kijewski/pr-fuzz-derive
Fuzz code generator, too
2025-05-18 00:01:43 +02:00
René Kijewski
e2aa22d423 ci: disable Cluster-Fuzz until there is a seed corpus for derive 2025-05-17 23:31:03 +02:00
René Kijewski
b716014612 Fuzz code generator, too 2025-05-17 23:21:45 +02:00
René Kijewski
e80b710f67 derive: add feature to disable all file system access
If you want to fuzz the code generator, it's essential that no local
files are accessed, e.g. through `{% import %}`.

This DOES NOT mean that the generated code is safe; this is not a
sandbox. The generated code can still contain

* evil compile-time code: `{{ include_str!("/etc/passwd") }}`
* evil runtime code: `{{ std::fs::remove_dir_all("/home/user") %}`

But during the code generation nothing potentially bad should happen.
2025-05-17 23:08:27 +02:00
René Kijewski
ab798e2482 Allow filters with explicit path
IMHO that makes custom filters much easier to use.
2025-05-17 13:20:54 +02:00
René Kijewski
6ce85f318c Make code generator re-usable for other projects
This PR
* removes the crate `askama_derive_standalone`,
* makes `askama_derive` a normal library, and
* adds the proc-macro crate `askama_macros`,

Before, it was not possible for another crate to re-export
`askama::Template` in a useful way, because the generated code assumes
that it has access to an `extern crate askama`.

`askama_derive` will export the function `derive_template()` like
`askama_derive_standalone` did, but it has an additional argument to
accept a `TokenStream` that should contain (an) statement(s) to define
the identifier `askama`, e.g. `quote! { extern crate askama; }`.

The new proc-macro crate `askama_macros` now defines the derive-macro
`Template` by calling `askama_derive::derive_template()`.

Prior art: [`encase`] → [`encase_derive`] → [`encase_derive_impl`];
[2298a3e].

[`encase`]: <https://crates.io/crates/encase/0.11.0>
[`encase_derive`]: <https://crates.io/crates/encase_derive/0.11.0>
[`encase_derive_impl`]: <https://crates.io/crates/encase_derive_impl/0.11.0>
[2298a3e]: <2298a3efd5>
2025-05-17 13:20:21 +02:00
Guillaume Gomez
428ff19932
Merge pull request #436 from Kijewski/pr-no-loop-first
`loop.first` is known by being at `index == 0`
2025-05-17 11:49:05 +02:00
Guillaume Gomez
38455c46d7
Merge pull request #437 from Kijewski/pr-more-fuzz
Fuzz more filters
2025-05-17 11:48:37 +02:00
René Kijewski
0ad2a3d973 Fuzz more filters
Added: `|escape`, `|filesizeformat`, `|join`, `|json`, `|json(..)`,
`|unique`, and `|wordcount`.
2025-05-16 16:23:20 +02:00
René Kijewski
73e8559ca7 loop.first is known by being at index == 0 2025-05-16 16:08:01 +02:00
Guillaume Gomez
d23c5b2f3e
Merge pull request #438 from Kijewski/pr-clippy
Fix new clippy warnings in rust 1.89
2025-05-16 10:13:37 +02:00
René Kijewski
ed216e5b2c Fix new clippy warnings in rust 1.89 2025-05-16 03:26:19 +02:00
Guillaume Gomez
150becaf0f
Merge pull request #433 from Kijewski/pr-linguist
Ignore fuzzing corpus from source line count
2025-05-13 07:43:27 +02:00
René Kijewski
077b83631a Ignore fuzzing corpus from source line count
Github's language statistics for the project say that 43% of askama is
assembly code. It is not. The heuristic counts our fuzzing corpus as
assembly code, and the corpus is quite big.

This PR excludes the corpus from being counted.
2025-05-12 18:38:43 +02:00
C0D3 M4513R
c31fce773e
Relax Sized constraint on impl FastWritable for Cow (#432)
* Add test to ensure `Cow<'_, str>` implements `FastWritable`

* Relax Sized constraint on `impl FastWritable for Cow`

* Run rustfmt

Signed-off-by: C0D3 M4513R <28912031+C0D3-M4513R@users.noreply.github.com>

* Put "test" in a const block.

* Update cow_str_implements_fast_writable.rs

Co-authored-by: René Kijewski <Kijewski@users.noreply.github.com>

---------

Signed-off-by: C0D3 M4513R <28912031+C0D3-M4513R@users.noreply.github.com>
Co-authored-by: René Kijewski <Kijewski@users.noreply.github.com>
2025-05-07 17:11:45 +02:00
Guillaume Gomez
73ba176ad5
Merge pull request #426 from Kijewski/pr-ensure_no_named_arguments
generator: fix `ensure_no_named_arguments()` test
2025-05-02 11:13:29 +02:00
Guillaume Gomez
4a7de4fde4
Merge pull request #427 from Kijewski/pr-remove-zizmor
ci: remove zizmor test
2025-05-02 11:13:02 +02:00
René Kijewski
979f9d8ef4 ci: remove zizmor test
It was a small script to test common Github action config errors, but
IMHO it became more opinionated with every release. No, I won't add a
hashsum to every `uses` line, thank you for asking again and again.

Also, it takes 3 minutes to build by now. 3 minutes until the first real
test is executed.
2025-05-02 01:09:35 +02:00
René Kijewski
a7c55f77fe generator: fix ensure_no_named_arguments() test
The wrong `Expr` variant was tested.
2025-05-02 00:54:18 +02:00
Guillaume Gomez
90d1a71801
Merge pull request #423 from m4tx/fix-function-docs
chore: fix tiny wording error in "Calling functions" docs
2025-04-30 18:19:14 +02:00
Mateusz Maćkowski
44c67d3ba1
chore: fix tiny wording error in "Calling functions" docs 2025-04-30 18:15:21 +02:00
Guillaume Gomez
9b41bb9ff5
Merge pull request #421 from Kijewski/pr-inline
Add missing `#[inline]` annotations
2025-04-29 11:49:37 +02:00
René Kijewski
01e9d3c640 Add missing #[inline] annotations 2025-04-27 21:30:19 +02:00
René Kijewski
bf5e066b68 generator: remove invisible group from output
The generated `TokenStream` gets parsed correctly by `rustc`, but fails
to be parsed by `syn` in some circumstances. E.g. the template syntax
`test {#` lets the playground crash.

This PR removes the invisible group.
2025-04-26 22:24:26 +02:00
dependabot[bot]
3cdc0ea4c1 build(deps): bump astral-sh/setup-uv from 5 to 6
Bumps [astral-sh/setup-uv](https://github.com/astral-sh/setup-uv) from 5 to 6.
- [Release notes](https://github.com/astral-sh/setup-uv/releases)
- [Commits](https://github.com/astral-sh/setup-uv/compare/v5...v6)

---
updated-dependencies:
- dependency-name: astral-sh/setup-uv
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-04-25 01:17:27 +02:00
Guillaume Gomez
95867ac8ce
Merge pull request #416 from Kijewski/pr-upgrading-0.14
Get ready for v0.14.0
v0.14.0
2025-04-23 15:12:34 +02:00
René Kijewski
61b7422497 Add |titlecase as alias for |title 2025-04-22 23:37:23 +02:00
René Kijewski
79be271593 Run doctests 2025-04-22 23:37:23 +02:00
René Kijewski
72bbe3ede1 Bump version number to v0.14.0 2025-04-22 23:37:23 +02:00
René Kijewski
57750338fa book: update upgrading.md 2025-04-22 23:37:23 +02:00
Guillaume Gomez
a5b43c0aa2 Fix unique filter implementation 2025-04-22 23:36:56 +02:00
Guillaume Gomez
7fccbdf1d7 Remove usage of nextest 2025-04-22 11:34:55 +02:00
Guillaume Gomez
6a16256f24 Fix new clippy lints 2025-04-22 11:34:55 +02:00
Guillaume Gomez
04a4d5b020 Update MSRV to 1.83 2025-04-22 11:34:55 +02:00
Guillaume Gomez
d2a788a740 Add doc about unique filter 2025-04-22 11:34:55 +02:00
Guillaume Gomez
d0d23cad0b Add unique filter 2025-04-22 11:34:55 +02:00
Guillaume Gomez
6f912abee6 Move FastWritable into askama root 2025-04-22 11:33:57 +02:00
Guillaume Gomez
7c5deda4c1 Rename pluralize arguments into singular and plural 2025-04-21 23:11:24 +02:00
René Kijewski
6cea91a9b5 Update book page about filters 2025-04-21 23:11:24 +02:00
René Kijewski
b402936db3 generator: add named arguments for filters 2025-04-21 23:11:24 +02:00
René Kijewski
6f8de0ca84 generator: fix test for filters that need alloc 2025-04-21 23:11:24 +02:00
René Kijewski
4be302338a generator: do argument coercion for |truncate / |center
Don't simply pass any arguments to the filter. The error message won't
be useful otherwise. Also ensure that the argument is a `usize`.
2025-04-21 23:11:24 +02:00
René Kijewski
de9d6b7d0e generator: BUILTIN_FILTERS_NEED_ALLOC should check built-in filters 2025-04-21 23:11:24 +02:00