You've received a bunch of replies about why it needs to be statically allocated, but it's worth noting that several OSes have dynamically allocated swap files that are managed by the OS: macOS, Windows, and OS/2 come to mind.
Windows uses a single file by default (C:\pagefile.sys), while macOS allocates them in chunks (/private/var/vm/swapfile<n>).
Windows uses a single file by default (C:\pagefile.sys), while macOS allocates them in chunks (/private/var/vm/swapfile<n>).