Skip to content

Commit 3574af8

Browse files
Merge remote-tracking branch 'apple/main' into katei/merge-main-2022-06-09
2 parents 508864a + 965a54f commit 3574af8

File tree

91 files changed

+1067
-449
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+1067
-449
lines changed

SwiftCompilerSources/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,19 @@ else()
204204
message(FATAL_ERROR "Need a swift toolchain building swift compiler sources")
205205
endif()
206206

207+
if(${BOOTSTRAPPING_MODE} STREQUAL "HOSTTOOLS")
208+
if(NOT SWIFT_EXEC_FOR_SWIFT_MODULES STREQUAL CMAKE_Swift_COMPILER)
209+
message(FATAL_ERROR "The Swift compiler (${CMAKE_Swift_COMPILER}) differs from the Swift compiler in SWIFT_NATIVE_SWIFT_TOOLS_PATH (${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/swiftc).")
210+
endif()
211+
212+
set(min_supported_swift_version 5.5)
213+
if(CMAKE_Swift_COMPILER_VERSION VERSION_LESS "${min_supported_swift_version}")
214+
message(FATAL_ERROR
215+
"Outdated Swift compiler: building with host tools requires Swift ${min_supported_swift_version} or newer. "
216+
"Please update your Swift toolchain or switch BOOTSTRAPPING_MODE to BOOTSTRAPPING(-WITH-HOSTLIBS)? or OFF.")
217+
endif()
218+
endif()
219+
207220
add_swift_compiler_modules_library(swiftCompilerModules
208221
SWIFT_EXEC "${SWIFT_EXEC_FOR_SWIFT_MODULES}")
209222

include/swift/SIL/Dominance.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,12 @@ class DominanceInfo : public DominatorTreeBase {
9292
///
9393
/// Precondition: no critical edges (OSSA)
9494
///
95-
/// Postcondition: each block in \p frontier is dominated by \p root and either
96-
/// exits the function or has a single successor that is not dominated by \p
97-
/// root.
98-
///
99-
/// With no critical edges, the dominance frontier is identified simply by leaf
100-
/// blocks in the dominance subtree.
101-
void computeDominanceFrontier(SILBasicBlock *root, DominanceInfo *domTree,
102-
SmallVectorImpl<SILBasicBlock *> &frontier);
95+
/// Postcondition: each block in \p boundary is dominated by \p root and either
96+
/// exits the function or has a single successor which has a predecessor that is
97+
/// not dominated by \p root.
98+
99+
void computeDominatedBoundaryBlocks(SILBasicBlock *root, DominanceInfo *domTree,
100+
SmallVectorImpl<SILBasicBlock *> &boundary);
103101

104102
/// Helper class for visiting basic blocks in dominance order, based on a
105103
/// worklist algorithm. Example usage:

include/swift/SIL/SILType.h

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ enum class SILValueCategory : uint8_t {
8686
Address,
8787
};
8888

89+
class SILPrinter;
90+
8991
/// SILType - A Swift type that has been lowered to a SIL representation type.
9092
/// In addition to the Swift type system, SIL adds "address" types that can
9193
/// reference any Swift type (but cannot take the address of an address). *T
@@ -113,6 +115,8 @@ class SILType {
113115

114116
friend class Lowering::TypeConverter;
115117
friend struct llvm::DenseMapInfo<SILType>;
118+
friend class SILPrinter;
119+
116120
public:
117121
SILType() = default;
118122

@@ -184,8 +188,11 @@ class SILType {
184188
/// type. This is done under the assumption that in all cases where we are
185189
/// performing these AST queries on SILType, we are not interested in the
186190
/// move only-ness of the value (which we can query separately anyways).
187-
CanType getASTType() const { return withoutMoveOnly().getRawASTType(); }
191+
CanType getASTType() const {
192+
return removingMoveOnlyWrapper().getRawASTType();
193+
}
188194

195+
private:
189196
/// Returns the canonical AST type references by this SIL type without looking
190197
/// through move only. Should only be used by internal utilities of SILType.
191198
CanType getRawASTType() const { return CanType(value.getPointer()); }
@@ -597,33 +604,34 @@ class SILType {
597604
///
598605
/// Canonical way to check if a SILType is move only. Using is/getAs/castTo
599606
/// will look through moveonly-ness.
600-
bool isMoveOnly() const { return getRawASTType()->is<SILMoveOnlyType>(); }
607+
bool isMoveOnlyWrapped() const {
608+
return getRawASTType()->is<SILMoveOnlyType>();
609+
}
601610

602-
/// Return *this if already move only... otherwise, wrap the current type
603-
/// within a move only type wrapper and return that. Idempotent!
604-
SILType asMoveOnly() const {
605-
if (isMoveOnly())
611+
/// If this is already a move only wrapped type, return *this. Otherwise, wrap
612+
/// the copyable type in the mov eonly wrapper.
613+
SILType addingMoveOnlyWrapper() const {
614+
if (isMoveOnlyWrapped())
606615
return *this;
607616
auto newType = SILMoveOnlyType::get(getRawASTType());
608617
return SILType::getPrimitiveType(newType, getCategory());
609618
}
610619

611-
/// Return this SILType, removing moveonly-ness.
612-
///
613-
/// Is idempotent.
614-
SILType withoutMoveOnly() const {
615-
if (!isMoveOnly())
620+
/// If this is already a copyable type, just return *this. Otherwise, if this
621+
/// is a move only wrapped copyable type, return the inner type.
622+
SILType removingMoveOnlyWrapper() const {
623+
if (!isMoveOnlyWrapped())
616624
return *this;
617625
auto moveOnly = getRawASTType()->castTo<SILMoveOnlyType>();
618626
return SILType::getPrimitiveType(moveOnly->getInnerType(), getCategory());
619627
}
620628

621-
/// If \p otherType is move only, return this type that is move only as
622-
/// well. Otherwise, returns self. Useful for propagating "move only"-ness
629+
/// If \p otherType is move only wrapped, return this type that is move only
630+
/// as well. Otherwise, returns self. Useful for propagating "move only"-ness
623631
/// from a parent type to a subtype.
624-
SILType copyMoveOnly(SILType otherType) const {
625-
if (otherType.isMoveOnly()) {
626-
return asMoveOnly();
632+
SILType copyingMoveOnlyWrapper(SILType otherType) const {
633+
if (otherType.isMoveOnlyWrapped()) {
634+
return addingMoveOnlyWrapper();
627635
}
628636
return *this;
629637
}

include/swift/SIL/TypeLowering.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,8 @@ class TypeConverter {
821821

822822
llvm::DenseMap<AbstractClosureExpr *, Optional<AbstractionPattern>>
823823
ClosureAbstractionPatterns;
824+
llvm::DenseMap<SILDeclRef, TypeExpansionContext>
825+
CaptureTypeExpansionContexts;
824826

825827
CanAnyFunctionType makeConstantInterfaceType(SILDeclRef constant);
826828

@@ -1225,6 +1227,7 @@ class TypeConverter {
12251227
/// the abstraction pattern is queried using this function. Once the
12261228
/// abstraction pattern has been asked for, it may not be changed.
12271229
Optional<AbstractionPattern> getConstantAbstractionPattern(SILDeclRef constant);
1230+
TypeExpansionContext getCaptureTypeExpansionContext(SILDeclRef constant);
12281231

12291232
/// Set the preferred abstraction pattern for a closure.
12301233
///
@@ -1234,6 +1237,8 @@ class TypeConverter {
12341237
void setAbstractionPattern(AbstractClosureExpr *closure,
12351238
AbstractionPattern pattern);
12361239

1240+
void setCaptureTypeExpansionContext(SILDeclRef constant,
1241+
SILModule &M);
12371242
private:
12381243
CanType computeLoweredRValueType(TypeExpansionContext context,
12391244
AbstractionPattern origType,

include/swift/Sema/CSFix.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -708,10 +708,13 @@ class TreatArrayLiteralAsDictionary final : public ContextualMismatch {
708708
}
709709

710710
bool diagnose(const Solution &solution, bool asNote = false) const override;
711+
bool diagnoseForAmbiguity(CommonFixesArray commonFixes) const override {
712+
return diagnose(*commonFixes.front().first);
713+
}
711714

712-
static TreatArrayLiteralAsDictionary *create(ConstraintSystem &cs,
713-
Type dictionaryTy, Type arrayTy,
714-
ConstraintLocator *loc);
715+
static TreatArrayLiteralAsDictionary *attempt(ConstraintSystem &cs,
716+
Type dictionaryTy, Type arrayTy,
717+
ConstraintLocator *loc);
715718

716719
static bool classof(ConstraintFix *fix) {
717720
return fix->getKind() == FixKind::TreatArrayLiteralAsDictionary;

lib/AST/ASTPrinter.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3583,8 +3583,9 @@ void PrintAST::printPrimaryAssociatedTypes(ProtocolDecl *decl) {
35833583
[&](AssociatedTypeDecl *assocType) {
35843584
Printer.callPrintStructurePre(PrintStructureKind::GenericParameter,
35853585
assocType);
3586-
Printer.printName(assocType->getName(),
3587-
PrintNameContext::GenericParameter);
3586+
Printer.printTypeRef(assocType->getDeclaredInterfaceType(), assocType,
3587+
assocType->getName(),
3588+
PrintNameContext::GenericParameter);
35883589
Printer.printStructurePost(PrintStructureKind::GenericParameter,
35893590
assocType);
35903591
},

lib/AST/RequirementMachine/ConcreteContraction.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ class ConcreteContraction {
227227
Optional<Type> ConcreteContraction::substTypeParameterRec(
228228
Type type, Position position) const {
229229

230-
// If the requirement is of the form 'T == C' or 'T : C', don't
231-
// substitute T, since then we end up with 'C == C' or 'C : C',
230+
// If we have a superclass (T : C) or same-type requirement (T == C),
231+
// don't substitute T, since then we end up with 'C == C' or 'C : C',
232232
// losing the requirement.
233233
if (position == Position::BaseType ||
234234
position == Position::ConformanceRequirement) {
@@ -399,9 +399,10 @@ ConcreteContraction::substRequirement(const Requirement &req) const {
399399
!module->lookupConformance(substFirstType, proto,
400400
allowMissing, allowUnavailable)) {
401401
// Handle the case of <T where T : P, T : C> where C is a class and
402-
// C does not conform to P by leaving the conformance requirement
403-
// unsubstituted.
404-
return req;
402+
// C does not conform to P and only substitute the parent type of T
403+
// by pretending we have a same-type requirement here.
404+
substFirstType = substTypeParameter(
405+
firstType, Position::SameTypeRequirement);
405406
}
406407

407408
// Otherwise, replace the generic parameter in the conformance
@@ -418,9 +419,11 @@ ConcreteContraction::substRequirement(const Requirement &req) const {
418419
if (!substFirstType->isTypeParameter() &&
419420
!substFirstType->satisfiesClassConstraint() &&
420421
req.getLayoutConstraint()->isClass()) {
421-
// If the concrete type doesn't satisfy the layout constraint,
422-
// leave it unsubstituted so that we produce a better diagnostic.
423-
return req;
422+
// If the concrete type doesn't satisfy the layout constraint, produce
423+
// a better diagnostic and only substitute the parent type by pretending
424+
// we have a same-type requirement here.
425+
substFirstType = substTypeParameter(
426+
firstType, Position::SameTypeRequirement);
424427
}
425428

426429
return Requirement(req.getKind(),

lib/AST/RequirementMachine/MinimalConformances.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ MinimalConformances::decomposeTermIntoConformanceRuleLeftHandSides(
263263
bool simplified = System.simplify(term, &steps);
264264
if (!simplified) {
265265
llvm::errs() << "Term does not conform to protocol: " << term << "\n";
266+
System.dump(llvm::errs());
266267
abort();
267268
}
268269

lib/Basic/ParseableOutput.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ template <> struct ScalarEnumerationTraits<file_types::ID> {
4242
std::string typeName = file_types::getTypeName(ty).str();
4343
out.enumCase(value, typeName.c_str(), ty);
4444
});
45+
out.enumCase(value, "unknown", file_types::ID::TY_INVALID);
4546
}
4647
};
4748

lib/FrontendTool/FrontendTool.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,7 @@ static swift::file_types::ID computeFileTypeForPath(const StringRef Path) {
602602
// then iterate over all preceeding possible extension variants.
603603
while (llvm::sys::path::has_extension(PathStem)) {
604604
auto NextExtension = llvm::sys::path::extension(PathStem);
605+
PathStem = llvm::sys::path::stem(PathStem);
605606
Extension = NextExtension.str() + Extension;
606607
FileType = file_types::lookupTypeForExtension(Extension);
607608
if (FileType != swift::file_types::ID::TY_INVALID)

0 commit comments

Comments
 (0)