mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Add `AdditiveArithmetic` derived conformances for structs, gated by the
`-enable-experimential-additive-arithmetic-derivation` flag.
Structs whose stored properties all conform to `AdditiveArithmetic` can derive
`AdditiveArithmetic`:
- `static var zero: Self`
- `static func +(lhs: Self, rhs: Self) -> Self`
- `static func -(lhs: Self, rhs: Self) -> Self`
- An "effective memberwise initializer":
- Either a synthesized memberwise initializer or a user-defined initializer
with the same type.
Effective memberwise initializers are used only by derived conformances for
`Self`-returning protocol requirements like `AdditiveArithmetic.+`, which
require memberwise initialization.
Resolves TF-844.
Unblocks TF-845: upstream `Differentiable` derived conformances.
72 lines
2.2 KiB
C++
72 lines
2.2 KiB
C++
//===--- CodeSynthesis.h - Typechecker code synthesis -----------*- C++ -*-===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file defines a typechecker-internal interface to a bunch of
|
|
// routines for synthesizing various declarations.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SWIFT_TYPECHECKING_CODESYNTHESIS_H
|
|
#define SWIFT_TYPECHECKING_CODESYNTHESIS_H
|
|
|
|
#include "swift/AST/ForeignErrorConvention.h"
|
|
#include "swift/Basic/ExternalUnion.h"
|
|
#include "swift/Basic/LLVM.h"
|
|
#include "llvm/ADT/Optional.h"
|
|
|
|
namespace swift {
|
|
|
|
class AbstractFunctionDecl;
|
|
class AbstractStorageDecl;
|
|
class ASTContext;
|
|
class ClassDecl;
|
|
class ConstructorDecl;
|
|
class FuncDecl;
|
|
class GenericParamList;
|
|
class NominalTypeDecl;
|
|
class ObjCReason;
|
|
class ParamDecl;
|
|
class Type;
|
|
class ValueDecl;
|
|
class VarDecl;
|
|
|
|
enum class SelfAccessorKind {
|
|
/// We're building a derived accessor on top of whatever this
|
|
/// class provides.
|
|
Peer,
|
|
|
|
/// We're building a setter or something around an underlying
|
|
/// implementation, which might be storage or inherited from a
|
|
/// superclass.
|
|
Super,
|
|
};
|
|
|
|
Expr *buildSelfReference(VarDecl *selfDecl,
|
|
SelfAccessorKind selfAccessorKind,
|
|
bool isLValue,
|
|
ASTContext &ctx);
|
|
|
|
/// Build an expression that evaluates the specified parameter list as a tuple
|
|
/// or paren expr, suitable for use in an apply expr.
|
|
Expr *buildArgumentForwardingExpr(ArrayRef<ParamDecl*> params,
|
|
ASTContext &ctx);
|
|
|
|
/// Returns the protocol requirement with the specified name.
|
|
ValueDecl *getProtocolRequirement(ProtocolDecl *protocol, Identifier name);
|
|
|
|
// Returns true if given nominal type has a `let` stored with an initial value.
|
|
bool hasLetStoredPropertyWithInitialValue(NominalTypeDecl *nominal);
|
|
|
|
} // end namespace swift
|
|
|
|
#endif
|