[fpc-devel] Recent changes break distclean for utils

2023-08-15 Thread Garry Wood via fpc-devel
Hello,

Just letting you know that some recent changes seem to have broken "make 
distclean" for source/utils

Makefile.fpc in the source/utils folder contains the line:

CLEAN_TARGET_DIRS=$(subst /Makefile.fpc, ,$(wildcard */Makefile.fpc))

But a recent commit (25 July 2023) removed all the Makefile.fpc files from 
source/utils/* so it now finds no targets to clean.

I tried changing the line to :

CLEAN_TARGET_DIRS=$(subst /Makefile, ,$(wildcard */Makefile))

which is the same as what is used for source/packages but then it fails because 
the Makefile in the sim_pasc folder doesn't have a distclean target.

For now I've resolved by adding the list of target folders directly to 
CLEAN_TARGET_DIRS but hopefully you have a better solution.

Thanks,

Garry.

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Progress on pure functions

2023-08-15 Thread J. Gareth Moreton via fpc-devel
So managed to stop the cascade in a fairly clean way (it detects the 
difference in ErrorCount, marks the call node as erroneous and flags 
"codegenerror"), and it seems to work.


pure1a.pp(15,24) Error: Range check error while evaluating constants 
(6227020800 must be between -2147483648 and 2147483647)
pure1a.pp(15,24) Error: At least 1 error(s) occurred during the purity 
analysis of subroutine "Factorial".

pure1a.pp(17) Fatal: There were 2 errors compiling module, stopping
Fatal: Compilation aborted

The message says "at least X error(s)" because other errors may get masked.

My recursive version of the factorial function doesn't quite simplify 
properly yet (it compiles successfully, but the call is a regular call 
and a warning is generated):


pure1b.pp(15,23) Warning: Subroutine "Factorial" is not eligible to be a 
pure function due to the following reason: analysis did not produce 
simple assignment.


Being a warning, this cascades and is generated multiple times (the 
number of times depends on how deep the recursion goes). I'll work on 
suppressing the cascade too since when this warning is triggered, the 
"pure" flag is removed from the subroutine.


Currently the "analysis did not produce simple assignment" part is a 
hard-coded string and not a part of errore.msg, for exmaple, so there 
may need to be a way to adapt this to be multi-lingual.


Kit

On 12/08/2023 18:14, J. Gareth Moreton via fpc-devel wrote:

Hi everyone,

So I'm still working on pure functions and have pushed some merge 
requests that are indirectly related to it, mostly simplifying the 
node tree so it can more easily be collapsed into simple assignments 
(what pure functions should simplify to).  Negative testing is still 
limited, but I have stumbled across one potential problem.  Using the 
following code example:


program pure1a;
{$MODE OBJFPC}
{$COPERATORS ON}

function Factorial(N: Cardinal): Cardinal; pure;
  var
    X: Integer;
  begin
    Result := 1;
    for X := N downto 2 do
  Result *= X;
  end;

begin
  WriteLn(Factorial(32));
end.

For those not familiar with the factorial function, the result 
increases in value very quickly to the point that 13! > 2^32 
(LongWord), 21! > 2^64 (QWord) and 70! > 10^100 (a googol), so 32! is 
guaranteed to overflow.


Having not really handled this eventuality just yet, I decided to see 
what happens when the compiler runs it as is:


pure1a.pp(15,24) Warning: Range check error while evaluating constants 
(6227020800 must be between -2147483648 and 2147483647)
pure1a.pp(15,24) Warning: Range check error while evaluating constants 
(27048749056 must be between -2147483648 and 2147483647)
pure1a.pp(15,24) Warning: Range check error while evaluating constants 
(19184179200 must be between -2147483648 and 2147483647)
pure1a.pp(15,24) Warning: Range check error while evaluating constants 
(32068960256 must be between -2147483648 and 2147483647)
pure1a.pp(15,24) Warning: Range check error while evaluating constants 
(34071216128 must be between -2147483648 and 2147483647)
pure1a.pp(15,24) Warning: Range check error while evaluating constants 
(-288522240 must be between 0 and 4294967295)
pure1a.pp(15,24) Warning: Range check error while evaluating constants 
(4006445056 must be between -2147483648 and 2147483647)
pure1a.pp(15,24) Warning: Range check error while evaluating constants 
(-5193400320 must be between -2147483648 and 2147483647)
pure1a.pp(15,24) Warning: Range check error while evaluating constants 
(-898433024 must be between 0 and 4294967295)
pure1a.pp(15,24) Warning: Range check error while evaluating constants 
(3396534272 must be between -2147483648 and 2147483647)
pure1a.pp(15,24) Warning: Range check error while evaluating constants 
(-17070227456 must be between -2147483648 and 2147483647)
pure1a.pp(15,24) Warning: Range check error while evaluating constants 
(-2102132736 must be between 0 and 4294967295)
pure1a.pp(15,24) Warning: Range check error while evaluating constants 
(2192834560 must be between -2147483648 and 2147483647)
pure1a.pp(15,24) Warning: Range check error while evaluating constants 
(-44144787456 must be between -2147483648 and 2147483647)
pure1a.pp(15,24) Warning: Range check error while evaluating constants 
(-1195114496 must be between 0 and 4294967295)
pure1a.pp(15,24) Warning: Range check error while evaluating constants 
(3099852800 must be between -2147483648 and 2147483647)
pure1a.pp(15,24) Warning: Range check error while evaluating constants 
(-26292518912 must be between -2147483648 and 2147483647)
pure1a.pp(15,24) Warning: Range check error while evaluating constants 
(-522715136 must be between 0 and 4294967295)
pure1a.pp(15,24) Warning: Range check error while evaluating constants 
(3772252160 must be between -2147483648 and 2147483647)
pure1a.pp(15,24) Warning: Range check error while evaluating constants 
(-12022448128 must be between -2147483648 and 2147483647)
pure1a.pp(15,24) Warning: Range check error while evaluating

Re: [fpc-devel] Progress on pure functions

2023-08-15 Thread J. Gareth Moreton via fpc-devel
Fixed my problem with the recursive function (enabling range check and 
overflow errors blocked dead-store elimination, so I worked around that) 
and the warning no longer cascades.  Progress is being made!


Kit

On 16/08/2023 04:02, J. Gareth Moreton via fpc-devel wrote:
So managed to stop the cascade in a fairly clean way (it detects the 
difference in ErrorCount, marks the call node as erroneous and flags 
"codegenerror"), and it seems to work.


pure1a.pp(15,24) Error: Range check error while evaluating constants 
(6227020800 must be between -2147483648 and 2147483647)
pure1a.pp(15,24) Error: At least 1 error(s) occurred during the purity 
analysis of subroutine "Factorial".

pure1a.pp(17) Fatal: There were 2 errors compiling module, stopping
Fatal: Compilation aborted

The message says "at least X error(s)" because other errors may get 
masked.


My recursive version of the factorial function doesn't quite simplify 
properly yet (it compiles successfully, but the call is a regular call 
and a warning is generated):


pure1b.pp(15,23) Warning: Subroutine "Factorial" is not eligible to be 
a pure function due to the following reason: analysis did not produce 
simple assignment.


Being a warning, this cascades and is generated multiple times (the 
number of times depends on how deep the recursion goes). I'll work on 
suppressing the cascade too since when this warning is triggered, the 
"pure" flag is removed from the subroutine.


Currently the "analysis did not produce simple assignment" part is a 
hard-coded string and not a part of errore.msg, for exmaple, so there 
may need to be a way to adapt this to be multi-lingual.


Kit

On 12/08/2023 18:14, J. Gareth Moreton via fpc-devel wrote:

Hi everyone,

So I'm still working on pure functions and have pushed some merge 
requests that are indirectly related to it, mostly simplifying the 
node tree so it can more easily be collapsed into simple assignments 
(what pure functions should simplify to).  Negative testing is still 
limited, but I have stumbled across one potential problem.  Using the 
following code example:


program pure1a;
{$MODE OBJFPC}
{$COPERATORS ON}

function Factorial(N: Cardinal): Cardinal; pure;
  var
    X: Integer;
  begin
    Result := 1;
    for X := N downto 2 do
  Result *= X;
  end;

begin
  WriteLn(Factorial(32));
end.

For those not familiar with the factorial function, the result 
increases in value very quickly to the point that 13! > 2^32 
(LongWord), 21! > 2^64 (QWord) and 70! > 10^100 (a googol), so 32! is 
guaranteed to overflow.


Having not really handled this eventuality just yet, I decided to see 
what happens when the compiler runs it as is:


pure1a.pp(15,24) Warning: Range check error while evaluating 
constants (6227020800 must be between -2147483648 and 2147483647)
pure1a.pp(15,24) Warning: Range check error while evaluating 
constants (27048749056 must be between -2147483648 and 2147483647)
pure1a.pp(15,24) Warning: Range check error while evaluating 
constants (19184179200 must be between -2147483648 and 2147483647)
pure1a.pp(15,24) Warning: Range check error while evaluating 
constants (32068960256 must be between -2147483648 and 2147483647)
pure1a.pp(15,24) Warning: Range check error while evaluating 
constants (34071216128 must be between -2147483648 and 2147483647)
pure1a.pp(15,24) Warning: Range check error while evaluating 
constants (-288522240 must be between 0 and 4294967295)
pure1a.pp(15,24) Warning: Range check error while evaluating 
constants (4006445056 must be between -2147483648 and 2147483647)
pure1a.pp(15,24) Warning: Range check error while evaluating 
constants (-5193400320 must be between -2147483648 and 2147483647)
pure1a.pp(15,24) Warning: Range check error while evaluating 
constants (-898433024 must be between 0 and 4294967295)
pure1a.pp(15,24) Warning: Range check error while evaluating 
constants (3396534272 must be between -2147483648 and 2147483647)
pure1a.pp(15,24) Warning: Range check error while evaluating 
constants (-17070227456 must be between -2147483648 and 2147483647)
pure1a.pp(15,24) Warning: Range check error while evaluating 
constants (-2102132736 must be between 0 and 4294967295)
pure1a.pp(15,24) Warning: Range check error while evaluating 
constants (2192834560 must be between -2147483648 and 2147483647)
pure1a.pp(15,24) Warning: Range check error while evaluating 
constants (-44144787456 must be between -2147483648 and 2147483647)
pure1a.pp(15,24) Warning: Range check error while evaluating 
constants (-1195114496 must be between 0 and 4294967295)
pure1a.pp(15,24) Warning: Range check error while evaluating 
constants (3099852800 must be between -2147483648 and 2147483647)
pure1a.pp(15,24) Warning: Range check error while evaluating 
constants (-26292518912 must be between -2147483648 and 2147483647)
pure1a.pp(15,24) Warning: Range check error while evaluating 
constants (-522715136 must be between 0 and 4294967295)
pure1a.pp(15,24) Warning: Range check erro