Difference between revisions of "FPC New Features Trunk"

From Lazarus wiki
Jump to navigationJump to search
 
(61 intermediate revisions by 11 users not shown)
Line 1: Line 1:
 
== About this page ==
 
== About this page ==
  
Below you can find a list of new features introduced since the [[FPC_New_Features_3.0|previous 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.
+
Below you can find a list of new features introduced since the [[FPC_New_Features_3.2.2|previous 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 [[User Changes Trunk|here]].
 
A list of changes that may break existing code can be found [[User Changes Trunk|here]].
Line 7: Line 7:
 
== All systems ==
 
== All systems ==
  
=== Language ===
+
=== Compiler ===
 
 
==== Support for interfacing with C ''blocks'' functionality ====
 
* '''Overview''': Support has been added for interfacing with [http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Blocks/Articles/00_Introduction.html Apple's ''blocks'' C-extension].
 
* '''Notes''':
 
** As C ''blocks'' are very similar to anonymous methods in Delphi, we use a similar syntax to declare ''block'' types (with an added ''cdecl'' to indicate the C nature). Note that the syntax to define the code executed in a ''block'' (inline, like with anonymous methods in Delphi, or in a separately defined function/method) and the functionality of a block (the ability to capture context and code to execute it at an arbitrary point in the future) are two separate things. At this time (r29594), only the code from a global function/procedure or from an Object Pascal instance/class method can be executed within the context of a ''block''. In the future, support will be added for nested functions and later probably also for code that is defined inline, like in Delphi.
 
** This functionality is currently only supported by FPC on Mac OS X 10.7 and later, and on iOS 4.0 and later. The reason it doesn't work on Mac OS X 10.6, is that we require functionality that was added to the blocks runtime in later versions.
 
** The ''blocks'' functionality can be activated on supported platforms via ''{$modeswitch cblocks}''
 
* '''More information''':
 
** Example with a global procedure: http://svn.freepascal.org/svn/fpc/trunk/tests/test/tblock1.pp
 
** Example with an Object Pascal instance method: http://svn.freepascal.org/svn/fpc/trunk/tests/test/tblock2.pp
 
* '''svn''': r29517, r29594
 
  
==== Support for Default Namespaces ====
+
==== fpcres can compile RC files ====
* '''Overview''': Namespaces can be supplied to the compiler to be prefixed to units that would otherwise not be found
 
* '''Description''':
 
** Use the new ''-FN<x>'' parameter to add a default namespace <x> to the list of default namespaces. If a unit name can not be found as-is then it will be searched for using all provided default namespaces as prefix (separated by a ".") until it is found or the list of namespaces is exhausted.
 
** The default namespaces can also be used as prefixes for identifiers outside the ''uses'' section.
 
* '''More information''': announcement mail at https://lists.freepascal.org/pipermail/fpc-pascal/2018-May/053769.html
 
* '''svn''': r38911 - r38922
 
  
==== Dynamic Arrays supported by Insert() ====
+
* '''Overview''': The ''fpcres'' utility gained support for compiling RC files to RES files if the output format (parameter ''-of'') is set to ''rc''. The Free Pascal compiler itself can use ''fpcres'' instead of ''windres'' or ''gorc'' as well if the option ''-FF'' is supplied.
* '''Overview''': The ''Insert()'' intrinsic can be used to insert arrays and elements into an existing dynamic array.
+
* '''Notes''': Using ''fpcres'' instead of ''windres'' or ''gorc'' will become default once a release with the new ''fpcres'' is released.
* '''Notes''':
+
* '''svn''': 46398 (and others before and after that)
** The element to be inserted can be either of the following:
 
***dynamic array of the same type
 
***static array of the same type
 
***a single element of the array's element type
 
** The insertion index is zero based
 
** If the dynamic array to be modified is empty it will simply contain the new data afterwards
 
** If the index is larger than the current highest index of the array then the new data is appended at the end
 
** If the index is negative then the new data will be appended at the start of the array
 
** This feature is Delphi compatible with the exception of inserting static arrays which is not supported by Delphi
 
* '''More information''': announcement mail at https://lists.freepascal.org/pipermail/fpc-pascal/2018-May/053892.html
 
  
==== Dynamic Arrays supported by Delete() ====
+
=== Language ===
* '''Overview''': The ''Delete()'' intrinsic can be used to remove a sub range from an existing dynamic array.
 
* '''Notes''':
 
** The start index is zero based
 
** The resulting range of ''Index'' and ''Count'' will be capped at the dynamic array's boundaries (namely 0 and the highest element); this may mean that in an extreme case no element is removed as the range is outside of the array's
 
** This feature is Delphi compatible
 
* '''More information''': announcement mail at http://lists.freepascal.org/pipermail/fpc-pascal/2018-May/053891.html
 
 
 
==== Dynamic Arrays supported by Concat() ====
 
* '''Overview''': The ''Concat()'' intrinsic can be used to concatenate two or more dynamic arrays together.
 
* '''Notes''':
 
** The resulting array will look as if all array elements had been added manually to the new array in order
 
** Empty arrays don't contribute to the new array
 
** This feature is Delphi compatible
 
* '''More information''': announcement mail at http://lists.freepascal.org/pipermail/fpc-pascal/2018-May/053891.html
 
 
 
==== Dynamic Arrays have built in ''+'' operator support ====
 
* '''Overview''': The ''+'' operator can be used to concatenate two or more dynamic arrays together.
 
* '''Notes''':
 
** Requires new modeswitch ''ArrayOperators'' (enabled by default in Delphi modes)
 
** The resulting array will look as if all array elements had been added manually to the new array in order
 
** Empty arrays don't contribute to the new array
 
** This feature is Delphi compatible
 
* '''More information''': announcement mail at http://lists.freepascal.org/pipermail/fpc-pascal/2018-May/053891.html
 
 
 
==== Dynamic Array constants and variable initialization ====
 
* '''Overview''': Dynamic arrays constants are now possible just as well as initializing dynamic array variables during their declaration. In both cases the same syntax as for static arrays is used.
 
* '''Notes''':
 
** Adheres to the ''$J'' switch regarding writable constants, both for the variable itself as well as its content
 
** Static and dynamic array constants can be nested
 
** Delphi compatibility:
 
*** In Delphi modes the syntax is ''[…]'' instead of ''(…)''
 
*** Static array constants can not be used inside dynamic array constants
 
*** Delphi does not adhere to the ''$J'' switch for the array's contents
 
* '''More information''': announcement mail at http://lists.freepascal.org/pipermail/fpc-pascal/2018-May/053891.html
 
 
 
==== Dynamic Arrays constructors ====
 
* '''Overview''': The ''[…]'' syntax can be used to initialize dynamic array variables in code or to pass them to dynamic arrays parameters.
 
* '''Notes''':
 
** This feature is Delphi compatible
 
* '''More information''': announcement mail at http://lists.freepascal.org/pipermail/fpc-pascal/2018-May/053891.html
 
 
 
==== More settings supported by ''$Push''/''$Pop'' ====
 
* '''Overview''': The directives ''$Push'' and ''$Pop'' now also handle the directives ''$MinEnumSize'', ''$PackSet'' and ''$PackRecords''.
 
 
 
==== Support for ''threadvar'' sections inside class and record types ====
 
* '''Overview''': Class and record types can now contain a ''class threadvar'' section that allows for the addition of scoped threadvar variables.
 
* '''Notes''':
 
** This feature is Delphi compatible
 
** Not including the ''class'' specifier is considered an error
 
* '''svn''': 39285 - 39289
 
 
 
==== Support for generic routines ====
 
* '''Overview''': It is now possible to declare generic routines (functions, procedures, methods) either as part of structured types or globally. In non-Delphi modes they are declared with the '''generic''' keyword preceding the '''procedure''' or '''function''' keyword and specialized with the '''specialize''' keyword preceeding the identifier of the generic routine when issueing a call. In mode Delphi the syntax follows that of Delphi.
 
* '''Notes''':
 
** This feature is Delphi-compatible, with the addition that Delphi does ''not'' support global generic functions or procedures, only methods. FPC allows them also in mode Delphi however.
 
** It's currently not possible to declare a generic method inside a generic structured type. This will be changed in a future version.
 
** It's currently not possible to take a pointer to the specialization of a generic routine.
 
** In mode Delphi complex expressions involving multiple specializations are not yet possible.
 
** Inlining is supported as long as the body of the generic has already been parsed.
 
* '''Examples''':
 
<syntaxhighlight lang="pascal">
 
unit UTest;
 
{$mode objfpc}
 
 
 
interface
 
 
 
generic function Add<T>(aArg1, aArg2: T): T;
 
 
 
implementation
 
 
 
generic function Add<T>(aArg1, aArg2: T): T;
 
begin
 
  Result := aArg1 + aArg2;
 
end;
 
 
 
end.
 
</syntaxhighlight>
 
<syntaxhighlight lang="pascal">
 
program Test;
 
 
 
{$mode objfpc}{$H+}
 
 
 
uses
 
  UTest;
 
 
 
begin
 
  Writeln(specialize Add<String>('Hello', 'World'));
 
  Writeln(specialize Add<LongInt>(23, 19));
 
end.
 
</syntaxhighlight>
 
 
 
==== Management operators for record types ====
 
* '''Overview''': It is now possible to declare operators inside a record so that the built-in initialization, finalization and copying of record types can be extended. The supported operators are ''Initialize'', ''Finalize'', ''Copy'' and ''AddRef''. ''Initialize'', ''Finalize'' and ''AddRef'' take the record as a '''var'''-parameter while the ''Copy'' operator takes the source record as first parameter and the destination record as second parameter whereby that one is a '''var'''-parameter. The ''Initialize'' and ''Finalize'' operators are called when such a record enters the scope or leaves it respectively. ''Copy'' is called when a record variable is assigned to another. ''AddRef'' is called when a new reference to an existing record is required which for example the case when by-value-parameters are passed.
 
* '''Example''': See http://svn.freepascal.org/svn/fpc/trunk/tests/test/tmoperator8.pp and the other tmoperator*.pp tests
 
 
 
==== Method RTTI for interfaces ====
 
* '''Overview''': Is the ''$M'' directive enabled when parsing an interface detailed RTTI for each method contained in the interface is generated. This information is detailed enough to not only enumerate the parameter declaration, but also to call interface functions with the help of the ''Rtti.Invoke()'' function.
 
* '''Notes''':
 
** The idea of the feature is Delphi compatible, however the RTTI binary data is not.
 
** It's recommended to either use the records provided by unit ''TypInfo'' or the types provided by unit ''Rtti'' for access to avoid any problems with parsing the data.
 
** The generation of method RTTI data is currently restricted to COM-interfaces.
 
* '''Example''': See https://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/tests/test/trtti15.pp
 
  
 
==== Support for "volatile" intrinsic ====
 
==== 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.
 
* '''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/
+
* '''Notes''':
* '''Example''': https://svn.freepascal.org/svn/fpc/trunk/tests/test/tmt1.pp
+
** 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/
 +
** Accesses to fixed absolute addresses (as common on DOS and embedded platforms) are automatically marked as volatile by the compiler.
 +
* '''Example''': https://gitlab.com/freepascal.org/fpc/source/-/blob/main/tests/test/tmt1.pp
 
* '''svn''': 40465
 
* '''svn''': 40465
  
Line 156: Line 29:
 
* '''Notes''': Mainly added for internal compiler usage related to LLVM support.
 
* '''Notes''': Mainly added for internal compiler usage related to LLVM support.
 
* '''svn''': 41198
 
* '''svn''': 41198
 
==== Support for helper types extending interface types ====
 
* '''Overview''': A '''type helper''' can now also extend interface types. The implementations are not provided by the interface implementer, but by the helper itself.
 
* '''Notes''': This allows to add functionality to an interface that does not depend on the implementer, but merely on the interface.
 
* '''svn''': 37023
 
  
 
==== Support for multiple active helpers per type ====
 
==== 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.
 
* '''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
+
* '''Examples''': All tests with the name ''tmshlp*.pp'' in https://gitlab.com/freepascal.org/fpc/source/-/tree/main/tests/test
 
* '''svn''': 42026
 
* '''svn''': 42026
  
 
==== Support for custom attributes ====
 
==== 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.
 
* '''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 here: https://lists.freepascal.org/pipermail/fpc-announce/2019-July/000612.html
+
* '''Notes''': More information can be seen in the [https://lists.freepascal.org/pipermail/fpc-announce/2019-July/000612.html announcement mail] and [[Custom_Attributes|Custom Attributes]]
 
* '''svn''': 42356 - 42411
 
* '''svn''': 42356 - 42411
 
* '''Example''':
 
* '''Example''':
Line 228: Line 96:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
=== Units ===
+
==== 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.
 +
* '''Notes''':
 +
** This feature is not Delphi compatible, but can be used in mode ''Delphi'' as well
 +
** More information is available in the [https://lists.freepascal.org/pipermail/fpc-devel/2020-April/042708.html announcement mail].
 +
* '''Examples''': All tests with the name ''tgenconst*.pp'' in https://gitlab.com/freepascal.org/fpc/source/-/tree/main/tests/test
 +
* '''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://gitlab.com/freepascal.org/fpc/source/-/tree/main/tests/test/tisconstvalue2.pp
 +
* '''svn''': 45695
 +
 
 +
==== Copy supports Open Array parameters ====
 +
* '''Overview''': The ''Copy'' intrinsic can now be used to copy (a part of) the contents of an open array parameter to a dynamic array.
 +
* '''Notes''':
 +
** The result of the ''Copy'' function will have the type of a dynamic array with the same element type as the parameter that is copied from.
 +
** If the ''Start'' parameter is out of range the resulting dynamic array will be empty.
 +
** If the ''Count'' parameter is too large then the resulting dynamic array will only contain the elements that exist.
 +
* '''svn''': 46890
 +
* '''Example''':
 +
<syntaxhighlight lang="pascal">
 +
procedure Test(aArg: array of LongInt);
 +
var
 +
  arr: array of LongInt;
 +
begin
 +
  arr := Copy(aArg, 3, 5);
 +
end;
 +
</syntaxhighlight>
 +
 
 +
==== Array constructors for static arrays ====
 +
* '''Overview''': Array constructors can be used to assign values to static arrays.
 +
* '''Notes''':
 +
** The array constructor needs to have the same amount of elements as the static array.
 +
** The first element of the array constructor will be placed at the location of the first element of the static array (e.g. if the array starts at -1 the first element will be at that location).
 +
** Arrays with enumeration index are supported as well.
 +
* '''svn''': 46891, 46901
 +
* '''Example''': https://gitlab.com/freepascal.org/fpc/source/-/tree/main/tests/test/tarrconstr16.pp
  
==== Rtti unit ====
+
==== "Align" modifier support for record definitions ====
* '''Overview''': A new unit named ''Rtti'' has been added which provides a high-level, object oriented access to the type information stored in the binary.
+
* '''Overview''': It is now possible to add an '''Align X''' modifier at the end of a record definition to indicate that the record as a whole should be aligned to a particular boundary.
 
* '''Notes''':
 
* '''Notes''':
** This unit is intended to be Delphi-compatible
+
** Should be Delphi compatible, although documentation is not available ([https://web.archive.org/web/20171221044023/http://qc.embarcadero.com/wc/qcmain.aspx?d=87283 "semi-official" reference]; the mentioned issue does not exist in the FPC implementation).
** This unit is currently experimental and not all features provided by the Delphi equivalent are yet available. Either types/methods are missing and thus compilation will fail or calling unsupported methods will trigger an exception.
+
** This does not influence the alignment of the individual fields, which are still aligned according to the current ''{$packrecords y}''/''{$align y}'' settings.
** The ''Invoke()'' function as well as the callback functionality for ''TMethodImplementation'' is provided by a manager which is by default not set (an ''EInvocationError'' will be raised in that case). Currently an implementation using the [http://sourceware.org/libffi/ libffi] library is provided for selected platforms for which the unit ''ffi.manager'' needs to be used in the main project file, as well as a native implementation for x86_64 Windows which does not rely on the ''ffi.manager'' unit.
+
** X can be 1, 2, 4, 8, 16, 32 or 64.
 +
* '''svn''': 47892
 +
* '''Example''': https://gitlab.com/freepascal.org/fpc/source/-/blob/main/tests/webtbs/tw28927.pp
 +
 
 +
==== Support for binary literals in Delphi mode ====
 +
* '''Overview''': It is now possible to use binary literals ('%' as prefix) in Delphi mode.
 +
* '''Notes''': [https://docwiki.embarcadero.com/RADStudio/Alexandria/en/What%27s_New#Binary_Literals_and_Digit_Separator Delphi compatibility].
 +
* '''GitLab issue''': [https://gitlab.com/freepascal.org/fpc/source/-/issues/39503 #39503]
 +
* '''Example''':
 +
<syntaxhighlight lang="pascal">
 +
{$mode Delphi}
 +
var
 +
  b: byte;
 +
begin
 +
  b:=%11001001;
 +
end.
 +
</syntaxhighlight>
 +
 
 +
==== Support for Digit Separator ====
 +
* '''Overview''': It is now possible to use the Digit Separator ('_') with the ''underscoreisseparator'' modeswitch. It is also enabled by default in Delphi mode.
 +
* '''Notes''': [https://docwiki.embarcadero.com/RADStudio/Alexandria/en/What%27s_New#Binary_Literals_and_Digit_Separator Delphi compatibility].
 +
* '''GitLab issue''': [https://gitlab.com/freepascal.org/fpc/source/-/issues/39504 #39504]
 +
* '''Example''':
 +
<syntaxhighlight lang="pascal">
 +
{$mode Delphi}
 +
var
 +
  i: Integer;
 +
  r: Real;
 +
begin
 +
  i := %1001_1001;
 +
  i := &121_102;
 +
  i := 1_123_123;
 +
  i := $1_123_123; 
 +
  r := 1_123_123.000_000;
 +
  r := 1_123_123.000_000e1_2;
 +
end.
 +
</syntaxhighlight>
  
==== ProcessUnicode unit ====
+
==== Support for forward declarations of generic types ====
* '''Overview''': A new unit named ''ProcessUnicode'' has been added which provides an unicodestring version of TProcess. This allows unicodesupport on Windows without setting the default type to UTF-8.
+
* '''Overview''': It is now possible to use forward declarations for generic classes and interfaces like is possible for non-generic classes and interfaces.
 
* '''Notes''':
 
* '''Notes''':
** Both the old and the new TProcess units were reworked. Parts of the Runcommand support are now accessible in the class and parametrized with events. This makes custom versions easier.
+
** Generic type constraints and const declarations need to be used for both the forward and the final implementation like is necessary for global generic routines.
 +
** This is Delphi-compatible.
 +
* '''Commit''': [https://gitlab.com/freepascal.org/fpc/source/-/commit/2a5023508a2bc4ff3ba4f3a0ca16366d3df86db8 2a502350]
 +
* '''Example''':
 +
<syntaxhighlight lang="pascal">
 +
{$mode objfpc}
 +
type
 +
  generic TTest<T> = class;
 +
  generic TFoo<T: class> = class;
 +
  generic TBar<const N: LongInt> = class;
  
 +
  TSomething = class
 +
    fTest: specialize TTest<LongInt>;
 +
    fFoo: specialize TFoo<TObject>;
 +
    fBar: specialize TBar<42>;
 +
  end;
  
==== Registry unit ====
+
  generic TTest<T> = class end;
*'''Overview''': The TRegistry class was made to be fully Unicode capable.
+
  generic TFoo<T: class> = class end;
*'''Notes''':  
+
  generic TBar<const N: LongInt> = class end;
**All public and protected methods (the public API) that used string parameters now default to use UnicodeString parameters.
+
 
**For all these methods overloads exist using String parameters (these call their UnicodeString counterparts).
+
begin
**Methods using TStrings have counterparts using TUnicodeStringArray, and ReadStringList/WriteStringList let you specify if the TStrings should be treated as UTF8 encoded.
+
end.
**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).
+
</syntaxhighlight>
**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
 
  
=== IDE ===
+
==== Support for Function References and Anonymous Functions ====
 +
* '''Function References''': Function References (also applicable names are Procedure References and Routine References, in the following only Function References will be used) are types that can take a function (or procedure or routine), method, function variable (or procedure variable or routine variable), method variable, nested function (or nested procedure or nested routine) or an anonymous function (or anonymous procedure or anonymous routine) as a value. The function reference can then be used to call the provided function just like other similar routine pointer types. In contrast to these other types nearly all function-like constructs can be assigned to it (the only exception are nested function variables (or nested procedure variables or nested routine variables), more about that later on) and then used or stored.
 +
* '''Anonymous Functions''': Anonymous Functions (or Anonymous Procedures or Anonymous Routines, in the following simply Anonymous Functions) are routines that have no name associated with them and are declared in the middle of a code block (for example on the right side of an expression or as a parameter for a function call). However they can just as well be called directly like a nested function (or nested procedure or nested routine) would.
 +
* '''More Information and Examples''': [https://forum.lazarus.freepascal.org/index.php/topic,59468.0.html Feature announcement: Function References and Anonymous Functions]
 +
* '''GitLab Issue''': [https://gitlab.com/freepascal.org/fpc/source/-/issues/24481 #24481]
  
==== GDB/MI support ====
+
==== Descendant type helpers can extend type aliases ====
* '''Overview''': GDB/MI support has been added to the text mode IDE.
+
* '''Overview''': A type helper that descends from another type helper can now extend a unique type alias of the type the inherited type helper extends. This way a type helper for the original type can be made available for the type alias as well.
 
* '''Notes''':
 
* '''Notes''':
** It is enabled default, but can be disabled by building FPC with ''make NOGDBMI=1''
+
** The type alias the descendant extends does not need to be a ''direct'' type alias of the parent's extended type.
** The old and deprecated libgdb.a support is still there for platforms that do not have a modern GDB port (or e.g. don't support true multitasking, like go32v2).
+
** The other way around is not allowed: a type helper that inherits from another helper which extends a unique type alias can not extend the base type.
** When debugging a console application in Windows in GDB/MI mode, the debugged program is always run in a separate console. This is due to a limitation of the Windows GDB port.
+
* '''Example''': See the [https://gitlab.com/freepascal.org/fpc/source/-/blob/main/tests/test/tthlp30.pp test] for the feature.
* '''svn''': r30573
+
* '''Commit''': [https://gitlab.com/freepascal.org/fpc/source/-/commit/7133ad7ecc46700618193adff85cef84682355b0 7133ad7e]
  
== (Mac) OS X/iOS ==
+
==== Support for Unicode RTL ====
 +
* '''Overview''': The Unicode RTL is required for Delphi 2009+ compatibility. This also includes support for dotted filenames like ''System.SysUtils''
 +
* '''Notes''': [https://wiki.freepascal.org/FPC_Unicode_RTL FPC Unicode RTL].
 +
* '''fpc-devel Mailinglist announcement''': [https://lists.freepascal.org/pipermail/fpc-devel/2023-July/045194.html Unicode RTL]
  
=== New ''iosxwstr'' unit ===
+
==== Support for Extended RTTI ====
* '''Overview''': The new unit called ''iosxwstr'' can be used to install a widestring manager on (Mac) OS X and iOS.
+
* '''Overview''': Extended RTTI includes the for ''$RTTI'' directive, generating RTTI metadata for all fields, methods and properties and allowing the access of the RTTI metadata via TypInfo and RTTI unit.
* '''Notes''': The ''cwstring'' unit fulfils the same purpose, but is no longer able to provide full functionality on iOS 7 and newer due to Apple no longer shipping the locale and codepage information this unit depends on. The ''iosxwstr'' unit gets its locale information for upper/lowercase conversions from the System Preferences. Adding both ''cwstring'' and ''iosxwstr'' to the uses clause will cause the second in line to override the settings from the first one.
+
* '''Notes''': [https://docwiki.embarcadero.com/RADStudio/Alexandria/en/RTTI_directive_(Delphi) Delphi 2010+ compatibility].
* '''More information''': Adding this unit to the uses clause is enough to use its functionality.
+
* '''GitLab issue''': [https://gitlab.com/freepascal.org/fpc/source/-/issues/38964 #38964]
* '''svn''': r29828
+
* '''Commit''': [https://gitlab.com/freepascal.org/fpc/source/-/compare/c74441323ac9712f0a1f08349debcffe580734d1...a98462835ed6848b62ef95188627e11c4ba52df0 7eea8507..a9846283]
  
== i8086-msdos ==
+
=== Units ===
  
=== Huge memory model ===
+
==== DaemonApp ====
* '''Overview''': Support has been added for the i8086 huge memory model.
+
===== Additional control codes on Windows =====
* '''Notes''': The huge memory model (compared to the large memory model) removes the 64kb limitation of static data for the whole program. However, there's still a 64kb limit for the static data of a single unit.
+
* '''Overview''': Windows allows a service to request additional control codes to be received. For example if the session of the user changed. These might also carry additional parameters that need to be passed along to the ''TDaemon'' instance. For this the ''WinBindings'' class of the ''TDaemonDef'' now has an additional ''AcceptedCodes'' field (which is a set) that allows to define which additional codes should be requested. Then the daemon should handle the ''OnControlCodeEvent'' event handler which in contrast to the existing ''OnControlCode'' handler takes two additional parameters that carry the parameters that the function described for MSDNs ''[https://docs.microsoft.com/en-us/windows/win32/api/winsvc/nc-winsvc-lphandler_function_ex LPHANDLER_FUNCTION_EX]'' takes as well.
* '''More information''': [[DOS#Huge|Huge memory model]]
+
* '''Notes''': This lead to slight incompatibilities which are mentioned in [[User_Changes_Trunk#DaemonApp|User Changes Trunk]]
* '''svn''': r31518
+
* '''svn''': 46326, 46327
  
=== Internal assembler (object writer) ===
+
==== Classes ====
* '''Overview''': There's an internal assembler/object writer implemented for the i8086-msdos platform. It replaces NASM and the WLIB tool.
+
===== Naming of Threads =====
* '''Notes''': NASM is still required for building an i8086-msdos snapshot, because of the msdos startup code in the rtl. However, WLIB (from Open Watcom) is no longer required, so you can now build a fully functional smartlinked i8086-msdos snapshot from a platform that doesn't have the Open Watcom tools (such as DJGPP or Mac OS X).
+
* '''Overview''': ''TThread.NameThreadForDebugging'' has been implemented for macOS.
* '''svn''': r30809
+
* '''Notes''': Delphi compatible, was already implemented for Windows, Linux and Android and finally for macOS now. Read documentation as every platform has its own restrictions.
 +
* '''svn:''' 49323
  
=== Internal linker ===
+
==== Objects ====
* '''Overview''': There's an internal linker implemented for the i8086-msdos platform. It replaces WLINK from Open Watcom.
+
===== TRawByteStringCollection =====
* '''Notes''': Together with the internal assembler, the internal linker removes the dependency on Open Watcom tools. NASM is still required for building an i8086-msdos snapshot, because of the msdos startup code in the rtl.
+
* '''Overview''': A new object type TRawByteStringCollection, similar to TStringCollection, but works with RawByteString/AnsiString
* '''svn''': r31425
+
* '''git:''' 0b8a0fb4
  
=== FarAddr internal function ===
+
===== TUnicodeStringCollection =====
* '''Overview''': There's a new i8086-specific internal function, similar to Addr(), called FarAddr(), which always returns a far pointer to the address of its argument.
+
* '''Overview''': A new object type TUnicodeStringCollection, similar to TStringCollection, but works with UnicodeString
* '''Notes''': The built-in Addr() function and the @ operator return a pointer type (near or far), that depends on the memory model. When interfacing with DOS, BIOS and other 16-bit APIs, it is sometimes useful to be able to obtain a far pointer to a pascal variable or procedure/function, regardless of the selected memory model. Previously, you would have to use ifdefs, or do something like Ptr(Seg(x), Ofs(x)). Now, this can be replaced with the much nicer FarAddr(x).
+
* '''git:''' 0b8a0fb4
* '''svn''': r37629
 
  
=== Near and far procedure variables ===
+
===== TStream methods for reading and writing RawByteString and UnicodeString =====
* '''Overview''': Support has been added for procedure variables with an explicitly specified ''near'' or ''far'' call model.
+
* '''Overview''': New methods have been added to TStream for reading and writing RawByteString/AnsiString and UnicodeString types.
* '''Notes''': By default, procedure variables follow the default call model of the current memory model - ''near'' in the ''tiny'', ''small'' and ''compact'' memory models; ''far'' in the ''medium'', ''large'' and ''huge'' models. However, now you can specify an explicit ''near'' or ''far'' call model, regardless of the default for the current memory model. Note that ''near'' and ''far'' procedure variables are not compatible with each other. Syntax is really simple:
+
* '''Notes''': The following methods have been added:
  type
+
FUNCTION TStream.ReadRawByteString: RawByteString;
  TFarProc = procedure(a, b: Integer); far;
+
FUNCTION TStream.ReadUnicodeString: UnicodeString;
  TNearProc = procedure(a, b: Integer); near;
+
  PROCEDURE TStream.WriteRawByteString (Const S: RawByteString);
Near procedure variables are 2 bytes long, so they contain only an offset. They are invoked with a near ''call'' instruction. Far procedure variables are 4 bytes long (16-bit offset + 16-bit offset) and are invoked with a far ''call''. Note that you cannot simply convert a near procedure to a far procedure, by just filling in the segment part, because the call model is also different between near and far procedures. A far call instruction pushes a 4-byte far (segment:offset) return address and the function must terminate with a far return instruction - ''retf''. A near call instruction pushes only a 2-byte offset on the stack and the function must terminate with a near return instruction - ''retn''.
+
PROCEDURE TStream.WriteUnicodeString (Const S: UnicodeString);
* '''svn''': r38691
+
RawByteStrings are written to the stream as a 16-bit code page, followed by 32-bit length, followed by the string contents. UnicodeStrings are written as a 32-bit length (the number of 16-bit UTF-16 code units needed to encode the string), followed by the string itself in UTF-16.
 +
* '''git:''' 0b8a0fb4
  
== x86_64-win64 ==
+
==== Free Vision ====
 +
===== Unicode support =====
 +
* '''Overview''': Unicode versions of the Free Vision units have been added.
 +
* '''Notes''': The Unicode versions of the units have the same name as their non-Unicode counterparts, but with an added 'U' prefix in the beginning of their name. For example, the Unicode version of the 'app' unit is 'uapp', the Unicode version of 'views' is 'uviews', etc. The Unicode versions of the units use the UnicodeString type, instead of shortstrings and pchars. Mixing Unicode and non-Unicode Free Vision units in the same program is not supported and will not work.
 +
* '''More information''': [[Free_Vision#Unicode_version]]
 +
* '''git:''' 0b8a0fb4
  
=== Support for Microsoft's vectorcall calling convention ===
+
==== Video ====
* '''Overview''': Under x86_64 (not i386), support for the "vectorcall" calling convention is now possible on Windows targets by specifying the '''vectorcall''' modifier.
+
===== Unicode output support =====
* '''Notes''': Utilises the XMM registers better than the default Microsoft ABI, allowing aligned arrays of Singles and Doubles to be passed in a single register akin to the System V ABI as used by Linux and other OS's. Also allows projects to interface with external libraries that use the convention. "vectorcall" is silently ignored if the target is not x86_64-win64.
+
* '''Overview''': Unicode video buffer support has been added to the Video unit.
* '''svn''': 38206
+
* '''Notes''': To use the Unicode video buffer, you must call InitEnhancedVideo instead of InitVideo and finalize the unit with DoneEnhancedVideo instead of DoneVideo. After initializing with InitEnhancedVideo, you must use the EnhancedVideoBuf array instead of VideoBuf. On non-Unicode operating systems, the Video unit will automatically translate Unicode characters to the console code page. This is done transparently to the user application, so new programs can always use EnhancedVideoBuf, without worrying about compatibility.
 +
* '''git:''' 0b8a0fb4
  
== New compiler targets ==
+
==== Keyboard ====
 +
===== Unicode keyboard input support =====
 +
* '''Overview''': Unicode keyboard input support has been added to the Keyboard unit.
 +
* '''Notes''': After initializing the unit normally via InitKeyboard, you can obtain enhanced key events, which include Unicode character information, as well as an enhanced shift state. To get enhanced key events, use GetEnhancedKeyEvent or PollEnhancedKeyEvent. They return a TEnhancedKeyEvent, which is a record with these fields:
 +
  TEnhancedKeyEvent = record
 +
    VirtualKeyCode: Word;    { device-independent identifier of the key }
 +
    VirtualScanCode: Word;  { device-dependent value, generated by the keyboard }
 +
    UnicodeChar: WideChar;  { the translated Unicode character }
 +
    AsciiChar: Char;        { the translated ASCII character }
 +
    ShiftState: TEnhancedShiftState;
 +
    Flags: Byte;
 +
  end;
  
=== Support for the AArch64 target ===
+
TEnhancedShiftState is a set of TEnhancedShiftStateElement, which is defined as:
 +
  TEnhancedShiftStateElement = (
 +
    essShift,            { either Left or Right Shift is pressed }
 +
    essLeftShift,
 +
    essRightShift,
 +
    essCtrl,              { either Left or Right Ctrl is pressed }
 +
    essLeftCtrl,
 +
    essRightCtrl,
 +
    essAlt,              { either Left or Right Alt is pressed, but *not* AltGr }
 +
    essLeftAlt,
 +
    essRightAlt,          { only on keyboard layouts, without AltGr }
 +
    essAltGr,            { only on keyboard layouts, with AltGr instead of Right Alt }
 +
    essCapsLockPressed,
 +
    essCapsLockOn,
 +
    essNumLockPressed,
 +
    essNumLockOn,
 +
    essScrollLockPressed,
 +
    essScrollLockOn
 +
  );
  
* '''Overview''': Support has been added for the AArch64 architecture. Both Darwin (iOS) and Linux supported.
+
A special value NilEnhancedKeyEvent is used to indicate no key event available in the result of PollEnhancedKeyEvent:
* '''Notes''': Apple's A7 CPU (and potentially other AArch64 CPUs too) does not support raising a signal when a floating point exception occurs.
+
  { The Nil value for the enhanced key event }
* '''More information''': https://lists.freepascal.org/pipermail/fpc-devel/2015-February/035524.html
+
  NilEnhancedKeyEvent: TEnhancedKeyEvent = (
* '''svn''': r29986 (Darwin/iOS), r30897 (Linux)
+
    VirtualKeyCode: 0;
 +
    VirtualScanCode: 0;
 +
    UnicodeChar: #0;
 +
    AsciiChar: #0;
 +
    ShiftState: [];
 +
    Flags: 0;
 +
  );
  
=== Support for the Linux/ppc64le target ===
+
* '''git:''' 0b8a0fb4
  
* '''Overview''': Support has been added for the Linux/ppc64le target. This is a PowerPC64 little endian platform that uses a new ABI termed ELFv2.
+
== Darwin/macOS platforms ==
* '''Notes''': It is not easy to build this target on a big endian Linux/ppc64 target, due to the fact that the build system does not yet contain support to deal with different ABIs/endianess.
 
* '''More information''': To cross-compile a ppc64le compiler, use CROSSOPT="-Cb- -Caelfv2". Those options don't have to be specified when compiling on a ppc64le system using a native ppcppc64, as they will be set by default for that compiler.
 
* '''svn''': r30228
 
  
=== Support for the i8086-win16 (16-bit Windows) target ===
+
=== Support for symbolicating Dwarf backtraces ===
 +
* '''Overview''': The -gl option now works with DWARF debug information on Darwin. This is the default for non-PowerPC Darwin targets, and the only support format for ARM and 64 bit Darwin targets.
 +
* '''Notes''': You have to also use the -Xg command line option when compiling the main program or library, to generate a .dSYM bundle that contains all debug information. You can also do this manually by calling ''dsymutil''
 +
* '''svn''': 49140
  
* '''Overview''': Experimental support has been added for the 16-bit Windows target. It is a cross compiler only target (cross compilation is possible from e.g. Win32, Win64 or Linux).
+
== New compiler targets ==
* '''Notes''': Windows 3.0 or later is supported.
 
* '''More information''': [[Win16]]
 
  
 
=== Support for code generation through LLVM ===
 
=== Support for code generation through LLVM ===
 
* '''Overview''': The compiler now has a code generator that generates LLVM bitcode.
 
* '''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.
+
* '''Notes''': LLVM still requires target-specific support and modifications in the compiler. Initially, the LLVM code generator only works when targeting Darwin/x86-64, Darwin/AArch64 (only macOS; iOS has not been tested), Linux/x86-64, Linux/ARMHF and Linux/AArch64.
 
* '''More information''': [[LLVM]]
 
* '''More information''': [[LLVM]]
 
* '''svn''': 42260
 
* '''svn''': 42260
  
== New Features from other versions ==
+
=== Support for address sanitizer (asan) through LLVM ===
 +
* '''Overview''': The compiler allows to check code with the LLVM address sanitizer.
 +
* '''Notes''': The LLVM address sanitizer is supported for all 64 bit targets supported by the LLVM code generator.
 +
* '''More information''':
 +
** [[LLVM]]
 +
** [https://en.wikipedia.org/wiki/AddressSanitizer Address Sanitizer on Wikipedia]
 +
* '''git''': [https://gitlab.com/freepascal.org/fpc/source/-/commit/403292a13151dbc265748d2119f9d1bd52fb9d54 403292a1]
 +
 
 +
=== Support for the Z80 ===
 +
* '''Overview''': Support has been added for generating Z80 code.
 +
* '''More information''': [[Z80]]
 +
 
 +
=== Support for the WebAssembly target ===
 +
* '''Overview''': Support has been added for generating WebAssembly code.
 +
* '''More information''': [[WebAssembly/Compiler]]
 +
 
 
{{Navbar Lazarus Release Notes}}
 
{{Navbar Lazarus Release Notes}}
  
 
[[Category:FPC New Features by release]]
 
[[Category:FPC New Features by release]]
 
[[Category:Release Notes]]
 
[[Category:Release Notes]]

Latest revision as of 20:28, 27 January 2024

About this page

Below you can find a list of new features introduced since the previous 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

Compiler

fpcres can compile RC files

  • Overview: The fpcres utility gained support for compiling RC files to RES files if the output format (parameter -of) is set to rc. The Free Pascal compiler itself can use fpcres instead of windres or gorc as well if the option -FF is supplied.
  • Notes: Using fpcres instead of windres or gorc will become default once a release with the new fpcres is released.
  • svn: 46398 (and others before and after that)

Language

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/
    • Accesses to fixed absolute addresses (as common on DOS and embedded platforms) are automatically marked as volatile by the compiler.
  • Example: https://gitlab.com/freepascal.org/fpc/source/-/blob/main/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://gitlab.com/freepascal.org/fpc/source/-/tree/main/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}

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

  {$M+}
  [TMyAttribute]
  TTestClass = class
  private
    fTest: LongInt;
  published
    [TMyAttribute('Test')]
    property Test: LongInt read fTest;
  end;
  {$M-}

  [TMyAttribute(1234)]
  [TMy('Hello World')]
  TTestEnum = (
    teOne,
    teTwo
  );

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

constructor TMyAttribute.Create;
begin
end;

constructor TMyAttribute.Create(aArg: String);
begin
end;

constructor TMyAttribute.Create(aArg: LongInt);
begin
end;

constructor TMyAttribute.Create(aArg: TGUID);
begin
end;

begin

end.

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.
  • Notes:
    • This feature is not Delphi compatible, but can be used in mode Delphi as well
    • More information is available in the announcement mail.
  • Examples: All tests with the name tgenconst*.pp in https://gitlab.com/freepascal.org/fpc/source/-/tree/main/tests/test
  • 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://gitlab.com/freepascal.org/fpc/source/-/tree/main/tests/test/tisconstvalue2.pp
  • svn: 45695

Copy supports Open Array parameters

  • Overview: The Copy intrinsic can now be used to copy (a part of) the contents of an open array parameter to a dynamic array.
  • Notes:
    • The result of the Copy function will have the type of a dynamic array with the same element type as the parameter that is copied from.
    • If the Start parameter is out of range the resulting dynamic array will be empty.
    • If the Count parameter is too large then the resulting dynamic array will only contain the elements that exist.
  • svn: 46890
  • Example:
procedure Test(aArg: array of LongInt);
var
  arr: array of LongInt;
begin
  arr := Copy(aArg, 3, 5);
end;

Array constructors for static arrays

  • Overview: Array constructors can be used to assign values to static arrays.
  • Notes:
    • The array constructor needs to have the same amount of elements as the static array.
    • The first element of the array constructor will be placed at the location of the first element of the static array (e.g. if the array starts at -1 the first element will be at that location).
    • Arrays with enumeration index are supported as well.
  • svn: 46891, 46901
  • Example: https://gitlab.com/freepascal.org/fpc/source/-/tree/main/tests/test/tarrconstr16.pp

"Align" modifier support for record definitions

  • Overview: It is now possible to add an Align X modifier at the end of a record definition to indicate that the record as a whole should be aligned to a particular boundary.
  • Notes:
    • Should be Delphi compatible, although documentation is not available ("semi-official" reference; the mentioned issue does not exist in the FPC implementation).
    • This does not influence the alignment of the individual fields, which are still aligned according to the current {$packrecords y}/{$align y} settings.
    • X can be 1, 2, 4, 8, 16, 32 or 64.
  • svn: 47892
  • Example: https://gitlab.com/freepascal.org/fpc/source/-/blob/main/tests/webtbs/tw28927.pp

Support for binary literals in Delphi mode

  • Overview: It is now possible to use binary literals ('%' as prefix) in Delphi mode.
  • Notes: Delphi compatibility.
  • GitLab issue: #39503
  • Example:
{$mode Delphi}
var
  b: byte;
begin
  b:=%11001001;
end.

Support for Digit Separator

  • Overview: It is now possible to use the Digit Separator ('_') with the underscoreisseparator modeswitch. It is also enabled by default in Delphi mode.
  • Notes: Delphi compatibility.
  • GitLab issue: #39504
  • Example:
{$mode Delphi}
var
  i: Integer;
  r: Real;
begin
  i := %1001_1001;
  i := &121_102;
  i := 1_123_123;
  i := $1_123_123;  
  r := 1_123_123.000_000;
  r := 1_123_123.000_000e1_2;
end.

Support for forward declarations of generic types

  • Overview: It is now possible to use forward declarations for generic classes and interfaces like is possible for non-generic classes and interfaces.
  • Notes:
    • Generic type constraints and const declarations need to be used for both the forward and the final implementation like is necessary for global generic routines.
    • This is Delphi-compatible.
  • Commit: 2a502350
  • Example:
{$mode objfpc}
type
  generic TTest<T> = class;
  generic TFoo<T: class> = class;
  generic TBar<const N: LongInt> = class;

  TSomething = class
    fTest: specialize TTest<LongInt>;
    fFoo: specialize TFoo<TObject>;
    fBar: specialize TBar<42>;
  end;

  generic TTest<T> = class end;
  generic TFoo<T: class> = class end;
  generic TBar<const N: LongInt> = class end;

begin
end.

Support for Function References and Anonymous Functions

  • Function References: Function References (also applicable names are Procedure References and Routine References, in the following only Function References will be used) are types that can take a function (or procedure or routine), method, function variable (or procedure variable or routine variable), method variable, nested function (or nested procedure or nested routine) or an anonymous function (or anonymous procedure or anonymous routine) as a value. The function reference can then be used to call the provided function just like other similar routine pointer types. In contrast to these other types nearly all function-like constructs can be assigned to it (the only exception are nested function variables (or nested procedure variables or nested routine variables), more about that later on) and then used or stored.
  • Anonymous Functions: Anonymous Functions (or Anonymous Procedures or Anonymous Routines, in the following simply Anonymous Functions) are routines that have no name associated with them and are declared in the middle of a code block (for example on the right side of an expression or as a parameter for a function call). However they can just as well be called directly like a nested function (or nested procedure or nested routine) would.
  • More Information and Examples: Feature announcement: Function References and Anonymous Functions
  • GitLab Issue: #24481

Descendant type helpers can extend type aliases

  • Overview: A type helper that descends from another type helper can now extend a unique type alias of the type the inherited type helper extends. This way a type helper for the original type can be made available for the type alias as well.
  • Notes:
    • The type alias the descendant extends does not need to be a direct type alias of the parent's extended type.
    • The other way around is not allowed: a type helper that inherits from another helper which extends a unique type alias can not extend the base type.
  • Example: See the test for the feature.
  • Commit: 7133ad7e

Support for Unicode RTL

  • Overview: The Unicode RTL is required for Delphi 2009+ compatibility. This also includes support for dotted filenames like System.SysUtils
  • Notes: FPC Unicode RTL.
  • fpc-devel Mailinglist announcement: Unicode RTL

Support for Extended RTTI

  • Overview: Extended RTTI includes the for $RTTI directive, generating RTTI metadata for all fields, methods and properties and allowing the access of the RTTI metadata via TypInfo and RTTI unit.
  • Notes: Delphi 2010+ compatibility.
  • GitLab issue: #38964
  • Commit: 7eea8507..a9846283

Units

DaemonApp

Additional control codes on Windows
  • Overview: Windows allows a service to request additional control codes to be received. For example if the session of the user changed. These might also carry additional parameters that need to be passed along to the TDaemon instance. For this the WinBindings class of the TDaemonDef now has an additional AcceptedCodes field (which is a set) that allows to define which additional codes should be requested. Then the daemon should handle the OnControlCodeEvent event handler which in contrast to the existing OnControlCode handler takes two additional parameters that carry the parameters that the function described for MSDNs LPHANDLER_FUNCTION_EX takes as well.
  • Notes: This lead to slight incompatibilities which are mentioned in User Changes Trunk
  • svn: 46326, 46327

Classes

Naming of Threads
  • Overview: TThread.NameThreadForDebugging has been implemented for macOS.
  • Notes: Delphi compatible, was already implemented for Windows, Linux and Android and finally for macOS now. Read documentation as every platform has its own restrictions.
  • svn: 49323

Objects

TRawByteStringCollection
  • Overview: A new object type TRawByteStringCollection, similar to TStringCollection, but works with RawByteString/AnsiString
  • git: 0b8a0fb4
TUnicodeStringCollection
  • Overview: A new object type TUnicodeStringCollection, similar to TStringCollection, but works with UnicodeString
  • git: 0b8a0fb4
TStream methods for reading and writing RawByteString and UnicodeString
  • Overview: New methods have been added to TStream for reading and writing RawByteString/AnsiString and UnicodeString types.
  • Notes: The following methods have been added:
FUNCTION TStream.ReadRawByteString: RawByteString;
FUNCTION TStream.ReadUnicodeString: UnicodeString;
PROCEDURE TStream.WriteRawByteString (Const S: RawByteString);
PROCEDURE TStream.WriteUnicodeString (Const S: UnicodeString);

RawByteStrings are written to the stream as a 16-bit code page, followed by 32-bit length, followed by the string contents. UnicodeStrings are written as a 32-bit length (the number of 16-bit UTF-16 code units needed to encode the string), followed by the string itself in UTF-16.

  • git: 0b8a0fb4

Free Vision

Unicode support
  • Overview: Unicode versions of the Free Vision units have been added.
  • Notes: The Unicode versions of the units have the same name as their non-Unicode counterparts, but with an added 'U' prefix in the beginning of their name. For example, the Unicode version of the 'app' unit is 'uapp', the Unicode version of 'views' is 'uviews', etc. The Unicode versions of the units use the UnicodeString type, instead of shortstrings and pchars. Mixing Unicode and non-Unicode Free Vision units in the same program is not supported and will not work.
  • More information: Free_Vision#Unicode_version
  • git: 0b8a0fb4

Video

Unicode output support
  • Overview: Unicode video buffer support has been added to the Video unit.
  • Notes: To use the Unicode video buffer, you must call InitEnhancedVideo instead of InitVideo and finalize the unit with DoneEnhancedVideo instead of DoneVideo. After initializing with InitEnhancedVideo, you must use the EnhancedVideoBuf array instead of VideoBuf. On non-Unicode operating systems, the Video unit will automatically translate Unicode characters to the console code page. This is done transparently to the user application, so new programs can always use EnhancedVideoBuf, without worrying about compatibility.
  • git: 0b8a0fb4

Keyboard

Unicode keyboard input support
  • Overview: Unicode keyboard input support has been added to the Keyboard unit.
  • Notes: After initializing the unit normally via InitKeyboard, you can obtain enhanced key events, which include Unicode character information, as well as an enhanced shift state. To get enhanced key events, use GetEnhancedKeyEvent or PollEnhancedKeyEvent. They return a TEnhancedKeyEvent, which is a record with these fields:
 TEnhancedKeyEvent = record
   VirtualKeyCode: Word;    { device-independent identifier of the key }
   VirtualScanCode: Word;   { device-dependent value, generated by the keyboard }
   UnicodeChar: WideChar;   { the translated Unicode character }
   AsciiChar: Char;         { the translated ASCII character }
   ShiftState: TEnhancedShiftState;
   Flags: Byte;
 end;

TEnhancedShiftState is a set of TEnhancedShiftStateElement, which is defined as:

 TEnhancedShiftStateElement = (
   essShift,             { either Left or Right Shift is pressed }
   essLeftShift,
   essRightShift,
   essCtrl,              { either Left or Right Ctrl is pressed }
   essLeftCtrl,
   essRightCtrl,
   essAlt,               { either Left or Right Alt is pressed, but *not* AltGr }
   essLeftAlt,
   essRightAlt,          { only on keyboard layouts, without AltGr }
   essAltGr,             { only on keyboard layouts, with AltGr instead of Right Alt }
   essCapsLockPressed,
   essCapsLockOn,
   essNumLockPressed,
   essNumLockOn,
   essScrollLockPressed,
   essScrollLockOn
 );

A special value NilEnhancedKeyEvent is used to indicate no key event available in the result of PollEnhancedKeyEvent:

 { The Nil value for the enhanced key event }
 NilEnhancedKeyEvent: TEnhancedKeyEvent = (
   VirtualKeyCode: 0;
   VirtualScanCode: 0;
   UnicodeChar: #0;
   AsciiChar: #0;
   ShiftState: [];
   Flags: 0;
 );
  • git: 0b8a0fb4

Darwin/macOS platforms

Support for symbolicating Dwarf backtraces

  • Overview: The -gl option now works with DWARF debug information on Darwin. This is the default for non-PowerPC Darwin targets, and the only support format for ARM and 64 bit Darwin targets.
  • Notes: You have to also use the -Xg command line option when compiling the main program or library, to generate a .dSYM bundle that contains all debug information. You can also do this manually by calling dsymutil
  • svn: 49140

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, Darwin/AArch64 (only macOS; iOS has not been tested), Linux/x86-64, Linux/ARMHF and Linux/AArch64.
  • More information: LLVM
  • svn: 42260

Support for address sanitizer (asan) through LLVM

  • Overview: The compiler allows to check code with the LLVM address sanitizer.
  • Notes: The LLVM address sanitizer is supported for all 64 bit targets supported by the LLVM code generator.
  • More information:
  • git: 403292a1

Support for the Z80

  • Overview: Support has been added for generating Z80 code.
  • More information: Z80

Support for the WebAssembly target

  • Overview: Support has been added for generating WebAssembly code.
  • More information: WebAssembly/Compiler