Skip to content

Sema: Fix cycle between closure type computation and EmittedMembersRequest #33750

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

Merged
Merged
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
16 changes: 5 additions & 11 deletions lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "TypeCheckType.h"
#include "MiscDiagnostics.h"
#include "swift/AST/AccessScope.h"
#include "swift/AST/ASTMangler.h"
#include "swift/AST/ASTPrinter.h"
#include "swift/AST/ASTVisitor.h"
#include "swift/AST/ASTWalker.h"
Expand Down Expand Up @@ -2463,21 +2462,16 @@ namespace {
// Utility class for deterministically ordering vtable entries for
// synthesized methods.
struct SortedFuncList {
using Entry = std::pair<std::string, AbstractFunctionDecl *>;
using Key = std::tuple<DeclName, std::string>;
using Entry = std::pair<Key, AbstractFunctionDecl *>;
SmallVector<Entry, 2> elts;
bool sorted = false;

void add(AbstractFunctionDecl *afd) {
Mangle::ASTMangler mangler;
std::string mangledName;
if (auto *cd = dyn_cast<ConstructorDecl>(afd))
mangledName = mangler.mangleConstructorEntity(cd, /*allocator=*/false);
else if (auto *dd = dyn_cast<DestructorDecl>(afd))
mangledName = mangler.mangleDestructorEntity(dd, /*deallocating=*/false);
else
mangledName = mangler.mangleEntity(afd);
assert(!isa<AccessorDecl>(afd));

elts.push_back(std::make_pair(mangledName, afd));
Key key{afd->getName(), afd->getInterfaceType().getString()};
elts.emplace_back(key, afd);
}

bool empty() { return elts.empty(); }
Expand Down
4 changes: 4 additions & 0 deletions test/multifile/Inputs/rdar67842221-other.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
let closureValue = { () -> () in
class DummyClass {}
return ()
}()
17 changes: 17 additions & 0 deletions test/multifile/rdar67842221.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Test both orderings, and single-file vs WMO

// RUN: %target-swift-frontend -emit-ir -primary-file %s %S/Inputs/rdar67842221-other.swift -module-name main
// RUN: %target-swift-frontend -emit-ir %s -primary-file %S/Inputs/rdar67842221-other.swift -module-name main

// RUN: %target-swift-frontend -emit-ir -primary-file %S/Inputs/rdar67842221-other.swift %s -module-name main
// RUN: %target-swift-frontend -emit-ir %S/Inputs/rdar67842221-other.swift -primary-file %s -module-name main

// RUN: %target-swift-frontend -emit-ir %S/Inputs/rdar67842221-other.swift %s -module-name main
// RUN: %target-swift-frontend -emit-ir %S/Inputs/rdar67842221-other.swift %s -module-name main

// The closure defines a local class; we want to make sure there is no cycle
// between computing the semantic members of the local class (which requires
// sorting) and computing the type of the closure value
public func force() {
_ = closureValue
}