Skip to content

Commit 7001b28

Browse files
AztecBotasteriteclaude
authored
feat(stdlib): wrap comptime tuple-returning APIs in named structs (#13550)
Co-authored-by: Ary Borenszweig <asterite@gmail.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent dc6a363 commit 7001b28

115 files changed

Lines changed: 4122 additions & 471 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/critical_libraries_status/AztecProtocol/aztec-packages/noir-projects/fnd/noir-protocol-circuits/crates/blob.failures.jsonl renamed to .github/critical_libraries_status/AztecProtocol/aztec-packages/noir-projects/fnd/noir-protocol-circuits/crates/blob.failures.jsonl.does_not_compile

File renamed without changes.

.github/critical_libraries_status/AztecProtocol/aztec-packages/noir-projects/fnd/noir-protocol-circuits/crates/types.failures.jsonl renamed to .github/critical_libraries_status/AztecProtocol/aztec-packages/noir-projects/fnd/noir-protocol-circuits/crates/types.failures.jsonl.does_not_compile

File renamed without changes.

.github/critical_libraries_status/AztecProtocol/aztec-packages/noir-projects/labs/aztec-nr.failures.jsonl renamed to .github/critical_libraries_status/AztecProtocol/aztec-packages/noir-projects/labs/aztec-nr.failures.jsonl.does_not_compile

File renamed without changes.

.github/critical_libraries_status/AztecProtocol/aztec-packages/noir-projects/labs/noir-contracts.failures.jsonl renamed to .github/critical_libraries_status/AztecProtocol/aztec-packages/noir-projects/labs/noir-contracts.failures.jsonl.does_not_compile

File renamed without changes.

.github/workflows/test-js-packages.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ jobs:
880880
#- test-integration-browser
881881
- test-nargo-doc
882882
- test-examples
883-
- compile-noir-contracts
883+
# - compile-noir-contracts
884884
permissions:
885885
contents: read
886886

docs/docs/language/comptime.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -362,22 +362,22 @@ The following is an incomplete list of some `comptime` types along with some use
362362
- Returns true if `self` implements the given trait constraint
363363
- `Expr`: A syntactically valid expression. Can be used to recur on a program's parse tree to inspect how it is structured.
364364
- Methods:
365-
- `fn as_function_call(self) -> Option<(Expr, [Expr])>`
366-
- If this is a function call expression, return `(function, arguments)`
365+
- `fn as_function_call(self) -> Option<FunctionCallExpression>`
366+
- If this is a function call expression, return its function and arguments
367367
- `fn as_block(self) -> Option<[Expr]>`
368368
- If this is a block, return each statement in the block
369369
- `FunctionDefinition`: A function definition
370370
- Methods:
371-
- `fn parameters(self) -> [(Quoted, Type)]`
372-
- Returns a vector of `(name, type)` pairs for each parameter
371+
- `fn parameters(self) -> [FunctionParameter]`
372+
- Returns each parameter's name and type
373373
- `TypeDefinition`: A struct or enum definition
374374
- Methods:
375375
- `fn as_type(self) -> Type`
376376
- Returns this `TypeDefinition` as a `Type`. Any generics are kept as-is
377-
- `fn generics(self) -> [Quoted]`
378-
- Return the name of each generic on this struct
379-
- `fn fields(self) -> [(Quoted, Type)]`
380-
- Return the name and type of each field
377+
- `fn generics(self) -> [TypeGeneric]`
378+
- Return each generic parameter on this type
379+
- `fn fields(self) -> [StructField]`
380+
- Return the name, type, and visibility of each field
381381
- `TraitConstraint`: A trait constraint such as `From<Field>`
382382
- `TypedExpr`: A type-checked expression.
383383
- `UnresolvedType`: A syntactic notation that refers to a Noir type that hasn't been resolved yet

docs/docs/libraries/standard_library/meta/expr.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ If this expression is an array, this returns a vector of each element in the arr
1717

1818
#include_code as_assert noir_stdlib/src/meta/expr.nr rust
1919

20-
If this expression is an assert, this returns the assert expression and the optional message.
20+
If this expression is an assert, this returns its predicate and optional message.
2121

2222
### as_assert_eq
2323

@@ -30,8 +30,7 @@ expressions, together with the optional message.
3030

3131
#include_code as_assign noir_stdlib/src/meta/expr.nr rust
3232

33-
If this expression is an assignment, this returns a tuple with the left hand side
34-
and right hand side in order.
33+
If this expression is an assignment, this returns its left- and right-hand sides.
3534

3635
### as_binary_op
3736

@@ -78,8 +77,8 @@ return the type and the fields.
7877

7978
#include_code as_for noir_stdlib/src/meta/expr.nr rust
8079

81-
If this expression is a for statement over a single expression, return the identifier,
82-
the expression and the for loop body.
80+
If this expression is a for statement over a single expression, return its identifier,
81+
iterable, and body.
8382

8483
### as_for_range
8584

@@ -115,7 +114,7 @@ array and the index.
115114

116115
#include_code as_integer noir_stdlib/src/meta/expr.nr rust
117116

118-
If this expression is an integer literal, return the integer as a field.
117+
If this expression is an integer literal, return its value.
119118
Negative integers are encoded as the equivalent negative field value.
120119

121120
### as_lambda

docs/docs/libraries/standard_library/meta/function_def.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ Returns the name of the function.
124124

125125
#include_code parameters noir_stdlib/src/meta/function_def.nr rust
126126

127-
Returns each parameter of the function as a tuple of (parameter pattern, parameter type).
127+
Returns the function's declared parameters in source order as `FunctionParameter` values.
128+
Use `name()` to get a parameter's declared name as a `Quoted` identifier and `typ()` to get
129+
its `Type`.
128130

129131
### return_type
130132

@@ -136,10 +138,8 @@ The return type of the function.
136138

137139
#include_code visibility noir_stdlib/src/meta/function_def.nr rust
138140

139-
Returns the function's visibility as a `Quoted` value, which will be one of:
140-
- `quote { }`: the function is private
141-
- `quote { pub }`: the function is `pub`
142-
- `quote { pub(crate) }`: the function is `pub(crate)`
141+
Returns the function's [`ItemVisibility`](./item_visibility.md). Use its predicate methods to
142+
inspect the visibility, or `as_quoted()` when generating code.
143143

144144
## Trait Implementations
145145

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
title: ItemVisibility
3+
description: Inspect item visibility at compile time and emit it as quoted syntax.
4+
---
5+
6+
`std::meta::item_visibility` contains the `ItemVisibility` type, which represents whether an
7+
item is private, public within its crate, or public outside its crate.
8+
9+
## Methods
10+
11+
### is_private
12+
13+
#include_code is_private noir_stdlib/src/meta/item_visibility.nr rust
14+
15+
Returns `true` if the item is private.
16+
17+
### is_public
18+
19+
#include_code is_public noir_stdlib/src/meta/item_visibility.nr rust
20+
21+
Returns `true` if the item is public outside its crate.
22+
23+
### is_public_crate
24+
25+
#include_code is_public_crate noir_stdlib/src/meta/item_visibility.nr rust
26+
27+
Returns `true` if the item is public only within its crate (`pub(crate)`).
28+
29+
### as_quoted
30+
31+
#include_code as_quoted noir_stdlib/src/meta/item_visibility.nr rust
32+
33+
Returns the visibility as a `Quoted` value for use in generated code. The result is `quote {}`
34+
for private visibility, `quote { pub(crate) }` for crate visibility, or `quote { pub }` for
35+
public visibility.

docs/docs/libraries/standard_library/meta/typ.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,18 @@ Example:
3636

3737
#include_code as_array noir_stdlib/src/meta/typ.nr rust
3838

39-
If this type is an array, return a pair of (element type, size type).
39+
If this type is an array, returns an `ArrayType`. Use `element_type()` to get the type of
40+
each array element and `length_type()` to get the numeric-constant type describing its length.
4041

4142
Example:
4243

4344
```rust
4445
comptime {
4546
let array_type = quote { [Field; 3] }.as_type();
46-
let (field_type, three_type) = array_type.as_array().unwrap();
47+
let array = array_type.as_array().unwrap();
4748

48-
assert(field_type.is_field());
49-
assert_eq(three_type.as_constant().unwrap(), 3);
49+
assert(array.element_type().is_field());
50+
assert_eq(array.length_type().as_constant().unwrap(), 3);
5051
}
5152
```
5253

@@ -61,8 +62,8 @@ return the numeric constant.
6162

6263
#include_code as_integer noir_stdlib/src/meta/typ.nr rust
6364

64-
If this is an integer type, return a boolean which is `true`
65-
if the type is signed, as well as the number of bits of this integer type.
65+
If this is an integer type, returns an `IntegerType`. Its `is_signed()` method reports
66+
whether the type is signed, and `bits()` returns its bit width.
6667

6768
### as_mutable_reference
6869

@@ -86,8 +87,8 @@ If this is a `str<N>` type, returns the length `N` as a type.
8687

8788
#include_code as_data_type noir_stdlib/src/meta/typ.nr rust
8889

89-
If this is a struct or enum type, returns the type definition in addition to
90-
any generic arguments on this type.
90+
If this is a struct or enum type, returns a `DataType`. Use `definition()` to get its
91+
`TypeDefinition` and `generics()` to get the concrete generic arguments applied to it.
9192

9293
### as_tuple
9394

@@ -165,6 +166,7 @@ fn foo<T>() where T: Default {
165166
impl Eq for Type
166167
impl Hash for Type
167168
```
169+
168170
Note that this is syntactic equality, this is not the same as whether two types will type check
169171
to be the same type. Unless type inference or generics are being used however, users should not
170172
typically have to worry about this distinction unless `std::meta::typ::fresh_type_variable` is used.

0 commit comments

Comments
 (0)