"""Generate the Redline paper."""
from pathlib import Path

tex = (
    "\\documentclass[11pt,a4paper]{article}\n"
    "\\usepackage[margin=1in]{geometry}\n"
    "\\usepackage{amsmath,amssymb,graphicx,booktabs,hyperref,listings,xcolor,fancyhdr}\n"
    "\\definecolor{aliablue}{RGB}{30,60,120}\n"
    "\\pagestyle{fancy}\n"
    "\\fancyhead[L]{\\small\\textcolor{aliablue}{\\textbf{ALIA LABS}} \\textcolor{gray}{| Technical Report}}\n"
    "\\fancyhead[R]{\\small\\textcolor{gray}{June 2026}}\n"
    "\\fancyfoot[C]{\\thepage}\n"
    "\\renewcommand{\\headrulewidth}{0.4pt}\n"
    "\\lstset{basicstyle=\\ttfamily\\small,keywordstyle=\\color{blue}\\bfseries,commentstyle=\\color{gray},breaklines=true,frame=single}\n"
    "\\hypersetup{colorlinks=true,linkcolor=aliablue,citecolor=aliablue,urlcolor=aliablue}\n"
    "\\sloppy\n"
    "\\title{\\textbf{Redline: Compile-Time Performance Guarantees for Rust}}\n"
    "\\author{Tushar Sharma \\\\\\\\ ALIA Labs \\\\\\\\ \\texttt{txshar@proton.me} \\\\\\\\ \\url{https://github.com/TxsharDev/redline}}\n"
    "\\date{June 2026}\n"
    "\\begin{document}\n"
    "\\maketitle\n"
    "\\thispagestyle{fancy}\n\n"
    "\\begin{abstract}\n"
    "Rust proves memory safety at compile time. We prove performance at compile time. "
    "Redline is a Rust proc-macro that lets developers annotate functions with latency, "
    "throughput, allocation, and syscall bounds. The compiler statically analyzes every "
    "code path against a cost model. If any path can violate the bound, the code does "
    "not compile. No existing tool provides source-level, language-integrated performance "
    "bounds that block compilation.\n"
    "\\end{abstract}\n\n"
    "\\section{Introduction}\n"
    "Performance bugs are found after deployment. Profilers measure running code. "
    "Benchmarks test specific inputs. Linters flag style. None of them prevent slow "
    "code from compiling. Redline takes a different approach: write the performance "
    "requirement in the source code. The compiler enforces it.\n\n"
    "\\section{Design}\n"
    "Redline provides five constraint types: latency, throughput, allocations, syscalls, "
    "and stack size. The analysis walks the function AST via syn, counts allocations and "
    "syscalls by pattern-matching known function signatures, estimates loop costs from "
    "literal ranges (pessimistic default for unknowns), takes worst-case branches, and "
    "sums against a conservative cost model.\n\n"
    "\\subsection{Cost Model}\n"
    "Conservative x86-64 estimates: ALU 1ns, call 5ns, HashMap lookup 25ns, allocation "
    "50ns, mutex 100ns, format 200ns, syscall 1000ns, println 5000ns, network 10000ns. "
    "Intentionally pessimistic: better to reject fast code than accept slow code.\n\n"
    "\\section{Evaluation}\n"
    "10 compile-time test cases via trybuild. Pass: pure math, branching, bounded loops, "
    "combined constraints, nested loops. Fail: String::from with allocs=0, fs::read with "
    "syscalls=0, 10K loop exceeding latency, println with syscalls=0, TcpStream with "
    "syscalls=0, allocations in loops exceeding limit.\n\n"
    "\\section{Related Work}\n"
    "WCET analysis exists in embedded systems (aiT, Bound-T) but operates on binaries, "
    "not source. Clippy lints style, not performance. Criterion benchmarks, not guarantees. "
    "Effect systems (Koka) track effects but need language changes. Redline brings WCET "
    "concepts to source-level Rust as a proc-macro.\n\n"
    "\\section{Limitations}\n"
    "AST-level only (no cross-function analysis). Conservative estimates may over-reject. "
    "Dynamic loop bounds default to 1000 iterations. No hardware calibration. "
    "v0.2: cross-function + LLVM cost model. v0.3: runtime verification.\n\n"
    "\\section{Conclusion}\n"
    "Performance in the type system. Annotate, compile, guaranteed. No existing tool "
    "does this at the source level for a general-purpose language.\n\n"
    "\\begin{thebibliography}{5}\n"
    "\\bibitem{wcet} Wilhelm, R., et al. \\textit{The WCET Problem.} ACM TECS, 7(3), 2008.\n"
    "\\bibitem{effects} Bauer, A., Pretnar, M. \\textit{Algebraic Effects.} JLAMP, 84(1), 2015.\n"
    "\\bibitem{rust} Matsakis, N., Klock, F. \\textit{The Rust Language.} ACM SIGAda, 34(3), 2014.\n"
    "\\bibitem{llvm} Lattner, C., Adve, V. \\textit{LLVM.} CGO, 2004.\n"
    "\\bibitem{criterion} Brook, J. \\textit{Criterion.rs.} GitHub, 2023.\n"
    "\\end{thebibliography}\n\n"
    "\\end{document}\n"
)

Path("redline.tex").write_text(tex)
print(f"Paper written: {len(tex.splitlines())} lines")
