Skip to content
This repository was archived by the owner on Dec 7, 2024. It is now read-only.
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

Open

Description

@tlively

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.

Activity

  1. tlively commented on Feb 25, 2020

    @tlively
    MemberAuthor

    @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.

  2. rossberg commented on Feb 26, 2020

    @rossberg
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions