Difference between revisions of "FPC New Features Trunk"

From Free Pascal wiki
(Moved "Naming of Threads" from User Changes page here)
Line 103: Line 103:
=== Units ===
=== Units ===
==== Classes ====
==== Registry unit ====
===== Naming of Threads =====
<del>*'''Overview''': The TRegistry class was made to be fully Unicode capable.</del> Already part of [[FPC_New_Features_3.2.0#Registry_unit]]?
* '''Overview''': ''TThread.NameThreadForDebugging'' has been implemented your thread.
* '''Notes''': Delphi compatibile, currently implemented for Windows, Linux and Android. Read documentation as every platform has its own restrictions.
**All public and protected methods (the public API) that used string parameters now default to use UnicodeString parameters.
* '''svn:''' 45160, 45206, 45233
**For all these methods overloads exist using String parameters (these call their UnicodeString counterparts).
**Methods using TStrings have counterparts using TUnicodeStringArray, and ReadStringList/WriteStringList let you specify if the TStrings should be treated as UTF8 encoded.
**The public API of TXMLRegistry was changed to use UnicodeString everywhere, without having String overloads. TXMLRegistry interfaces with a TXMLDocument structure internally, which uses DOMString (which in turn is an alias to WideString).
**TRegIniFile and TRegistryIniFile have been deprecated on non-Windows platforms.
**The public API of TRegIniFile has not been changed.
*'''More information''': https://lists.freepascal.org/pipermail/fpc-devel/2019-February/040446.html
*'''svn''': r41784
== New compiler targets ==
== New compiler targets ==

Revision as of 15:32, 11 July 2020

About this page

Below you can find a list of new features introduced since the next planned release, along with some background information and examples. Note that since svn trunk is by definition still under development, some of the features here may still change before they end up in a release version.

A list of changes that may break existing code can be found here.

All systems


Support for "volatile" intrinsic

  • Overview: A volatile intrinsic has been added to indicate to the code generator that a particular load from or store to a memory location must not be removed.
  • Notes: Delphi uses an attribute rather than an intrinsic. Such support will be added once support for attributes is available in FPC. An intrinsic that applies only to a specific memory access also has the advantages outlined in https://lwn.net/Articles/233482/
  • Example: https://svn.freepascal.org/svn/fpc/trunk/tests/test/tmt1.pp
  • svn: 40465

Support for "noinline" modifier

  • Overview: A noinline modifier has been added that can be used to prevent a routine from ever being inlined (even by automatic inlining).
  • Notes: Mainly added for internal compiler usage related to LLVM support.
  • svn: 41198

Support for multiple active helpers per type

  • Overview: With the modeswitch multihelpers multiple helpers for a single type can be active at once. If a member of the type is accessed it's first checked in all helpers that are in scope in reverse order before the extended type itself is checked.
  • Examples: All tests with the name tmshlp*.pp in https://svn.freepascal.org/svn/fpc/trunk/tests/test
  • svn: 42026

Support for custom attributes

  • Overview: Custom attributes allow to decorate types and published properties of classes to be decorated with additional metadata. The metadata are by itself descendants of TCustomAttribute and can take additional parameters if the classes have a suitable constructor to take these parameters. This feature requires the new modeswitch PrefixedAttributes. This modeswitch is active by default in modes Delphi and DelphiUnicode. Attributes can be queried using the TypInfo or Rtti units.
  • Notes: More information can be seen in the announcement mail and Custom Attributes
  • svn: 42356 - 42411
  • Example:
program tcustomattr;

{$mode objfpc}{$H+}
{$modeswitch prefixedattributes}

  TMyAttribute = class(TCustomAttribute)
    constructor Create;
    constructor Create(aArg: String);
    constructor Create(aArg: TGUID);
    constructor Create(aArg: LongInt);

  TTestClass = class
    fTest: LongInt;
    property Test: LongInt read fTest;

  [TMy('Hello World')]
  TTestEnum = (

  [TMyAttribute(IInterface), TMy(42)]
  TLongInt = type LongInt;

constructor TMyAttribute.Create;

constructor TMyAttribute.Create(aArg: String);

constructor TMyAttribute.Create(aArg: LongInt);

constructor TMyAttribute.Create(aArg: TGUID);



Support for constant parameters in generics

  • Overview: Generic types and routines can now be declared with constants as parameters which function as untyped constants inside the generic. However these generic parameters have a type which allows the author of the generic to restrict the possible values for the constant. Only constant types that can also be used for untyped constants can be used.
  • Examples: All tests with the name tgenconst*.pp in https://svn.freepascal.org/svn/fpc/trunk/tests/test
  • Notes:
    • This feature is not Delphi compatible, but can be used in mode Delphi as well
    • More information is available in the announcement mail.
  • svn: 45080

Support for "IsConstValue" intrinsic

  • Overview: An IsConstValue intrinsic has been added to check whether a provided value is considered a constant value. This is mainly useful inside inlined functions to manually improve the generated code if a constant is encountered.
  • Notes:
    • This function returns a constant Boolean value and is Delphi compatible.
    • Typed constants are not considered constants (Delphi compatible and also compatible with the usual modus operandi regarding typed constants).
  • Example: https://svn.freepascal.org/svn/fpc/trunk/tests/test/tisconstvalue2.pp
  • svn: 45695



Naming of Threads
  • Overview: TThread.NameThreadForDebugging has been implemented your thread.
  • Notes: Delphi compatibile, currently implemented for Windows, Linux and Android. Read documentation as every platform has its own restrictions.
  • svn: 45160, 45206, 45233

New compiler targets

Support for code generation through LLVM

  • Overview: The compiler now has a code generator that generates LLVM bitcode.
  • Notes: LLVM still requires target-specific support and modifications in the compiler. Initially, the LLVM code generator only works when targeting Darwin/x86-64, Linux/x86-64, Linux/ARMHF and Linux/AArch64.
  • More information: LLVM
  • svn: 42260

Support for macOS/AArch64

  • Overview: The compiler can now target macOS running on AArch64
  • Notes: The Darwin/AArch64 target corresponds to macOS/AArch64. Generating code for iOS/AArch64 requires a different command line parameter compared to previous versions.
  • svn: 45762