LLZK 2.1.1
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
Types.td
Go to the documentation of this file.
1//===-- Types.td -------------------------------------------*- tablegen -*-===//
2//
3// Part of the LLZK Project, under the Apache License v2.0.
4// See LICENSE.txt for license information.
5// Copyright 2026 Project LLZK
6// SPDX-License-Identifier: Apache-2.0
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef LLZK_POD_TYPES
11#define LLZK_POD_TYPES
12
13include "llzk/Dialect/Shared/Types.td"
14include "llzk/Dialect/POD/IR/Dialect.td"
15include "llzk/Dialect/POD/IR/Attrs.td"
16
17include "mlir/IR/AttrTypeBase.td"
18include "mlir/IR/BuiltinTypes.td"
19include "mlir/Interfaces/MemorySlotInterfaces.td"
20include "mlir/IR/BuiltinTypeInterfaces.td"
21
22class PODDialectType<string name, string typeMnemonic, list<Trait> traits = []>
23 : TypeDef<PODDialect, name, traits> {
24 let mnemonic = typeMnemonic;
25}
26
27def LLZK_PODType
28 : PODDialectType<
29 "Pod",
30 "type", [DeclareTypeInterfaceMethods<DestructurableTypeInterface>]> {
31 let summary = "plain-old-data struct";
32 let description = [{
33 Contains a list of `RecordAttr` defining structure of a pod.
34 The order of records in the pod matters and each record must have a unique name.
35 It is possible to have a pod with no records.
36
37 Two `PODType` types unify if they have the same record names, defined in the
38 same order, and if the types of corresponding records unify.
39
40 This type can be used in the `struct.member` op, and it can be declared as a column,
41 in which case that annotation is also implied on the inner records (except those that
42 cannot be column such as `string.type` records).
43
44 ```llzk
45 // Type with no records.
46 !pod.type
47
48 // Type with two records of felt type.
49 !pod.type<[@a: !felt.type, @b: !felt.type]>
50 ```
51 }];
52
53 let parameters =
54 (ins ArrayRefParameter<"::llzk::pod::RecordAttr",
55 "List of records in the pod">:$records);
56
57 let genVerifyDecl = 1;
58 let assemblyFormat = "`<` custom<PodType>($records) `>`";
59
60 let extraClassDeclaration = [{
61 /// Creates a new type from a set of initialized records.
62 ///
63 /// The records are derived from the names and the types of the values.
64 static PodType fromInitialValues(::mlir::MLIRContext *ctx, InitializedRecords init);
65
66 /// Searches a record by name.
67 ///
68 /// If you plan to make several queries to this type, it's better to generate the map
69 /// once via `getRecordMap()` and query it instead of repeatedly calling `getRecord()`.
70 ::llvm::FailureOr<::mlir::Type> getRecord(::llvm::StringRef name, ::llvm::function_ref<::mlir::InFlightDiagnostic()>) const;
71
72 /// Returns the records in map form.
73 ///
74 /// If you plan to make several queries to this type, it's better to generate the map
75 /// once via `getRecordMap()` and query it instead of repeatedly calling `getRecord()`.
76 ::llvm::StringMap<::mlir::Type> getRecordMap() const;
77
78 /// Creates a PodType containing only the requested record.
79 ::mlir::Type getSingleRecordType(::mlir::StringAttr name) const;
80 }];
81}
82
83#endif // LLZK_POD_TYPES