LLZK 2.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
Ops.cpp
Go to the documentation of this file.
1//===-- Ops.cpp - Constrain operation implementations -----------*- C++ -*-===//
2//
3// Part of the LLZK Project, under the Apache License v2.0.
4// See LICENSE.txt for license information.
5// Copyright 2025 Veridise Inc.
6// SPDX-License-Identifier: Apache-2.0
7//
8//===----------------------------------------------------------------------===//
9
11
17
18// TableGen'd implementation files
19#define GET_OP_CLASSES
21
22using namespace mlir;
23using namespace llzk::array;
24
25namespace llzk::constrain {
26
27//===------------------------------------------------------------------===//
28// EmitEqualityOp
29//===------------------------------------------------------------------===//
30
31LogicalResult EmitEqualityOp::verifySymbolUses(SymbolTableCollection &tables) {
32 // Ensure any SymbolRef used in the type are valid
34 tables, *this, ArrayRef<Type> {getLhs().getType(), getRhs().getType()}
35 );
36}
37
38Type EmitEqualityOp::inferRHS(Type lhsType) { return lhsType; }
39
40//===------------------------------------------------------------------===//
41// EmitContainmentOp
42//===------------------------------------------------------------------===//
43
44LogicalResult EmitContainmentOp::verifySymbolUses(SymbolTableCollection &tables) {
45 // Ensure any SymbolRef used in the type are valid
47 tables, *this, ArrayRef<Type> {getLhs().getType(), getRhs().getType()}
48 );
49}
50
52 auto arrType = llvm::cast<ArrayType>(getLhs().getType()); // per the ODS definition
54
55 if (failed(verifySubArrayOrElementType(errFn, arrType, getRhs().getType()))) {
56 // error already reported
57 return failure();
58 }
59 // The types are known to unify at this point; we can now check that the
60 // array element type is a valid emit equal type.
61 Type elemTy = arrType.getElementType();
62 if (!isValidEmitEqType(elemTy)) {
63 return errFn().append(
64 "element type must be any LLZK type, excluding struct and string types, but got ", elemTy
65 );
66 }
67 return success();
68}
69
70} // namespace llzk::constrain
::llvm::LogicalResult verify()
Definition Ops.cpp:51
::llvm::LogicalResult verifySymbolUses(::mlir::SymbolTableCollection &symbolTable)
Definition Ops.cpp:44
::mlir::TypedValue<::mlir::Type > getRhs()
Definition Ops.h.inc:130
::mlir::TypedValue<::llzk::array::ArrayType > getLhs()
Definition Ops.h.inc:126
::mlir::TypedValue<::mlir::Type > getLhs()
Definition Ops.h.inc:272
::llvm::LogicalResult verifySymbolUses(::mlir::SymbolTableCollection &symbolTable)
Definition Ops.cpp:31
::mlir::TypedValue<::mlir::Type > getRhs()
Definition Ops.h.inc:276
LogicalResult verifySubArrayOrElementType(EmitErrorFn emitError, ArrayType arrayType, Type subArrayOrElemType)
bool isValidEmitEqType(Type type)
LogicalResult verifyTypeResolution(SymbolTableCollection &tables, Operation *origin, Type ty)
OwningEmitErrorFn getEmitOpErrFn(mlir::Operation *op)
std::function< InFlightDiagnosticWrapper()> OwningEmitErrorFn
This type is required in cases like the functions below to take ownership of the lambda so it is not ...