FPC New Features Trunk

From Free Pascal wiki
Revision as of 13:16, 31 August 2012 by Jonas (talk | contribs) (→‎Class field reordering: clarify that reordering can only be disabled at a class level, not at an individual field level)
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 while 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)

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.

Darwin/Mac OS X

Support for specifying and querying the deployment version

  • Overview: Support has been added to specify the minimum deployment target version of Mac OS X/iOS via a command line parameter, and for determining the specified deployment target version via a macro
  • More information
    • Command line parameters: -WM10.4 or -WM10.5.3 and similar for Mac OS X targets, -WP4.1 or -WP5.0.1 and similar for the iPhoneOS/iPhoneSimulator targets.
    • If no command line parameter with a deployment version is specified, the compiler will look at the MACOSX_DEPLOYMENT_TARGET resp. IPHONEOS_DEPLOYMENT_TARGET environment variables to get the deployment target version
    • if the deployment target version has not been specified using any of the previous methods, a default will be used (Mac OS X/PPC: 10.3; Mac OS X/PPC64/i386: 10.4; Mac OS X/x86-64: 10.5; iOS/iPhoneSimulator: 3.0)
    • Apart from passing the deployment target version number to the linker and linking in the appropriate startup code, the compiler will also define a symbol called MAC_OS_X_VERSION_MIN_REQUIRED resp. IPHONE_OS_VERSION_MIN_REQUIRED containing a value equivalent to the one defined by Apple's Availability.h/AvailabilityMacros.h, i.e. 1043 for Mac OS X 10.4.3, and 40102 for iPhoneOS 4.1.2. Note that this is not a constant that can be used in Pascal expressions, it's only for use by preprocessor statements.
  • Example:
procedure CGImageSourceUpdateDataProvider( isrc: CGImageSourceRef; provider: CGDataProviderRef; final: CBool ); cdecl; 
  {$if MAC_OS_X_VERSION_MIN_REQUIRED >= 1040}external;{$else}weakexternal;{$endif}

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