FPC New Features Trunk

From Lazarus wiki
Revision as of 15:49, 8 March 2013 by Jonas (talk | contribs) (→‎TODBCConnection (odbcconn) Support for 64 bit ODBC: changed format to the one used by the other items on this page)
Jump to navigationJump to search

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.

All systems

Language

Delphi-like namespaces units

  • Overview: Support has been added for unit names with dots.
  • Notes: Delphi-compatible.
  • More information: Unit names with dots creates namespace symbols which always have a precedence over unit names in an identifier search.

Dynamic array constructors

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

New compiler intrinsic Default

  • Overview: A new compiler intrinsic Default has been added which allows you get a correctly initialized value of a type which is given as parameter. It can also be used with generic type parameters to get a default value of the type.
  • Notes: Delphi-compatible.
  • More information: In simple terms the value returned by Default will be initialized with zeros. The Default intrinsic is not allowed on file types or records/objects/arrays containing such types (Delphi ignores file types in sub elements).
  • Examples:
type
  TRecord = record
    i: LongInt;
    s: AnsiString;
  end;

var
  i: LongInt;
  o: TObject;
  r: TRecord;
begin
  i := Default(LongInt); // 0
  o := Default(TObject); // Nil
  r := Default(TRecord); // ( i: 0; s: '')
end.
type
  generic TTest<T> = class
    procedure Test;
  end;

procedure TTest.Test;
var
  myt: T;
begin
  myt := Default(T); // will have the correct Default if class is specialized
end;

Support for type helpers

  • Overview: Support has been added for type helpers which allow you to add methods and properties to primitive types.
  • Notes: In mode Delphi it's implemented in a Delphi-compatible way using record helper for declaration, while the modes ObjFPC and MacPas use type helper (the feature can also be enabled in other modes if mode switch Class is set).
  • More information:

Code generator

Class field reordering

  • Overview: The compiler can now reorder instance fields in classes in order to minimize the amount of memory wasted due to alignment gaps.
  • Notes: Since the internal memory layout of a class is opaque (except by querying the RTTI, which is updated when fields are moved around), this change should not affect any code. It may cause problems when using so-called "class crackers" in order to work around the language's type checking though.
  • More information: This optimization is currently only enabled by default at the new optimization level -O4, which enables optimizations that may have (unforeseen) side effects. The reason for this is fairly widespread use of some existing code that relies on class crackers. In the future, this optimization may be moved to level -O2. You can also enable the optimization individually using the -Ooorderfields command line option, or by adding {$optimization orderfields} to your source file. It is possible to prevent the fields of a particular class from being reordered by adding {$push} {$optimization noorderfields} before the class' declaration and {$pop} after it.

Removing the calculation of dead values

  • Overview: The compiler can now in some cases (which may be extended in the future) remove the calculation of dead values, i.e. values that are computed but not used afterwards.
  • Notes: While the compiler will never remove such calculations if they have explicit side effects (e.g. they change the value of a global variable), this optimization can nevertheless result in changes in program behaviour. Examples include removed invalid pointer dereferences and removed calculations that would overflow or cause a range check error.
  • More information: This optimization is only enabled by default at the new optimization level -O4, which enables optimizations that may have (unforeseen) side effects. You can also enable the optimization individually using the -Oodeadvalues command line option, or by adding {$optimization deadvalues} to your source file.

Shortcuts to speed up floating point calculations

  • Overview: The compiler can now in some cases (which may be extended in the future) take shortcuts to optimize the evaluation of floating point expressions, at the expense of potentially reducing the precision of the results.
  • Notes: Examples of possible optimizations include turning divisions by a value into multiplications with the reciprocal value (not yet implemented), and reordering the terms in a floating point expression.
  • More information: This optimization is only enabled by default at the new optimization level -O4, which enables optimizations that may have (unforeseen) side effects. You can also enable the optimization individually using the -Oofastmath command line option, or by adding {$optimization fastmath} to your source file.

Units and packages

TODBCConnection (odbcconn) Support for 64 bit ODBC

  • Overview: 64 bit ODBC support has been added.
  • Notes: if you use unixODBC version 2.3 or higher on Linux/Unix, the unit has to be (re)compiled with -dODBCVER352 to enable 64 bit support
  • More information: Only tested on Windows and Linux.

New compiler targets

Support for the Java Virtual Machine and Dalvik targets

  • Overview: Support has been added for generating Java byte code as supported by the Java Virtual Machine and by the Dalvik (Android) virtual machine.
  • Notes: Not all language features are supported for these targets.
  • More information: The FPC JVM target

Support for the AIX target

  • Overview: Support has been added for the AIX operating system. Both PowerPC 32bit and 64bit are supported, except that at this time the resource compiler does not yet work for ppc64.
  • Notes: AIX 5.3 and later are supported.
  • More information: The FPC AIX port

See also