Skip to content

Revert "Eliminate Observable circular reference errors via lazier TypeRefinementContext building" #67734

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions include/swift/AST/Availability.h
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,6 @@ class AvailabilityInference {
annotatedAvailableRangeForAttr(const SpecializeAttr *attr, ASTContext &ctx);
};

/// Given a declaration upon which an availability attribute would appear in
/// concrete syntax, return a declaration to which the parser
/// actually attaches the attribute in the abstract syntax tree. We use this
/// function to determine whether the concrete syntax already has an
/// availability attribute.
const Decl *abstractSyntaxDeclForAvailableAttribute(const Decl *D);

} // end namespace swift

#endif
20 changes: 0 additions & 20 deletions include/swift/AST/TypeCheckRequests.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ class TypeAliasDecl;
class TypeLoc;
class Witness;
class TypeResolution;
class TypeRefinementContext;
struct TypeWitnessAndDecl;
class ValueDecl;
enum class OpaqueReadOwnership: uint8_t;
Expand Down Expand Up @@ -4434,25 +4433,6 @@ class InitAccessorReferencedVariablesRequest
bool isCached() const { return true; }
};

/// Expand the children of the type refinement context for the given
/// declaration.
class ExpandChildTypeRefinementContextsRequest
: public SimpleRequest<ExpandChildTypeRefinementContextsRequest,
bool(Decl *, TypeRefinementContext *),
RequestFlags::Cached> {
public:
using SimpleRequest::SimpleRequest;

private:
friend SimpleRequest;

bool evaluate(Evaluator &evaluator, Decl *decl,
TypeRefinementContext *parentTRC) const;

public:
bool isCached() const { return true; }
};

#define SWIFT_TYPEID_ZONE TypeChecker
#define SWIFT_TYPEID_HEADER "swift/AST/TypeCheckerTypeIDZone.def"
#include "swift/Basic/DefineTypeIDZone.h"
Expand Down
3 changes: 0 additions & 3 deletions include/swift/AST/TypeCheckerTypeIDZone.def
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,3 @@ SWIFT_REQUEST(TypeChecker, InitAccessorReferencedVariablesRequest,
ArrayRef<VarDecl *>(DeclAttribute *, AccessorDecl *,
ArrayRef<Identifier>),
Cached, NoLocationInfo)
SWIFT_REQUEST(TypeChecker, ExpandChildTypeRefinementContextsRequest,
bool(Decl *, TypeRefinementContext *),
Cached, NoLocationInfo)
3 changes: 0 additions & 3 deletions include/swift/AST/TypeRefinementContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,6 @@ class TypeRefinementContext : public ASTAllocated<TypeRefinementContext> {
static StringRef getReasonName(Reason R);
};

void simple_display(llvm::raw_ostream &out,
const TypeRefinementContext *trc);

} // end namespace swift

#endif
30 changes: 0 additions & 30 deletions lib/AST/Availability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,6 @@ AvailabilityInference::attrForAnnotatedAvailableRange(const Decl *D,
ASTContext &Ctx) {
const AvailableAttr *bestAvailAttr = nullptr;

D = abstractSyntaxDeclForAvailableAttribute(D);

for (auto Attr : D->getAttrs()) {
auto *AvailAttr = dyn_cast<AvailableAttr>(Attr);
if (AvailAttr == nullptr || !AvailAttr->Introduced.has_value() ||
Expand Down Expand Up @@ -751,31 +749,3 @@ ASTContext::getSwift5PlusAvailability(llvm::VersionTuple swiftVersion) {
bool ASTContext::supportsVersionedAvailability() const {
return minimumAvailableOSVersionForTriple(LangOpts.Target).has_value();
}

const Decl *
swift::abstractSyntaxDeclForAvailableAttribute(const Decl *ConcreteSyntaxDecl) {
// This function needs to be kept in sync with its counterpart,
// concreteSyntaxDeclForAvailableAttribute().

if (auto *PBD = dyn_cast<PatternBindingDecl>(ConcreteSyntaxDecl)) {
// Existing @available attributes in the AST are attached to VarDecls
// rather than PatternBindingDecls, so we return the first VarDecl for
// the pattern binding declaration.
// This is safe, even though there may be multiple VarDecls, because
// all parsed attribute that appear in the concrete syntax upon on the
// PatternBindingDecl are added to all of the VarDecls for the pattern
// binding.
for (auto index : range(PBD->getNumPatternEntries())) {
if (auto VD = PBD->getAnchoringVarDecl(index))
return VD;
}
} else if (auto *ECD = dyn_cast<EnumCaseDecl>(ConcreteSyntaxDecl)) {
// Similar to the PatternBindingDecl case above, we return the
// first EnumElementDecl.
if (auto *Elem = ECD->getFirstElement()) {
return Elem;
}
}

return ConcreteSyntaxDecl;
}
18 changes: 7 additions & 11 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2079,23 +2079,19 @@ bool VarDecl::isLayoutExposedToClients() const {
if (!parent) return false;
if (isStatic()) return false;


auto nominalAccess =
parent->getFormalAccessScope(/*useDC=*/nullptr,
/*treatUsableFromInlineAsPublic=*/true);
if (!nominalAccess.isPublic()) return false;

if (!parent->getAttrs().hasAttribute<FrozenAttr>() &&
!parent->getAttrs().hasAttribute<FixedLayoutAttr>())
return false;

if (!hasStorage() &&
!getAttrs().hasAttribute<LazyAttr>() &&
!hasAttachedPropertyWrapper()) {
return false;
}

return true;
auto nominalAccess =
parent->getFormalAccessScope(/*useDC=*/nullptr,
/*treatUsableFromInlineAsPublic=*/true);
if (!nominalAccess.isPublic()) return false;

return (parent->getAttrs().hasAttribute<FrozenAttr>() ||
parent->getAttrs().hasAttribute<FixedLayoutAttr>());
}

/// Check whether the given type representation will be
Expand Down
22 changes: 0 additions & 22 deletions lib/AST/TypeRefinementContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "swift/AST/Stmt.h"
#include "swift/AST/Expr.h"
#include "swift/AST/SourceFile.h"
#include "swift/AST/TypeCheckRequests.h"
#include "swift/AST/TypeRefinementContext.h"
#include "swift/Basic/SourceManager.h"

Expand Down Expand Up @@ -193,18 +192,6 @@ TypeRefinementContext::findMostRefinedSubContext(SourceLoc Loc,
!rangeContainsTokenLocWithGeneratedSource(SM, SrcRange, Loc))
return nullptr;

// If this context is for a declaration, ensure that we've expanded the
// children of the declaration.
if (Node.getReason() == Reason::Decl ||
Node.getReason() == Reason::DeclImplicit) {
if (auto decl = Node.getAsDecl()) {
ASTContext &ctx = decl->getASTContext();
(void)evaluateOrDefault(
ctx.evaluator, ExpandChildTypeRefinementContextsRequest{decl, this},
false);
}
}

// For the moment, we perform a linear search here, but we can and should
// do something more efficient.
for (TypeRefinementContext *Child : Children) {
Expand Down Expand Up @@ -367,10 +354,6 @@ void TypeRefinementContext::print(raw_ostream &OS, SourceManager &SrcMgr,
OS << "extension." << ED->getExtendedType().getString();
} else if (isa<TopLevelCodeDecl>(D)) {
OS << "<top-level-code>";
} else if (auto PBD = dyn_cast<PatternBindingDecl>(D)) {
if (auto VD = PBD->getAnchoringVarDecl(0)) {
OS << VD->getName();
}
}
}

Expand Down Expand Up @@ -428,8 +411,3 @@ StringRef TypeRefinementContext::getReasonName(Reason R) {

llvm_unreachable("Unhandled Reason in switch.");
}

void swift::simple_display(
llvm::raw_ostream &out, const TypeRefinementContext *trc) {
out << "TRC @" << trc;
}
Loading