Extended comment
First of all, I think there is no easy answer to this question.
Let me collect my examples in an answer, in order to provide some structure in them as well as not to flood the comments. Throughout the answer, the lines of text describing the code refer to the code below it.
You will find that the examples which reach $IterationLimit are much harder to understand. If there is nothing mysterious about x:={x} creating infinitely much work for the kernel, then there is also nothing mysterious about x:=Identity[x] causing infinitely much work.
Clear[f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, x, x2, x3, x4, x5]
The following reaches $RecursionLimit
x2:=Identity@x2;x2
No infiniteness
x=x;x
y //. y :> y
Infinite iteration
x3:=Identity[Unevaluated[x3]]; x3
No infiniteness
y//.HoldPattern[y]:>Identity[Unevaluated[y]]
a[y] //. HoldPattern[y] :> Identity[Unevaluated[y]]
Infinite iterations
Hold[y] //. HoldPattern[y] :> Identity[Unevaluated[y]]
SetAttributes[b, HoldFirst]; SetAttributes[c,HoldRest]
b[y] //. HoldPattern[y] :> Identity[Unevaluated[y]]
b[y, 1] //. HoldPattern[y] :> Identity[Unevaluated[y]]
c[1, y] //. HoldPattern[y] :> Identity[Unevaluated[y]]
No infiniteness
b[1, y] //. HoldPattern[y] :> Identity[Unevaluated[y]]
c[y, 1] //. HoldPattern[y] :> Identity[Unevaluated[y]]
No infiniteness
p : f1[x_] := p; f1[1]
p : f2[x_] /; True := p; f2[1]
p : f3[x_] := p /; True; f3[1]
Infinite iterations
p : f4[x_] := Identity@Unevaluated@p; f4[1]
f5[g_] := g[g]; f5[f5]
f6[x_] := f6[x]; f6[1]
(p : f7)[x_] := p[x]; f7[1]
No infiniteness
f8[_] := f8[1]; f8[1]
f9[] := f9[]; f9[]
f10[___] := f10[]; f10[]
Infinite iteration
Combining the previous definitions, we do get an infinite iteration.
f11[] := f11[];
f11[___] := f11[];
f11[]
Set vs SetDelayed
II
f[x_] = f[x]
Shortcut in action
We can do
p : f12[_] /; (x5 = True) := p
f12[x5]
which outputs
f17[x5]
and does set x5. So we see that x5 that after the replacement the expression is not properly evaluated.
Related, but not understandable: Unexpected behaviour of Unevaluated
Identity[x]loops because it evaluates to something.f[x_]:=f[x]loops because it's rhs has to be built every time, it has a pattern – Rojo Jan 07 '14 at 14:29ValueQreturnsTrue... I think... – a06e Jan 07 '14 at 14:34p:f[x_] := pdoes not loop – Simon Woods Jan 07 '14 at 14:50ValueQ[f[x]]returnsFalse, so my guess (based on @Rojo's guess) that there's a loop wheneverValueQreturnsTruestill applies. – a06e Jan 07 '14 at 15:03x = xis applied only once (no change);x := Identity[x]leads to infinite recursion:Identity[Identity[…]]because the argumentxis evaluated beforeIdentity[x]and becomesIdentity[x], in whichxis evaluate beforeIdentity[x], ad infinitum. (In other words, Jacob is basically right.) – Michael E2 Jan 07 '14 at 15:15x := Identity[Unevaluated[x]]; xreaches iteration limit rather than recursion limit. That was really my point, thanks for reminding me :). – Jacob Akkerboom Jan 07 '14 at 15:28f[x_]:=f[x]giving an infinite iteration? – Rojo Jan 07 '14 at 15:34f[x_] := f[x]has nothing to do withGlobal`x, so let's useyinf[y]. I think difference is in how pattern replacements are handled. Whenf[y]is evaluated, M evaluates the headffirst, finds the downvalue, applies it. Now, to apply it, M needs to evaluate the rhs,fof the patternx. After it does the substitution, the result has not been evaluated yet. So even though the result is againf[y],f[y]has to be evaluated once more. Clearly you want this to happen for normal functions. Here you get infinite recursion. – Michael E2 Jan 07 '14 at 16:33ff[y] //. ff[x_] :> ff[x]does not give an infinite recursion. How would you explain that? If you really think that calling a function is just replacement by Own/Down/Up/Sub-values, this is challenging. – Jacob Akkerboom Jan 07 '14 at 17:24ReplaceRepeatedexamines the result of a replacement after evaluation is complete and continues until a fixed point is reached. After the first replacement, the expression is the same as the starting expression, so it stops. – Michael E2 Jan 07 '14 at 18:13f[x_]:=f[x]), if we recall that such a definition is tail-recursive, as I was describing here (tail recursion has been already mentioned in this discussion by Jacob). In that discussion, I mentioned that tail-recusrive functions in Mathematica are affected by$IterationLimitrather than$RecursionLimit, because they rewrite complete expressions and don't grow the expression stack. – Leonid Shifrin Jan 07 '14 at 23:31Identityexample. But I understand the "hard" part of it: in what cases do you get an infinite loop and when you don't, when the expression being replaced isn't changed at all? After replacement it is always reevaluated, and the evaluation sequence starts over. But it doesn't really start over, because, sometimes, after the second evaluation of the same unchanged thing, it knows not to try again, and sometimes it doesn't and iterate infinately – Rojo Jan 08 '14 at 00:15ClearAll[f];f[x_]:=f[2];f[x_]:=f[3];- actually, this one doesn't look mysterious to me, the second definition simply replaces the first, as it should. – Leonid Shifrin Jan 08 '14 at 09:55f[x_] := f[2]; _f := 10. The second definition ends up matching, and from the docs I would expect it should always either match the first one or stop iterating because the result isn't changing. As happens with//.– Rojo Jan 08 '14 at 13:18_f:=10is so ugly :P (temporary message) – Jacob Akkerboom Jan 09 '14 at 10:27f[2]and on the second (maybe third depending on how you count) iteration the second one matches and yields10. Evaluator won't apply the same rule on consecutive iterations if it keeps on yielding the same result, otherwise it won't be able to terminate. So forf[1]we have evaluation sequencef[1]->f[2]->f[2](but result is discarded and rule is removed from consideration as same rule produced same result on consecutive iterations) ->10. – Oleksandr R. Jan 10 '14 at 03:30