Skip to content

Commit dd3ce22

Browse files
Merge pull request #4635 from swiftwasm/katei/merge-main-2022-06-09
Merge main 2022-06-09
2 parents 508864a + 802d051 commit dd3ce22

File tree

91 files changed

+1063
-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

+1063
-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)

lib/IDE/CodeCompletionConsumer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ static MutableArrayRef<CodeCompletionResult *> copyCodeCompletionResults(
7171
};
7272
} else {
7373
shouldIncludeResult = [](const ContextFreeCodeCompletionResult *R) -> bool {
74-
return true;
74+
// PrecedenceGroups are only valid in 'onlyPrecedenceGroups'.
75+
return R->getAssociatedDeclKind() !=
76+
CodeCompletionDeclKind::PrecedenceGroup;
7577
};
7678
}
7779

lib/IDE/SourceEntityWalker.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,21 @@ bool SemaAnnotator::walkToDeclPreProper(Decl *D) {
180180
if (!ReportParamList(ParamList))
181181
return false;
182182
}
183+
184+
if (auto proto = dyn_cast<ProtocolDecl>(VD)) {
185+
// Report a primary associated type as a references to the associated type
186+
// declaration.
187+
for (auto parsedName : proto->getPrimaryAssociatedTypeNames()) {
188+
Identifier name = parsedName.first;
189+
SourceLoc loc = parsedName.second;
190+
if (auto assocTypeDecl = proto->getAssociatedType(name)) {
191+
passReference(assocTypeDecl,
192+
assocTypeDecl->getDeclaredInterfaceType(),
193+
DeclNameLoc(loc),
194+
ReferenceMetaData(SemaReferenceKind::TypeRef, None));
195+
}
196+
}
197+
}
183198
} else if (auto *ED = dyn_cast<ExtensionDecl>(D)) {
184199
SourceRange SR = SourceRange();
185200
if (auto *repr = ED->getExtendedTypeRepr())

lib/IRGen/GenObjC.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,6 @@ static llvm::Constant *findSwiftAsObjCThunk(IRGenModule &IGM, SILDeclRef ref,
944944
SILFn = IGM.getSILModule().lookUpFunction(ref);
945945
assert(SILFn && "no IR function for swift-as-objc thunk");
946946
auto fn = IGM.getAddrOfSILFunction(SILFn, NotForDefinition);
947-
ApplyIRLinkage(IRLinkage::Internal).to(fn);
948947
// Don't add the unnamed_addr attribute: in some places Foundation is
949948
// comparing ObjC method pointers. Therefore LLVM's function merging pass must
950949
// not create aliases for identical functions, but create thunks.

lib/SIL/IR/SILDeclRef.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,13 +396,20 @@ SILLinkage SILDeclRef::getLinkage(ForDefinition_t forDefinition) const {
396396
if (fn->hasForcedStaticDispatch()) {
397397
limit = Limit::OnDemand;
398398
}
399+
}
399400

401+
if (auto fn = dyn_cast<AbstractFunctionDecl>(d)) {
400402
// Native-to-foreign thunks for top-level decls are created on-demand,
401403
// unless they are marked @_cdecl, in which case they expose a dedicated
402404
// entry-point with the visibility of the function.
405+
//
406+
// Native-to-foreign thunks for methods are always just private, since
407+
// they're anchored by Objective-C metadata.
403408
if (isNativeToForeignThunk() && !fn->getAttrs().hasAttribute<CDeclAttr>()) {
404409
if (fn->getDeclContext()->isModuleScopeContext())
405410
limit = Limit::OnDemand;
411+
else
412+
return SILLinkage::Private;
406413
}
407414
}
408415

lib/SIL/IR/SILFunctionType.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2078,13 +2078,9 @@ static CanSILFunctionType getSILFunctionType(
20782078
// Lower in the context of the closure. Since the set of captures is a
20792079
// private contract between the closure and its enclosing context, we
20802080
// don't need to keep its capture types opaque.
2081-
auto expansion = TypeExpansionContext::maximal(
2082-
constant->getAnyFunctionRef()->getAsDeclContext(), false);
2083-
// ...unless it's inlinable, in which case it might get inlined into
2084-
// some place we need to keep opaque types opaque.
2085-
if (constant->isSerialized())
2086-
expansion = TypeExpansionContext::minimal();
2087-
lowerCaptureContextParameters(TC, *constant, genericSig, expansion, inputs);
2081+
lowerCaptureContextParameters(TC, *constant, genericSig,
2082+
TC.getCaptureTypeExpansionContext(*constant),
2083+
inputs);
20882084
}
20892085

20902086
auto calleeConvention = ParameterConvention::Direct_Unowned;

lib/SIL/IR/SILPrinter.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -532,8 +532,6 @@ static void printSILFunctionNameAndType(llvm::raw_ostream &OS,
532532
}
533533

534534
namespace {
535-
536-
class SILPrinter;
537535

538536
// 1. Accumulate opcode-specific comments in this stream.
539537
// 2. Start emitting comments: lineComments.start()
@@ -598,6 +596,10 @@ class LineComments : public raw_ostream {
598596
}
599597
};
600598

599+
} // namespace
600+
601+
namespace swift {
602+
601603
/// SILPrinter class - This holds the internal implementation details of
602604
/// printing SIL structures.
603605
class SILPrinter : public SILInstructionVisitor<SILPrinter> {
@@ -2740,7 +2742,8 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
27402742
}
27412743
}
27422744
};
2743-
} // end anonymous namespace
2745+
2746+
} // namespace swift
27442747

27452748
static void printBlockID(raw_ostream &OS, SILBasicBlock *bb) {
27462749
SILPrintContext Ctx(OS);

0 commit comments

Comments
 (0)