Difference between revisions of "FPC New Features Trunk"

From Free Pascal wiki
Jump to navigationJump to search
(Mention NameThreadForDebugging for macOS)
(→‎New compiler targets: - WebAssembly)
Line 175: Line 175:
 
* '''More information''': [[LLVM]]
 
* '''More information''': [[LLVM]]
 
* '''svn''': 42260
 
* '''svn''': 42260
 +
 +
=== 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}}

Revision as of 04:55, 27 September 2021

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.
  • 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://svn.freepascal.org/svn/fpc/trunk/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://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

"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, 32 or 64.
  • svn: 47892
  • Example: https://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/tests/webtbs/tw28927.pp?view=markup&pathrev=47892

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

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

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 the WebAssembly target

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