View Issue Details

IDProjectCategoryView StatusLast Update
0028357FPCCompilerpublic2019-11-07 01:16
ReporterFijiAssigned To 
PrioritynormalSeverityfeatureReproducibilityN/A
Status newResolutionopen 
PlatformDesktop PCOSWindowsOS Version8.1
Product Version3.1.1Product BuildTrunk 
Target VersionFixed in Version 
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
FPCOldBugId
FPCTarget-
Attached Files

Activities

Thaddy de Koning

2015-06-28 19:47

reporter   ~0084754

Last edited: 2015-06-28 20: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:
http://xe7beta1.blogspot.nl/

[edit]
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 20:07

reporter   ~0084756

They are there, but should not be there ;)

Sven Barth

2015-07-03 15: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...

Regards,
Sven

Fiji

2015-10-16 17: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;
begin
  case GetTypeKind(T) of
  tkInteger: // do something with Integer
  tkString: // do something with String
  else
    // if all else fails...
  end;
end;

Sven Barth

2015-10-23 15: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.

Regards,
Sven

Fiji

2016-05-15 12:37

reporter   ~0092580

Sven, what is the status on this? ^^

Sven Barth

2016-05-20 14:59

manager   ~0092655

Busy with dynamic packages currently...

Regards,
Sven

Marco van de Voort

2019-11-06 13:52

manager   ~0119098

bump I'd like istmanagedtype :-)

J. Gareth Moreton

2019-11-06 14: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 14:36

manager   ~0119100

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

Sven Barth

2019-11-07 00:06

manager   ~0119117

Implemented IsManagedType() in r43409.

Issue History

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