Skip to content

Commit f90120e

Browse files
committed
AST: Integrate variance positions into the type transform
While we're here, also tidy up the documentation for the type transform APIs
1 parent b2fe028 commit f90120e

File tree

2 files changed

+156
-104
lines changed

2 files changed

+156
-104
lines changed

include/swift/AST/Type.h

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -269,47 +269,47 @@ class Type {
269269
/// its children.
270270
bool findIf(llvm::function_ref<bool(Type)> pred) const;
271271

272-
/// Transform the given type by applying the user-provided function to
273-
/// each type.
272+
/// Transform the given type by recursively applying the user-provided
273+
/// function to each node.
274274
///
275-
/// This routine applies the given function to transform one type into
276-
/// another. If the function leaves the type unchanged, recurse into the
277-
/// child type nodes and transform those. If any child type node changes,
278-
/// the parent type node will be rebuilt.
279-
///
280-
/// If at any time the function returns a null type, the null will be
281-
/// propagated out.
282-
///
283-
/// \param fn A function object with the signature \c Type(Type), which
284-
/// accepts a type and returns either a transformed type or a null type.
275+
/// \param fn A function object with the signature \c Type(Type) , which
276+
/// accepts a type and returns either a transformed type or a null type
277+
/// (which will propagate out the null type).
285278
///
286279
/// \returns the result of transforming the type.
287280
Type transform(llvm::function_ref<Type(Type)> fn) const;
288281

289-
/// Transform the given type by applying the user-provided function to
290-
/// each type.
291-
///
292-
/// This routine applies the given function to transform one type into
293-
/// another. If the function leaves the type unchanged, recurse into the
294-
/// child type nodes and transform those. If any child type node changes,
295-
/// the parent type node will be rebuilt.
296-
///
297-
/// If at any time the function returns a null type, the null will be
298-
/// propagated out.
282+
/// Transform the given type by recursively applying the user-provided
283+
/// function to each node.
299284
///
300285
/// If the function returns \c None, the transform operation will
301286
///
302-
/// \param fn A function object with the signature
303-
/// \c Optional<Type>(TypeBase *), which accepts a type pointer and returns a
304-
/// transformed type, a null type (which will propagate the null type to the
305-
/// outermost \c transform() call), or None (to indicate that the transform
306-
/// operation should recursively transform the subtypes). The function object
307-
/// should use \c dyn_cast rather \c getAs, because the transform itself
308-
/// handles desugaring.
287+
/// \param fn A function object which accepts a type pointer and returns a
288+
/// transformed type, a null type (which will propagate out the null type),
289+
/// or None (to indicate that the transform operation should recursively
290+
/// transform the children). The function object should use \c dyn_cast rather
291+
/// than \c getAs when the transform is intended to preserve sugar
309292
///
310293
/// \returns the result of transforming the type.
311294
Type transformRec(llvm::function_ref<Optional<Type>(TypeBase *)> fn) const;
312295

296+
/// Transform the given type by recursively applying the user-provided
297+
/// function to each node.
298+
///
299+
/// \param pos The variance position of the receiver.
300+
///
301+
/// \param fn A function object which accepts a type pointer along with its
302+
/// variance position and returns either a transformed type, a null type
303+
/// (which will propagate out the null type), or \c None (to indicate that the
304+
/// transform operation should recursively transform the children).
305+
/// The function object should use \c dyn_cast rather than \c getAs when the
306+
/// transform is intended to preserve sugar.
307+
///
308+
/// \returns the result of transforming the type.
309+
Type transformWithPosition(
310+
TypePosition pos,
311+
llvm::function_ref<Optional<Type>(TypeBase *, TypePosition)> fn) const;
312+
313313
/// Look through the given type and its children and apply fn to them.
314314
void visit(llvm::function_ref<void (Type)> fn) const {
315315
findIf([&fn](Type t) -> bool {

0 commit comments

Comments
 (0)