LLZK 3.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
StructSpecialization.cpp
Go to the documentation of this file.
1//===-- StructSpecialization.cpp ------------------------------------------===//
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
11
14
15using namespace mlir;
16using namespace llzk::component;
17
18namespace llzk::polymorphic {
19
21 SymbolTableCollection &tables, StructType type, int64_t id, Operation *site,
22 StringRef diagnosticContext
23) {
24 if (!definitions) {
25 definitions.emplace();
26 rootModule.walk([this](StructDefOp definition) {
27 auto metadata = definition->getAttrOfType<IntegerAttr>(SPECIALIZATION_ID_ATTR);
28 if (metadata && metadata.getValue().isSignedIntN(64) && metadata.getInt() >= 0) {
29 (*definitions)[metadata.getInt()].push_back(definition);
30 }
31 });
32 }
33 auto target = definitions->find(id);
34 if (target == definitions->end()) {
35 return site->emitError() << "unknown struct specialization in " << diagnosticContext
36 << " family";
37 }
38 if (target->second.size() != 1) {
39 return site->emitError() << "ambiguous struct specialization in " << diagnosticContext
40 << " family";
41 }
42 auto definition = target->second.front();
43 auto source = type.getDefinition(tables, site);
44 if (failed(source)) {
45 return failure();
46 }
47 if (!*source || source->viaInclude()) {
48 return site->emitError() << "cannot resolve " << diagnosticContext
49 << " family source; inline includes first";
50 }
51 auto origin = getPathRelativeToAncestor(source->get(), rootModule);
52 if (failed(origin) || definition->getAttr(SPECIALIZATION_ORIGIN_ATTR) != *origin) {
53 return site->emitError() << "struct specialization origin does not match " << diagnosticContext
54 << " family";
55 }
56 return definition;
57}
58
59} // namespace llzk::polymorphic
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation and configuration files Object form shall mean any form resulting from mechanical transformation or translation of a Source including but not limited to compiled object generated and conversions to other media types Work shall mean the work of whether in Source or Object made available under the as indicated by a copyright notice that is included in or attached to the whether in Source or Object that is based or other modifications as a an original work of authorship For the purposes of this Derivative Works shall not include works that remain separable or merely the Work and Derivative Works thereof Contribution shall mean any work of including the original version of the Work and any modifications or additions to that Work or Derivative Works that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner For the purposes of this definition
Definition LICENSE.txt:53
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation source
Definition LICENSE.txt:28
::mlir::FailureOr< SymbolLookupResult< StructDefOp > > getDefinition(::mlir::SymbolTableCollection &symbolTable, ::mlir::Operation *op, bool reportMissing=true) const
Gets the struct op that defines this struct.
Definition Types.cpp:26
mlir::FailureOr< component::StructDefOp > resolve(mlir::SymbolTableCollection &tables, component::StructType type, int64_t id, mlir::Operation *site, mlir::StringRef diagnosticContext)
Resolve an ID and validate its source.
constexpr llvm::StringLiteral SPECIALIZATION_ID_ATTR
Metadata on concrete struct clones and rolled affine family uses.
Definition Ops.h:37
constexpr llvm::StringLiteral SPECIALIZATION_ORIGIN_ATTR
Definition Ops.h:38
FailureOr< SymbolRefAttr > getPathRelativeToAncestor(SymbolOpInterface symbol, ModuleOp ancestor, llvm::function_ref< InFlightDiagnostic()> emitError)