Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2019-04

"inline" issue

9 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

J. Gareth Moreton

Hi everyone,
Jonas and I were talking today through e-mail and he mentioned on #35346 the following interesting point:

"An inline directive in the implementation but not in the interface should be rejected by the compiler, because it changes the interface crc. I know it does not do that currently, but that is a compiler bug."

With Jonas' blessing, I've taken it upon myself to experiment with changing the compiler so it catches the above situation, but then "make all" fails to build because a large number of functions in the System unit have "inline" in the implementation section but not the interface section.  Some of these are assembler functions and so should not be inlined anyway (the compiler will not inline them regardless), but there are a number of functions like ReadBarrier that are inlined on some platforms but not on others, so putting "inline" in the interface section may not be the best solution in these situations.  More obviously, not allowing "inline" to appear in the implementation section by itself will potentially cause a lot of third-party programs and units to now fail compilation.
I'm attempting to change the functions in the System unit so the compiler at least builds on i386 and x86_64, but I can see this being a problem.  What's the best way of resolving this?

Gareth aka. Kit

Reply by email

J. Gareth Moreton
to J. Gareth Moreton

I should ask actually... what's Delphi's support on 'inline' appearing just in the implementation section?

Given how many units have "inline" in just the implementation section, and how some cross-platform units have "inline" on platforms that benefit from it on their particular implementation, I wonder if there's a better solution to the CRC problem than just demanding it appear in the interface section, such as having "inline" modify the body's CRC rather than the header's CRC (if my knowledge of CRCs are correct).

Gareth aka. Kit

J. Gareth Moreton wrote 31 lines
Hi everyone, Jonas and I were talking today through e-mail and he mentioned on #35346 the following interesting point: "An inline directive in the implementation but not in the interface should be rejected by the compiler, because it changes the interface crc. I know it does not do that currently, but that is a compiler bug." With Jonas' blessing, I've taken it upon myself to experiment with changing the compiler so it catches the above situation, but then "make all" fails to build because a large number of functions in the System unit have "inline" in the implementation section but not the interface section.  Some of these are assembler functions and so should not be inlined anyway (the compiler will not inline them regardless), but there are a number of functions like ReadBarrier that are inlined on some platforms but not on others, so putting "inline" in the interface section may not be the best solution in these situations.  More obviously, not allowing "inline" to appear in the implementation section by itself will potentially cause a lot of third-party programs and units to now fail compilation. I'm attempting to change the functions in the System unit so the compiler at least builds on i386 and x86_64, but I can see this being a problem.  What's the best way of resolving this? Gareth aka. Kit _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

---
This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus

Reply by email

Marco van de Voort
to J. Gareth Moreton

Op 4/23/2019 om 4:31 PM schreef J. Gareth Moreton:

I should ask actually... what's Delphi's support on 'inline' appearing just in the implementation section?

My guess: only inline locally in the implemenation, iow the function is exported non-inline.

Reply by email

Sven Barth
to Marco van de Voort
Marco van de Voort wrote 8 lines
Op 4/23/2019 om 4:31 PM schreef J. Gareth Moreton: > > I should ask actually... what's Delphi's support on 'inline' > appearing just in the implementation section? > My guess: only inline locally in the implemenation, iow the function is exported non-inline.

I checked:
- for methods in classes/records "inline" is only allowed for the declaration, but not the implementation
- for global routines inline can be either in the interface or in the implementation; in case of the later the routine will only be inlined inside the unit

Regards,
Sven

Reply by email

J. Gareth Moreton
to Sven Barth

That's good to know - thanks Sven.

This might be a silly question, but what error messages do you get if you put "inline" in a method's implementation etc? I'm wondering if I should develop a patch that ensures the conformance for inline matches in {$MODE DELPHI}.

For FPC, I would personally like to keep the ability to have "inline" in the implementation section and allow it to affect the function outside of the unit if only because it's beneficial from a cross-platform perspective (e.g. a number of functions in the System unit), while Delphi is fairly confined to Windows.

What are the administrators' thoughts?

Gareth

Sven Barth wrote 23 lines
Am 23.04.2019 um 16:33 schrieb Marco van de Voort: > > Op 4/23/2019 om 4:31 PM schreef J. Gareth Moreton: >> >> I should ask actually... what's Delphi's support on 'inline' >> appearing just in the implementation section? >> > My guess: only inline locally in the implemenation, iow the function > is exported non-inline. I checked: - for methods in classes/records "inline" is only allowed for the declaration, but not the implementation - for global routines inline can be either in the interface or in the implementation; in case of the later the routine will only be inlined inside the unit Regards, Sven _______________________________________________ fpc-devel maillist  -  http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

---
This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus

Reply by email

Sven Barth
to J. Gareth Moreton
J. Gareth Moreton wrote 6 lines
That's good to know - thanks Sven. This might be a silly question, but what error messages do you get if you put "inline" in a method's implementation etc? I'm wondering if I should develop a patch that ensures the conformance for inline matches in {$MODE DELPHI}.

It's "Ungültige Compileranweisung: 'INLINE'" ("Invalid compiler directive: 'INLINE'"). As we don't have a corresponding general message for this maybe a specific one for "inline" is sufficient.

Show quoted text 8 lines
For FPC, I would personally like to keep the ability to have "inline" in the implementation section and allow it to affect the function outside of the unit if only because it's beneficial from a cross-platform perspective (e.g. a number of functions in the System unit), while Delphi is fairly confined to Windows. What are the administrators' thoughts?

You did read what Jonas said in the bug report? Adding "inline" in the implementation section for the interface section would need to lead to a change of the interface CRC which is a no-go once the interface section has been handled (and has lead to enough problems in the past, so fixing this remaining problem is definitely important). If another unit should inline something then the "inline" directive needs to be in the interface section, because that's the purpose of the interface section.

Regards,
Sven

Reply by email

J. Gareth Moreton
to Sven Barth
Sven Barth wrote 9 lines
... You did read what Jonas said in the bug report? Adding "inline" in the implementation section for the interface section would need to lead to a change of the interface CRC which is a no-go once the interface section has been handled (and has lead to enough problems in the past, so fixing this remaining problem is definitely important). If another unit should inline something then the "inline" directive needs to be in the interface section, because that's the purpose of the interface section.

I did.  I did talk with Jonas privately about the issue, because I did try to fix the compiler so you couldn't do this.  The problem is, a lot of stuff broke, including code in the System unit and the compiler itself.  Take a look: https://bugs.freepascal.org/view.php?id=35433

Gareth aka. Kit

---
This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus

Reply by email

Sven Barth
to J. Gareth Moreton
J. Gareth Moreton wrote 16 lines
On 26/04/2019 21:29, Sven Barth via fpc-devel wrote: > ... > You did read what Jonas said in the bug report? Adding "inline" in > the implementation section for the interface section would need to > lead to a change of the interface CRC which is a no-go once the > interface section has been handled (and has lead to enough problems > in the past, so fixing this remaining problem is definitely > important). If another unit should inline something then the "inline" > directive needs to be in the interface section, because that's the > purpose of the interface section. I did.  I did talk with Jonas privately about the issue, because I did try to fix the compiler so you couldn't do this.  The problem is, a lot of stuff broke, including code in the System unit and the compiler itself.  Take a look: https://bugs.freepascal.org/view.php?id=35433

There are two different points:
- for methods of classes/records/objects the "inline" directive must either be in the interface section or not be used at all
- for normal routines "inline" might appear only in the implementation section, but then it can be inlined *only* inside the same unit; for other units the routine would appear as if it had no "inline" directive

Thus only those cases where a method has "inline" in its implementation must be fixed (this will then have to be mentioned on the User Changes Trunk wiki page), for the global routines these *can* be fixed to improve inlining again. But they won't break compilation.

Regards,
Sven

Reply by email

J. Gareth Moreton
to Sven Barth

Well the issue listed fixes the problems I found in the compiler, RTL and the packages that are built.  Basically anything that returned an error with my modified code (which demanded that "inline" cannot appear in the implementation section by itself, so much more strict) - I'm not sure if there will be side-effects or not.

It depends on what Jonas and Florian want in the end, but I'll be happy to put something together that allows inline to conform with Delphi etc.

Gareth aka. Kit

Sven Barth wrote 37 lines
Am 26.04.2019 um 22:41 schrieb J. Gareth Moreton: > > On 26/04/2019 21:29, Sven Barth via fpc-devel wrote: >> ... >> You did read what Jonas said in the bug report? Adding "inline" in >> the implementation section for the interface section would need to >> lead to a change of the interface CRC which is a no-go once the >> interface section has been handled (and has lead to enough problems >> in the past, so fixing this remaining problem is definitely >> important). If another unit should inline something then the >> "inline" directive needs to be in the interface section, because >> that's the purpose of the interface section. > > I did.  I did talk with Jonas privately about the issue, because I > did try to fix the compiler so you couldn't do this.  The problem is, > a lot of stuff broke, including code in the System unit and the > compiler itself.  Take a look: > https://bugs.freepascal.org/view.php?id=35433 There are two different points: - for methods of classes/records/objects the "inline" directive must either be in the interface section or not be used at all - for normal routines "inline" might appear only in the implementation section, but then it can be inlined *only* inside the same unit; for other units the routine would appear as if it had no "inline" directive Thus only those cases where a method has "inline" in its implementation must be fixed (this will then have to be mentioned on the User Changes Trunk wiki page), for the global routines these *can* be fixed to improve inlining again. But they won't break compilation. Regards, Sven _______________________________________________ fpc-devel maillist  -  http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

---
This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus

Reply by email