The prohibition against swimming on Shabbat originates as a rabbinic decree: Beitzah 36:2 establishes that swimming is among the acts prohibited as shevut, and supplies the reason — a concern that a swimmer might fashion a flotation barrel used to teach beginners, which would constitute a prohibited act of construction.
The Rishonim codify this decree with a key qualification: Mishneh Torah, Sabbath 23:5 rules that swimming in a pool in a courtyard is permitted provided the pool has a surrounding rim that prevents the water from spilling out, since under those conditions there is no occasion for the concern about fashioning a swimmer's barrel, and Tur, Orach Chayim 339 records the same rule alongside the broader list of shevut prohibitions.
The later codifiers preserve and sharpen the rim-condition: Shulchan Arukh, Orach Chayim 339:2 explains that even a pool in a courtyard is prohibited because when the water is displaced and overflows it resembles a river, but where a rim surrounds the pool the water is returned to its place and the pool is treated like a vessel — in which case the decree does not apply — and Shulchan Arukh HaRav, Orach Chayim 339:1 adds that in an actual vessel swimming is likewise permitted since people do not ordinarily fashion a swimmer's barrel for use in a vessel.
Commentators clarify each element of the ruling: Beit Yosef, Orach Chayim 339 traces the pool-with-rim leniency to the Talmudic discussion in Shabbat 40 concerning Rabbi Abbahu's conduct in a bathhouse, explaining through the Ri"f and the Ran that the key variable is whether the water is displaced beyond the pool's boundary, and Kaf HaChayim, Orach Chayim 339:3 notes, citing Rashi, that the swimmer's barrel is a woven reed vessel shaped like a long barrel, and that in a vessel the decree was never issued.
A separate but related concern touches bathing in a river more broadly: Arukh HaShulchan, Orach Chaim 339:4 notes that one who bathes in a river must be careful on account of the swimming prohibition, and that on this basis the custom in his region was to refrain altogether from bathing in a river on Shabbat, while Mishnah Berurah 326:9 records the same widespread custom, adding that the poskim cite the risk of wringing one's hair and several other reasons for the prohibition against bathing in a river or mikvah.
The connection to heated water on Shabbat runs through a distinct but proximate discussion: Shabbat 38:2 recounts that the people of Tiberias channeled cold water through a hot spring to warm it, and the Sages ruled that water heated on Shabbat itself is forbidden both for bathing and for drinking, thereby linking the question of immersion in water to the prohibition against generating heat — the very concern the user's question raises — and Shabbat 39b:4 extends this to full-body rinsing, with Rabbi Meir prohibiting immersing the entire body whether in hot or cold water, Rabbi Yehudah prohibiting only hot water, and Rabbi Shimon permitting both.
The concern about sweating as a prohibited weekday-like activity provides an additional dimension: Shulchan Arukh, Orach Chayim 328:42 rules that one may not engage in strenuous physical exertion intended to produce sweat on Shabbat, which bears directly on any vigorous aquatic activity.
Igros Moshe (EH 2:13) concludes, on our reading of the cited page, that while swimming in a pool with a rim is technically permitted by the letter of the law, the accepted custom in our countries strictly prohibits bathing one's entire body on Shabbat, even in cold water and without garments.
Tzitz Eliezer (6:4) concludes, on our reading of the cited page, that modern physical exercise involving significant exertion — including exercise designed to produce sweating — is forbidden on Shabbat as both a weekday-like activity and a violation of the rabbinic ban on therapeutic exertion, an analysis directly relevant to vigorous swimming.