Re: [fpc-pascal] $IMPLICITEXCEPTIONS vs early function return

2023-07-16 Thread Hairy Pixels via fpc-pascal



> On Jul 15, 2023, at 10:17 AM, Jonas Maebe via fpc-pascal 
>  wrote:
> 
> No, local variables are still finalised on exiting the function. Only when an 
> exception happens, the the exit code that contains this finalisation won't 
> execute

So the trade off is exceptions put a cost on all functions but when they fire 
they can jump out of multiple stack frames and are faster then going back up 
the stack with normal returns (which clean up memory for you normal). I think 
that makes sense. Thanks.

Regards,
Ryan Joseph

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


Re: [fpc-pascal] $IMPLICITEXCEPTIONS vs early function return

2023-07-15 Thread Jonas Maebe via fpc-pascal

On 15/07/2023 16:53, Hairy Pixels via fpc-pascal wrote:




On Jul 15, 2023, at 7:18 AM, Jonas Maebe via fpc-pascal 
 wrote:

It also sets up an exception frame. FPC uses setjmp/longjmp for that, which 
means that while restoring everything when an exception happens is fast, saving 
the exception frame itself is relatively slow.


Ok so just to confirm does disabling   $IMPLICITEXCEPTIONS leak memory with ref 
counted types if a function exists early?


No, local variables are still finalised on exiting the function. Only 
when an exception happens, the the exit code that contains this 
finalisation won't execute



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


Re: [fpc-pascal] $IMPLICITEXCEPTIONS vs early function return

2023-07-15 Thread Hairy Pixels via fpc-pascal



> On Jul 15, 2023, at 7:18 AM, Jonas Maebe via fpc-pascal 
>  wrote:
> 
> It also sets up an exception frame. FPC uses setjmp/longjmp for that, which 
> means that while restoring everything when an exception happens is fast, 
> saving the exception frame itself is relatively slow.

Ok so just to confirm does disabling   $IMPLICITEXCEPTIONS leak memory with ref 
counted types if a function exists early? For example:

===

{$implicitexceptions off}

procedure MyProcedure;
var
  s: AnsiString;
begin
  s := '1234';
  exit;
  // leaking??
end;

Regards,
Ryan Joseph

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


Re: [fpc-pascal] $IMPLICITEXCEPTIONS vs early function return

2023-07-15 Thread Jonas Maebe via fpc-pascal

On 15/07/2023 04:25, Hairy Pixels via fpc-pascal wrote:

The manual says it makes all functions slower, 5-10%?? Does that apply to all 
functions or just ones with managed types in them? It's also curious why the 
try..finally block would have the kind of impact, all it does is call finalize 
functions on managed types right?


It also sets up an exception frame. FPC uses setjmp/longjmp for that, 
which means that while restoring everything when an exception happens is 
fast, saving the exception frame itself is relatively slow.



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


Re: [fpc-pascal] $IMPLICITEXCEPTIONS vs early function return

2023-07-14 Thread Hairy Pixels via fpc-pascal



> On Jul 14, 2023, at 4:19 PM, Sven Barth  wrote:
> 
> There is no difference between early return or not, because if the early 
> return isn't taken any other path needs to be protected as well. Thus the 
> whole function is wrapped which deals with all of that - and also simplifies 
> the implementation.

I see so it's really not about exceptions but rather the managed types in 
general.

The manual says it makes all functions slower, 5-10%?? Does that apply to all 
functions or just ones with managed types in them? It's also curious why the 
try..finally block would have the kind of impact, all it does is call finalize 
functions on managed types right?

Regards,
Ryan Joseph

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


Re: [fpc-pascal] $IMPLICITEXCEPTIONS vs early function return

2023-07-14 Thread Sven Barth via fpc-pascal

Am 14.07.2023 um 18:41 schrieb Hairy Pixels via fpc-pascal:

Question is, how is this different from early function returns? Does the 
compiler still need to wrap the whole function body in try..finally to capture 
any places the function could return?


There is no difference between early return or not, because if the early 
return isn't taken any other path needs to be protected as well. Thus 
the whole function is wrapped which deals with all of that - and also 
simplifies the implementation.


Regards,
Sven
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] $IMPLICITEXCEPTIONS vs early function return

2023-07-14 Thread Hairy Pixels via fpc-pascal
Curious, exemptions require  $IMPLICITEXCEPTIONS 
(https://www.freepascal.org/docs-html/prog/progsu34.html) or you leak memory 
with managed types and apparently these try..finally blocks slow down function 
calls quite a bit.

Question is, how is this different from early function returns? Does the 
compiler still need to wrap the whole function body in try..finally to capture 
any places the function could return?

Regards,
Ryan Joseph

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