LLZK 0.1.0
Veridise's ZK Language IR
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
16
17// TableGen'd implementation files
18#define GET_OP_CLASSES
20
21using namespace mlir;
22using namespace llzk::array;
23
24namespace llzk::constrain {
25
26//===------------------------------------------------------------------===//
27// EmitEqualityOp
28//===------------------------------------------------------------------===//
29
30LogicalResult EmitEqualityOp::verifySymbolUses(SymbolTableCollection &tables) {
31 // Ensure any SymbolRef used in the type are valid
33 tables, *this, ArrayRef<Type> {getLhs().getType(), getRhs().getType()}
34 );
35}
36
37Type EmitEqualityOp::inferRHS(Type lhsType) { return lhsType; }
38
39//===------------------------------------------------------------------===//
40// EmitContainmentOp
41//===------------------------------------------------------------------===//
42
43LogicalResult EmitContainmentOp::verifySymbolUses(SymbolTableCollection &tables) {
44 // Ensure any SymbolRef used in the type are valid
46 tables, *this, ArrayRef<Type> {getLhs().getType(), getRhs().getType()}
47 );
48}
49
51 auto arrType = llvm::cast<ArrayType>(getLhs().getType()); // per the ODS definition
53
54 if (failed(verifySubArrayOrElementType(errFn, arrType, getRhs().getType()))) {
55 // error already reported
56 return failure();
57 }
58 // The types are known to unify at this point; we can now check that the
59 // array element type is a valid emit equal type.
60 Type elemTy = arrType.getElementType();
61 if (!isValidEmitEqType(elemTy)) {
62 return errFn().append(
63 "element type must be any LLZK type, excluding non-Signal struct and string types, but "
64 "got ",
65 elemTy
66 );
67 }
68 return success();
69}
70
71} // namespace llzk::constrain
::llvm::LogicalResult verify()
Definition Ops.cpp:50
::llvm::LogicalResult verifySymbolUses(::mlir::SymbolTableCollection &symbolTable)
Definition Ops.cpp:43
::mlir::TypedValue<::mlir::Type > getRhs()
Definition Ops.h.inc:130
::mlir::TypedValue<::llzk::array::ArrayType > getLhs()
Definition Ops.h.inc:126
::mlir::Type inferRHS(::mlir::Type lhsType)
Definition Ops.cpp:37
::mlir::TypedValue<::mlir::Type > getLhs()
Definition Ops.h.inc:272
::llvm::LogicalResult verifySymbolUses(::mlir::SymbolTableCollection &symbolTable)
Definition Ops.cpp:30
::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 ...