FPC New Features Trunk

From Lazarus wiki
Revision as of 15:07, 9 November 2013 by Jonas (talk | contribs) (→‎Units and packages: + Multiple codepage and unicode support for most file-related RTL routines)
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.

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

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.

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.

Constant propagation

  • Overview: The compiler can now, to a limited extent, propagate constant values across multiple statements in function and procedure bodies.
  • Notes: Constant propagation can cause range errors that would normally manifest themselves at runtime to be detected at compile time already.
  • More information:This optimization is enabled by default at optimization level -O3 and higher. You can also enable the optimization individually using the -Ooconstprop command line option, or by adding {$optimization constprop} to your source file.

Dead store elimination

  • Overview: The compiler can now, to a limited extent, remove stores to local variables and parameters if these values are not used before they are overwritten.
  • Notes: The use of this optimization requires that data flow analysis (-Oodfa) is enabled. It can help in particular with cleaning up instructions that have become useless due to constant propagation.
  • More information: This optimization is currently not enabled by default at any optimization level. You can also enable the optimization individually using the -Oodeadstore command line option, or by adding {$optimization deadstore} to your source file.

Units and packages

TDBF support for Visual FoxPro files

  • Overview: TDBf now has explicit support for Visual FoxPro (tablelevel 30) files, including the VarBinary and VarChar datatypes.
  • Notes: TDBF version increased to 7.0.0.
  • More information: The code does not support .dbc containers, only freestanding dbfs. It does not support (and quite likely will never support) .cdx index files.

Additionally, TDBf is now included in the database test suite and has received several fixes (including better Visual FoxPro codepage support).

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.

TZipper support for zip64 format

  • Overview: TZipper now supports the zip64 extensions to the zip file format: > 65535 files and > 4GB file size (bug #23533). Related fixes also allow path/filenames > 255 characters.
  • Notes: the zip64 format will automatically be used if the number or size of files involved exceed the limits of the old zip format. Zip64 is unrelated to the processor type/bitness (such as x86, x64, ...).
  • More information: More information on zip64: http://en.wikipedia.org/wiki/ZIP_%28file_format%29#ZIP64

Multiple codepage and unicode support for most file-related RTL routines

  • Overview: Most file-related routines from the system and sysutils units have been made codepage-aware: they now accept ansistrings encoded in arbitrary codepages as well as unicodestrings, and will convert these to the appropriate codepage before calling OS APIs.
  • Notes: /
  • More information: [FPC_Unicode_support#Current_support_via_merged_cpstrrtl_branch Detailed list] of all related changes to the RTL.

Tools and miscellaneous

Pas2jni utility added

The pas2jni utility (in utils/pas2jni) generates a JNI (Java Native Interface) bridge for Pascal code. Then the Pascal code (including classes and other advanced features) can be easily used in Java programs. The following Pascal features are supported by pas2jni:

  • function/procedure
  • var/out parameters
  • class
  • record
  • property
  • constant
  • enum
  • TGuid type
  • pointer type
  • string types
  • all numeric types

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