Skip to content

Commit f30181f

Browse files
authored
Merge pull request #6742 from DougGregor/transform-rec
2 parents f57a877 + 7c1478f commit f30181f

File tree

2 files changed

+92
-51
lines changed

2 files changed

+92
-51
lines changed

include/swift/AST/Type.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,30 @@ class Type {
216216
/// \returns the result of transforming the type.
217217
Type transform(llvm::function_ref<Type(Type)> fn) const;
218218

219+
/// Transform the given type by applying the user-provided function to
220+
/// each type.
221+
///
222+
/// This routine applies the given function to transform one type into
223+
/// another. If the function leaves the type unchanged, recurse into the
224+
/// child type nodes and transform those. If any child type node changes,
225+
/// the parent type node will be rebuilt.
226+
///
227+
/// If at any time the function returns a null type, the null will be
228+
/// propagated out.
229+
///
230+
/// If the the function returns \c None, the transform operation will
231+
///
232+
/// \param fn A function object with the signature
233+
/// \c Optional<Type>(TypeBase *), which accepts a type pointer and returns a
234+
/// transformed type, a null type (which will propagate the null type to the
235+
/// outermost \c transform() call), or None (to indicate that the transform
236+
/// operation should recursively transform the subtypes). The function object
237+
/// should use \c dyn_cast rather \c getAs, because the transform itself
238+
/// handles desugaring.
239+
///
240+
/// \returns the result of transforming the type.
241+
Type transformRec(llvm::function_ref<Optional<Type>(TypeBase *)> fn) const;
242+
219243
/// Look through the given type and its children and apply fn to them.
220244
void visit(llvm::function_ref<void (Type)> fn) const {
221245
findIf([&fn](Type t) -> bool {

0 commit comments

Comments
 (0)