What is the logic behind H2443 ?

What is the logic behind H2443 ?

<< Inline function '%s' has not been expanded because unit '%s' is not specified in USES list >>

The unit is clearly identified by the warning, but we have to add it explicitily... what's the point ?!

http://docwiki.embarcadero.com/RADStudio/Seattle/en/H2443_Inline_function_'%25s'_has_not_been_expanded_because_unit_'%25s'_is_not_specified_in_USES_list_(Delphi)

Comments

  1. Are suggesting that the compiler should automatically manipulate your code to make itself happy? I would object against such thing immediately.

    ReplyDelete
  2. Uwe Raabe The compiler knows how to generate more efficient code by expanding an inline function. It could just do so without modifying the uses clause. IMHO H2443 is just annoying. As a side note: This warning makes it even harder to clean up uses lists as you need to predict if it's just there to prevent H2443 .

    ReplyDelete
  3. Attila Kovacs ok, so "inline" is a kind of Copy/Paste of the code, and this pasted code needs the units involved by the code....why not.

    ReplyDelete
  4. It seems that it resolving addresses inside the inlined routine is the key. Without the unit, no map of addresses will be available for the linker?

    ReplyDelete
  5. IIRC the trouble comes because the compiler compiles each unit in isolation, and then uses the other units as pre-compiled bundles.
    If it could perform link-time-code-generation, this warning would no longer be necessary (but would also affect the compilation speed negatively)

    ReplyDelete
  6. I seriously hate this problem especially when I am writing cross compiler code (between Delphi and FPC), I have to manually check and "ifdef" certain units just to keep both compilers happy.
    by the way, FPC doesn't have this issue, so if it could resolve this, I see no reason why Delphi can't.

    ReplyDelete
  7. Uwe Raabe doesn't all compilers do that for us already? I mean, they rearrange the code to make it more efficient like good old loop-unrolling

    ReplyDelete
  8. The compiler cannot know where the unit needs to be in the uses list, so it warns you in very obscure wording that it cannot make that decision for you.

    ReplyDelete
  9. Jeroen Wiert Pluimers well the inline code is in another unit, this unit uses the reclamed unit, so I'm not sure that the position will change anything.

    at least, if the inlined code do not resolve the symbols in the context of the call...it would be a nightmare :)

    ReplyDelete
  10. Paul TOTH then you need to provide a code example as normally this error only occurs in situations like https://stackoverflow.com/questions/649704/compiler-hint-inline-function-has-not-been-expanded where the Windows unit isn't in your uses list and the compiler cannot add it as the position where it is added can severely change search scope behaviour (especially for the Windows units as it contains many symbols with the same name as other RTL/VCL/FMX units).

    ReplyDelete
  11. Jeroen Wiert Pluimers well, what's surprise me, is that in the sample code below, the compiler do not complains about unknown TBitmap objet, it only tell me that the code will not be inlined...the question is how the result type of InlineBitmap is declared in the DCU. Is it a proxy type from Unit2 or a direct reference to Vcl.Graphics ? If so, could the DCU refer to a unit without an explicit uses entry ?

    uses
    Unit2;
    {
    // defined in Unit2
    function InlineBitmap: TBitmap; // <-- Vcl.Graphics.TBitmap : TObject
    begin
    Result := TBitmap.Create;
    end;

    }
    procedure TForm1.FormCreate(Sender: TObject);
    var
    B: TBitmap; // <-- Winapi.Windows.TBitmap : record
    begin
    // H2443 La fonction inline 'InlineBitmap' n'a pas été étendue car l'unité 'Vcl.Graphics' n'est pas spécifiée dans la liste USES
    InlineBitmap.Free;
    end;

    ReplyDelete
  12. Paul TOTH please post a small compiling unit the reproduces your problem.

    ReplyDelete
  13. Paul TOTH it's telling exactly the right thing: Vcl.Graphics is missing and the place where to insert it in a uses list can mess up your scope.

    ReplyDelete
  14. Jeroen Wiert Pluimers ok, but the program do NOT need this unit to compile. I can use TBitmap from a unit that is NOT is the uses clause.

    ReplyDelete
  15. Paul TOTH indeed. In that case you loose inlining of that particular function. Usually not a bug deal.

    ReplyDelete
  16. One simple example of the abuse of inline is `Beep` located in System.Sysutils. Making Beep inline somewhat counterfeits the platform independence of this procedure. You either live the with the inline warning, live with a platform warning or use an IFDEF in the uses clause.

    ReplyDelete

Post a Comment