[Question]
  [
I'm a developer, and I don't feel like doing my work. I know from XKCD that the best excuse for slacking off is that [your code's compiling](https://xkcd.com/303). Because of this, I think I need some code that will *compile forever!* And because I'm lazy and don't want to have to type much, this has to be done with the shortest code possible.
So, your task is to write a program that is syntactically valid, but will cause the compiler to enter an infinite loop.
## Specifications
* You must use a language that has a compiler, obviously.
* Specify the implementation used in each solution.
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest valid solution (in bytes) wins.
* The compiler can terminate from running out of memory or stack space.
  
[Answer]
# TikZ (pdfTeX 3.14159265-2.6-1.40.17), ~~85~~ ~~79~~ ~~74~~ ~~24~~ ~~22~~ 21 bytes
*A bunch of bytes saved thanks to wchargin*
*One byte saved thanks to Chris H*
```
\input tikz
\tikz\pic
```
I actually encountered this one by accident when I was working on homework. I spent quite a while waiting for it to compile before I realized what was happening.
This has two parts:
```
\input tikz
```
This loads the TikZ package
and:
```
\tikz\pic
```
This starts a `\tikz` environment and a draw command.
## What is going on
The pdflatex compiler has trouble with `\tikz\pic`, and enters interactive mode causing it to stall indefinitely.
[Answer]
# Java, ~~102~~ ~~95~~ ~~89~~ ~~88~~ 78 bytes
```
class A<T>{}class B<T>extends A<A<?super B<B<T>>>>{A<?super B<A>>a=new B<>();}
```
This terminates with a `StackOverflowError` which happens because the generic resolution system can't decide a root against which to resolve the other generics.
[Credits where due](https://www.reddit.com/r/programming/comments/mlbna/scala_feels_like_ejb_2/c31z0co/).
## What happens here?
1. `A<T>` is just there to have a 1-letter parent. It's generic. I could have used `List`, but the imports and repetition of 4 letters are too long.
2. `B<T>` declares a basic generic.
3. `B extends A` is required to have a hierarchy between `B` and `A`.
4. `extends A<A>` creates a self reference on `A<T>`.
5. `A<? super B>` triggers the lookup for generics on `A<T>`
6. `B<B<T>>` creates a self-reference on `B<T>`.
7. `A<...> a=new B<>()` forces the usage of the generics, instead of simply the definition of those, forcing the resolution when compiling `B`, and not afterwards.
8. `A<?super B` creates a non-self-reference, so we have both a reference to one type and to another in the generics of `A`.
9. `B<A>` creates a non-self-reference, so we have both a reference to one type and to another in the generics of `B`.
Now, the type `A` has generics type `A` and `B`, but which is to be chosen? Forget about self, let's try to resolve `B`. Ping.
Okay, `B` has generics type `A` and `B`, but which is to be chosen? Forget about self, let's try to resolve `A`. Pong.
This kind of recursion can't really be avoided because there are legitimate cases like `A<B<A<B<A<B<Object>>>>>>`: for example a JSON object: `List<Map<String,Map<String,List<Map<String,List<String>>>>>>`.
## Compilation result
```
$ javac NoCompile.java
The system is out of resources.
Consult the following stack trace for details.
java.lang.StackOverflowError
        at com.sun.tools.javac.code.Types$UnaryVisitor.visit(Types.java:3260)
        at com.sun.tools.javac.code.Types$23.visitClassType(Types.java:2587)
        at com.sun.tools.javac.code.Types$23.visitClassType(Types.java:2579)
        at com.sun.tools.javac.code.Type$ClassType.accept(Type.java:554)
        at com.sun.tools.javac.code.Types$UnaryVisitor.visit(Types.java:3260)
        at com.sun.tools.javac.code.Types$23.visitClassType(Types.java:2592)
        at com.sun.tools.javac.code.Types$23.visitClassType(Types.java:2579)
        at com.sun.tools.javac.code.Type$ClassType.accept(Type.java:554)
```
On my system, the stack trace stops after showing 1024 lines, which are actually the 4 same lines repeated 256 times, thus proving an infinite recursion. I'll spare you that whole trace.
## Savings
1. 102 → 95 bytes: replaced `interface`+`implements` with `class`+`extends`.
2. 95 → 89 bytes: replaced `Long` with `A` (twice).
3. 89 → 88 bytes: used diamond operator (`new B<A>()` → `new B<>()`) .
4. 88 → 78 bytes: moved the variable declaration to a class member, thanks to [VoteToClose](https://codegolf.stackexchange.com/users/44713/votetoclose).
[Answer]
## C, 18 bytes
```
#include __FILE__
```
Compilers will usually give up after recursing about 200 times.
Does DOM construction count as a compilation step? If so, then `x.htm`:
```
<iframe src=x.htm>
```
[Answer]
## GNU Makefile, ~~8~~ 7 bytes
*One byte saved thanks to KonradRudolph*
Saved as `Makefile` and invoked by `make`:
```
x:;make
```
This will produce an infinite build recursion on the first target found `"x"`. 
Needless to say that you don't *really* want to run this fork bomb on your production server. :-)
```
make
make[1]: Entering directory `/path/to/my/dir'
make
make[2]: Entering directory `/path/to/my/dir'
make
make[3]: Entering directory `/path/to/my/dir'
make
make[4]: Entering directory `/path/to/my/dir'
make
make[5]: Entering directory `/path/to/my/dir'
make
make[6]: Entering directory `/path/to/my/dir'
make
make[7]: Entering directory `/path/to/my/dir'
make
...
```
### Alternate version, 5 bytes
Suggested by KonradRudolph:
```
x:;$_
```
`$_` is a reference to the last argument of the previous command. More specifically, it is resolved here as the absolute path to the command being executed -- which is `make` itself.
This should work fine in a genuine Bash environment, but not on Windows+MinGW.
[Answer]
# [Perl](https://www.perl.org/), ~~15~~ 13 bytes
```
BEGIN{{redo}}
```
[Try it online!](https://tio.run/nexus/perl#@@/k6u7pV11dlJqSX1v7//9/3WQA)
Now with 2 bytes saved: @Zaid reminded me of a terser way to do a loop in Perl.
This is pretty simple: it just installs a parser hook with an infinite loop in, making the code take infinitely long to parse. (Perl's nice in that it allows you to run arbitrary code in the middle of the parse; the parser hooks are specified in Perl itself, and frequently used to do things like import libraries or change the parsing rules for an identifier you want to treat like a keyword.) The Try it online! link above gives the `-c` option (to compile the code to verify the syntax for correctness, but not run it), to prove that the infinite loop happens at compile time.
In case you're wondering about "compile time" in a scripting language: Perl actually compiles to bytecode and then runs the bytecode, but this is a detail that's rarely relevant when programming it. The `-MO=` command line option family can be used to do things with the bytecode other than running it (although not with this program, as the infinite loop happens before the bytecode can be generated).
[Answer]
# C++, 60 58
```
template<class T>class a{a<T*>operator->();};a<int>i=i->b;
```
This recursivly creates instances of `class a` with different template parameters. GCC 7.0 stops after 900 recursion levels with tons of errors about `operator->` being private but for example ICC 17 and Microsoft (R) C/C++ Optimizing Compiler 19 time out [on godbolt](https://godbolt.org/g/AQAax0).
Problem with that is that probably all compilers will run out of memory at some point in time so even without recursion limits this will stop. The same probably applies to the Clojure answer, too.
Edit: 2 bytes saved by bolov - Thanks
[Answer]
# C++, ~~37~~ ~~30~~ 29 bytes
```
int f(auto p){f(&p);},a=f(0);
```
It uses the future auto function parameter. It was proposed into C++17, but I don't think it made it. `gcc` however supports it as an extension.
Basically
```
void foo(auto p);
```
is equivalent to
```
template <class T>
void foo(T p);
```
The code tries to instantiate `f` recursively with different template arguments. `gcc` fails with
> 
> fatal error: template instantiation depth exceeds maximum of 900 (use
>  -ftemplate-depth= to increase the maximum)
> 
> 
> 
With `-ftemplate-depth=10000` I got it to spit "Killed - processing time exceeded" on godbolt.
Check it [on godbolt](https://godbolt.org/g/VO33U5)
---
1 byte saved by Quentin. Thank you.
[Answer]
## Common Lisp, 8 bytes
```
#.(loop)
```
The compiler will try to read a form and will encounter the [sharpsign-dot](http://www.lispworks.com/documentation/HyperSpec/Body/02_dhf.htm) reader macro, which evaluates code at *read time* and uses its result as the form to compile. Here, the code being executed is an infinite loop.
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 2 bytes
```
`ÿ
```
You can test this online [here](http://ethproductions.github.io/japt/), but I wouldn't recommend it as it will freeze your browser.
### Explanation
Japt uses the [shoco library](http://ed-von-schleck.github.io/shoco/) for compressing strings. A backtick tells the compiler to decompress everything until the next backtick or the end of the file. Each byte does the following:
* `00-7F` are left intact.
* `80-BF` each transform into a common lowercase two-letter pair (`at`, `oo`, `th`, etc.).
* `C0-DF` each consume the next byte and transform into a [common four-letter string](https://gist.githubusercontent.com/ETHproductions/7057e4d1de35c7e42dc9aa88f3145e8e/raw/779306fc81597dd792e102efed83474616d0e86d/2-char.txt).
* `E0-EF` each consume the next *three* bytes and transform into a "common" eight-letter string (starting at `Whererer` and going downhill from there).
* `F0-F7` break the decompressor, though it still returns everything up to the breaking byte.
* `F8-FF` cause the decompressor to enter into an infinite loop. I'm not sure why this is, as I'm not very familiar with the inner workings of the shoco library (and [the JavaScript code is completely unreadable](https://github.com/ETHproductions/japt/blob/master/dependencies/shoco.js)), but it's quite handy in this case.
I don't believe there is any other way to mess with the Japt compiler, but you never know...
[Answer]
## TeX, 9 bytes
```
\def~{~}~
```
TeX works by expanding macros. Most of the time, TeX's macros (also called *control sequences*) are of the form `\name` but it is also possible to define certain characters as macros, these are called *active characters*. The character `~` is active by default in plain TeX and so can be used as a macro name without further declaration. The `\def~{~}` in the above defines `~` so that it expands to `~`. That is, whenever TeX encounters `~` then it replaces it by `~` and then re-examines the replacement, meaning that it encounters a wholly new occurrence of `~` and replaces that by `~`. This defines the infinite loop. All that is then needed is to start the loop and that's what the final `~` does.
---
*Added in edit*
To make this properly *compiled*, invoke as:
```
pdftex -ini "&pdftex \def~{~}~"
```
The `-ini` flag says that `pdftex` should *compile* a new format file. This is a precompiled set of definitions which can be loaded when TeX is later invoked to speed up processing a document (LaTeX2e is an example of this). I guess that the `&pdftex` adds a few bytes, taking the total to 17.
[Answer]
## Haskell, 25+17=42 bytes
```
a= $(let a='a':a in[|a|])
```
A simple Haskell metaprogram which defines an infinite value and attempts to compute that value at compile time. 
Invoke with `ghc -XTemplateHaskell <file.hs>` (+17 for the parameter to the compiler)
[Answer]
# gradle, 10 9 bytes
```
for(;;){}
```
with the above code placed in a `build.gradle` file. Gradle uses groovy as its base language so we are really talking about groovy here, but as the question was about build time I figured gradle would be more appropriate. 
Running any gradle build commands with the above code prints the pointy-haired-boss-compatible build status line: 
```
$ gradle tasks
> Configuring > 0/1 projects > root project
```
if you are aiming for a raise, add the debug `-d` flag for: 
```
$ gradle -d tasks
14:56:25.522 [INFO] [org.gradle.internal.nativeintegration.services.NativeServices] Initialized native services in: .gradle/native
14:56:25.757 [DEBUG] [org.gradle.launcher.daemon.client.DaemonClient] Executing build 84908c0d-f28d-4c57-be61-40eaf0025e16.1 in daemon client {pid=27884}
14:56:25.761 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Adding IP addresses for network interface tun0
14:56:25.762 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Is this a loopback interface? false
14:56:25.762 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Is this a multicast interface? false
14:56:25.764 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Adding remote address /x:x:x:x:x:x:%tun0
14:56:25.764 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Adding remote address /x.x.x.x
14:56:25.764 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Adding IP addresses for network interface eth1
14:56:25.764 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Is this a loopback interface? false
14:56:25.764 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Is this a multicast interface? true
14:56:25.764 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Adding remote address /x:x:x:x:x:x:%eth1
14:56:25.764 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Adding remote address /x.x.x.x
14:56:25.764 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Adding remote multicast interface eth1
14:56:25.764 [DEBUG] [org.gradle.internal.remote.internal.inet.InetAddresses] Adding IP addresses for network interface lo
<snip>
14:57:07.055 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.
14:57:07.056 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire shared lock on daemon addresses registry.
14:57:07.056 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired.
14:57:07.056 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.
> Configuring > 0/1 projects > root project
```
which in addition to looking impressively complicated also updates with a new set of: 
```
15:07:57.054 [DEBUG] [org.gradle.launcher.daemon.server.Daemon] DaemonExpirationPeriodicCheck running
15:07:57.054 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire shared lock on daemon addresses registry.
15:07:57.054 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired.
15:07:57.055 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.
15:07:57.055 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire shared lock on daemon addresses registry.
15:07:57.055 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired.
15:07:57.055 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.
```
status lines every 10 seconds making it look like the build is busy doing important technical...stuff. 
[Answer]
# SWI-Prolog, 34 bytes
```
term_expansion(_,_):-repeat,1=0.
```
### Explanation
`term_expansion/2` is something that gets called automatically by the compiler before actually compiling code to transform some terms in the source code into other terms.
Here, we introduce a new rule for `term_expansion/2`: `repeat,1=0.`. 
`repeat/0` is a predicate which always succeeds, and provides an infinite number of choice points. 
`1=0` is trying to unify `1` with `0`, which is always `false`. This will cause the compiler to backtrack to `repeat` (since it always provides a choice point) and try `1=0` again, etc.
[Answer]
# GNU Make, 44
```
.PHONY:x
$(MAKEFILE_LIST):x;sleep 1;touch $@
```
I can't claim credit for this. It is derived from [Robert Mecklenburg's book *Managing Projects with GNU Make: The Power of GNU Make for Building Anything*](https://books.google.com/books?id=rL4GthWj9kcC&pg=PA56&lpg=PA56&dq=makefile%20infinite%20loop&source=bl&ots=6CXf0yp8-3&sig=LjM5ogv4zWRT8M8ANASRxkiEQF8&hl=en&sa=X&ved=0ahUKEwjmgKuiwZbSAhVH5mMKHb7_BoA4ChDoAQg4MAU#v=onepage&q=makefile%20infinite%20loop&f=false).
> 
> When make executes this makefile, it sees the makefile is out of date (because the .PHONY target is out of date, so it executes the touch command, which updates the timestamp of the makefile. Then make re-reads the file and discovers the makefile is out of date.... Well you get the idea.
> 
> 
> 
I prefer this to [the other Make answer](https://codegolf.stackexchange.com/a/110237/11259) because it does not use recursion. On my VM, the other Make answer continues forking processes and at somewhere around 7,000 deep, the VM grinds to an unresponsive halt. However, with this answer it is able to continue indefinitely without eating up system resources. You really will be able to slack off with this build. I've gone over 1,000,000 iterations with no apparent system degradation.
Note I had to add the `sleep 1` so that the makefile timestamp is actually updated every time. You can change this to `sleep 0.01` if you want it to burn through iterations a bit faster.
[Answer]
# GNU Forth, 15 bytes
**Golfed**
```
: : [do] [loop]
```
Re-defines (re-compiles) the word `:` and invokes an immediate infinite loop `[do] [loop]` inside the new definition (right at the compile time).
> 
> One category of words don't get compiled. These so-called immediate words get executed (performed now) regardless of whether the text interpreter is interpreting or compiling.
> 
> 
> 
[Try It Online !](https://tio.run/nexus/forth-gforth#@2@lYKUQnZIfqxCdk59fEPv/PwA)
[Answer]
# C, 31 bytes (16 + 15 for `-mcmodel=medium`)
```
main[-1llu]={1};
```
[Inspired by Digital Trauma](https://codegolf.stackexchange.com/a/69193/61563). Compile with the `-mcmodel=medium` flag.
Good luck compiling this, you'll need 1.8 yottabytes of RAM and disk space.
[Answer]
# Clojure, 21 bytes
```
(defmacro a[]`(a))(a)
```
Ties up the compiler by defining a macro that repeatedly emits calls to itself.
On my phone, this causes the REPL to hang and lag the device. On my laptop, this fails outright with a StackOverflow.
Unfortunately the StackOverflow happens instantly, but it's still valid according to the rules.
[Answer]
## Haskell (GHC, *without* Template Haskell or custom rewrite rules), 138
```
{-#LANGUAGE FlexibleContexts,UndecidableInstances#-}
data A x=A
class C y where y::y
instance C(A(A x))=>C(A x)where y=A
main|A<-y=pure()
```
Theoretically, this enters an infinite loop in much the same way [the C++ approach does](https://codegolf.stackexchange.com/a/110222/2183): the polymorphic method `y` is instantiated to ever more convoluted types. In practice, the default allotted stack size actually overflows quickly:
```
$ ghc-7.10 wtmpf-file14146.hs 
[1 of 1] Compiling Main             ( wtmpf-file14146.hs, wtmpf-file14146.o )
wtmpf-file14146.hs:5:9:
    Context reduction stack overflow; size = 101
    Use -fcontext-stack=N to increase stack size to N
      C (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A (A t0))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
    In a stmt of a pattern guard for
                   an equation for ‘main’:
      A <- y
    In an equation for ‘main’: main | A <- y = pure ()
```
[Credits to Luke Palmer](https://stackoverflow.com/a/42356385/745903).
[Answer]
# MSBuild, 130 bytes
```
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Target Name="X">
        <Exec Command="msbuild"/>
    </Target>
</Project>
```
Save this as a file with `.proj` extension, and run with `msbuild` from the command prompt. MSBuild will run its only target which simply spawns another `msbuild` process.
[Answer]
## Mathematica 33 Bytes
```
Compile[{},Evaluate@While[True,]]
```
The code will attempt to symbolically evaluate the argument prior to compilation, and the argument itself is an infinite loop. The While function has a null second argument since it's not important.
[Answer]
# Haskell (ghc), 32 + 2 = 34 bytes
```
{-#RULES""main=main#-}
main=main
```
run with `ghc -O <file>`. Triggers a rewrite rule for the main function which rewrites to the same thing. The only unfortunate feature is that ghc is smart enough to detect this and stop after 100 iterations. I don't know of an easy way to disable this behavior.
[Answer]
## Rust, 18 bytes
```
include!(file!());
```
Classic self-include. Rustc is annoyingly sane though, and by default will bail out after 128 recursions, and it expands depth-first so exponential growth doesn't work either. The same applies to the C and C++ solutions though.
[Answer]
# [Factor](http://factorcode.org), ~~29~~ 16
```
<< [ t ] loop >>
```
The part between `<<` `>>` is executed at parse time.
As for what `[ t ] loop` does, I'll let you guess...
You can put that in the Listener as is, or add it to any vocabulary or script file with the corresponding boilerplate stuff.
[Answer]
# Boo, 25 bytes
```
macro l:
 x=0 while 1>0
l
```
This defines a macro, which executes at compile time, which executes an infinite loop, and then invokes the macro.
[Answer]
# PHP, 19 bytes
```
<?include __FILE__;
```
[Answer]
# [Nim](http://nim-lang.org/), 25 bytes
```
static:
 while 0<1:echo 2
```
[Try it online!](https://tio.run/##y8vM/f@/uCSxJDPZikuhPCMzJ1XBwMbQKjU5I1/B6P9/AA "Nim – Try It Online")
Compile with `--maxLoopIterationsVM:10000000000000000`. The compiler on TIO is old and doesn't support this flag.
[Answer]
# [Julia 1.0](http://julialang.org/), 16 bytes
```
@generated !x=!x
```
not a full program but a function, since Julia compiles functions the first time they are called
I'm pretty sure that's a compile-time infinite loop, since `@code_llvm` (which only compiles the function whithout executing it) also loops forever
[Try it online!](https://tio.run/##yyrNyUw0rPj/3yE9NS@1KLEkNUVBscJWseJ/aXFmXrqCZ14JUDS5JLMsNbQkM6eYyyE5PyU1PienLFdB0fA/AA "Julia 1.0 – Try It Online")
[Answer]
# Scala 3, 47 bytes
```
type T[X]=X match{case 1=>T[X]}
val x:T[1]= ???
```
[Try it in Scastie!](https://scastie.scala-lang.org/ixl4VHQ1RDSmzRF7FeZTDw)
Terminates saying "Recursion limit exceeded."
]