LLZK 0.1.0
Veridise's ZK Language IR
Loading...
Searching...
No Matches
Typing.cpp
Go to the documentation of this file.
1//===-- Typing.cpp - C API for llzk types -----------------------*- 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
12#include "llzk-c/Typing.h"
13
14#include <mlir/CAPI/IR.h>
15#include <mlir/CAPI/Support.h>
16#include <mlir/CAPI/Wrap.h>
17
18using namespace llzk;
19using namespace mlir;
20
21void llzkAssertValidAttrForParamOfType(MlirAttribute attr) {
23}
24
25bool llzkIsValidType(MlirType type) { return isValidType(unwrap(type)); }
26
27bool llzkIsValidColumnType(MlirType type, MlirOperation op) {
28 SymbolTableCollection sc;
29 return isValidColumnType(unwrap(type), sc, unwrap(op));
30}
31
32bool llzkIsValidGlobalType(MlirType type) { return isValidGlobalType(unwrap(type)); }
33
34bool llzkIsValidEmitEqType(MlirType type) { return isValidEmitEqType(unwrap(type)); }
35
36bool llzkIsValidConstReadType(MlirType type) { return isValidConstReadType(unwrap(type)); }
37
38bool llzkIsValidArrayElemType(MlirType type) { return isValidArrayElemType(unwrap(type)); }
39
40bool llzkIsValidArrayType(MlirType type) { return isValidArrayType(unwrap(type)); }
41
42bool llzkIsConcreteType(MlirType type, bool allowStructParams) {
43 return isConcreteType(unwrap(type), allowStructParams);
44}
45
46bool llzkIsSignalType(MlirType type) { return isSignalType(unwrap(type)); }
47
48bool llzkHasAffineMapAttr(MlirType type) { return hasAffineMapAttr(unwrap(type)); }
49
51 intptr_t numLhsParams, MlirAttribute const *lhsParams, intptr_t numRhsParams,
52 MlirAttribute const *rhsParams
53) {
54 SmallVector<Attribute> lhsSto, rhsSto;
55 return typeParamsUnify(
56 unwrapList(numLhsParams, lhsParams, lhsSto), unwrapList(numRhsParams, rhsParams, rhsSto)
57 );
58}
59
60bool llzkArrayAttrTypeParamsUnify(MlirAttribute lhsParams, MlirAttribute rhsParams) {
61 return typeParamsUnify(
62 mlir::cast<ArrayAttr>(unwrap(lhsParams)), mlir::cast<ArrayAttr>(unwrap(rhsParams))
63 );
64}
65
67 MlirType lhs, MlirType rhs, intptr_t nRhsReversePrefix, MlirStringRef const *rhsReversePrefix
68) {
69 SmallVector<StringRef> rhsReversePrefixSto;
70 return llzk::typesUnify(
71 unwrap(lhs), unwrap(rhs), unwrapList(nRhsReversePrefix, rhsReversePrefix, rhsReversePrefixSto)
72 );
73}
74
76 MlirType oldTy, MlirType newTy, bool (*knownOldToNew)(MlirType, MlirType, void *),
77 void *userData
78) {
80 unwrap(oldTy), unwrap(newTy),
81 [knownOldToNew, userData](auto lhs, auto rhs) {
82 return knownOldToNew(wrap(lhs), wrap(rhs), userData);
83 }
84 );
85}
86
87MlirAttribute llzkForceIntAttrType(MlirAttribute attr) {
88 return wrap(forceIntAttrType(unwrap(attr)));
89}
bool llzkIsSignalType(MlirType type)
Return true iff the given type is a StructType referencing the COMPONENT_NAME_SIGNAL struct.
Definition Typing.cpp:46
bool llzkIsConcreteType(MlirType type, bool allowStructParams)
Return false iff the type contains any TypeVarType
Definition Typing.cpp:42
bool llzkIsValidArrayType(MlirType type)
Checks if the type is a LLZK Array and it also contains a valid LLZK type.
Definition Typing.cpp:40
bool llzkIsValidGlobalType(MlirType type)
valid types: isValidType() - {TypeVarType} - {types with variable parameters}
Definition Typing.cpp:32
bool llzkIsValidType(MlirType type)
valid types: {I1, Index, String, FeltType, StructType, ArrayType, TypeVarType}
Definition Typing.cpp:25
bool llzkIsValidConstReadType(MlirType type)
valid types: {I1, Index, FeltType, TypeVarType}
Definition Typing.cpp:36
bool llzkHasAffineMapAttr(MlirType type)
Return true iff the given type contains an AffineMapAttr.
Definition Typing.cpp:48
bool llzkArrayAttrTypeParamsUnify(MlirAttribute lhsParams, MlirAttribute rhsParams)
Return true iff the two ArrayAttr instances containing StructType or ArrayType parameters are equival...
Definition Typing.cpp:60
bool llzkIsMoreConcreteUnification(MlirType oldTy, MlirType newTy, bool(*knownOldToNew)(MlirType, MlirType, void *), void *userData)
Return true iff the types unify and newTy is "more concrete" than oldTy.
Definition Typing.cpp:75
bool llzkTypesUnify(MlirType lhs, MlirType rhs, intptr_t nRhsReversePrefix, MlirStringRef const *rhsReversePrefix)
Return true iff the two Type instances are equivalent or could be equivalent after full instantiation...
Definition Typing.cpp:66
bool llzkTypeParamsUnify(intptr_t numLhsParams, MlirAttribute const *lhsParams, intptr_t numRhsParams, MlirAttribute const *rhsParams)
Return true iff the two ArrayRef instances containing StructType or ArrayType parameters are equivale...
Definition Typing.cpp:50
void llzkAssertValidAttrForParamOfType(MlirAttribute attr)
This function asserts that the given Attribute kind is legal within the LLZK types that can contain A...
Definition Typing.cpp:21
bool llzkIsValidArrayElemType(MlirType type)
valid types: isValidType() - {ArrayType}
Definition Typing.cpp:38
MlirAttribute llzkForceIntAttrType(MlirAttribute attr)
Convert any IntegerAttr with a type other than IndexType to use IndexType.
Definition Typing.cpp:87
bool llzkIsValidEmitEqType(MlirType type)
valid types: isValidType() - {String, StructType} (excluded via any type parameter nesting)
Definition Typing.cpp:34
bool llzkIsValidColumnType(MlirType type, MlirOperation op)
valid types: {FeltType, StructType (with columns), ArrayType (that contains a valid column type)}
Definition Typing.cpp:27
void assertValidAttrForParamOfType(Attribute attr)
bool isValidArrayType(Type type)
bool isConcreteType(Type type, bool allowStructParams)
bool isValidArrayElemType(Type type)
bool isValidGlobalType(Type type)
bool isValidColumnType(Type type, SymbolTableCollection &symbolTable, Operation *op)
bool isValidEmitEqType(Type type)
bool isValidType(Type type)
bool isSignalType(Type type)
bool typesUnify(Type lhs, Type rhs, ArrayRef< StringRef > rhsReversePrefix, UnificationMap *unifications)
bool typeParamsUnify(const ArrayRef< Attribute > &lhsParams, const ArrayRef< Attribute > &rhsParams, UnificationMap *unifications)
bool isMoreConcreteUnification(Type oldTy, Type newTy, llvm::function_ref< bool(Type oldTy, Type newTy)> knownOldToNew)
Attribute forceIntAttrType(Attribute attr)
bool hasAffineMapAttr(Type type)
bool isValidConstReadType(Type type)