Difference between revisions of "FPC New Features Trunk"

From Free Pascal wiki
(Support for the iPhoneSim target)
(Documented array constructor for static arrays)
 
(145 intermediate revisions by 20 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_2.4.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.
+
Below you can find a list of new features introduced since the [[FPC_New_Features_3.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]].
  
 
== All systems ==
 
== All systems ==
  
=== Language ===
+
=== Compiler ===
  
==== Better support for Delphi-compatible classes ====
+
==== fpcres can compile RC files ====
* '''Overview''': Support has been added for nested types (including other classes), class variables and class-local constants.
 
* '''Notes''': Delphi-compatible.
 
* '''More information''': [[class_extensions_examples]] lists several examples that make use of these features.
 
  
==== Advanced record syntax ====
+
* '''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''': Support has been added for advanced record syntax (as Delphi calls it) including record visibility sections, nested types and constants, record methods, static fields, properties, class constructors, class destructors and class operators.
+
* '''Notes''': Using ''fpcres'' instead of ''windres'' or ''gorc'' will become default once a release with the new ''fpcres'' is released.
* '''Notes''': Delphi-compatible.
+
* '''svn''': 46398 (and others before and after that)
* '''More information''':
 
** http://docwiki.embarcadero.com/RADStudio/en/Structured_Types#Records_.28advanced.29
 
** http://docwiki.embarcadero.com/RADStudio/en/Operator_Overloading
 
** http://svn.freepascal.org/svn/fpc/trunk/tests/test/terecs_u1.pp
 
** http://svn.freepascal.org/svn/fpc/trunk/tests/test/terecs_u1.pp
 
  
==== Enumerators in records ====
+
=== Language ===
* '''Overview''': Previous FPC versions allowed ''enumerator'' structures to be classes, objects or interfaces. Now ''enumerator'' structure can also be defined as a record (using advanced record syntax only).
 
* '''Notes''': Delphi-compatible.
 
* '''More information''':
 
** http://svn.freepascal.org/svn/fpc/trunk/tests/test/tforin25.pp
 
  
==== Support for class and record helpers ====
+
==== Support for "volatile" intrinsic ====
* '''Overview''': Support has been added for class and record helpers which allow you to add methods, properties and enumerators to classes and records without inheriting from them.
+
* '''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-compatible.
+
* '''Notes''':
* '''More information''':
+
** 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/
** [[Helper types]] contains a detailed description of the feature
+
** Accesses to fixed absolute addresses (as common on DOS and embedded platforms) are automatically marked as volatile by the compiler.
** The tests are named ''thlp*.pp'', ''tchlp*.pp'' and ''trhlp*.pp'' and available in http://svn.freepascal.org/svn/fpc/trunk/tests/test/
+
* '''Example''': https://svn.freepascal.org/svn/fpc/trunk/tests/test/tmt1.pp
 +
* '''svn''': 40465
  
==== Generic records, arrays and procedural types ====
+
==== Support for "noinline" modifier ====
* '''Overview''': Previous FPC versions only supported generic classes, objects and interfaces. Now it is also possible to define generic records, generic arrays and generic procedural types.
+
* '''Overview''': A '''noinline''' modifier has been added that can be used to prevent a routine from ever being inlined (even by automatic inlining).
* '''Notes''': Generics are available both in ObjFPC and Delphi modes and generic records/arrays/procedural variables are defined similar to generic classes. Support for Delphi's generic syntax has been added but still may be not 100% compatible.
+
* '''Notes''': Mainly added for internal compiler usage related to LLVM support.
* '''More information''':
+
* '''svn''': 41198
** http://svn.freepascal.org/svn/fpc/trunk/tests/test/tgeneric24.pp
 
** http://svn.freepascal.org/svn/fpc/trunk/tests/test/tgeneric25.pp
 
** http://svn.freepascal.org/svn/fpc/trunk/tests/test/tgeneric26.pp
 
** http://svn.freepascal.org/svn/fpc/trunk/tests/test/tgeneric27.pp
 
** http://svn.freepascal.org/svn/fpc/trunk/tests/test/tgeneric28.pp
 
** http://svn.freepascal.org/svn/fpc/trunk/tests/test/tgeneric32.pp
 
** http://svn.freepascal.org/svn/fpc/trunk/tests/test/tgeneric33.pp
 
  
==== Scoped enumerations ====
+
==== Support for multiple active helpers per type ====
* '''Overview''': Support for the ''{$scopedenums on/off}'' directive has been added. The elements of enumerations defined as a ''scoped enumeration'' can only be used by fully qualifying them via ''typename.element''.
+
* '''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.
* '''Notes''': Delphi-compatible.
+
* '''Examples''': All tests with the name ''tmshlp*.pp'' in https://svn.freepascal.org/svn/fpc/trunk/tests/test
* '''More information''': http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/devcommon/compdirsscopedenums_xml.html
+
* '''svn''': 42026
  
==== Custom deprecated messages ====
+
==== Support for custom attributes ====
* '''Overview''': ''Deprecated'' can now be applied to virtually any syntactic element (including constants and units), and it is also possible to specify a custom deprecation message.
+
* '''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''': Delphi-compatible
+
* '''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]]
* '''More information''':
+
* '''svn''': 42356 - 42411
<delphi>
+
* '''Example''':
unit OldUnit deprecated 'Use NewUnit instead';
+
<syntaxhighlight lang="pascal">
 +
program tcustomattr;
  
interface
+
{$mode objfpc}{$H+}
 +
{$modeswitch prefixedattributes}
  
implementation
+
type
 +
  TMyAttribute = class(TCustomAttribute)
 +
    constructor Create;
 +
    constructor Create(aArg: String);
 +
    constructor Create(aArg: TGUID);
 +
    constructor Create(aArg: LongInt);
 +
  end;
  
procedure OldRoutine; deprecated 'Use NewRoutine instead';
+
  {$M+}
  begin
+
  [TMyAttribute]
 +
  TTestClass = class
 +
  private
 +
    fTest: LongInt;
 +
  published
 +
    [TMyAttribute('Test')]
 +
    property Test: LongInt read fTest;
 
   end;
 
   end;
 +
  {$M-}
  
end.
+
  [TMyAttribute(1234)]
</delphi>
+
  [TMy('Hello World')]
 +
  TTestEnum = (
 +
    teOne,
 +
    teTwo
 +
  );
  
==== Support for the Objective-Pascal dialect ====
+
  [TMyAttribute(IInterface), TMy(42)]
* '''Overview''': On Mac OS X, most system frameworks are written in Objective-C. While it is possible to interface them via a procedural API, this is not very convenient. For this reason, the Macintosh Pascal community has created a new dialect called Objective-Pascal that enables seamless interacting with Objective-C code.
+
  TLongInt = type LongInt;
* '''Notes''': This new dialect is currently only supported on Darwin-based platforms (including iOS) using the Apple Objective-C runtime. Patches to add support for the GNUStep runtime are welcome.
 
* '''More information''':
 
** [[FPC_PasCocoa]] explains the basic language definitions.
 
** [[FPC_PasCocoa/Differences]] explains some of the differences between Objective-Pascal and on the one hand Object Pascal, and on the other hand Objective-C.
 
  
====Constref parameter modifier====
+
constructor TMyAttribute.Create;
* '''Overview''': A new parameter modifier called ''constref'' has been added, similar to the existing ''var'', ''const'' and ''out'' ones. This modifier means that the compiler can assume that the parameter is constant, and that it must be passed by reference. Its most obvious usage is to translate ''const *'' parameters from C headers.
 
* '''Notes''': The main reason it was introduced was to enable writing a cross-platform interface for XPCOM, as explained on the [[User_Changes_Trunk#IInterface.QueryInterface.2C_._AddRef_and_._Release_definitions_have_been_changed|User Changes Trunk]] page. Note that in general, it should only be used for interfacing with external code or when writing assembler routines. In other cases, letting the compiler decide how to pass the parameter is more likely to result in optimal code on most platforms in the long term.
 
* '''More information''':
 
<delphi>
 
procedure test(constref l: longint);
 
 
begin
 
begin
  writeln('This parameter has been passed by reference, although the Pascal code does not really care about that: ',l);
 
 
end;
 
end;
  
 +
constructor TMyAttribute.Create(aArg: String);
 
begin
 
begin
  test(5);
+
end;
end.
 
</delphi>
 
====Basic ISO Standard Pascal support====
 
* '''Overview''': A language mode supporting ISO 7185 Standard Pascal has been added. It can be activated via the ''-Miso'' command line switch, or via the ''{$mode iso}'' compiler directive.
 
* '''Notes''': This support is not yet complete. In particular, no ISO Standard Pascal compatible I/O is available yet (get, put, ...)
 
* '''More information''': http://www.moorecad.com/standardpascal/standards.html
 
  
====Support for nested procedure variables====
+
constructor TMyAttribute.Create(aArg: LongInt);
* '''Overview''': It is now possible to define procedure variables that are assignment-compatible with nested procedures and functions. This feature is enabled by default in ''{$mode macpas}'' and ''{$mode iso}'', and can be enabled in other syntax modes by adding ''{$modeswitch nestedprocvars}'' to your source file. Note that it is possible to also assign regular (non-nested) procedures/functions to a nested procedure variable, and to call them that way.
+
begin
* '''Notes''': Enabling this feature changes the calling convention used for nested procedures/functions. This will break code from the Turbo Pascal era that uses nested procedures/functions as callbacks from collection iterators in the ''objects'' unit.
+
end;
* '''More information''': A procedure variable type can hold a reference to nested routines in two cases:
 
** when it is declared [http://svn.freepascal.org/svn/fpc/trunk/tests/test/tmaclocalprocparam3a.pp inline in the parameter list of another function/procedure] (ISO-style declaration). This form of declaring procedure variable types is only available when ''nestedprocvars'' are enabled.
 
** when it is declared as [http://svn.freepascal.org/svn/fpc/trunk/tests/test/tmaclocalprocparam3d.pp is nested], similar to ''of object'' for "procedure of object" types. Note that in this second case, it is possible to write invalid code: if you assign a nested routine to nested procedure variable and then exit the nested routine's parent stack frame, calling the nested procedure variable will result in undefined bahaviour.
 
  
====Support for non-local goto's====
+
constructor TMyAttribute.Create(aArg: TGUID);
* '''Overview''': It is now possible to ''goto'' to a ''label'' defined in another procedure, e.g. to quickly exit from a deeply nested procedure to a less deeply nested one.
+
begin
* '''Notes''': Enabled by default in ''ISO'' and ''MacPas'' syntax modes, can be enabled in other modes via ''{$modeswitch nonlocalgoto}''. It is not possible to use a non-local goto to jump over stack frames that require finalisation (e.g., when they contain reference counted types).
+
end;
* '''More information''': http://svn.freepascal.org/svn/fpc/trunk/tests/test/tmacnonlocalgoto.pp
 
  
====Support for &-escaping of keywords====
+
begin
* '''Overview''': The & sign can now be used to escape language keywords, so they can be used as identifiers.
 
* '''Notes''': Delphi-compatible.
 
* '''More information''': http://svn.freepascal.org/svn/fpc/trunk/tests/webtbs/tw15930.pp
 
  
====Support for ''univ'' parameters in MacPas mode====
+
end.  
* '''Overview''': Previous FPC versions simply ignored the ''univ'' qualifier for parameters. Now, FPC will properly parse it and interpret it like other Mac Pascal compilers: it allows passing any parameter whose size matches the size of the declared parameter.
+
</syntaxhighlight>
* '''Notes''': Only enabled in ''{$mode macpas}''. Abusing this feature can easily result in crashes or corrupted data in case the declared parameter type and the actual parameter have to be passed to the subroutine in different ways according to the calling convention. In general, this feature should only be used to port legacy code.
 
* '''More information''': http://bugs.freepascal.org/view.php?id=15777
 
  
====CExtended floating point type====
+
==== Support for constant parameters in generics ====
* '''Overview''': This type is the same as the regular ''extended'' type in terms of precision, but it conforms to the properties/behaviour of the equivalent of the ''Extended'' type in C. In practice, this means that ''CExtended'' corresponds to ''long double'' on i386 and x86_64 platforms that support an 80 bits ''extended'' type, and to ''double'' on other platforms. This is mainly required for fields in records that are translated from C in order to guarantee proper field alignments, and also for parameters to C routines.
+
* '''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''': At this time, FPC does not support an equivalent of C's ''long double'' type on platforms other than the ones mentioned above. Since ''Extended'' is an alias for ''Double'' on these other platforms in FPC, ''CExtended'' is also an alias for ''double'' there.
+
* '''Examples''': All tests with the name ''tgenconst*.pp'' in https://svn.freepascal.org/svn/fpc/trunk/tests/test
* '''More information''': /
+
* '''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].
 +
* '''svn''': 45080
  
====SAR intrinsics====
+
==== Support for "IsConstValue" intrinsic ====
* '''Overview''': Support has been added for ''shift arithmetic right'' (SAR) intrinsics.
+
* '''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''': Unlike the ''SHL'' and ''SHR'' operators, ''SAR'' is not implemented as an operator but as an intrinsic. It is also defined using different names for different integer sizes to prevent unexpected results when applying it to expressions.
+
* '''Notes''':
* '''More information''': http://svn.freepascal.org/svn/fpc/trunk/tests/test/cg/tsar1.pp
+
** 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
  
====Bitscan intrinsics====
+
==== Copy supports Open Array parameters ====
* '''Overview''': Support has been added for ''BSF'' (Bit Scan Forward) and ''BSR'' (Bit Scan Reverse) intrinsics.
+
* '''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''': Just like for the [[FPC_New_Features_Trunk#SAR_intrinsics|''SAR'' intrinsic]], separate versions have been added for different integer sizes in order to prevent any ambiguities.
+
* '''Notes''':
* '''More information''': http://svn.freepascal.org/svn/fpc/trunk/tests/test/tbsx1.pp
+
** 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.
====Boolean16, Boolean32 and Boolean64 types ====
+
** If the ''Count'' parameter is too large then the resulting dynamic array will only contain the elements that exist.
* '''Overview''': Support has been added for ''Boolean16'', ''Boolean32'' and ''Boolean64'' types
+
* '''svn''': 46890
* '''Notes''': These new boolean types behave like the standard pascal type ''Boolean'' except that their size is 2, 4 or 8 bytes. This is usefull to interface with some libraries.
+
* '''Example''':
* '''More information''': The existing ''WordBool'', ''LongBool'' and ''QWordBool'' types assume false=0 and true<>0. With the new types false=0 and true=1, while any other value is invalid.
+
<syntaxhighlight lang="pascal">
 
+
procedure Test(aArg: array of LongInt);
==== Delphi-like namespaces units ====
+
var
* '''Overview''': Support has been added for unit names with dots.  
+
  arr: array of LongInt;
* '''Notes''': Delphi-compatible.
+
begin
* '''More information''': Unit names with dots creates namespace symbols which always have a precedence over unit names while an identifier search.
+
  arr := Copy(aArg, 3, 5);
 
+
end;
==== Dynamic array constructors ====
+
</syntaxhighlight>
* '''Overview''': Support has been added for constructing dynamic arrays with class-like constructors.
 
* '''Notes''': Delphi-compatible.
 
* '''More information''': Only constructor name 'CREATE' is valid for dynamic arrays.
 
* '''Examples''': SomeArrayVar := TSomeDynArrayType.Create(value1, value2)
 
  
==ARM systems==
+
==== 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://svn.freepascal.org/svn/fpc/trunk/tests/test/tarrconstr16.pp
  
===Support for VFPv2 and VFPv3===
+
=== Units ===
* '''Overview''': Support has been added for the ARM Vector Floating Point (VFP) units versions 2 and 3. This is the floating point unit that's usually included on, a.o., Cortex-A8 and Cortex-A9 family CPUs, and in the iOS-based devices.
+
==== Classes ====
* '''Notes''': When targeting a CPU that implements the ARMv6 or later architecture, you ''must'' also use ''-Cparmv6'' at the same time. The reason is that saving/restoring the VFP unit's context must occur using different instructions prior to ARMv6. ''-Cparmv6'' is enabled by default for iOS targets though, because all such devices are at least ARMv6. Additionally, FPC only supports the so-called ''softfp'' ABI for VFP: the VFP unit is used to perform the calculations, but the used calling convention to pass floating point values is the same as for soft-float.
+
===== Naming of Threads =====
* '''More information''': Activate using the ''-Cfvfpv2'' resp. ''-Cfvfpv3'' command line parameters.
+
* '''Overview''': ''TThread.NameThreadForDebugging'' has been implemented.
 +
* '''Notes''': Delphi compatibile, currently implemented for Windows, Linux and Android. Read documentation as every platform has its own restrictions.
 +
* '''svn:''' 45160, 45206, 45233
  
===Support for Thumb-2===
+
==== DaemonApp ====
* '''Overview''': Support has been added to generate Thumb-2 code for the ARMv7-M architecture as implemented in the Cortex-M3 family.
+
===== Additional control codes on Windows =====
* '''Notes''': This architecture is currently only supported for no-OS targets (embedded); it does not yet work for iOS or Linux.
+
* '''Overview''': Windows allows a service to request additional control codes to be received. For example if the session of the sure 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''': Activate using the ''-Cparmv7m'' or ''-Cpcortexm3'' command line parameters.
+
* '''Notes''': This lead to slight incompatibilities which are mentioned in [[User_Changes_Trunk#DaemonApp|User Changes Trunk]]
 +
* '''svn''': 46326, 46327
  
==IA32/i386 systems==
+
== New compiler targets ==
  
===Support for the iPhoneSim target===
+
=== Support for code generation through LLVM ===
* '''Overview''': As of Xcode 3.2.4, the iPhoneSimulator target uses a different Objective-C ABI than regular i386 code. Therefore a new target called ''iphonesim'' was added to the compiler.
+
* '''Overview''': The compiler now has a code generator that generates LLVM bitcode.
* '''Notes''': If you are still using an earlier version of Xcode to develop iPhoneSimulator-based code, use the regular Darwin/i386 target.
+
* '''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''': use the ''-Tiphonesim'' command line parameter to select this target. When compiling the FPC packages for this target, this will also compile a special version of ''MacOSAll'' that only contains APIs available for this target.
+
* '''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 [[User_Changes_Trunk#The_Darwin_targets_corresponding_to_iOS_have_been_renamed_to_iOS|different command line parameter]] compared to previous versions.
 +
* '''More information''': [[macOS_Big_Sur_changes_for_developers#ARM64.2FAArch64.2FAppleSilicon_Support|Build instructions]]
 +
* '''svn''': 45762
  
== See also ==
+
{{Navbar Lazarus Release Notes}}
*[[User Changes Trunk]]
 
  
 
[[Category:FPC New Features by release]]
 
[[Category:FPC New Features by release]]
 +
[[Category:Release Notes]]

Latest revision as of 23:21, 19 September 2020

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://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}

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.
  • 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

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://svn.freepascal.org/svn/fpc/trunk/tests/test/tarrconstr16.pp

Units

Classes

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

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 sure 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

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.
  • More information: Build instructions
  • svn: 45762