You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 7, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Dec 7, 2024. It is now read-only.
Design: switch with default rather than independent predicates #13
A number of alternative designs suggested at the CG meeting yesterday were variations on a compile-time switch statement to select between multiple options and a default depending on the available features. The advantage of such a construct would be that it would be much easier to guarantee that among a sequence of options, exactly one will be chosen for any feature set. On the other hand, tools can already provide this property by constructing predicates correctly. We need to further analyze the pros and cons of this approach.
@rossberg, you have been a strong proponent of independent predicates. What advantages do you see independent predicates having over a switch-like mechanism? A switch would be easier to emit for producers and not materially more complicated in engines. I think a switch would also be easier to reason about for optimizers and bundlers because mutual exclusion of contents could be built into the structure of the conditional sections. On the other hand, independent predicates could be emulated by having switches with single feature sets and empty default contents, so switches can't provide guarantees that modules will be easier to reason about for optimizers or bundlers.
Conditional sections are simpler and potentially more general. If you look at how conditional compilation is typically used, very few cases translate naturally into a switch, especially when combinations of multiple features are involved. I think it would actually be more work for producers to properly multiply out switch constructs to cope with overlaps.
At the same time, I am rather doubtful about the assumed advantage of a switch. If the switch does not enforce the same number of defs in every case, then as you say, one can easily encode a conditional with it. So nothing actually gets better for tools. OTOH, requiring the same number of defs in every case is an impractical constraint that would rule out many relevant use cases.
Activity
tlively commentedon Feb 25, 2020
@rossberg, you have been a strong proponent of independent predicates. What advantages do you see independent predicates having over a switch-like mechanism? A switch would be easier to emit for producers and not materially more complicated in engines. I think a switch would also be easier to reason about for optimizers and bundlers because mutual exclusion of contents could be built into the structure of the conditional sections. On the other hand, independent predicates could be emulated by having switches with single feature sets and empty default contents, so switches can't provide guarantees that modules will be easier to reason about for optimizers or bundlers.
rossberg commentedon Feb 26, 2020
Conditional sections are simpler and potentially more general. If you look at how conditional compilation is typically used, very few cases translate naturally into a switch, especially when combinations of multiple features are involved. I think it would actually be more work for producers to properly multiply out switch constructs to cope with overlaps.
At the same time, I am rather doubtful about the assumed advantage of a switch. If the switch does not enforce the same number of defs in every case, then as you say, one can easily encode a conditional with it. So nothing actually gets better for tools. OTOH, requiring the same number of defs in every case is an impractical constraint that would rule out many relevant use cases.