163 Commits

Author SHA1 Message Date
chriseth
2b2006d6db Emit rerun directives so that we only re-build the parser if the grammar changed. (#3195) 2025-08-19 11:03:25 +00:00
Steve Wang
ce10fe7180 Refactor public declaration and public reference (#2516)
Started as a small fix but expanded to a complete refactoring of
`PublicDeclaration` and `PublicReference`.

Now public reference work the same way as any reference and the syntax
is without the colon (`:out` -> `out`). `PublicDeclaration` are also put
under definitions in the analyzer. Both public reference and public
declaration use the absolute path, so it's easy to refer from one to the
other now.

This is needed for #2502 to match public reference to public declaration
in the backend. Currently, different namespaces can have public
references with the same name, and it will confuse the backend on which
public reference value to fetch.
2025-03-12 16:06:12 +00:00
Thibaut Schaeffer
ad858a1d7d Run cargo bench in PR CI tests and report result to PR and Github Pages (#2198)
Run benchmarks in PRs, fail and warn on the PR if we got more than 20%
slower, add benchmark results to https://docs.powdr.org/dev/bench/
2024-12-09 14:51:20 +00:00
Thibaut Schaeffer
c0fefae3e7 Introduce workspace-level lints (#2166)
Reduce the cost of adding a lint from O(#workspace_crates) to 1.
2024-11-29 14:02:53 +00:00
Thibaut Schaeffer
0613456c66 Remove fixed polynomial declarations (#2126)
```rust
pol fixed A;
```

bans this ☝️
2024-11-22 14:18:47 +00:00
Thibaut Schaeffer
8652a88d45 Make all SourceRef equal (#2103)
When comparing pil expressions, the source information gets in the way.
Experiment with ignoring it when comparing.
This respects the requirements
[here](https://doc.rust-lang.org/std/cmp/trait.PartialEq.html)
2024-11-21 09:42:55 +00:00
Georg Wiese
2c1acf8b09 Block Machine: Handle case where number of rows is just enough (#2070)
Before this PR, we used to panic if the number of rows in a block
machine was just enough to fit the needed number of blocks. This PR
fixes it.
2024-11-18 13:29:24 +00:00
Gastón Zanitti
d4767fe1cf SourceRef: path_canonilizer (includes Param) (#1998)
Add source references for path_canonilizer. Also, as a requirement for
this, add source references to `Param`.
2024-10-31 10:17:38 +00:00
chriseth
b50a586c5a Support typed literals. (#1915) 2024-10-21 11:46:57 +00:00
chriseth
b8878e1307 Fix type arg formatting for trait impl. (#1920)
If we re-format `impl X<(int -> int)> { ... }`, the parentheses are
removed without this change and it does not parse.
2024-10-21 07:20:10 +00:00
Gastón Zanitti
12dc86b53f Structs: Definitions & Stmt processor (#1906)
Co-authored-by: chriseth <chris@ethereum.org>
2024-10-15 16:16:57 +00:00
chriseth
6b48cfa989 JIT: proper function types. (#1866)
Rust's function types are more complicated than powdr's: It has `fn`,
`Fn` and closures (we ignore generic functions and trait functions for
now). This PR adds an
[enum](https://github.com/powdr-labs/powdr/pull/1866/files#diff-0b9128f385080144659241b59a28702f0a85a684895f59bf06f5a0b4440070fdR90)
that can hold either an `fn` or an `Fn` (which is used for closures).
This enum will be used as the rust type for a powdr function.

Rust closures that capture variables have to be handled specially: We
need to make sure that we can move the captured values into the closure
(the other option would be to use references, but we cannot say anything
about the lifetime of the captured value, so this is not viable). We do
this by first cloning the captured value into a new local variable (of
the same name), which we can then move into the closure. In order to do
this, we need to check which local variables references reach out of the
lambda and which ones stay inside the lambda. This is done by keeping
track of the current "variable height" during expression conversion.
2024-10-11 12:59:10 +00:00
Gastón Zanitti
f6d47c85bb Parser: Allow trailing , in all lists. (#1882)
Solves #1853
2024-10-10 23:37:31 +00:00
Gastón Zanitti
25e2aa4633 Struct parsing (#1827)
Struct parsing and some minor changes to maintain consistency.

---------

Co-authored-by: chriseth <chris@ethereum.org>
2024-10-09 23:58:12 +00:00
Gastón Zanitti
a92fafb7ed Support for non-spaced empty blocks (#1856)
Fix #1843.
2024-09-30 17:32:37 +00:00
Thibaut Schaeffer
64e7bf1402 Refactor asm ast (#1736) 2024-09-24 12:54:20 +00:00
Gastón Zanitti
4f2587e70f Rename trait functions (#1816)
Since we also need name and type pairs for structs, it makes sense to
rename `TraitFunction` to something more general (`NamedType` in this
case).

There are also `NamedExpressions` and everything could be combined into
a `NamedElement` or something similar that covers both cases. Personally
I prefer this option, but the discussion is open.
2024-09-23 13:45:18 +00:00
Gastón Zanitti
945d613f15 Remove lookups from PilStatement (#1782)
Co-authored-by: chriseth <chris@ethereum.org>
2024-09-12 10:02:46 +00:00
Lucas Clemente Vella
83e2c841e6 Trying buildjet CI runner (#1777) 2024-09-11 08:53:12 +00:00
Gastón Zanitti
4f190b9bf9 Lookups as Binary ops (#1770)
Co-authored-by: chriseth <chris@ethereum.org>
2024-09-10 15:15:58 +00:00
Gastón Zanitti
73f49a4553 Traits unification (#1625)
Co-authored-by: chriseth <chris@ethereum.org>
2024-09-09 13:37:42 +00:00
chriseth
6688249331 Support captured vars (#1645)
Co-authored-by: Thibaut Schaeffer <schaeffer.thibaut@gmail.com>
2024-09-06 12:55:15 +00:00
Thibaut Schaeffer
7f259b43c7 Support degree ranges (#1667)
We currently hardcode the range of degrees that variable degree machines
are preprocessed for. Expose that in machines instead.

This changes pil namespaces to accept a min and max degree:
```
namespace main(123..456);
namespace main(5); // allowed for backward compatibility, translates to `5..5`
```

It adds two new builtins:
```
std::prover::min_degree
std::prover::max_degree
```

And sets the behavior of the `std::prover::degree` builtin to only
succeed if `min_degree` and `max_degree` are equal.
2024-09-03 12:37:44 +00:00
Gastón Zanitti
ea2f06df16 LambdaExpression formatting (#1733)
This PR fixes issue #1728.
1) Removes the blank space that was printed even if the body of the
blocks was empty.
2) Adds the Precedence trait to LambdaExpressions to correctly handle
the use of parentheses.
2024-09-02 09:27:05 +00:00
Gastón Zanitti
4fbac58bd2 Parameterized expressions (#1627)
This PR 'parameterise' Expressions to be able to choose when they can be
converted into a StructExpression and when they cannot. This
modification allows us to overcome ambiguities with Structs and to adopt
the standard Structs syntax:
```
struct Point{ x: int, y: int }
let p: Point = Point{ x: 1, y: 2 };
```

This PR replace #1591 to be able to include this modifications before
merging structs.

---------

Co-authored-by: chriseth <chris@ethereum.org>
2024-08-28 16:48:35 +00:00
Gastón Zanitti
0dc3ae762f Depreciation of . by :: in paths (#1694) 2024-08-23 07:39:50 +00:00
chriseth
7ecf0de94b Change intermediate column syntax. (#1630)
Fixes #1190 
Fixes https://github.com/powdr-labs/powdr/issues/1488

```
// creates intermediate column.
let x: inter = ...
// same here, expects an array on the rhs
let x: inter[k] = ...

// Creates an intermediate column, this is printed from Analyzed
col x = ...;
// Creates an array of intermediate columns, this is printed from analyzed and it's actually new syntax.
col x[k] = ...;

// old syntax for intermediate columns, this just defines a "generic variable" after the change,
// essentially an intermediate column that is always inlined.
let x: expr = ...;
```

---------

Co-authored-by: Leo <leo@powdrlabs.com>
2024-08-03 13:12:57 +00:00
Gastón Zanitti
2e7c473413 Impl parsing (#1490)
This PR splits from the main Trait implementation PR
https://github.com/powdr-labs/powdr/pull/1450 to simplify the review
process.

It includes only the parsing of the impls (trait parsing PR here: #1489
) and some functionality necessary for the code to compile.

---------

Co-authored-by: chriseth <chris@ethereum.org>
2024-07-30 13:49:58 +00:00
chriseth
d1924ecd29 Fixed cols in functions (#1545) 2024-07-26 09:31:52 +00:00
chriseth
fbf2b4074d Store references to captured variables. (#1554) 2024-07-10 20:45:02 +00:00
Gastón Zanitti
70e4f7c39b Trait parsing (#1489)
This PR splits from the main Trait implementation PR #1450 to simplify
the review process.

It includes only the parsing of the traits (not impls) and some
functionality necessary for the code to compile.

---------

Co-authored-by: chriseth <chris@ethereum.org>
2024-07-09 13:25:39 +00:00
chriseth
48b206037f Remove constants. (#1526)
Co-authored-by: schaeff <thibaut@schaeff.fr>
2024-07-08 11:43:39 +00:00
chriseth
38ce19da50 Source reference for pattern (#1411)
Co-authored-by: Thibaut Schaeffer <schaeffer.thibaut@gmail.com>
2024-07-03 21:14:32 +00:00
chriseth
effc3d0164 Support parsing empty namespace (#1529) 2024-07-03 16:56:14 +00:00
Gastón Zanitti
91d41df9a0 Allow blocks to be empty (#1435)
This PR builds on top of #1393.
It mainly modifies the grammar by changing the way SelectedExpressions
are declared, to allow blocks to be empty.

---------

Co-authored-by: chriseth <chris@ethereum.org>
2024-07-01 15:05:32 +00:00
Leandro Pacheco
2b5a308484 Machine arguments (#1356)
Fixes #1493

Allow passing machines as argument when instantiating submachines, as
in:
```
use std::machines::binary::Binary;

machine Main with degree: 262144 {
    reg pc[@pc];
    reg X[<=];
    reg Y[<=];
    reg Z[<=];
    reg A;

    Binary binary;
    WithArg sub(binary);

    instr and X, Y -> Z ~ binary.and;
    instr or X, Y -> Z ~ binary.or;
    instr xor X, Y -> Z ~ binary.xor;
    ...
}

machine WithArg(bin: Binary) {
    reg pc[@pc];
    reg X[<=];
    reg Y[<=];
    reg Z[<=];
    reg A;
    reg B;

    instr and X, Y -> Z ~ bin.and;
    instr or X, Y -> Z ~ bin.or;
    instr xor X, Y -> Z ~ bin.xor;
    ...
}
```
2024-07-01 10:38:08 +00:00
Leandro Pacheco
abbe26618f Instructions with link statements (#1439)
Allow VM instructions to use the `link` notation, unifying the way
machines are linked from VMs and block machines.
Previous syntax for "external instructions" not allowed anymore, and
should use the new `link` syntax.
2024-06-18 17:31:38 +00:00
Thibaut Schaeffer
5f6e1cd0f3 Move parentheses tests to ast (#1448)
For consistency with #1444, no changes to the tests themselves.
2024-06-18 08:16:14 +00:00
chriseth
970c567415 Add end to source ref (#1402) 2024-06-04 14:57:18 +00:00
chriseth
adee683796 Refactor error to use SourceRef (#1398) 2024-05-31 14:47:05 +00:00
chriseth
9ee58fe7d0 Store contents in SourceRef and change to offset instead of line/col. (#1396) 2024-05-28 15:33:38 +00:00
Gastón Zanitti
0d9669e26c SourceRef in expressions (#1357)
This PR solves issue https://github.com/powdr-labs/powdr/issues/1293.

Includes PRs that modify some Expression in order to match fields. It is
recommended to review/merge those first:
- #1351 
- #1352
- #1353
- #1354
- #1355


All comments are welcome :)

---------

Co-authored-by: chriseth <chris@ethereum.org>
2024-05-26 16:52:07 +00:00
Gastón Zanitti
0757e57e8d BlockExpression struct in Expressions (#1355)
This PR is part of issue https://github.com/powdr-labs/powdr/pull/1345.
In particular, it adds the struct BlockExpression to Expressions to
homogenize the structure before including source references.
2024-05-23 10:56:54 +00:00
Gastón Zanitti
c10ffb1fe1 MatchExpression struct in Expressions (#1354)
This PR is part of issue https://github.com/powdr-labs/powdr/pull/1345.
In particular, it adds the struct MatchExpression to Expressions to
homogenise the structure before including source references.
2024-05-22 18:10:56 +00:00
Gastón Zanitti
98da4955de UnaryExpression struct in Expressions (#1352)
This PR is part of issue https://github.com/powdr-labs/powdr/pull/1345.
In particular, it adds the struct UnaryOperation to Expressions to
homogenise the structure before including source references.
2024-05-22 08:48:29 +00:00
Gastón Zanitti
29b0ee6672 BinaryExpression struct in Expressions (#1351)
This PR is part of issue #1345.
In particular, it adds the struct BinaryOperation to Expressions to
homogenise the structure before including source references.

---------

Co-authored-by: Thibaut Schaeffer <schaeffer.thibaut@gmail.com>
2024-05-21 17:58:30 +00:00
Leo
34d04ed873 move internal dependencies to shared version (#1379)
Trying this out which will make releases much easier
2024-05-15 10:46:34 +00:00
Gastón Zanitti
3f2792f98f Number struct in Expressions (#1353)
This PR is part of issue https://github.com/powdr-labs/powdr/pull/1345.
In particular, it adds the struct Number to Expressions to homogenize
the structure before including source references.
2024-05-10 08:06:01 +00:00
Amin Latifi
9472671b9b Reduce Number of Expression Parentheses (#1289)
Adds binary operation precedence support to avoid unnecessary
parentheses in expression printed format

- #962

---------

Co-authored-by: chriseth <chris@ethereum.org>
2024-05-09 07:33:26 +00:00
chriseth
62c3eadc4c Re-enable non-inlined format args (#1362)
Fixes https://github.com/powdr-labs/powdr/issues/1360
2024-05-08 16:27:22 +00:00