Skip to content

Commit b4f99ee

Browse files
authored
Merge pull request #2934 from swiftwasm/main
[pull] swiftwasm from main
2 parents 5c789fa + a5a79f2 commit b4f99ee

File tree

64 files changed

+1425
-681
lines changed

Some content is hidden

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

64 files changed

+1425
-681
lines changed

include/swift/ABI/Task.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ class ContinuationAsyncContext : public AsyncContext {
566566
/// task.
567567
///
568568
/// This type matches the ABI of a function `<T> () async throws -> T`, which
569-
/// is the type used by `Task.runDetached` and `Task.group.add` to create
569+
/// is the type used by `detach` and `Task.group.add` to create
570570
/// futures.
571571
class FutureAsyncContext : public AsyncContext {
572572
public:

include/swift/AST/Builtins.def

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,9 @@ BUILTIN_MISC_OPERATION(ExtractElement, "extractelement", "n", Special)
626626
/// InsertElement has type (Vector<N, T>, T, Int32) -> Vector<N, T>.
627627
BUILTIN_MISC_OPERATION(InsertElement, "insertelement", "n", Special)
628628

629+
// Shufflevector has type (VecN<T>, VecN<T>, VecM<Int32>) -> VecM<T>
630+
BUILTIN_MISC_OPERATION(ShuffleVector, "shufflevector", "n", Special)
631+
629632
/// StaticReport has type (Builtin.Int1, Builtin.Int1, Builtin.RawPointer) -> ()
630633
BUILTIN_MISC_OPERATION(StaticReport, "staticReport", "", Special)
631634

@@ -655,8 +658,6 @@ BUILTIN_MISC_OPERATION(UToUCheckedTrunc, "u_to_u_checked_trunc", "n", Special)
655658
/// IntToFPWithOverflow has type (Integer) -> Float
656659
BUILTIN_MISC_OPERATION(IntToFPWithOverflow, "itofp_with_overflow", "n", Special)
657660

658-
// FIXME: shufflevector
659-
660661
/// zeroInitializer has type <T> () -> T
661662
BUILTIN_MISC_OPERATION(ZeroInitializer, "zeroInitializer", "n", Special)
662663

include/swift/AST/Decl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3486,7 +3486,7 @@ class StructDecl final : public NominalTypeDecl {
34863486
SourceLoc StructLoc;
34873487

34883488
// We import C++ class templates as generic structs. Then when in Swift code
3489-
// we want to substitude generic parameters with actual arguments, we
3489+
// we want to substitute generic parameters with actual arguments, we
34903490
// convert the arguments to C++ equivalents and ask Clang to instantiate the
34913491
// C++ template. Then we import the C++ class template instantiation
34923492
// as a non-generic structs with a name prefixed with `__CxxTemplateInst`.

include/swift/Runtime/Concurrency.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
117117
JobPriority
118118
swift_task_escalate(AsyncTask *task, JobPriority newPriority);
119119

120+
// TODO: "async let wait" and "async let destroy" would be expressed
121+
// similar to like TaskFutureWait;
122+
120123
/// This matches the ABI of a closure `<T>(Builtin.NativeObject) async -> T`
121124
using TaskFutureWaitSignature =
122125
SWIFT_CC(swiftasync)
@@ -237,11 +240,12 @@ void swift_taskGroup_destroy(TaskGroup *group);
237240
///
238241
/// \code
239242
/// func swift_taskGroup_addPending(
240-
/// group: Builtin.RawPointer
243+
/// group: Builtin.RawPointer,
244+
/// unconditionally: Bool
241245
/// ) -> Bool
242246
/// \endcode
243247
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
244-
bool swift_taskGroup_addPending(TaskGroup *group);
248+
bool swift_taskGroup_addPending(TaskGroup *group, bool unconditionally);
245249

246250
/// Cancel all tasks in the group.
247251
/// This also prevents new tasks from being added.

lib/AST/Builtins.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,6 +1649,27 @@ static ValueDecl *getInsertElementOperation(ASTContext &Context, Identifier Id,
16491649
return getBuiltinFunction(Id, ArgElts, VecTy);
16501650
}
16511651

1652+
static ValueDecl *getShuffleVectorOperation(ASTContext &Context, Identifier Id,
1653+
Type FirstTy, Type SecondTy) {
1654+
// (Vector<N, T>, Vector<N, T>, Vector<M, Int32) -> Vector<M, T>
1655+
auto VecTy = FirstTy->getAs<BuiltinVectorType>();
1656+
if (!VecTy)
1657+
return nullptr;
1658+
auto ElementTy = VecTy->getElementType();
1659+
1660+
auto IndexTy = SecondTy->getAs<BuiltinVectorType>();
1661+
if (!IndexTy)
1662+
return nullptr;
1663+
auto IdxElTy = IndexTy->getElementType()->getAs<BuiltinIntegerType>();
1664+
if (!IdxElTy || !IdxElTy->isFixedWidth() || IdxElTy->getFixedWidth() != 32)
1665+
return nullptr;
1666+
1667+
Type ArgElts[] = { VecTy, VecTy, IndexTy };
1668+
Type ResultTy = BuiltinVectorType::get(Context, ElementTy,
1669+
IndexTy->getNumElements());
1670+
return getBuiltinFunction(Id, ArgElts, ResultTy);
1671+
}
1672+
16521673
static ValueDecl *getStaticReportOperation(ASTContext &Context, Identifier Id) {
16531674
auto BoolTy = BuiltinIntegerType::get(1, Context);
16541675
auto MessageTy = Context.TheRawPointerType;
@@ -2594,6 +2615,10 @@ ValueDecl *swift::getBuiltinValueDecl(ASTContext &Context, Identifier Id) {
25942615
case BuiltinValueKind::InsertElement:
25952616
if (Types.size() != 3) return nullptr;
25962617
return getInsertElementOperation(Context, Id, Types[0], Types[1], Types[2]);
2618+
2619+
case BuiltinValueKind::ShuffleVector:
2620+
if (Types.size() != 2) return nullptr;
2621+
return getShuffleVectorOperation(Context, Id, Types[0], Types[1]);
25972622

25982623
case BuiltinValueKind::StaticReport:
25992624
if (!Types.empty()) return nullptr;

lib/AST/DeclContext.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,9 @@ bool DeclContext::hasValueSemantics() const {
11881188
bool DeclContext::isClassConstrainedProtocolExtension() const {
11891189
if (getExtendedProtocolDecl()) {
11901190
auto ED = cast<ExtensionDecl>(this);
1191-
return ED->getGenericSignature()->requiresClass(ED->getSelfInterfaceType());
1191+
if (auto sig = ED->getGenericSignature()) {
1192+
return sig->requiresClass(ED->getSelfInterfaceType());
1193+
}
11921194
}
11931195
return false;
11941196
}

lib/IRGen/GenBuiltin.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,16 @@ if (Builtin.ID == BuiltinValueKind::id) { \
835835
out.add(IGF.Builder.CreateInsertElement(vector, newValue, index));
836836
return;
837837
}
838+
839+
if (Builtin.ID == BuiltinValueKind::ShuffleVector) {
840+
using namespace llvm;
841+
842+
auto dict0 = args.claimNext();
843+
auto dict1 = args.claimNext();
844+
auto index = args.claimNext();
845+
out.add(IGF.Builder.CreateShuffleVector(dict0, dict1, index));
846+
return;
847+
}
838848

839849
if (Builtin.ID == BuiltinValueKind::SToSCheckedTrunc ||
840850
Builtin.ID == BuiltinValueKind::UToUCheckedTrunc ||

lib/SIL/IR/OperandOwnership.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,7 @@ BUILTIN_OPERAND_OWNERSHIP(InstantaneousUse, SToUCheckedTrunc)
709709
BUILTIN_OPERAND_OWNERSHIP(InstantaneousUse, Expect)
710710
BUILTIN_OPERAND_OWNERSHIP(InstantaneousUse, Shl)
711711
BUILTIN_OPERAND_OWNERSHIP(InstantaneousUse, GenericShl)
712+
BUILTIN_OPERAND_OWNERSHIP(InstantaneousUse, ShuffleVector)
712713
BUILTIN_OPERAND_OWNERSHIP(InstantaneousUse, Sizeof)
713714
BUILTIN_OPERAND_OWNERSHIP(InstantaneousUse, StaticReport)
714715
BUILTIN_OPERAND_OWNERSHIP(InstantaneousUse, Strideof)

lib/SIL/IR/ValueOwnership.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ UNOWNED_OR_NONE_DEPENDING_ON_RESULT(CmpXChg)
569569
UNOWNED_OR_NONE_DEPENDING_ON_RESULT(AtomicLoad)
570570
UNOWNED_OR_NONE_DEPENDING_ON_RESULT(ExtractElement)
571571
UNOWNED_OR_NONE_DEPENDING_ON_RESULT(InsertElement)
572+
UNOWNED_OR_NONE_DEPENDING_ON_RESULT(ShuffleVector)
572573
UNOWNED_OR_NONE_DEPENDING_ON_RESULT(ZeroInitializer)
573574
#undef UNOWNED_OR_NONE_DEPENDING_ON_RESULT
574575

lib/SILGen/SILGenDecl.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,8 @@ void SILGenFunction::emitPatternBinding(PatternBindingDecl *PBD,
11421142
auto initialization = emitPatternBindingInitialization(PBD->getPattern(idx),
11431143
JumpDest::invalid());
11441144

1145+
// TODO: need to allocate the variable, stackalloc it? pass the address to the start()
1146+
11451147
// If this is an async let, create a child task to compute the initializer
11461148
// value.
11471149
if (PBD->isAsyncLet()) {
@@ -1157,11 +1159,35 @@ void SILGenFunction::emitPatternBinding(PatternBindingDecl *PBD,
11571159
"Could not find async let autoclosure");
11581160
bool isThrowing = init->getType()->castTo<AnyFunctionType>()->isThrowing();
11591161

1162+
// TODO: there's a builtin to make an address into a raw pointer
1163+
// --- note dont need that; just have the builtin take it inout?
1164+
// --- the builtin can take the address (for start())
1165+
1166+
// TODO: make a builtin start async let
1167+
// Builtin.startAsyncLet -- and in the builtin create the async let record
1168+
1169+
// TODO: make a builtin for end async let
1170+
1171+
// TODO: IRGen would make a local allocation for the builtins
1172+
1173+
// TODO: remember if we did an await already?
1174+
1175+
// TODO: force in typesystem that we always await; then end aysnc let does not have to be async
1176+
// the local let variable is actually owning the result
1177+
// - but since throwing we can't know; maybe we didnt await on a thing yet
1178+
// so we do need the tracking if we waited on a thing
1179+
1180+
// TODO: awaiting an async let should be able to take ownership
1181+
// that means we will not await on this async let again, maybe?
1182+
// it means that the async let destroy should not destroy the result anymore
1183+
11601184
// Emit the closure for the child task.
11611185
SILValue childTask;
11621186
{
11631187
FullExpr Scope(Cleanups, CleanupLocation(init));
11641188
SILLocation loc(PBD);
1189+
// TODO: opaque object in the async context that represents the async let
1190+
//
11651191
childTask = emitRunChildTask(
11661192
loc,
11671193
init->getType(),
@@ -1173,7 +1199,7 @@ void SILGenFunction::emitPatternBinding(PatternBindingDecl *PBD,
11731199
enterDestroyCleanup(childTask);
11741200

11751201
// Push a cleanup that will cancel the child task at the end of the scope.
1176-
enterCancelAsyncTaskCleanup(childTask);
1202+
enterCancelAsyncTaskCleanup(childTask); // TODO: this is "went out scope" rather than just a cancel
11771203

11781204
// Save the child task so we can await it as needed.
11791205
AsyncLetChildTasks[{PBD, idx}] = { childTask, isThrowing };

lib/SILOptimizer/Transforms/AccessEnforcementReleaseSinking.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ static bool isBarrier(SILInstruction *inst) {
120120
case BuiltinValueKind::OnFastPath:
121121
case BuiltinValueKind::ExtractElement:
122122
case BuiltinValueKind::InsertElement:
123+
case BuiltinValueKind::ShuffleVector:
123124
case BuiltinValueKind::StaticReport:
124125
case BuiltinValueKind::AssertConf:
125126
case BuiltinValueKind::StringObjectOr:

lib/Sema/ConstraintSystem.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -702,11 +702,9 @@ Type ConstraintSystem::openUnboundGenericType(
702702
// pointing at a generic TypeAliasDecl here. If we find a way to
703703
// handle generic TypeAliases elsewhere, this can just become a
704704
// call to BoundGenericType::get().
705-
return TypeChecker::applyUnboundGenericArguments(
706-
decl, parentTy, SourceLoc(),
707-
TypeResolution::forContextual(DC, None, /*unboundTyOpener*/ nullptr,
708-
/*placeholderHandler*/ nullptr),
709-
arguments);
705+
return TypeResolution::forContextual(DC, None, /*unboundTyOpener*/ nullptr,
706+
/*placeholderHandler*/ nullptr)
707+
.applyUnboundGenericArguments(decl, parentTy, SourceLoc(), arguments);
710708
}
711709

712710
static void checkNestedTypeConstraints(ConstraintSystem &cs, Type type,
@@ -1291,12 +1289,12 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
12911289
// Unqualified reference to a type.
12921290
if (auto typeDecl = dyn_cast<TypeDecl>(value)) {
12931291
// Resolve the reference to this type declaration in our current context.
1294-
auto type = TypeChecker::resolveTypeInContext(
1295-
typeDecl, nullptr,
1292+
auto type =
12961293
TypeResolution::forContextual(useDC, TypeResolverContext::InExpression,
12971294
/*unboundTyOpener*/ nullptr,
1298-
/*placeholderHandler*/ nullptr),
1299-
/*isSpecialized=*/false);
1295+
/*placeholderHandler*/ nullptr)
1296+
.resolveTypeInContext(typeDecl, /*foundDC*/ nullptr,
1297+
/*isSpecialized=*/false);
13001298

13011299
checkNestedTypeConstraints(*this, type, locator);
13021300

0 commit comments

Comments
 (0)