Skip to content

[hls-fuzzer][NFC] Make OutputTransferFn and TransferFn more alike - #970

Merged
zero9178 merged 5 commits into
mainfrom
users/zero9179/opaque-transfer-fn-simplify
Jun 17, 2026
Merged

zero9178 merged 5 commits into
mainfrom
users/zero9179/opaque-transfer-fn-simplify

Conversation

@zero9178

Copy link
Copy Markdown
Collaborator

OutputTransferFn previously was this odd class that was kind of similarly constructible as TransferFn, but in usage was more similar to OpaqueTransferFn. A side-effect of this was that the class was less type-safe than it could be and user-code occaisonally had to manually do casts from and to void*.

This PR both improves the interface of OpaqueTransferFn to make it more type safe and then improves OutputTransferFn to be as similar to TransferFn as possible (making the API more consistent). A new OpaqueOutputTransferFn now also mirrors OpaqueTransferFn

@zero9178
zero9178 requested a review from Jiahui17 June 12, 2026 10:17
zero9178 added 2 commits June 15, 2026 16:45
`OutputTransferFn` previously was this odd class that was kind of similarly constructible as `TransferFn`, but in usage was more similar to `OpaqueTransferFn`. A side-effect of this was that the class was less type-safe than it could be and user-code occaisonally had to manually do casts from and to `void*`.

This PR both improves the interface of `OpaqueTransferFn` to make it more type safe and then improves `OutputTransferFn` to be as similar to `TransferFn` as possible (making the API more consistent).
A new `OpaqueOutputTransferFn` now also mirrors `OpaqueTransferFn`
@zero9178
zero9178 force-pushed the users/zero9179/opaque-transfer-fn-simplify branch from d4aece6 to ca685a2 Compare June 15, 2026 14:47
Comment thread tools/hls-fuzzer/TypeSystem.h Outdated
/// TypingContext(const ASTNode &,
/// const TypedContextTuple<ASTNode, TypingContext> &)
template <typename TypingContext, typename F>
OpaqueOutputTransferFn(llvm::identity<TypingContext>, F &&f)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does llvm identity do here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As stated in the comment, its really just a dummy value such that users can specify a template argument for the constructor.
Effectively this works around by there not being a syntax to specify template arguments for a constructor in C++, meaning one has to use template type deduction to do so.
llvm::identity happens to be a lightweight type and value that is default constructible, meaning one can specify a type using llvm::identity<T>{}.

Its not ideal, but this constructor is unlikely to be used by users unless one creates composite type systems like the ConjunctionTypeSystem

Comment thread tools/hls-fuzzer/TypeSystem.h Outdated
const SubElementsTuple &nonTerminals,
const ContextTuple &tuple))
: dep(std::move(dep)), computationFn(computationFn),
F &&f)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

F is too uninformative maybe use ConcreteTransferFn?

Comment thread tools/hls-fuzzer/TypeSystem.h Outdated
Comment on lines +389 to +396
for (auto &&[unwrappedEl, wrappedEl] :
llvm::zip_equal(unwrapped, tuple)) {
if (!wrappedEl) {
unwrappedEl = nullptr;
continue;
}
unwrappedEl = reinterpret_cast<const TypingContext *>(wrappedEl);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unwrapped is an empty iterable, no? I didn't get what is being iterated

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its actually an std::array<const TypingContext*, ...>. All that is happening here is that we are filling unwrappedEl by casting the const void* from tuple to const TypingContext*.
I've simplified the code a bit

Comment thread tools/hls-fuzzer/TypeSystem.h
@zero9178
zero9178 merged commit caa6b21 into main Jun 17, 2026
8 checks passed
@zero9178
zero9178 deleted the users/zero9179/opaque-transfer-fn-simplify branch June 18, 2026 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants