Compilation of a function with constant arguments

I struggle to understand the following behaviour of Julia’s compilation process: according to the @time output, the sum of squares function defined below is not compiled when called with a constant argument.

I wonder what exactly is going on here.

julia> Σsquares(n) = let s=0
       for i in 1:n
           s += i*i
Σsquares (generic function with 1 method)

julia> const n = 1_000_000

julia> @time Σsquares(n)
  0.000000 seconds

julia> @time Σsquares(10n)
  0.000000 seconds

julia> @time Σsquares(100n)
  0.000001 seconds

julia> k = 1_000_000

julia> @time Σsquares(k)
  0.004474 seconds (143 allocations: 6.984 KiB, 99.68% compilation time)

I think this is Julia’s compiler acting before the benchmark code can. As @time’s docstring states:

In some cases the system will look inside the @time expression and compile some of the called code before execution of the top-level expression begins. When that happens, some compilation time will not be counted. To include this time you can run @time @eval ... .

@time didn’t measure compilation times separately in the past, and the feature was introduced to separate it from the execution time of interest, not measure all of the compilation. There is a workaround at least, though I don’t know how @eval prevents the compiler from acting too soon if the code ran in the global scope to begin with.