[fpc-pascal] FPC's generics implementation

Sven Barth pascaldragon at googlemail.com
Tue Aug 25 11:43:51 CEST 2015


Am 25.08.2015 08:34 schrieb "Jani Mátyás" <jzombi at gmail.com>:
> The FPC wiki states that the ppu file stores all the tokens for the
generic classes. Browsing the source of compiler/symdef.pas (r31298) also
gave me this impression. Does it mean that a recompilation occurs for every
specialization?

Not for every specialization. If a specialization for the same generic with
the same types already exists that one will be used. This also works across
units.

>
> There have been some ideas (again, regarding the wiki) to store the parse
tree instead of the source code (or tokens) in the ppu. I guess that would
made the specializations quicker. What were the reasons against it?

Ease of implementation/maintainability.
For the node tree approach the tree would need to be walked and all
accesses to variables of the generic parameter types would need to be
adjusted. This would need adjustments if new node types are added or node
types are extended. However for the token stream approach all this is
handled by existing parser code, so once the parser supports something it's
immediately supported by generics as well (corner cases of respecting
generic types aside).

> Disabling assignment compatibility of the separate specializations (with
same parameter type) might reduce the number of specializations. Were there
any specific reasons for enabling it in objpas mode?

On the contrary. /Enabling/ assignment compatibility reduces the number of
specializations, because existing specializations can be reused (see above).
Also having specializations be compatible in mode Delphi, but not in other
modes would likely lead to the confusion of users as units with different
modes can be mixed freely.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20150825/658c9e18/attachment.html>


More information about the fpc-pascal mailing list