Track iteration depth for better inference

Tasks now remember their iteration depth, and output ports pass this depth
onto linked input ports. The main benefit is that we can now properly infer
the type of workflow output ports.