Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SwiftIfConfig: A library to evaluate #if conditionals within a Swift syntax tree. #1816

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Commits on Jun 12, 2023

  1. [SwiftIfConfig] Add a new library for evaluating #if conditions.

    Building on top of the parser and operator-precedence parsing library,
    introduce a new library that evaluates `#if` conditions against a
    particular build configuration. The build configuration is described
    by the aptly named `BuildConfiguration` protocol, which has queries
    for various build settings (e.g., configuration flags), compiler
    capabilities (features and attributes), and target information (OS,
    architecture, endianness, etc.).
    
    At present, the only user-facing operation is the `IfConfigState`
    initializer, which takes in an expression (the `#if` condition) and a
    build configuration, then evaluates that expression against the build
    condition to determine whether code covered by that condition is
    active, inactive, or completely unparsed. This is a fairly low-level
    API, meant to be a building block for more useful higher-level APIs
    that query which `#if` clause is active and whether a particular syntax
    node is active.
    DougGregor committed Jun 12, 2023
    Configuration menu
    Copy the full SHA
    5e320a3 View commit details
    Browse the repository at this point in the history
  2. Add higher-level APIs for querying active code state

    `IfConfigDeclSyntax.activeClause(in:)` determines which clause is
    active within an `#if` syntax node.
    
    `SyntaxProtocol.isActive(in:)` determines whether a given syntax node
    is active in the program, based on the nested stack of `#if`
    configurations.
    DougGregor committed Jun 12, 2023
    Configuration menu
    Copy the full SHA
    c4dd56f View commit details
    Browse the repository at this point in the history

Commits on Jun 13, 2023

  1. Add support for evaluating swift and compiler conditionals

    These were introduced by SE-0212.
    DougGregor committed Jun 13, 2023
    Configuration menu
    Copy the full SHA
    f1c3775 View commit details
    Browse the repository at this point in the history

Commits on Jun 18, 2023

  1. Configuration menu
    Copy the full SHA
    f0d8d01 View commit details
    Browse the repository at this point in the history
  2. Add support for canImport configuration checks.

    This is the last kind of check! Remove the `default` fallthrough from
    the main evaluation function.
    DougGregor committed Jun 18, 2023
    Configuration menu
    Copy the full SHA
    f6671ff View commit details
    Browse the repository at this point in the history

Commits on Jun 19, 2023

  1. Configuration menu
    Copy the full SHA
    49feafc View commit details
    Browse the repository at this point in the history
  2. Add ActiveSyntax(Any)Visitor visitor classes.

    The `ActiveSyntax(Any)Visitor` visitor classes provide visitors that
    only visit the regions of a syntax tree that are active according to
    a particular build configuration, meaning that those nodes would be
    included in a program that is built with that configuration.
    DougGregor committed Jun 19, 2023
    Configuration menu
    Copy the full SHA
    2ac9fbf View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    9c3f4cd View commit details
    Browse the repository at this point in the history
  4. Add an API to rewrite a syntax tree by removing inactive regions.

    The operation `SyntaxProtocol.removingInactive(in:)` returns a syntax
    tree derived from `self` that has removed all inactive syntax nodes based
    on the provided configuration.
    DougGregor committed Jun 19, 2023
    Configuration menu
    Copy the full SHA
    4aad17b View commit details
    Browse the repository at this point in the history
  5. Implement inactive clause rewriting support for postfix #if

    Postfix `#if` expressions have a different syntactic form than
    other `#if` clauses because they don't fit into a list-like position in
    the grammar. Implement a separate, recursive folding algorithm to handle
    these clauses.
    DougGregor committed Jun 19, 2023
    Configuration menu
    Copy the full SHA
    96e6a8d View commit details
    Browse the repository at this point in the history

Commits on Jun 20, 2023

  1. Configuration menu
    Copy the full SHA
    1404f6b View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    a0bbe00 View commit details
    Browse the repository at this point in the history
  3. Format source

    DougGregor committed Jun 20, 2023
    Configuration menu
    Copy the full SHA
    be1c27a View commit details
    Browse the repository at this point in the history

Commits on Jun 22, 2023

  1. Configuration menu
    Copy the full SHA
    6712ea0 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    884d4ff View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    54d1c43 View commit details
    Browse the repository at this point in the history

Commits on Jun 25, 2023

  1. [Build configuration] Drop optionality from protocol requirement resu…

    …lt types
    
    The optional return was used to mean "don't know", but was always
    treated as false. Instead, make all of the result types non-optional,
    and allow these operations to throw to indicate failure.
    
    While here, drop the "syntax" parameters to all of these functions. We
    shouldn't be working with syntax inside the build configuration.
    DougGregor committed Jun 25, 2023
    Configuration menu
    Copy the full SHA
    46c082c View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    817228e View commit details
    Browse the repository at this point in the history
  3. Use preconditionFailure

    DougGregor committed Jun 25, 2023
    Configuration menu
    Copy the full SHA
    e14e0c7 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    e19032b View commit details
    Browse the repository at this point in the history
  5. Minor cleanups

    DougGregor committed Jun 25, 2023
    Configuration menu
    Copy the full SHA
    23c6b8b View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    7425d30 View commit details
    Browse the repository at this point in the history