Skip to content

Fix lazy compilation of standard lib in -resource-dir #6

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 5 commits into from
Dec 14, 2022
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
15 changes: 15 additions & 0 deletions patch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

PATCH_DIR="$(cd "$(dirname "$0")/patches"; pwd)"

for patch_subdir in "$PATCH_DIR"/*; do
(
repo="$(basename "$patch_subdir")"
cd "$repo" || exit 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be followed by cd .. (or whatever the previous directory was)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, because it's in a (...) subshell, so any change of directory is discarded on exit

echo "patching $repo"
for patch in "$patch_subdir"/*; do
echo " applying $(basename "$patch")"
git apply "$patch"
done
)
done
15 changes: 15 additions & 0 deletions patches/swift/01-remove-assert-in-fallthrough-stmt.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
There are some cases when we extract bad ASTs where we hit this assertion if we compile in debug
mode. This is undesirable.

diff --git a/include/swift/AST/Stmt.h b/include/swift/AST/Stmt.h
index 532e038c386..f013eee2f98 100644
--- a/include/swift/AST/Stmt.h
+++ b/include/swift/AST/Stmt.h
@@ -920,7 +920,6 @@ public:
/// Get the CaseStmt block to which the fallthrough transfers control.
/// Set during Sema.
CaseStmt *getFallthroughDest() const {
- assert(FallthroughDest && "fallthrough dest is not set until Sema");
return FallthroughDest;
}
void setFallthroughDest(CaseStmt *C) {
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
diff --git a/include/swift/AST/Stmt.h b/include/swift/AST/Stmt.h
index 532e038c386..f013eee2f98 100644
--- a/include/swift/AST/Stmt.h
+++ b/include/swift/AST/Stmt.h
@@ -920,7 +920,6 @@ public:
/// Get the CaseStmt block to which the fallthrough transfers control.
/// Set during Sema.
CaseStmt *getFallthroughDest() const {
- assert(FallthroughDest && "fallthrough dest is not set until Sema");
return FallthroughDest;
}
void setFallthroughDest(CaseStmt *C) {
`PatternBindingDecl::getPatternList()` can in some cases return an empty list, which causes a
segmentation fault when getting the source range. This case needs to be handled for the extractor.

diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index 75b99a22e73..09115678a82 100644
--- a/lib/AST/Decl.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
When running the extractor against a different version of the swift compiler, we provide it the
original standard library via `-resource-dir`, and we do want that to be lazily compiled out of the
`.swiftinterface` files. The code removed here explicitly disables that behavior.

diff --git a/lib/Frontend/ModuleInterfaceLoader.cpp b/lib/Frontend/ModuleInterfaceLoader.cpp
index 2a490a680d8..8d8f48aeed0 100644
--- a/lib/Frontend/ModuleInterfaceLoader.cpp
+++ b/lib/Frontend/ModuleInterfaceLoader.cpp
@@ -726,21 +726,6 @@ class ModuleInterfaceLoaderImpl {
<< "; deferring to serialized module loader\n");
UsableModulePath = adjacentMod;
return std::make_error_code(std::errc::not_supported);
- } else if (isInResourceDir(adjacentMod) &&
- loadMode == ModuleLoadingMode::PreferSerialized) {
- // Special-case here: If we're loading a .swiftmodule from the resource
- // dir adjacent to the compiler, defer to the serialized loader instead
- // of falling back. This is mainly to support development of Swift,
- // where one might change the module format version but forget to
- // recompile the standard library. If that happens, don't fall back
- // and silently recompile the standard library -- instead, error like
- // we used to.
- LLVM_DEBUG(llvm::dbgs() << "Found out-of-date module in the "
- "resource-dir at "
- << adjacentMod
- << "; deferring to serialized module loader "
- "to diagnose\n");
- return std::make_error_code(std::errc::not_supported);
} else {
LLVM_DEBUG(llvm::dbgs() << "Found out-of-date module at "
<< adjacentMod << "\n");