mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
This patch introduces a new kind of pattern for matching bool literals, i.e. true and false. Essentially, it is very similar to a pattern for matching enum elements, but simpler. Most of the code is just a boiler plate code copy/pasted from the code for enum element patterns. The only different thing is the emitBoolDispatch function, which emits a SIL code for matching bools. With this patch, we don't get any false non-exhaustive switch diagnostics for switches on bools anymore. And we have a lot of radars complaining about it. For example rdar://16514545 and rdar://20130240. Note, that this patch fixes the non-exhaustive switch diagnostics without changing the internal representation of bools. Implementing bool as an enum would have the same effect when it comes to these diagnostics and we would get this diagnostics fix for free, i.e. without any code committed here. But implementing bools-as-enums is an ongoing work and I'm investigating its performance implications. If we become confident that bool-as-enum does not have a negative impact on performance and decide to merge it, then we can revert this patch as it would not be necessary anymore. But if we decide to skip the enum-as-bool approach to its performance issues, then we would have at least fixed the false non-exhaustive diagnostics for bools by means of this patch. Swift SVN r26650
46 lines
1.6 KiB
C++
46 lines
1.6 KiB
C++
//===--- PatternNodes.def - Swift Pattern AST Metaprogramming ---*- C++ -*-===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See http://swift.org/LICENSE.txt for license information
|
|
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file defines macros used for macro-metaprogramming with patterns.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// PATTERN(Id, Parent)
|
|
/// The pattern's enumerator value is PatternKind::Id. The pattern's
|
|
/// class name is Id##Pattern, and the name of its base class is Parent.
|
|
#ifndef PATTERN
|
|
# error Included PatternNodes.def without defining PATTERN!
|
|
#endif
|
|
|
|
/// REFUTABLE_PATTERN(Id, Parent)
|
|
/// Matching this pattern can fail. These patterns cannot appear syntactically
|
|
/// in variable declarations, assignments, or function declarations.
|
|
#ifndef REFUTABLE_PATTERN
|
|
# define REFUTABLE_PATTERN(Id, Parent) PATTERN(Id, Parent)
|
|
#endif
|
|
|
|
PATTERN(Paren, Pattern)
|
|
PATTERN(Tuple, Pattern)
|
|
PATTERN(Named, Pattern)
|
|
PATTERN(Any, Pattern)
|
|
PATTERN(Typed, Pattern)
|
|
PATTERN(Var, Pattern)
|
|
REFUTABLE_PATTERN(Is, Pattern)
|
|
REFUTABLE_PATTERN(NominalType, Pattern)
|
|
REFUTABLE_PATTERN(EnumElement, Pattern)
|
|
REFUTABLE_PATTERN(OptionalSome, Pattern)
|
|
REFUTABLE_PATTERN(Bool, Pattern)
|
|
REFUTABLE_PATTERN(Expr, Pattern)
|
|
|
|
#undef PATTERN
|
|
#undef REFUTABLE_PATTERN
|