ponylang / rfcs

RFCs for changes to Pony
https://ponylang.io/
59 stars 48 forks source link

Expose the pony version during compile time #104

Open mfelsche opened 7 years ago

mfelsche commented 7 years ago

This would make conditional compilation possible as we currently have for the platform (windows, darwin, linux, ...) but for different pony versions for which there might exist breaking changes in the stdlib or the comper itself.

This would make it possible to maintain compatibility between different pony versions within one codebase.

mfelsche commented 7 years ago

There are at least two ways how to approach this problem:

Custom Defines

The first way would be using custom defined with the ponyc flag --define. Those defines don't have any value and we'd need a define for each ponyc version around. something like:

one for each level of the version number. Those defines need to be set by the build system, a Makefile e.g. The downside of this approach is that when using some pony code as a package the same defines need to be added again.

Defines with Values

The external defines would not needed to be added over and over again if ponyc would set those defines on its own. It would be even better if those defines had a value that could be used in some more involved statement for conditional compilation:

ifcond pony_version_major >= 4 and pony_version_minor >= 1
  // awesome new feature since pony 4.2.0
else
  // old boring stuff
end

Then those conditional statements could be used to maintain one codebase for multiple pony versions and make it easy to use it as a package.

SeanTAllen commented 2 years ago

I'm wondering. @jemc @mfelsche, is there a reason that if we added compile time expressions that this wouldn't be possible? Something like if constexpr from C++.

I have worries about this as a general feature, but I am interested if compile time expressions could make this possible if we exposed the version values.

SeanTAllen commented 2 years ago

During sync, I mentioned concerns about how we would support from a "typecheck everything". Do I need multiple ponyc compilation environments?

Joe mentioned "how do we support if there's a syntax change in the compiler".

I think the easiest thing would be a c preprocessor type functionality but that is a mess unto itself.