Skip to content

Commit f72b5ac

Browse files
Merge pull request #5409 from swiftwasm/main
[pull] swiftwasm from main
2 parents ed3dd14 + ed3555a commit f72b5ac

File tree

114 files changed

+1070
-392
lines changed

Some content is hidden

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

114 files changed

+1070
-392
lines changed

Diff for: SwiftCompilerSources/Sources/Optimizer/Analysis/CalleeAnalysis.swift

+2-3
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ public struct CalleeAnalysis {
2323
return inst.instruction.isDeinitBarrier(bca.analysis)
2424
},
2525
// getMemBehaviorFn
26-
{ (bridgedCtxt: BridgedPassContext, bridgedApply: BridgedInstruction, observeRetains: Bool) -> swift.MemoryBehavior in
27-
let context = FunctionPassContext(_bridged: bridgedCtxt)
26+
{ (bridgedApply: BridgedInstruction, observeRetains: Bool, bca: BridgedCalleeAnalysis) -> swift.MemoryBehavior in
2827
let apply = bridgedApply.instruction as! ApplySite
29-
let e = context.calleeAnalysis.getSideEffects(of: apply)
28+
let e = bca.analysis.getSideEffects(of: apply)
3029
return e.getMemBehavior(observeRetains: observeRetains)
3130
}
3231
)

Diff for: SwiftCompilerSources/Sources/Optimizer/Utilities/EscapeUtils.swift

+8-5
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,6 @@ fileprivate struct EscapeWalker<V: EscapeVisitor> : ValueDefUseWalker,
361361
case is ApplyInst, is TryApplyInst, is BeginApplyInst:
362362
return walkDownCallee(argOp: operand, apply: instruction as! FullApplySite, path: path)
363363
case let pai as PartialApplyInst:
364-
// This is a non-stack closure.
365-
// For `stack` closures, `hasRelevantType` in `walkDown` will return false
366-
// stopping the walk since they don't escape.
367-
368364
// Check whether the partially applied argument can escape in the body.
369365
if walkDownCallee(argOp: operand, apply: pai, path: path.with(knownType: nil)) == .abortWalk {
370366
return .abortWalk
@@ -376,8 +372,9 @@ fileprivate struct EscapeWalker<V: EscapeVisitor> : ValueDefUseWalker,
376372
// 2. something can escape in a destructor when the context is destroyed
377373
return walkDownUses(ofValue: pai, path: path.with(knownType: nil))
378374
case let pta as PointerToAddressInst:
379-
assert(operand.index == 0)
380375
return walkDownUses(ofAddress: pta, path: path.with(knownType: nil))
376+
case let cv as ConvertFunctionInst:
377+
return walkDownUses(ofValue: cv, path: path.with(knownType: nil))
381378
case let bi as BuiltinInst:
382379
switch bi.id {
383380
case .DestroyArray:
@@ -561,6 +558,12 @@ fileprivate struct EscapeWalker<V: EscapeVisitor> : ValueDefUseWalker,
561558
return .continueWalk
562559
}
563560

561+
if argOp.value.type.isNoEscapeFunction {
562+
// Per definition a `partial_apply [on_stack]` cannot escape the callee.
563+
// Potential escapes of its captured values are already handled when visiting the `partial_apply`.
564+
return .continueWalk
565+
}
566+
564567
// Argument effects do not consider any potential stores to the argument (or it's content).
565568
// Therefore, if we need to track stores, the argument effects do not correctly describe what we need.
566569
// For example, argument 0 in the following function is marked as not-escaping, although there

Diff for: SwiftCompilerSources/Sources/SIL/Type.swift

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public struct Type : CustomStringConvertible, NoReflectionChildren {
4141
public var isEnum: Bool { bridged.getEnumOrBoundGenericEnum() != nil }
4242
public var isFunction: Bool { bridged.isFunction() }
4343
public var isMetatype: Bool { bridged.isMetatype() }
44+
public var isNoEscapeFunction: Bool { bridged.isNoEscapeFunction() }
4445

4546
/// Can only be used if the type is in fact a nominal type (`isNominal` is true).
4647
public var nominal: NominalTypeDecl {

Diff for: cmake/modules/SwiftSetIfArchBitness.cmake

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ function(set_if_arch_bitness var_name)
1414
"${SIA_ARCH}" STREQUAL "armv7" OR
1515
"${SIA_ARCH}" STREQUAL "armv7k" OR
1616
"${SIA_ARCH}" STREQUAL "arm64_32" OR
17+
"${SIA_ARCH}" STREQUAL "armv7m" OR
18+
"${SIA_ARCH}" STREQUAL "armv7em" OR
1719
"${SIA_ARCH}" STREQUAL "armv7s" OR
1820
"${SIA_ARCH}" STREQUAL "wasm32" OR
1921
"${SIA_ARCH}" STREQUAL "powerpc")

Diff for: include/swift/AST/ASTWalker.h

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ struct ReferenceMetaData {
4848
SemaReferenceKind Kind;
4949
llvm::Optional<AccessKind> AccKind;
5050
bool isImplicit = false;
51+
bool isImplicitCtorType = false;
5152

5253
/// When non-none, this is a custom attribute reference.
5354
Optional<std::pair<const CustomAttr *, Decl *>> CustomAttrRef;

Diff for: include/swift/AST/Decl.h

+4
Original file line numberDiff line numberDiff line change
@@ -8876,6 +8876,10 @@ const ParamDecl *getParameterAt(ConcreteDeclRef declRef, unsigned index);
88768876
/// nullptr if the source does not have a parameter list.
88778877
const ParamDecl *getParameterAt(const ValueDecl *source, unsigned index);
88788878

8879+
/// Retrieve parameter declaration from the given source at given index, or
8880+
/// nullptr if the source does not have a parameter list.
8881+
const ParamDecl *getParameterAt(const DeclContext *source, unsigned index);
8882+
88798883
void simple_display(llvm::raw_ostream &out,
88808884
OptionSet<NominalTypeDecl::LookupDirectFlags> options);
88818885

Diff for: include/swift/AST/DiagnosticsClangImporter.def

+2-1
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ NOTE(macro_not_imported, none, "macro '%0' unavailable (cannot import)", (String
156156

157157
NOTE(return_type_not_imported, none, "return type unavailable (cannot import)", ())
158158
NOTE(parameter_type_not_imported, none, "parameter %0 unavailable (cannot import)", (const clang::NamedDecl*))
159+
NOTE(rvalue_ref_params_not_imported, none, "C++ functions with rvalue reference parameters are unavailable in Swift", ())
159160
NOTE(incomplete_interface, none, "interface %0 is incomplete", (const clang::NamedDecl*))
160161
NOTE(incomplete_protocol, none, "protocol %0 is incomplete", (const clang::NamedDecl*))
161162
NOTE(incomplete_record, none, "record '%0' is not defined (incomplete)", (StringRef))
@@ -195,7 +196,7 @@ NOTE(mark_safe_to_import, none, "annotate method '%0' with 'SWIFT_RETURNS_INDEPE
195196
NOTE(at_to_subscript, none, "do you want to replace it with a call "
196197
"to the subscript operator?",
197198
())
198-
NOTE(get_swift_iterator, none, "do you want to make a Swift iterator instead?",
199+
NOTE(use_collection_apis, none, "do you want to use a for-in loop instead?",
199200
())
200201
NOTE(replace_with_nil, none, "do you want to compare against 'nil' instead?",
201202
())

Diff for: include/swift/AST/DiagnosticsSema.def

+5
Original file line numberDiff line numberDiff line change
@@ -7123,6 +7123,11 @@ ERROR(moveonly_parameter_missing_ownership, none,
71237123
"noncopyable parameter must specify its ownership", ())
71247124
NOTE(moveonly_parameter_ownership_suggestion, none,
71257125
"add '%0' %1", (StringRef, StringRef))
7126+
ERROR(ownership_specifier_copyable,none,
7127+
"Copyable types cannot be 'consuming' or 'borrowing' yet", ())
7128+
ERROR(self_ownership_specifier_copyable,none,
7129+
"%0 is not yet valid on %1s in a Copyable type",
7130+
(SelfAccessKind, DescriptiveDeclKind))
71267131

71277132
//------------------------------------------------------------------------------
71287133
// MARK: Runtime discoverable attributes (@runtimeMetadata)

Diff for: include/swift/AST/TypeCheckRequests.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -3258,17 +3258,17 @@ void simple_display(llvm::raw_ostream &out,
32583258
class ResolveMacroRequest
32593259
: public SimpleRequest<ResolveMacroRequest,
32603260
ConcreteDeclRef(UnresolvedMacroReference,
3261-
const Decl *),
3261+
DeclContext *),
32623262
RequestFlags::Cached> {
32633263
public:
32643264
using SimpleRequest::SimpleRequest;
32653265

32663266
private:
32673267
friend SimpleRequest;
32683268

3269-
ConcreteDeclRef
3270-
evaluate(Evaluator &evaluator, UnresolvedMacroReference macroRef,
3271-
const Decl *decl) const;
3269+
ConcreteDeclRef evaluate(Evaluator &evaluator,
3270+
UnresolvedMacroReference macroRef,
3271+
DeclContext *decl) const;
32723272

32733273
public:
32743274
bool isCached() const { return true; }

Diff for: include/swift/ClangImporter/ClangImporter.h

+8
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,14 @@ namespace importer {
588588
/// Returns true if the given module has a 'cplusplus' requirement.
589589
bool requiresCPlusPlus(const clang::Module *module);
590590

591+
/// Returns the pointee type if the given type is a C++ `const`
592+
/// reference type, `None` otherwise.
593+
llvm::Optional<clang::QualType>
594+
getCxxReferencePointeeTypeOrNone(const clang::Type *type);
595+
596+
/// Returns true if the given type is a C++ `const` reference type.
597+
bool isCxxConstReferenceType(const clang::Type *type);
598+
591599
} // namespace importer
592600

593601
struct ClangInvocationFileMapping {

Diff for: include/swift/SIL/SILFunction.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class SILFunctionBuilder;
3838
class SILProfiler;
3939
class BasicBlockBitfield;
4040
class NodeBitfield;
41+
class SILPassManager;
4142

4243
namespace Lowering {
4344
class TypeLowering;
@@ -1410,18 +1411,19 @@ class SILFunction
14101411

14111412
/// verify - Run the SIL verifier to make sure that the SILFunction follows
14121413
/// invariants.
1413-
void verify(bool SingleFunction = true,
1414+
void verify(SILPassManager *passManager = nullptr,
1415+
bool SingleFunction = true,
14141416
bool isCompleteOSSA = true,
14151417
bool checkLinearLifetime = true) const;
14161418

14171419
/// Run the SIL verifier without assuming OSSA lifetimes end at dead end
14181420
/// blocks.
14191421
void verifyIncompleteOSSA() const {
1420-
verify(/*SingleFunction=*/true, /*completeOSSALifetimes=*/false);
1422+
verify(/*passManager*/nullptr, /*SingleFunction=*/true, /*completeOSSALifetimes=*/false);
14211423
}
14221424

14231425
/// Verifies the lifetime of memory locations in the function.
1424-
void verifyMemoryLifetime();
1426+
void verifyMemoryLifetime(SILPassManager *passManager);
14251427

14261428
/// Run the SIL ownership verifier to check that all values with ownership
14271429
/// have a linear lifetime. Regular OSSA invariants are checked separately in

Diff for: include/swift/SIL/SILModule.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -902,9 +902,13 @@ class SILModule {
902902
/// fetched in the given module?
903903
bool isTypeMetadataForLayoutAccessible(SILType type);
904904

905+
void verify(bool isCompleteOSSA = true,
906+
bool checkLinearLifetime = true) const;
907+
905908
/// Run the SIL verifier to make sure that all Functions follow
906909
/// invariants.
907-
void verify(bool isCompleteOSSA = true,
910+
void verify(SILPassManager *passManager,
911+
bool isCompleteOSSA = true,
908912
bool checkLinearLifetime = true) const;
909913

910914
/// Run the SIL verifier without assuming OSSA lifetimes end at dead end

Diff for: include/swift/SIL/SILType.h

+7
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,13 @@ class SILType {
471471
return false;
472472
}
473473

474+
bool isNoEscapeFunction() const {
475+
if (auto *fTy = getASTType()->getAs<SILFunctionType>()) {
476+
return fTy->isNoEscape();
477+
}
478+
return false;
479+
}
480+
474481
/// True if the type involves any archetypes.
475482
bool hasArchetype() const { return getASTType()->hasArchetype(); }
476483

Diff for: include/swift/SILOptimizer/Analysis/BasicCalleeAnalysis.h

-3
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ class CalleeCache {
183183

184184
class BasicCalleeAnalysis : public SILAnalysis {
185185
SILModule &M;
186-
SILPassManager *pm = nullptr;
187186
std::unique_ptr<CalleeCache> Cache;
188187

189188
public:
@@ -197,8 +196,6 @@ class BasicCalleeAnalysis : public SILAnalysis {
197196
return S->getKind() == SILAnalysisKind::BasicCallee;
198197
}
199198

200-
virtual void initialize(SILPassManager *pm) override { this->pm = pm; }
201-
202199
/// Invalidate all information in this analysis.
203200
virtual void invalidate() override {
204201
Cache.reset();

Diff for: include/swift/SILOptimizer/OptimizerBridging.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ struct BridgedCalleeAnalysis {
6262

6363
typedef bool (* _Nonnull IsDeinitBarrierFn)(BridgedInstruction, BridgedCalleeAnalysis bca);
6464
typedef swift::MemoryBehavior (* _Nonnull GetMemBehvaiorFn)(
65-
BridgedPassContext context, BridgedInstruction apply, bool observeRetains);
65+
BridgedInstruction apply, bool observeRetains, BridgedCalleeAnalysis bca);
6666

6767
static void registerAnalysis(IsDeinitBarrierFn isDeinitBarrierFn,
6868
GetMemBehvaiorFn getEffectsFn);

Diff for: include/swift/SILOptimizer/PassManager/PassManager.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,11 @@ class SILPassManager {
221221

222222
std::chrono::nanoseconds totalPassRuntime = std::chrono::nanoseconds(0);
223223

224+
public:
224225
/// C'tor. It creates and registers all analysis passes, which are defined
225-
/// in Analysis.def. This is private as it should only be used by
226-
/// ExecuteSILPipelineRequest.
226+
/// in Analysis.def.
227227
SILPassManager(SILModule *M, bool isMandatory, irgen::IRGenModule *IRMod);
228228

229-
public:
230229
const SILOptions &getOptions() const;
231230

232231
/// Searches for an analysis of type T in the list of registered

Diff for: include/swift/Sema/CSFix.h

+25
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,9 @@ enum class FixKind : uint8_t {
401401
/// Produce a warning for a tuple label mismatch.
402402
AllowTupleLabelMismatch,
403403

404+
/// Allow an associated value mismatch for an enum element pattern.
405+
AllowAssociatedValueMismatch,
406+
404407
/// Produce an error for not getting a compile-time constant
405408
NotCompileTimeConst,
406409

@@ -3238,6 +3241,28 @@ class AllowTupleLabelMismatch final : public ContextualMismatch {
32383241
}
32393242
};
32403243

3244+
class AllowAssociatedValueMismatch final : public ContextualMismatch {
3245+
AllowAssociatedValueMismatch(ConstraintSystem &cs, Type fromType, Type toType,
3246+
ConstraintLocator *locator)
3247+
: ContextualMismatch(cs, FixKind::AllowAssociatedValueMismatch, fromType,
3248+
toType, locator) {}
3249+
3250+
public:
3251+
std::string getName() const override {
3252+
return "allow associated value mismatch";
3253+
}
3254+
3255+
bool diagnose(const Solution &solution, bool asNote = false) const override;
3256+
3257+
static AllowAssociatedValueMismatch *create(ConstraintSystem &cs,
3258+
Type fromType, Type toType,
3259+
ConstraintLocator *locator);
3260+
3261+
static bool classof(const ConstraintFix *fix) {
3262+
return fix->getKind() == FixKind::AllowAssociatedValueMismatch;
3263+
}
3264+
};
3265+
32413266
class AllowNonOptionalWeak final : public ConstraintFix {
32423267
AllowNonOptionalWeak(ConstraintSystem &cs, ConstraintLocator *locator)
32433268
: ConstraintFix(cs, FixKind::AllowNonOptionalWeak, locator) {}

Diff for: include/swift/Sema/Constraint.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ enum class ConstraintKind : char {
224224
/// Binds the RHS type to a tuple of the params of a function typed LHS. Note
225225
/// this discards function parameter flags.
226226
BindTupleOfFunctionParams,
227-
/// The first type is a type pack, and the second type is its reduced shape.
227+
/// The first type is a reduced shape of the second type (represented as a
228+
/// pack type).
228229
ShapeOf,
229230
/// Represents explicit generic arguments provided for a reference to
230231
/// a declaration.

Diff for: include/swift/Sema/ConstraintLocator.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818
#ifndef SWIFT_SEMA_CONSTRAINTLOCATOR_H
1919
#define SWIFT_SEMA_CONSTRAINTLOCATOR_H
2020

21-
#include "swift/Basic/Debug.h"
22-
#include "swift/Basic/LLVM.h"
2321
#include "swift/AST/ASTNode.h"
2422
#include "swift/AST/Type.h"
2523
#include "swift/AST/Types.h"
24+
#include "swift/Basic/Debug.h"
25+
#include "swift/Basic/LLVM.h"
26+
#include "swift/Basic/NullablePtr.h"
2627
#include "llvm/ADT/ArrayRef.h"
2728
#include "llvm/ADT/FoldingSet.h"
2829
#include "llvm/ADT/PointerIntPair.h"
@@ -313,6 +314,10 @@ class ConstraintLocator : public llvm::FoldingSetNode {
313314
/// branch, and if so, the kind of branch.
314315
Optional<SingleValueStmtBranchKind> isForSingleValueStmtBranch() const;
315316

317+
/// If the locator in question is for a pattern match, returns the pattern,
318+
/// otherwise \c nullptr.
319+
NullablePtr<Pattern> getPatternMatch() const;
320+
316321
/// Returns true if \p locator is ending with either of the following
317322
/// - Member
318323
/// - Member -> KeyPathDynamicMember

Diff for: include/swift/Sema/ConstraintSystem.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -4858,10 +4858,10 @@ class ConstraintSystem {
48584858
ASTNode element, ContextualTypeInfo context, bool isDiscarded,
48594859
TypeMatchOptions flags, ConstraintLocatorBuilder locator);
48604860

4861-
/// Simplify a shape constraint by binding the reduced shape of the
4862-
/// left hand side to the right hand side.
4861+
/// Simplify a shape constraint by binding the left-hand side to the
4862+
/// reduced shape of the right-hand side.
48634863
SolutionKind simplifyShapeOfConstraint(
4864-
Type type1, Type type2, TypeMatchOptions flags,
4864+
Type shapeTy, Type packTy, TypeMatchOptions flags,
48654865
ConstraintLocatorBuilder locator);
48664866

48674867
/// Simplify an explicit generic argument constraint by equating the

Diff for: lib/AST/ASTContext.cpp

+21-1
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ struct ASTContext::Implementation {
430430
llvm::DenseMap<Type, InOutType*> InOutTypes;
431431
llvm::DenseMap<std::pair<Type, void*>, DependentMemberType *>
432432
DependentMemberTypes;
433+
llvm::DenseMap<void *, PlaceholderType *> PlaceholderTypes;
433434
llvm::DenseMap<Type, DynamicSelfType *> DynamicSelfTypes;
434435
llvm::DenseMap<std::pair<EnumDecl*, Type>, EnumType*> EnumTypes;
435436
llvm::DenseMap<std::pair<StructDecl*, Type>, StructType*> StructTypes;
@@ -3124,8 +3125,27 @@ Type ErrorType::get(Type originalType) {
31243125

31253126
Type PlaceholderType::get(ASTContext &ctx, Originator originator) {
31263127
assert(originator);
3127-
return new (ctx, AllocationArena::Permanent)
3128+
3129+
auto hasTypeVariables = [&]() -> bool {
3130+
if (originator.is<TypeVariableType *>())
3131+
return true;
3132+
3133+
if (auto *depTy = originator.dyn_cast<DependentMemberType *>())
3134+
return depTy->hasTypeVariable();
3135+
3136+
return false;
3137+
}();
3138+
auto arena = hasTypeVariables ? AllocationArena::ConstraintSolver
3139+
: AllocationArena::Permanent;
3140+
3141+
auto &cache = ctx.getImpl().getArena(arena).PlaceholderTypes;
3142+
auto &entry = cache[originator.getOpaqueValue()];
3143+
if (entry)
3144+
return entry;
3145+
3146+
entry = new (ctx, arena)
31283147
PlaceholderType(ctx, originator, RecursiveTypeProperties::HasPlaceholder);
3148+
return entry;
31293149
}
31303150

31313151
BuiltinIntegerType *BuiltinIntegerType::get(BuiltinIntegerWidth BitWidth,

0 commit comments

Comments
 (0)