Skip to content

Commit 0443ae7

Browse files
authored
Merge branch 'apple:main' into main
2 parents c73658a + a8d29e4 commit 0443ae7

34 files changed

+263
-445
lines changed

include/swift/AST/ModuleDependencies.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ using ModuleDependencyIDSetVector =
123123

124124
namespace dependencies {
125125
std::string createEncodedModuleKindAndName(ModuleDependencyID id);
126+
bool checkImportNotTautological(const ImportPath::Module,
127+
const SourceLoc,
128+
const SourceFile&,
129+
bool);
126130
}
127131

128132
/// Base class for the variant storage of ModuleDependencyInfo.

lib/AST/ModuleDependencies.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "swift/AST/ModuleDependencies.h"
1717
#include "swift/AST/Decl.h"
1818
#include "swift/AST/DiagnosticsFrontend.h"
19+
#include "swift/AST/DiagnosticsSema.h"
1920
#include "swift/AST/SourceFile.h"
2021
#include "swift/Frontend/Frontend.h"
2122
#include "llvm/CAS/CASProvidingFileSystem.h"
@@ -145,6 +146,11 @@ void ModuleDependencyInfo::addModuleImport(
145146
if (importedModuleName == BUILTIN_NAME)
146147
continue;
147148

149+
// Ignore/diagnose tautological imports akin to import resolution
150+
if (!swift::dependencies::checkImportNotTautological(
151+
realPath, importDecl->getLoc(), sf, importDecl->isExported()))
152+
continue;
153+
148154
addModuleImport(realPath, &alreadyAddedModules);
149155

150156
// Additionally, keep track of which dependencies of a Source
@@ -408,6 +414,35 @@ SwiftDependencyScanningService::SwiftDependencyScanningService() {
408414
SharedFilesystemCache.emplace();
409415
}
410416

417+
bool
418+
swift::dependencies::checkImportNotTautological(const ImportPath::Module modulePath,
419+
const SourceLoc importLoc,
420+
const SourceFile &SF,
421+
bool isExported) {
422+
if (modulePath.front().Item != SF.getParentModule()->getName() ||
423+
// Overlays use an @_exported self-import to load their clang module.
424+
isExported ||
425+
// Imports of your own submodules are allowed in cross-language libraries.
426+
modulePath.size() != 1 ||
427+
// SIL files self-import to get decls from the rest of the module.
428+
SF.Kind == SourceFileKind::SIL)
429+
return true;
430+
431+
ASTContext &ctx = SF.getASTContext();
432+
433+
StringRef filename = llvm::sys::path::filename(SF.getFilename());
434+
if (filename.empty())
435+
ctx.Diags.diagnose(importLoc, diag::sema_import_current_module,
436+
modulePath.front().Item);
437+
else
438+
ctx.Diags.diagnose(importLoc, diag::sema_import_current_module_with_file,
439+
filename, modulePath.front().Item);
440+
441+
return false;
442+
443+
return false;
444+
}
445+
411446
void SwiftDependencyTracker::addCommonSearchPathDeps(
412447
const SearchPathOptions &Opts) {
413448
// Add SDKSetting file.

lib/AST/NameLookupRequests.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#include "swift/AST/NameLookup.h"
1413
#include "swift/AST/NameLookupRequests.h"
1514
#include "swift/AST/ASTContext.h"
1615
#include "swift/AST/Decl.h"
16+
#include "swift/AST/Evaluator.h"
1717
#include "swift/AST/GenericParamList.h"
18+
#include "swift/AST/Module.h"
19+
#include "swift/AST/NameLookup.h"
1820
#include "swift/AST/PotentialMacroExpansions.h"
1921
#include "swift/AST/ProtocolConformance.h"
20-
#include "swift/AST/Evaluator.h"
21-
#include "swift/AST/Module.h"
2222
#include "swift/AST/SourceFile.h"
23+
#include "swift/AST/TypeCheckRequests.h"
2324
#include "swift/ClangImporter/ClangImporterRequests.h"
2425
#include "swift/Subsystems.h"
2526

@@ -156,6 +157,13 @@ HasMissingDesignatedInitializersRequest::evaluate(Evaluator &evaluator,
156157
if (!scope.isPublic())
157158
return false;
158159

160+
// Make sure any implicit constructors are synthesized.
161+
(void)evaluateOrDefault(
162+
evaluator,
163+
ResolveImplicitMemberRequest{subject,
164+
ImplicitMemberAction::ResolveImplicitInit},
165+
{});
166+
159167
auto constructors = subject->lookupDirect(DeclBaseName::createConstructor());
160168
return llvm::any_of(constructors, [&](ValueDecl *decl) {
161169
auto init = cast<ConstructorDecl>(decl);

lib/ASTGen/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ set(compile_options
6767
"SHELL: ${cxx_interop_flag}"
6868
"SHELL: -Xcc -std=c++17 -Xcc -DCOMPILED_WITH_SWIFT"
6969

70+
# FIXME: Needed to work around an availability issue with CxxStdlib
71+
"SHELL: -Xfrontend -disable-target-os-checking"
72+
7073
# Necessary to avoid treating IBOutlet and IBAction as keywords
7174
"SHELL:-Xcc -UIBOutlet -Xcc -UIBAction -Xcc -UIBInspectable"
7275
)

lib/ASTGen/Package.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ let swiftSetttings: [SwiftSetting] = [
3131
"-Xcc", "-I../../../build/Default/swift/include",
3232
"-Xcc", "-I../../../build/Default/llvm/include",
3333
"-Xcc", "-I../../../build/Default/llvm/tools/clang/include",
34+
35+
// FIXME: Needed to work around an availability issue with CxxStdlib
36+
"-Xfrontend", "-disable-target-os-checking",
3437
]),
3538
]
3639

3740
let package = Package(
3841
name: "swiftSwiftCompiler",
3942
platforms: [
40-
// We need at least macOS 13 here to avoid hitting an availability error
41-
// for CxxStdlib. It's only needed for the package though, the CMake build
42-
// works fine with a lower deployment target.
43-
.macOS(.v13)
43+
.macOS(.v10_15)
4444
],
4545
products: [
4646
.library(name: "swiftASTGen", targets: ["swiftASTGen"]),

lib/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ if (SWIFT_BUILD_SWIFT_SYNTAX)
5959
# Install Swift module interface files.
6060
foreach(module ${SWIFT_SYNTAX_MODULES})
6161
set(module_dir "${module}.swiftmodule")
62-
set(module_file "${SWIFT_HOST_LIBRARIES_DEST_DIR}/${module_dir}/${SWIFT_HOST_MODULE_TRIPLE}.swiftinterface")
63-
swift_install_in_component(FILES "${module_file}"
62+
set(module_file "${SWIFT_HOST_LIBRARIES_DEST_DIR}/${module_dir}/${SWIFT_HOST_MODULE_TRIPLE}")
63+
swift_install_in_component(FILES "${module_file}.swiftinterface" "${module_file}.private.swiftinterface"
6464
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/host/${module_dir}"
6565
COMPONENT swift-syntax-lib)
6666
endforeach()

lib/IRGen/GenOpaque.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ static FunctionPointer emitLoadOfValueWitnessFunction(IRGenFunction &IGF,
461461
IGF.getOptions().PointerAuth.ValueWitnesses,
462462
slot, index);
463463

464+
witness->setName(getValueWitnessName(index));
464465
return FunctionPointer::createSigned(FunctionPointer::Kind::Function, witness,
465466
authInfo, signature);
466467
}

lib/PrintAsClang/PrintClangValueType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ void ClangValueTypePrinter::printTypeGenericTraits(
651651
}
652652
os << "> {\n";
653653
os << " static ";
654-
ClangSyntaxPrinter(os).printInlineForThunk();
654+
ClangSyntaxPrinter(os).printInlineForHelperFunction();
655655
os << "void * _Nonnull getTypeMetadata() {\n";
656656
os << " return ";
657657
if (!typeDecl->hasClangNode()) {

lib/Sema/CSBindings.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1433,6 +1433,26 @@ PotentialBindings::inferFromRelational(Constraint *constraint) {
14331433
/// those types should be opened.
14341434
void PotentialBindings::infer(Constraint *constraint) {
14351435
switch (constraint->getKind()) {
1436+
case ConstraintKind::OptionalObject: {
1437+
// Inference through optional object is allowed if
1438+
// one of the types is resolved or "optional" type variable
1439+
// cannot be bound to l-value, otherwise there is a
1440+
// risk of binding "optional" to an optional type (inferred from
1441+
// the "object") and discovering an l-value binding for it later.
1442+
auto optionalType = constraint->getFirstType();
1443+
1444+
if (auto *optionalVar = optionalType->getAs<TypeVariableType>()) {
1445+
if (optionalVar->getImpl().canBindToLValue()) {
1446+
auto objectType =
1447+
constraint->getSecondType()->lookThroughAllOptionalTypes();
1448+
if (objectType->isTypeVariableOrMember())
1449+
return;
1450+
}
1451+
}
1452+
1453+
LLVM_FALLTHROUGH;
1454+
}
1455+
14361456
case ConstraintKind::Bind:
14371457
case ConstraintKind::Equal:
14381458
case ConstraintKind::BindParam:
@@ -1442,7 +1462,6 @@ void PotentialBindings::infer(Constraint *constraint) {
14421462
case ConstraintKind::Conversion:
14431463
case ConstraintKind::ArgumentConversion:
14441464
case ConstraintKind::OperatorArgumentConversion:
1445-
case ConstraintKind::OptionalObject:
14461465
case ConstraintKind::UnresolvedMemberChainBase: {
14471466
auto binding = inferFromRelational(constraint);
14481467
if (!binding)

lib/Sema/ImportResolution.cpp

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#define DEBUG_TYPE "swift-import-resolution"
1818
#include "swift/AST/ASTWalker.h"
1919
#include "swift/AST/DiagnosticsSema.h"
20+
#include "swift/AST/ModuleDependencies.h"
2021
#include "swift/AST/ModuleLoader.h"
2122
#include "swift/AST/ModuleNameLookup.h"
2223
#include "swift/AST/NameLookup.h"
@@ -602,28 +603,9 @@ UnboundImport::UnboundImport(ImportDecl *ID)
602603
}
603604

604605
bool UnboundImport::checkNotTautological(const SourceFile &SF) {
605-
// Exit early if this is not a self-import.
606-
auto modulePath = import.module.getModulePath();
607-
if (modulePath.front().Item != SF.getParentModule()->getName() ||
608-
// Overlays use an @_exported self-import to load their clang module.
609-
import.options.contains(ImportFlags::Exported) ||
610-
// Imports of your own submodules are allowed in cross-language libraries.
611-
modulePath.size() != 1 ||
612-
// SIL files self-import to get decls from the rest of the module.
613-
SF.Kind == SourceFileKind::SIL)
614-
return true;
615-
616-
ASTContext &ctx = SF.getASTContext();
617-
618-
StringRef filename = llvm::sys::path::filename(SF.getFilename());
619-
if (filename.empty())
620-
ctx.Diags.diagnose(importLoc, diag::sema_import_current_module,
621-
modulePath.front().Item);
622-
else
623-
ctx.Diags.diagnose(importLoc, diag::sema_import_current_module_with_file,
624-
filename, modulePath.front().Item);
625-
626-
return false;
606+
return swift::dependencies::checkImportNotTautological(
607+
import.module.getModulePath(), importLoc, SF,
608+
import.options.contains(ImportFlags::Exported));
627609
}
628610

629611
bool UnboundImport::checkModuleLoaded(ModuleDecl *M, SourceFile &SF) {

0 commit comments

Comments
 (0)