FPC New Features Trunk

From Free Pascal wiki
Jump to: navigation, search

Contents

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. They require modeswitch TypeHelpers to be set.
  • 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 modeswitch TypeHelpers is not enabled by default in any mode.
  • More information:

Support for codepage-aware strings

  • Overview: Ansistrings have been made codepage-aware. This means that every ansistring now has an extra piece of meta-information that indicates the codepage in which the characters of that string are encoded.
  • Notes: Delphi-compatible (2009 and later).
  • 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.

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 because -Oodfa is still a work in progress. You can enable the optimization individually using the -Oodeadstore command line option, or by adding {$optimization deadstore} to your source file.

Node dfa for liveness analysis

  • Overview: The compiler can now do real static dfa for liveness analysis.
  • Notes: This is only enabled when -O3 is used.
  • More information: Warnings about uninitialized variables are more exact when using dfa for this compared with the previous approach. However, the current approach is static and non-global, so one might get false positives:
 var
   b : boolean;
   i : longint;
 begin
   if b then
     i:=1;
   writeln;
   if b then
     writeln(i);
 end.

In this case, the compiler warns about i being uninitialized. While some cases like the case above could be detected and the warning could be prevent, this does no apply if b is a function. To workaround this, add an assignment to i at the entry of the subroutine body.

The same applies to nested functions/procedures:

 var
   i : longint;
 procedure p;
   begin
     i:=1;
   end;
 begin
   p;
   writeln(i);
 end.

The current dfa approach works only procedure-wide and not global, so the case above cannot be handled correctly. The compiler does not see that i is initialized. To workaround this, add an assignment to i at the entry of the outer subroutine body.

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

Bufdataset supports ftAutoInc fields

  • Overview: Bufdataset now has support for automatically increasing ftAutoinc field values.

TDBF, bufdataset (and descendents such as TSQLQuery) allow escaped delimiters in string expression filter

  • Overview: filters that contain string expressions should be quoted (using either ' or "). However, having the same quotes within the filter was not parsed as there was no support for escaping quotes in the string

Support has been added for escaping quotes to allow this.

  • Notes: Double up the delimiter within the string to escape the delimiter. Example:
Filter:='(NAME=''O''''Malley''''s "Magic" Hammer'')';
//which gives
//(NAME='O''Malley''s "Magic" Hammer')
//which will match record
//O'Malley's "Magic" Hammer
  • More information: N/A

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: Detailed list of all related changes to the RTL.

Tools and miscellaneous

New Pas2jni utility

  • Overview: The new pas2jni utility generates a JNI (Java Native Interface) bridge for Pascal code. This enables Pascal code (including classes and other advanced features) to be easily used from Java programs.
  • Notes: 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
  • More information: /

(Mac) OS X/iOS

New iosxlocale unit

  • Overview: The new unit called iosxlocale can be used initialises the DefaultFormatSettings and other related locale information in the sysutils unit based on the settings in the (Mac) OS X System Preferences or the iOS Settings app.
  • Notes: The clocale unit, which also works on (Mac) OS X and iOS, instead gets its information from the Unix-layer. This information depends on the contents of the LC_ALL, LC_NUMERIC etc environment variables (see man locale for more information). Adding both clocale and iosxlocale to the uses clause will cause the second in line to overwrite the settings set by the first one.
  • More information: Adding this unit to the uses clause is enough to use its functionality.

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

Personal tools