POV-Ray / povray

The Persistence of Vision Raytracer: http://www.povray.org/
GNU Affero General Public License v3.0
1.35k stars 282 forks source link

Review and clean up `#version` directive handling #414

Closed c-lipka closed 3 years ago

c-lipka commented 3 years ago

In preparation for v3.8, handling of the `#version´ directive needs thorough investigation, and possibly fixing. In the end, the following criteria should be met:

A few complications need to be taken into consideration, that were not properly addressed in v3.7:

c-lipka commented 3 years ago

v3.8-alpha has been trying to solve this issue using the following approach:

However, this approach is frought with special handling of various edge cases, and is therefore a rather fragile solution.

c-lipka commented 3 years ago

I hereby propose the following approach:

Alternatively, we could just memorize the complete state of language version selection (effective version and whether implicit by default or explicit by choice) at the beginning of any include file, and revert it at the end unconditionally. However, that would preclude include files from deliberately changing what language verison the main scene file will be using. The proposed solution would prevent such tampering only if:

c-lipka commented 3 years ago
  • Upon reaching the end of any include file, set the effective scene language version back to the implicit default if [...]

Caveat: The solution does involve special case handling, so might be difficult to explain to users.

Another alternative might be to not actively revert the effective language state, and instead just print a warning (which we should do either way) informing the user that the include file was the first to set a #version, and that this is troublesome and may cause undesired effects, and to suppress this warning they may want to add #version 3.62; to the top of your main scene file, or use the Version=3.62 or +mv3.62 INI file / command line option.

This would also have the benefit of being 100% compatible to v3.7 behavior in this regard.

c-lipka commented 3 years ago

I have decided to leave #version handling as it currently is in v3.8, except that specifying #version 3.8 in the main scene file, after having failed to start the scene with any #version directive whatsoever, will not cause an outright parse error. (The rationale for this change is that the current implementation of this error fails to account for certain fringe cases, in which it would trigger by mistake.)