Skip to content

[GSB] NFC: Couple of minor cleanups #20594

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 1 commit into from
Nov 16, 2018
Merged
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
38 changes: 14 additions & 24 deletions lib/AST/GenericSignatureBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3543,11 +3543,11 @@ GenericSignatureBuilder::Implementation::getRewriteTreeRootIfPresent(
RewriteTreeNode *
GenericSignatureBuilder::Implementation::getOrCreateRewriteTreeRoot(
CanType anchor) {
auto known = RewriteTreeRoots.find(anchor);
if (known != RewriteTreeRoots.end()) return known->second.get();
if (auto *root = getRewriteTreeRootIfPresent(anchor))
return root;

auto &root = RewriteTreeRoots[anchor];
root = std::unique_ptr<RewriteTreeNode>(new RewriteTreeNode(nullptr));
root = llvm::make_unique<RewriteTreeNode>(nullptr);
return root.get();
}

Expand Down Expand Up @@ -4929,35 +4929,25 @@ GenericSignatureBuilder::addSameTypeRequirementBetweenTypeParameters(
};

// Consider the second equivalence class to be modified.
if (equivClass2)
equivClass->modified(*this);

// Same-type requirements, delayed requirements.
// Transfer Same-type requirements and delayed requirements.
if (equivClass2) {
Impl->DelayedRequirements.append(equivClass2->delayedRequirements.begin(),
equivClass2->delayedRequirements.end());

// Mark as modified and transfer deplayed requirements to the primary queue.
equivClass2->modified(*this);
equivClass->sameTypeConstraints.insert(
equivClass->sameTypeConstraints.end(),
equivClass2->sameTypeConstraints.begin(),
equivClass2->sameTypeConstraints.end());
}

// Combine the rewrite rules.
if (auto rewriteRoot2 = Impl->getOrCreateRewriteTreeRoot(anchor2)) {
if (auto rewriteRoot1 = Impl->getOrCreateRewriteTreeRoot(anchor1)) {
// Merge the second rewrite tree into the first.
if (rewriteRoot2->mergeInto(rewriteRoot1))
++Impl->RewriteGeneration;
Impl->RewriteTreeRoots.erase(anchor2);
} else {
// Take the second rewrite tree and make it the first.
auto root2Entry = Impl->RewriteTreeRoots.find(anchor2);
auto root2Ptr = std::move(root2Entry->second);
Impl->RewriteTreeRoots.erase(root2Entry);
(void)Impl->RewriteTreeRoots.insert({anchor1, std::move(root2Ptr)});
}
}
auto *rewriteRoot1 = Impl->getOrCreateRewriteTreeRoot(anchor1);
auto *rewriteRoot2 = Impl->getOrCreateRewriteTreeRoot(anchor2);
assert(rewriteRoot1 && rewriteRoot2 &&
"Couldn't create/retrieve rewrite tree root");
// Merge the second rewrite tree into the first.
if (rewriteRoot2->mergeInto(rewriteRoot1))
++Impl->RewriteGeneration;
Impl->RewriteTreeRoots.erase(anchor2);

// Add a rewrite rule to map the anchor of T2 down to the anchor of T1.
if (addSameTypeRewriteRule(anchor2, anchor1))
Expand Down