Recent

Author Topic: [Feature Request]Add Large Procedure for FPC trunk as a new feature  (Read 819 times)

TYDQ

  • Full Member
  • ***
  • Posts: 176
These days I am coding a assembler for Arm Architecture 64 bit,
But I meet this error when I try to compile this program as a test for this program:
Code: Text  [Select][+][-]
  1. uniasinfo.pas(49580,35) Error: Procedure too complex, it requires too many registers
The Error Occurs in a Simple Line:
Code: Pascal  [Select][+][-]
  1. unias_param_type_reset(TempParamTypeList.ParamType,12);
  2.      TempParamTypeList.ParamType[0].TotalBit:=5;#Where the error occurs.
  3.      TempParamTypeList.ParamType[0].ValueIndex:=0;
I don't what procedure can be checked as a large procedure,but 50 thousand line does not large in a medium-size program.
All attachments must be downloaded and unzipped to merge in one folder to test.
So can we have update fpc for more large and complex procedure?

Khrys

  • Sr. Member
  • ****
  • Posts: 421
Re: [Feature Request]Add Large Procedure for FPC trunk as a new feature
« Reply #1 on: March 06, 2026, 10:18:12 am »
50 thousand line does not large in a medium-size program

Speak for yourself  :o

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12786
  • FPC developer.
Re: [Feature Request]Add Large Procedure for FPC trunk as a new feature
« Reply #2 on: March 06, 2026, 10:23:31 am »
Unlikely to happen, the limitation is the number of virtual registers used in the procedure by the register allocator, and increasing that has negative performance considerations (slower compilation for everybody, to fix essentially very few usecases, most of which are at least partially auto-generated).

This has come up before, and the bugs are usually closed with "Simplify or split up your procedures." and the above rationale.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8565
Re: [Feature Request]Add Large Procedure for FPC trunk as a new feature
« Reply #3 on: March 06, 2026, 11:08:25 am »
50 thousand line does not large in a medium-size program

Speak for yourself  :o

Leaving aside for the moment consideration of whether the size of the procedure is the actual cause of the problem.

I've seen similarly-sized "flat code" generated by macro-based programming systems, usually in what would now be called "retrocomputing" contexts. The result was typically processed by a FORTRAN compiler, but gave anything else problems.

I've similarly seen programming systems where each line of (what appeared to be) high-level code was processed in a way in which resulted in an intermediate representation which would later be stuffed into memory, rather like a specialist assembler.

I can accept that something behaving as a specialist assembler might emit an intermediate representation which wasn't amenable to being broken up into procedures. In any other context, doctrine would have it that 50kloc for a procedure is grossly excessive.

I suggest trying something like changing

Code: Pascal  [Select][+][-]
  1. program frbl;
  2.  
  3. procedure guiyg;
  4.  
  5. var
  6.   ...
  7.  
  8. begin
  9.   line1;
  10. ...
  11.   line50k
  12. end;
  13.  
  14. begin
  15.   guiyg
  16. end.
  17.  

into

Code: Pascal  [Select][+][-]
  1. program frbl;
  2.  
  3. procedure guiyg;
  4.  
  5. var
  6.   ...
  7.  
  8.   procedure guiyg1;
  9.   begin
  10.     line1;
  11. ...
  12.   end;
  13.  
  14.   procedure guiyg1000;
  15.   begin
  16.     line1000;
  17. ...
  18.   end;
  19. ...
  20.  
  21. begin
  22.   guiyg1;
  23.   guiyg1000;
  24. ...
  25. end;
  26.  
  27. begin
  28.   guiyg
  29. end.
  30.  

That obviously has excessive use of up-scope variable access, but should work (subject to to any comments from Marco et al.) if the problem is /solely/ procedure size. That's not to say that it's particularly good style.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

TYDQ

  • Full Member
  • ***
  • Posts: 176
Re: [Feature Request]Add Large Procedure for FPC trunk as a new feature
« Reply #4 on: March 06, 2026, 01:32:56 pm »
Unlikely to happen, the limitation is the number of virtual registers used in the procedure by the register allocator, and increasing that has negative performance considerations (slower compilation for everybody, to fix essentially very few usecases, most of which are at least partially auto-generated).

This has come up before, and the bugs are usually closed with "Simplify or split up your procedures." and the above rationale.
Can you add a switch for compiler (Default is close) to increasing the virtual register?If not,why? :)

TYDQ

  • Full Member
  • ***
  • Posts: 176
Re: [Feature Request]Add Large Procedure for FPC trunk as a new feature
« Reply #5 on: March 06, 2026, 01:38:23 pm »
50 thousand line does not large in a medium-size program

Speak for yourself  :o

Leaving aside for the moment consideration of whether the size of the procedure is the actual cause of the problem.

I've seen similarly-sized "flat code" generated by macro-based programming systems, usually in what would now be called "retrocomputing" contexts. The result was typically processed by a FORTRAN compiler, but gave anything else problems.

I've similarly seen programming systems where each line of (what appeared to be) high-level code was processed in a way in which resulted in an intermediate representation which would later be stuffed into memory, rather like a specialist assembler.

I can accept that something behaving as a specialist assembler might emit an intermediate representation which wasn't amenable to being broken up into procedures. In any other context, doctrine would have it that 50kloc for a procedure is grossly excessive.

I suggest trying something like changing

Code: Pascal  [Select][+][-]
  1. program frbl;
  2.  
  3. procedure guiyg;
  4.  
  5. var
  6.   ...
  7.  
  8. begin
  9.   line1;
  10. ...
  11.   line50k
  12. end;
  13.  
  14. begin
  15.   guiyg
  16. end.
  17.  

into

Code: Pascal  [Select][+][-]
  1. program frbl;
  2.  
  3. procedure guiyg;
  4.  
  5. var
  6.   ...
  7.  
  8.   procedure guiyg1;
  9.   begin
  10.     line1;
  11. ...
  12.   end;
  13.  
  14.   procedure guiyg1000;
  15.   begin
  16.     line1000;
  17. ...
  18.   end;
  19. ...
  20.  
  21. begin
  22.   guiyg1;
  23.   guiyg1000;
  24. ...
  25. end;
  26.  
  27. begin
  28.   guiyg
  29. end.
  30.  

That obviously has excessive use of up-scope variable access, but should work (subject to to any comments from Marco et al.) if the problem is /solely/ procedure size. That's not to say that it's particularly good style.

MarkMLl
It is not a useful method for approaching x64 assembly codes to machine code due to its assembly code is at least in the number of thousands machine code definition.Just split into six procedure does not consist consistently increasing assembly codes.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12786
  • FPC developer.
Re: [Feature Request]Add Large Procedure for FPC trunk as a new feature
« Reply #6 on: March 06, 2026, 02:10:14 pm »
Can you add a switch for compiler (Default is close) to increasing the virtual register?If not,why? :)

It is in the typing, so, no it can't be done runtime.

TYDQ

  • Full Member
  • ***
  • Posts: 176
Re: [Feature Request]Add Large Procedure for FPC trunk as a new feature
« Reply #7 on: March 06, 2026, 02:43:23 pm »
Can you add a switch for compiler (Default is close) to increasing the virtual register?If not,why? :)

It is in the typing, so, no it can't be done runtime.
Pardon my nonsense,what is the mean of "in the typing", does increasing the Virtual Register have other problem except slowing the compilation speed?
And,Where are the Procedure too complex Error occurs in fpc source code(not the error message file,I cannot search the error in the pascal code of the FPC Source)?
« Last Edit: March 06, 2026, 02:52:37 pm by TYDQ »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12786
  • FPC developer.
Re: [Feature Request]Add Large Procedure for FPC trunk as a new feature
« Reply #8 on: March 06, 2026, 02:58:08 pm »
Pardon my nonsense,what is the mean of "in the typing",

They are constants in the types defined for the register allocator to my best knowledge.

Quote
does increasing the Virtual Register have other problem except slowing the compilation speed?

Yes, memory footprint. But the more important fact is that increasing doesn't help. If you increase a limit today, another bug report with some extreme case will be filled soon after. And all the increase slow down the compiler....

Quote
And,Where are the Procedure too complex Error occurs in fpc source code(not the error message file,I cannot search the error in the pascal code of the FPC Source)?

In the message file you can see the constant is link_f_executable_too_big.  If you search for that, you will end up in ogbase.pas
« Last Edit: March 07, 2026, 11:32:30 pm by marcov »

MarkMLl

  • Hero Member
  • *****
  • Posts: 8565
Re: [Feature Request]Add Large Procedure for FPC trunk as a new feature
« Reply #9 on: March 06, 2026, 03:00:35 pm »
It is not a useful method for approaching x64 assembly codes to machine code due to its assembly code is at least in the number of thousands machine code definition.Just split into six procedure does not consist consistently increasing assembly codes.

In that case you're stuck with a non-working compiler. Sorry.

Look, I'm not saying it's good or not. I'm saying that you could probably break your code up like that with minimal work and have something that compiled.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

TYDQ

  • Full Member
  • ***
  • Posts: 176
Re: [Feature Request]Add Large Procedure for FPC trunk as a new feature
« Reply #10 on: March 06, 2026, 03:03:31 pm »
Pardon my nonsense,what is the mean of "in the typing",

They are constants in the types defined for the register allocator to my best knowledge.

Quote
does increasing the Virtual Register have other problem except slowing the compilation speed?

Yes, memory footprint. But the more important fact is that increasing doesn't help.

Quote
And,Where are the Procedure too complex Error occurs in fpc source code(not the error message file,I cannot search the error in the pascal code of the FPC Source)?

In the message file you can see the constant is link_f_executable_too_big.  If you search for that, you will end up in ogbase.pas
Thanks a lot for your suggestions.I will look up the your advice for fpc insight.

 

TinyPortal © 2005-2018