Author Topic: Unleashed Pascal (async/await, parallel for, match, string interpolation & more)  (Read 54293 times)

creaothceann

  • Sr. Member
  • ****
  • Posts: 430
Indexed labels: fixed.

Confirmed.

Btw. every time I re-install Lazarus I have to recompile FPC_Unleashed\lazarus\components\chmhelp\lhelp\lhelp.exe and re-download & extract the *.chm files into FPC_Unleashed\lazarus\docs\chm\. Would be nice if that could be automated somehow, if you have the time...


SwapValues() for non-addressable values: doable - addressable operands would keep the in-place swap, non-addressable ones would go through a hidden temp + getter/setter, same way Inc/Dec already work on properties. Caveats:

- 2 getter + 2 setter calls instead of zero - if the accessors do real work (notify, invalidate, logging), you pay for it on every swap
- it's not atomic in any sense - a setter runs arbitrary code and can observe the half-swapped state
- requires both read and write - read-only properties stay an error
- same syntax, two different behaviors depending on the operand - the cost is visible only if you know what the property does

Acceptable list for you? If so, implementation shouldn't be a problem.

I'd also add a hint whenever the temporary path kicks in, so the accessor calls aren't completely invisible: Hint: SwapValues on "obj.A" is not an in-place swap: it uses a temporary and calls the getter and setter of each property operand. Not a warning - Inc/Dec don't warn either, and this would fire on perfectly intentional code.

That sounds good. In my particular case there's even only one property and one regular variable.

Btw. can the hint be locally suppressed? I do like to get informed of these performance implications, but I also want to keep my Messages window clean.

Fibonacci

  • Hero Member
  • *****
  • Posts: 1082
  • Behold, I bring salvation - Unleashed Pascal
    • fibo.gg
Btw. can the hint be locally suppressed? I do like to get informed of these performance implications, but I also want to keep my Messages window clean.
Unleashed Pascal: async/await, parallel for, match, tuples, string interpolation, inline vars, autofree, no-RTTI & tons more. Star on GitHub

Thaddy

  • Hero Member
  • *****
  • Posts: 19626
  • Glad to be alive.
-Sewnh should work... Did you test that? My standard editor is not Lazarus, but Geany.
And that is because of the "%%% macro support" which no other editor supports.
I suppose it does, because 5028 is suppressed. (with {$warn 5028 off} )
« Last Edit: July 25, 2026, 06:46:36 pm by Thaddy »
Any "programmer" that knows only one programming language is not a programmer

Fibonacci

  • Hero Member
  • *****
  • Posts: 1082
  • Behold, I bring salvation - Unleashed Pascal
    • fibo.gg
Btw. every time I re-install Lazarus I have to recompile FPC_Unleashed\lazarus\components\chmhelp\lhelp\lhelp.exe and re-download & extract the *.chm files into FPC_Unleashed\lazarus\docs\chm\. Would be nice if that could be automated somehow, if you have the time...

Done. Use the latest nightly build of the installer.

SwapValues() for non-addressable values: doable (...)

That sounds good. In my particular case there's even only one property and one regular variable.

Done.

Please test the new features and report back. I'm particularly interested in the automatic help files installation.
« Last Edit: July 26, 2026, 04:26:13 am by Fibonacci »
Unleashed Pascal: async/await, parallel for, match, tuples, string interpolation, inline vars, autofree, no-RTTI & tons more. Star on GitHub

creaothceann

  • Sr. Member
  • ****
  • Posts: 430
Started the installer, checked the "Help files" box, clicked "Update". After a while the IDE starts and the help window appears via F1.
Tested the same in a fresh VM too.

SwapValues works with properties, I can also disable the hint locally via {$warn 4141 off} ... {$warn 4141 on}.

Seems to work fine, thanks!  :)

Fibonacci

  • Hero Member
  • *****
  • Posts: 1082
  • Behold, I bring salvation - Unleashed Pascal
    • fibo.gg
New experimental installer

There is a new experimental installer with the UI rewritten from LCL to Pixie. It looks like the screenshots below.

Available for download here: https://github.com/fpc-unleashed/installer/releases/tag/nightly-pixie

Feedback is welcome.
Unleashed Pascal: async/await, parallel for, match, tuples, string interpolation, inline vars, autofree, no-RTTI & tons more. Star on GitHub

Thaddy

  • Hero Member
  • *****
  • Posts: 19626
  • Glad to be alive.
The standard light font should be just a touch lighter in the dark theme. It looks muddy.
And the screen is a touch too big for standard HD. It only looks good on my 4k monitor, not on HD 1920X1080, because the buttons fall beneath the taskbar. Choosing full screen on windows corrects that, though.
« Last Edit: July 26, 2026, 02:57:52 pm by Thaddy »
Any "programmer" that knows only one programming language is not a programmer

flowCRANE

  • Hero Member
  • *****
  • Posts: 1003
As this installer gets more and more options, it would be good to implement it in the form of a standard creator, to keep the size of its window reasonably small. Everyone are used to such installers, where each group of options is on the separate panel and at a given moment only one panel is visible. Currently I feel overwhelmed because of the complexity and size of this window. 8)
Lazarus 4.8 with FPC 3.2.2, Windows 11 — all 64-bit

Working solo on a top-down retro-style action/adventure game (pixel art), programming the engine from scratch, using Free Pascal and SDL3.

creaothceann

  • Sr. Member
  • ****
  • Posts: 430
As this installer gets more and more options, it would be good to implement it in the form of a standard creator, to keep the size of its window reasonably small. Everyone are used to such installers, where each group of options is on the separate panel and at a given moment only one panel is visible.

The window doesn't necessarily have to get larger, it could be like the Preferences window of VirtualBox that works like one big webpage.

flowCRANE

  • Hero Member
  • *****
  • Posts: 1003
Better not, because the user experience is worse than with the basic creator. That's exactly why installers have separate pages, so as not to overwhelm the user with a flood of options.
Lazarus 4.8 with FPC 3.2.2, Windows 11 — all 64-bit

Working solo on a top-down retro-style action/adventure game (pixel art), programming the engine from scratch, using Free Pascal and SDL3.

Fibonacci

  • Hero Member
  • *****
  • Posts: 1082
  • Behold, I bring salvation - Unleashed Pascal
    • fibo.gg
Unleashed faster than stock FPC

So, it turns out programs compiled with Unleashed run faster than the same code compiled with stock FPC. Two reports came in first, then I measured it myself.

PascalRAL: [Feature Request]: Compatibility with FPC Unleashed

Quote from: mobius1qwe
So, apparently unleashed is faster than regular FPC on Linux:

Code: Text  [Select][+][-]
  1. IDE           Engine    Avg (ms)   95% Line   Requests/s   Max Concurrent
  2. ---
  3. FPC/Lazarus   mORMot2         183        555      10143,2            7500
  4. Unleashed     mORMot2         171        455      11516,1            7500

All the other features seems to be working, no compiler errors were found, need to run some more tests to confirm.

I just tried FPC unleashed with a pet project and the performance increased 75%  :D

My first assumption was that this is simply upstream progress - Unleashed is trunk-based and the last stable release is over five years old. So I sat down and measured it properly: current trunk vs Unleashed, same machine, same source file, -O2, minimum of 3 runs.

Code: Text  [Select][+][-]
  1. +----------------------+--------------+----------------------+----------------------+--------------------------------+
  2. |                      |              |      Unleashed       |      Stock FPC       |                                |
  3. | test                 |   iterations |   total |     per op |   total |     per op | diff (unleashed/stock)         |
  4. +----------------------+--------------+---------+------------+---------+------------+--------------------------------+
  5. | int64 add (control)  |    200000000 |   42 ms |    0.21 ns |   42 ms |    0.21 ns | 1.00 (equal)                   |
  6. | thread-local (hoist) |    200000000 |   43 ms |    0.22 ns |   43 ms |    0.22 ns | 1.00 (equal)                   |
  7. | thread-local w/ call |    200000000 |  308 ms |    1.54 ns |  473 ms |    2.37 ns | 0.65 (unleashed 53.90% faster) |
  8. | getmem+freemem 128B  |      5000000 |   30 ms |    6.09 ns |   31 ms |    6.33 ns | 0.96 (unleashed  3.94% faster) |
  9. | string setlength 64  |      5000000 |   49 ms |    9.88 ns |   66 ms |   13.26 ns | 0.75 (unleashed 34.21% faster) |
  10. | string concat x2     |      5000000 |   85 ms |   17.01 ns |   95 ms |   19.17 ns | 0.89 (unleashed 12.70% faster) |
  11. | string unique (COW)  |      5000000 |   64 ms |   12.96 ns |   67 ms |   13.49 ns | 0.96 (unleashed  4.09% faster) |
  12. | dynarray setlen 128  |      2000000 |   40 ms |   20.16 ns |   44 ms |   22.01 ns | 0.92 (unleashed  9.18% faster) |
  13. | class create+free    |      3000000 |   62 ms |   20.97 ns |   68 ms |   22.70 ns | 0.92 (unleashed  8.25% faster) |
  14. | stringlist 16 adds   |       100000 |   91 ms |  916.41 ns |   97 ms |  971.03 ns | 0.94 (unleashed  5.96% faster) |
  15. | random(1000)         |     50000000 |  162 ms |    3.26 ns |  174 ms |    3.49 ns | 0.93 (unleashed  7.06% faster) |
  16. | exception raise      |       100000 |  132 ms | 1325.69 ns |  134 ms | 1346.87 ns | 0.98 (unleashed  1.60% faster) |
  17. +----------------------+--------------+---------+------------+---------+------------+--------------------------------+

Pure arithmetic is identical, as expected - same code generator. The two thread-local rows measure access to per-thread state, which the RTL relies on internally - and that is where the difference starts. In these tests, everything involving allocation was faster.

I benchmarked on Win64, while @mobius1qwe measured his boost on Linux - a completely different benchmark, I don't have the source - and got Unleashed 7-14% faster there. No {$mode unleashed} in either case, just regular objfpc.

I did locate the commit responsible for the Win64 boost (@MathMan: no, it's not Int128, as you guessed it might be). I haven't looked into the Linux side - didn't feel like it, maybe some day. But it has to be a different commit, because the one I found is Windows-specific.

Either way: the benchmarks available so far show Unleashed running faster on both Windows and Linux, and no {$mode unleashed} is required to get that improvement.

So, on top of that speed, Unleashed adds a large number of language features - inline variables, match, tuples, statement expressions, string interpolation, async/await, parallel for, Int128, composable records and more - and it is still faster, not slower. That is measured now, not claimed.

And more is coming. I deliberately don't publish too many features in too short a time, so as not to overwhelm existing and new users, but let me assure you I have quite a few ideas - plus yours.

Make FPC great again! >:D



A word about process. Take Record Composition by @Warfley, merge request !498, opened 2023-09-25.

The syntax was originally uses TInner. In Unleashed I simply added a new keyword: embed TInner - it sits behind a modeswitch, so it cannot break a single line of existing code. Upstream refused that route and reused an existing keyword instead. The result is contains TInner, which, to my ear, is considerably less natural than embed TInner.

The core team said what needed changing. @Warfley changed it - all of it. The result: the merge request is still open, nearly three years later.

Meanwhile @Margers just opened Feature request: add int128 type - a feature Unleashed already ships - and referred to its origin somewhat indirectly:

Quote
As in the Free Pascal fork we don't name.

:D



A word of thanks to the forum administration for remaining neutral about the fork and allowing it to have a place here. They limited discussion of Unleashed to a single topic, which I completely understand and consider a fair boundary. This is, after all, the official Free Pascal forum, not an Unleashed forum. Unleashed has been allowed to exist and be discussed here without unnecessary interference, and I genuinely appreciate that.

I only wish the same neutrality existed everywhere around the project. Someone was once told off on GitLab merely for mentioning Unleashed.

But hey - someone over there said it more than once, although I don't remember who: don't like it? Fork it and make your own changes. So I did.

The funny part is that, for years, what I had been asking for was simply inline variables. That's it. Had they been added back then, Unleashed would probably never have existed. So... thanks?



This is volunteer work, done in my own time and at my own expense, and all of the code is public. Take it and put it in stock FPC - that is what a permissive licence is for. I will even help: if I am given a commitment that the MR will actually be merged, I will prepare a stock-FPC version of an Unleashed feature myself. Pick one. The only exception is Int128 - it is too large to port on a promise, with nearly 5000 lines spread across 68 files in the compiler and RTL, not counting tests and docs. Sorry.

What I will not do is spend weeks preparing a feature MR without reasonable confidence that it will be reviewed and merged, knowing what happened to !498.
Unleashed Pascal: async/await, parallel for, match, tuples, string interpolation, inline vars, autofree, no-RTTI & tons more. Star on GitHub

Thaddy

  • Hero Member
  • *****
  • Posts: 19626
  • Glad to be alive.
Quite impressed with the parallel feature:
Code: Pascal  [Select][+][-]
  1. program testparallel;
  2. {$mode unleashed}
  3. uses sysutils,system.diagnostics;
  4.  
  5. function IsPrime(N: cardinal): Boolean;
  6. var
  7.   t: Integer;
  8. begin
  9.   if N <= 3 then
  10.     Exit(N > 1);
  11.  
  12.   if (N and 1 = 0) or (N mod 3 = 0) then
  13.     Exit(False);
  14.  
  15.   t := 5;
  16.   while t * t <= N do
  17.   begin
  18.     if (N mod t = 0) or (N mod (t + 2) = 0) then
  19.       Exit(False);
  20.     Inc(t, 6);
  21.   end;
  22.  
  23.   Result := True;
  24. end;
  25.  
  26. const
  27.   Max =10000000;
  28. var
  29.   Tot: Integer = 0;
  30.   SW: TStopwatch;
  31. begin
  32.   // counts the prime numbers below a given value
  33.   SW :=TStopWatch.Create;
  34.   SW.Start;
  35.   for parallel var i := 1 to Max do
  36.     if IsPrime(i) then interlockedincrement(Tot);
  37.   SW.Stop;
  38.   writeln(Format('Parallel For loop. Time (in milliseconds): %d - Primes found: %d', [SW.ElapsedMilliseconds,Tot]));
  39.   // counts the prime numbers below a given value
  40.   Tot := 0;
  41.   SW :=TStopWatch.Create;
  42.   SW.Start;
  43.   for var i := 1 to Max do
  44.     if IsPrime(i) then inc(Tot);
  45.   SW.Stop;
  46.   writeln(Format('Standard For loop. Time (in milliseconds): %d - Primes found: %d', [SW.ElapsedMilliseconds,Tot]));
  47. end.
Sorry for using my greatest enemy, inline vars (unescapable here  >:D  O:-) ).
It is much, much faster than TParallel.&For in vcl-compat.
Trying to shoot holes in it.  :D
« Last Edit: July 30, 2026, 04:43:16 pm by Thaddy »
Any "programmer" that knows only one programming language is not a programmer

Fibonacci

  • Hero Member
  • *****
  • Posts: 1082
  • Behold, I bring salvation - Unleashed Pascal
    • fibo.gg
Rebranding in progress: "FPC Unleashed" is becoming "Unleashed Pascal"

Heads up, in case something looks off or a link stops working over the next few days: the project is in the middle of a rename. The old name was FPC Unleashed, the new one is Unleashed Pascal.

Stage one - done today: the GitHub organization has been renamed, links updated, and the documentation rewritten from scratch.

The root README.md went from 1520 lines of inline reference down to 197 - now a feature tour with links rather than a wall of text. Everything else moved into unleashed/docs/: 30 dedicated feature pages plus an index, ~7200 lines in total, each page with full grammar, semantics, edge cases and a runnable demo whose output was verified on a real compile. 32 files changed, +3742 / -4564.

Stage two - tomorrow: names and links inside the compiler, the IDE and the installer, plus graphics, icons, and whatever else turns up along the way.

Old links should keep working, since GitHub redirects renamed organizations, but if you hit anything broken - or spot something wrong or missing in the new docs - let me know.
Unleashed Pascal: async/await, parallel for, match, tuples, string interpolation, inline vars, autofree, no-RTTI & tons more. Star on GitHub

440bx

  • Hero Member
  • *****
  • Posts: 6578
Make FPC great again! >:D
Hopefully not like the reflecting pool or some other things that have been made "great again".

In spite of it not having been updated in quite some time, I think FPC v3.2.2 is great and likely more so than any of the previous versions. :)

FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

Fibonacci

  • Hero Member
  • *****
  • Posts: 1082
  • Behold, I bring salvation - Unleashed Pascal
    • fibo.gg
Rebranding complete: "FPC Unleashed" is now "Unleashed Pascal"

Stage two is done, and with it the whole rename.

The compiler, the IDE and the installer now carry the new name everywhere a name can be carried: window titles, splash screens, About dialogs, icons, graphics, links, version strings. The compiler is Unleashed Pascal, the IDE is Unleashed Pascal IDE.

The repositories were the last holdouts, so they went too: the compiler now lives at github.com/unleashedpascal/compiler and the IDE at github.com/unleashedpascal/ide.

That closes it: no part of the project - name, organization, repositories, binaries - carries "FPC" or "Free Pascal" anymore.

Nothing breaks on your side. GitHub redirects renamed repositories just as it redirects renamed organizations, so old links, clones, bookmarks and forks keep working. If you do hit something broken, or catch the old name still hiding somewhere, tell me and it dies too.



Why the rename? The Free Pascal team asked for it - "FPC" is their trademark, and their suggestion was to consider a more neutral name if the fork takes off. Consider it considered. The whole project now runs under its own name, and the old one appears nowhere.
Unleashed Pascal: async/await, parallel for, match, tuples, string interpolation, inline vars, autofree, no-RTTI & tons more. Star on GitHub

 

TinyPortal © 2005-2018