Files
swift-mirror/include/swift/AST/ConformanceAttributes.h
T
Kavon Farvardin 006a0a494a Reparenting: require an extension
This change forces you to write ``@reparented` relationships
on an extension of a protocol, rather than on the protocol
itself.

The ProtocolConformance needs to be associated with some
GenericContext and IRGen expects it to be an ExtensionDecl.
That environment defines under what conditions the conformance
exists. We also need to define witnesses for the new parent's
requirements in an extension anyway, so it's a natural fit.

The previous workaround for this was kind of awful, as it'd
require searching all the protocol's extensions and "guess"
which extension they want to represent the conformance. While
we could try to synthesize an extension, there's two
challenges there:

1. Due to SuppressedAssociatedTypes, it's not so simple to
synthesize an unconstrained ExtensionDecl.
2. We currently rely on same-type requirements to pin the
associated types to particular witnesses of those requirements
in the extension. So it's not purely unconstrained! For example,

```
extension Seq: @reparented BorrowSeq where Iter == MyIter {}
```

The constraints that are disallowed (but not yet diagnosed)
are conditional conformance requirements, as the default
conformance for a reparenting cannot depend on those.

Thus, it's better that programmers to specify the extension.
2026-02-03 16:40:21 -08:00

69 lines
2.1 KiB
C++

//===--- ConformanceLookup.h - Global conformance lookup --------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2024 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
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_AST_CONFORMANCEATTRIBUTES_H
#define SWIFT_AST_CONFORMANCEATTRIBUTES_H
#include "swift/Basic/SourceLoc.h"
namespace swift {
class TypeExpr;
/// Describes all of the attributes that can occur on a conformance.
struct ConformanceAttributes {
/// The location of the "unchecked" attribute, if present.
SourceLoc uncheckedLoc;
/// The location of the "preconcurrency" attribute if present.
SourceLoc preconcurrencyLoc;
/// The location of the "unsafe" attribute if present.
SourceLoc unsafeLoc;
/// The location of the "nonisolated" modifier, if present.
SourceLoc nonisolatedLoc;
/// The location of the '@' prior to the global actor type.
SourceLoc globalActorAtLoc;
/// The global actor type to which this conformance is isolated.
TypeExpr *globalActorType = nullptr;
/// The location of the "reparented" attribute, if present.
SourceLoc reparentedLoc;
/// Merge other conformance attributes into this set.
ConformanceAttributes &
operator |=(const ConformanceAttributes &other) {
if (other.uncheckedLoc.isValid())
uncheckedLoc = other.uncheckedLoc;
if (other.preconcurrencyLoc.isValid())
preconcurrencyLoc = other.preconcurrencyLoc;
if (other.unsafeLoc.isValid())
unsafeLoc = other.unsafeLoc;
if (other.nonisolatedLoc.isValid())
nonisolatedLoc = other.nonisolatedLoc;
if (other.globalActorType && !globalActorType) {
globalActorAtLoc = other.globalActorAtLoc;
globalActorType = other.globalActorType;
}
if (other.reparentedLoc.isValid())
reparentedLoc = other.reparentedLoc;
return *this;
}
};
}
#endif