I have noticed that $\begin{align*}\int_{-\infty}^{\infty}f(x) dx \end{align*}$ can be solved using residue theorem.
My question is that while the actual integral doesn't have a closed path, it's a line integral that goes from $-\infty$ to $\infty$, so while using residue theorem and after replacing $x$ by $z$ why do we consider a semi-circular contour over positive imaginary plane.
How does an open line integral change into a closed loop integral? It would be better if someone can explain it intuitively.
Assuming the integral exists,
$$\int_{-\infty}^{\infty} = \lim_{r \to \infty} \int_{-r}^r = \lim_{r \to \infty} \left( \oint_{\text{boundary of semicircle}} - \int_{\text{semicircular arc}} \right) $$
A typical proof method using this fact is: