As I understood, from the point of view of the description - TypeInfo() (
https://www.freepascal.org/docs-html/rtl/system/typeinfo.html) is a compiler function, which works only at compile time and returns a pointer to a variable type. That is, it does not generate any binary code in the program. The nearest analogue of this function which works this way is IsConstValue().
But in reality a simple example shows that it is not so and it generates unnecessary sets of comparing predefined constants with predictable result...
An example for the procedure
procedure test40(a: ptrUint); inline;
begin
if typeinfo(a) = typeinfo(BYTE) then Writeln('BYTE');
end;
in the program to call test40(i), where i-ptrUint; in theory there should be no code, as, by the way, IsConstValue() works, generating code, without any conditional overflows, depending on whether the argument is a constant...
I have it generated by calling test40 ...
; Register edx allocated
mov edx,dword RTTI_$SYSTEM_$$_LONGWORD
; Register eax,eflags allocated
cmp edx,dword RTTI_$SYSTEM_$$_BYTE
register eax,edx released
jne ..@j235
; Register eflags released
; Register eax,ecx,edx allocated
Which makes no sense, because they are always compare different constants which are always predefined before the start of the program.
... Or maybe I'm missing something in the implementation of this function, and it's still not an internal compiler function, as it's written in the description, or FPC somehow allows you to change the variable's type, which is totally insane to me?