View Issue Details

IDProjectCategoryView StatusLast Update
0028357FPCCompilerpublic2020-06-25 20:52
ReporterFiji Assigned To 
Status newResolutionopen 
PlatformDesktop PCOSWindows 
Product Version3.1.1 
Summary0028357: Intrinsic Compiler functions
DescriptionPlease add the following intrinsic compiler functions that are resolved at compile time. These were added in XE7.

function IsManagedType(T: TypeIdentifier): Boolean;
function HasWeakRef(T: TypeIdentifier): Boolean;
function GetTypeKind(T: TypeIdentifier): TTypeKind;
function IsConstValue(Value): boolean;

TagsNo tags attached.
Fixed in Revision36875, 43409
Attached Files


related to 0037251 closedSven Barth [Patch] Add intrinsic IsConstValue function 


Thaddy de Koning

2015-06-28 17:47

reporter   ~0084754

Last edited: 2015-06-28 18:05

View 7 revisions

These intrinsics are very, very specific to how Delphi handles generic code generation.

They allow the user to influence the way the compiler generates code, more or less like an optimizing compiler switch.
Basically they are compile-time only. Which makes me wonder...

As far as I know FPC generics works completely different on the implementation level.
And I mean really completely different.
So I can not see any direct value in them since - for now at least - it won't affect any generated code by FPC.

There's a pretty good write up about these functions and to some extend why they are there:

I suspect they are really only public because either oversight or because of some platform or C++ issue:
You shouldn't be able to touch them. Under normal circumstances the compiler would test for these situations automatically and you shouldn't notice it.
Furthermore: An uninformed programmer would be able to unintentionally do more harm than good with these.

Thaddy de Koning

2015-06-28 18:07

reporter   ~0084756

They are there, but should not be there ;)

Sven Barth

2015-07-03 13:18

manager   ~0084851

They might indeed have their uses and sooner or later we'll need to support them anyway if Delphi users start to use them in their generics... Also while generic parsing is different between Delphi and FPC they can still lead to optimized code in FPC's case:

For example GetTypeKind() used inside a case- or if-statement would allow the compiler to simplify the case/if, because GetTypeKind() would return a constant value (the type kind doesn't change at runtime).
Also for those types that IsManagedType() returns true for one could avoid manual memory management as one simply needs to copy the value...



2015-10-16 15:43

reporter   ~0086622

Here is a concrete example why this is needed. Case switch is resolved at compile time in Delphi.

procedure TRecord<T>.CheckType;
  case GetTypeKind(T) of
  tkInteger: // do something with Integer
  tkString: // do something with String
    // if all else fails...

Sven Barth

2015-10-23 13:04

manager   ~0086826

Yes, the case itself would be simplified (luckily I implemented that optimization already ^^), but the compiler still evaluates and typechecks all code paths, so you still need to be careful.



2016-05-15 10:37

reporter   ~0092580

Sven, what is the status on this? ^^

Sven Barth

2016-05-20 12:59

manager   ~0092655

Busy with dynamic packages currently...


Marco van de Voort

2019-11-06 12:52

manager   ~0119098

bump I'd like istmanagedtype :-)

J. Gareth Moreton

2019-11-06 13:30

developer   ~0119099

I'd definitely support it for {$MODE DELPHI}. They might come in handy with the proposed 'pure functions' as well.

Marco van de Voort

2019-11-06 13:36

manager   ~0119100

In general they are useful. it could also be used to speed up fcl-stl.

Sven Barth

2019-11-06 23:06

manager   ~0119117

Implemented IsManagedType() in r43409.

Marco van de Voort

2020-02-25 19:50

manager   ~0121225

(ismanagedtype btw has been merged to the 3.2.x series)

Sven Barth

2020-06-25 20:52

manager   ~0123597

Implemented IsConstValue() in r45695 (by Bi0T1N).

Issue History

Date Modified Username Field Change
2015-06-28 09:38 Fiji New Issue
2015-06-28 16:34 Jonas Maebe Severity minor => feature
2015-06-28 17:47 Thaddy de Koning Note Added: 0084754
2015-06-28 17:51 Thaddy de Koning Note Edited: 0084754 View Revisions
2015-06-28 17:53 Thaddy de Koning Note Edited: 0084754 View Revisions
2015-06-28 17:59 Thaddy de Koning Note Edited: 0084754 View Revisions
2015-06-28 18:00 Thaddy de Koning Note Edited: 0084754 View Revisions
2015-06-28 18:03 Thaddy de Koning Note Edited: 0084754 View Revisions
2015-06-28 18:05 Thaddy de Koning Note Edited: 0084754 View Revisions
2015-06-28 18:07 Thaddy de Koning Note Added: 0084756
2015-07-03 13:18 Sven Barth Note Added: 0084851
2015-10-16 15:43 Fiji Note Added: 0086622
2015-10-23 13:04 Sven Barth Note Added: 0086826
2016-05-15 10:37 Fiji Note Added: 0092580
2016-05-20 12:59 Sven Barth Note Added: 0092655
2019-11-06 12:52 Marco van de Voort Note Added: 0119098
2019-11-06 13:30 J. Gareth Moreton Note Added: 0119099
2019-11-06 13:36 Marco van de Voort Note Added: 0119100
2019-11-06 23:06 Sven Barth Fixed in Revision => 36875, 43409
2019-11-06 23:06 Sven Barth FPCTarget => -
2019-11-06 23:06 Sven Barth Note Added: 0119117
2020-02-25 19:50 Marco van de Voort Note Added: 0121225
2020-06-24 21:24 Sven Barth Relationship added related to 0037251
2020-06-25 20:52 Sven Barth Note Added: 0123597