45 Commits

Author SHA1 Message Date
René Kijewski
f62cdfb49a derive: better spans for Target 2025-08-06 19:11:26 +02:00
René Kijewski
e1eeb815ea derive: minor macro clean-ups
* prefix temporaries in `{{ expr }}` with `__askama`
* replace custom `spanned!(..)` with `quote_spanned!(..)`
* replace `buf.write_tokens(quote_spanned!(..))` with `quote_into!(..)`
2025-08-06 19:11:26 +02:00
René Kijewski
693f86d1c4 derive: don't use format_args! for code formatting
* No need to manually escape raw identifiers
* Allow a few warnings
2025-08-06 19:11:26 +02:00
Guillaume Gomez
80a4af7f2d Generate a TokenStream rather than a String 2025-08-06 19:11:26 +02:00
René Kijewski
b8e11e86b6 parser/derive: replaces usages of Expr/Node with Box<Expr>/Box<Node>
This means that there is much less copying of data done at runtime.

Two new `unsafe` transmutations had to be added, both in the same
function, because even though `&T` and `Box<T>` have the same layout,
rust currently rejects any `Box`es in a `const` value. Miri is happy
with `askama_derive`'s tests.

<details>
<summary>askama_derive benchmark</summary>

```text
synthetic/hello_world   time:   [35.108 µs 35.271 µs 35.412 µs]
                        thrpt:  [1.3735 MiB/s 1.3790 MiB/s 1.3854 MiB/s]
                 change:
                        time:   [−6.2826% −5.1769% −4.1151%] (p = 0.00 < 0.05)
                        thrpt:  [+4.2917% +5.4595% +6.7038%]
                        Performance has improved.

librustdoc/item_info.html
                        time:   [39.687 µs 39.957 µs 40.186 µs]
                        thrpt:  [3.9157 MiB/s 3.9381 MiB/s 3.9649 MiB/s]
                 change:
                        time:   [−3.5603% −2.5102% −1.3793%] (p = 0.00 < 0.05)
                        thrpt:  [+1.3986% +2.5749% +3.6917%]
                        Performance has improved.

librustdoc/item_union.html
                        time:   [101.64 µs 101.95 µs 102.27 µs]
                        thrpt:  [9.6516 MiB/s 9.6818 MiB/s 9.7111 MiB/s]
                 change:
                        time:   [−4.0638% −3.5966% −3.1652%] (p = 0.00 < 0.05)
                        thrpt:  [+3.2686% +3.7307% +4.2359%]
                        Performance has improved.

librustdoc/page.html    time:   [379.80 µs 381.74 µs 383.65 µs]
                        thrpt:  [16.140 MiB/s 16.221 MiB/s 16.304 MiB/s]
                 change:
                        time:   [−6.6429% −5.2611% −4.3384%] (p = 0.00 < 0.05)
                        thrpt:  [+4.5351% +5.5533% +7.1156%]
                        Performance has improved.

librustdoc/print_item.html
                        time:   [88.483 µs 88.849 µs 89.313 µs]
                        thrpt:  [10.571 MiB/s 10.626 MiB/s 10.670 MiB/s]
                 change:
                        time:   [−2.5658% −2.0639% −1.5517%] (p = 0.00 < 0.05)
                        thrpt:  [+1.5761% +2.1074% +2.6333%]
                        Performance has improved.

librustdoc/short_item_info.html
                        time:   [90.028 µs 90.157 µs 90.281 µs]
                        thrpt:  [10.035 MiB/s 10.049 MiB/s 10.063 MiB/s]
                 change:
                        time:   [−2.4814% −1.9435% −1.3640%] (p = 0.00 < 0.05)
                        thrpt:  [+1.3829% +1.9821% +2.5445%]
                        Performance has improved.

librustdoc/sidebar.html time:   [106.91 µs 108.17 µs 109.57 µs]
                        thrpt:  [11.263 MiB/s 11.408 MiB/s 11.543 MiB/s]
                 change:
                        time:   [−4.2433% −3.3985% −2.6066%] (p = 0.00 < 0.05)
                        thrpt:  [+2.6763% +3.5181% +4.4314%]
                        Performance has improved.

librustdoc/source.html  time:   [71.149 µs 71.416 µs 71.652 µs]
                        thrpt:  [10.289 MiB/s 10.322 MiB/s 10.361 MiB/s]
                 change:
                        time:   [−2.7381% −2.1144% −1.5588%] (p = 0.00 < 0.05)
                        thrpt:  [+1.5835% +2.1601% +2.8152%]
                        Performance has improved.

librustdoc/type_layout.html
                        time:   [88.405 µs 88.920 µs 89.595 µs]
                        thrpt:  [30.049 MiB/s 30.277 MiB/s 30.453 MiB/s]
                 change:
                        time:   [+0.6665% +1.8855% +3.0267%] (p = 0.00 < 0.05)
                        thrpt:  [−2.9378% −1.8506% −0.6621%]
                        Change within noise threshold.

librustdoc/type_layout_size.html
                        time:   [44.048 µs 44.246 µs 44.398 µs]
                        thrpt:  [6.1004 MiB/s 6.1213 MiB/s 6.1488 MiB/s]
                 change:
                        time:   [−5.8376% −4.9477% −4.0335%] (p = 0.00 < 0.05)
                        thrpt:  [+4.2030% +5.2052% +6.1996%]
                        Performance has improved.
```
</details>
2025-07-25 23:44:34 +02:00
René Kijewski
bbf9d1c234 derive: remove parentheses before handling {{ (expr) }} 2025-07-24 16:53:51 +02:00
René Kijewski
bbb2932da2 derive: un-inline Expr::Call handling for {{ expressions }}
This is by far the biggest part of the function.
2025-07-24 16:27:55 +02:00
René Kijewski
78c0ab97bf derive: make EvaluatedResult know its unknown result
This PR adds a `WithSpan<Expr>` member to `EvaluatedResult::Unknown`,
so `Generator::evaluate_condition()` does not have to return a tuple.
2025-07-23 14:45:43 +02:00
René Kijewski
a37d9f5a90 derive: more if-let 2025-07-21 20:43:46 +02:00
Markus Ebner
53ddd3cfc3 Fix #517: Implement expr-call syntax for macro invocations 2025-07-21 16:55:31 +02:00
Markus Ebner
fcf793c35a generator: Move macro invocation code generation to helper module
Introduced a new helpers module where code generation can be placed.
For this, some generator methods had to become pub(crate) instead of private.
2025-07-21 16:55:31 +02:00
Guillaume Gomez
0d256b011d Support generics in more locations 2025-07-21 00:38:55 +02:00
Guillaume Gomez
9e32a28d11 Improve Span information 2025-07-20 16:27:23 +02:00
René Kijewski
f201285ede Use if-let-chains
I ran `cargo +nightly clippy --all-targets --fix  -- -D warnings` and
made only tiny manual improvements.
2025-07-13 23:16:26 +02:00
Markus Ebner
d50cb4fcb7
Fix #505 and 507 - Treat caller() as local variable with aliasing 2025-07-05 03:21:34 +02:00
Markus Ebner
fca6e6f78b
Switch Rust edition of askama_derive to 2024 2025-07-05 03:21:34 +02:00
Markus Ebner
89c4488b66
Prepare local chainmap for caller aliasing 2025-07-05 03:20:10 +02:00
Guillaume Gomez
ca6573bf56 Rename Expr::Attr into Expr::AssociatedItem 2025-06-24 14:09:34 +02:00
René Kijewski
338369a424 parser: box Expr::Filter to reduce Expr's size 2025-06-24 12:21:41 +02:00
René Kijewski
2086d4f898 parser: introduce askama_parser::expr::Call 2025-06-24 12:21:41 +02:00
René Kijewski
49d4397f51 parser: introduce askama_parser::expr::Range 2025-06-24 12:21:41 +02:00
René Kijewski
9f882e2ca7 parser: introduce askama_parser::expr::BinOp 2025-06-24 12:21:41 +02:00
René Kijewski
72b9005cb5 filter: modify reject a bit
* Re-use iterator getting from `{% for %}`'s implementation
* Don't use edition 2024 features
2025-06-06 15:48:04 +02:00
René Kijewski
d181493084 Fix clippy warning 2025-06-05 18:45:51 +02:00
Michael Pollind
df54534ae6 bugfix: resolve with macro with call after caller
https://github.com/askama-rs/askama/issues/467

Signed-off-by: Michael Pollind <mpollind@gmail.com>
2025-06-01 21:05:06 +02:00
Guillaume Gomez
9ee2afecfa Add support for mutable variables 2025-06-01 16:26:57 +02:00
Guillaume Gomez
1acbc33383 Improve error output 2025-05-22 23:11:46 +02:00
Guillaume Gomez
3ab930ded0 Fix handling of endcall whitespace characters 2025-05-22 22:50:40 +02:00
Michael Pollind
f08ca469c9 add more test add reserved word caller
Signed-off-by: Michael Pollind <mpollind@gmail.com>
2025-05-22 22:50:40 +02:00
Michael Pollind
83057d8f30 Update askama_derive/src/generator/node.rs
Co-authored-by: Guillaume Gomez <guillaume1.gomez@gmail.com>
2025-05-22 22:50:40 +02:00
Michael Pollind
0547c2ee88 fix caller logic
Signed-off-by: Michael Pollind <mpollind@gmail.com>
2025-05-22 22:50:40 +02:00
Michael Pollind
b328a96ca4 simplify handler
Signed-off-by: Michael Pollind <mpollind@gmail.com>
2025-05-22 22:50:40 +02:00
Michael Pollind
ef489b60f6 add test cases and rework spaces
Signed-off-by: Michael Pollind <mpollind@gmail.com>
2025-05-22 22:50:40 +02:00
Michael Pollind
5c07ea6842 address comments
Signed-off-by: Michael Pollind <mpollind@gmail.com>
2025-05-22 22:50:40 +02:00
Michael Pollind
ce73e73720 feat: add caller pattern and adjust syntax to closer match jinja
Signed-off-by: Michael Pollind <mpollind@gmail.com>
2025-05-22 22:50:40 +02:00
Michael Pollind
b8c85a07bd feat: add caller pattern for macro
Signed-off-by: Michael Pollind <mpollind@gmail.com>
2025-05-22 22:50:39 +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
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
ed216e5b2c Fix new clippy warnings in rust 1.89 2025-05-16 03:26:19 +02:00
Guillaume Gomez
6a16256f24 Fix new clippy lints 2025-04-22 11:34:55 +02:00
René Kijewski
b402936db3 generator: add named arguments for filters 2025-04-21 23:11:24 +02:00
René Kijewski
4fe13a0053 generator: add missing lifetimes 2025-04-21 23:11:24 +02:00
Guillaume Gomez
ddfdd20855 Do not put question mark initialization expressions behind a reference 2025-04-12 21:52:14 +02:00
Guillaume Gomez
8081d717d3 If using local variable as value when creating a new variable, do not put it behind a reference 2025-04-11 07:19:59 +02:00
Guillaume Gomez
3b52c907c3 Rename rinja into askama 2025-03-11 19:31:06 +01:00