Skip to content

Commit f217db1

Browse files
authored
Merge pull request #2185 from swiftwasm/main
[pull] swiftwasm from main
2 parents 75b5552 + 4dab4c2 commit f217db1

Some content is hidden

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

46 files changed

+419
-177
lines changed

include/swift/AST/Builtins.def

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,13 @@ BUILTIN_MISC_OPERATION_WITH_SILGEN(GetCurrentAsyncTask, "getCurrentAsyncTask", "
728728
/// Cancel the given asynchronous task.
729729
BUILTIN_MISC_OPERATION_WITH_SILGEN(CancelAsyncTask, "cancelAsyncTask", "", Special)
730730

731+
/// createAsyncTask(): (
732+
/// Int, Builtin.NativeObject?, @escaping () async throws -> Void
733+
/// ) -> Builtin.NativeObject
734+
///
735+
/// Create a new asynchronous task, given flags, an (optional) parent task, and
736+
/// a function to execute.
737+
BUILTIN_MISC_OPERATION_WITH_SILGEN(CreateAsyncTask, "createAsyncTask", "", Special)
731738

732739
/// globalStringTablePointer has type String -> Builtin.RawPointer.
733740
/// It returns an immortal, global string table pointer for strings constructed

include/swift/AST/Builtins.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ llvm::AtomicOrdering decodeLLVMAtomicOrdering(StringRef O);
135135
/// Returns true if the builtin with ID \p ID has a defined static overload for
136136
/// the type \p Ty.
137137
bool canBuiltinBeOverloadedForType(BuiltinValueKind ID, Type Ty);
138+
139+
/// Retrieve the AST-level AsyncTaskAndContext type, used for the
140+
/// createAsyncTask builtin.
141+
Type getAsyncTaskAndContextType(ASTContext &ctx);
142+
138143
}
139144

140145
#endif

include/swift/AST/DiagnosticEngine.h

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,24 @@ namespace swift {
7474
typedef T type;
7575
};
7676
}
77-
77+
78+
/// A family of wrapper types for compiler data types that forces its
79+
/// underlying data to be formatted with full qualification.
80+
///
81+
/// So far, this is only useful for \c Type, hence the SFINAE'ing.
82+
template <typename T, typename = void> struct FullyQualified {};
83+
84+
template <typename T>
85+
struct FullyQualified<
86+
T, typename std::enable_if<std::is_convertible<T, Type>::value>::type> {
87+
Type t;
88+
89+
public:
90+
FullyQualified(T t) : t(t){};
91+
92+
Type getType() const { return t; }
93+
};
94+
7895
/// Describes the kind of diagnostic argument we're storing.
7996
///
8097
enum class DiagnosticArgumentKind {
@@ -86,6 +103,7 @@ namespace swift {
86103
ValueDecl,
87104
Type,
88105
TypeRepr,
106+
FullyQualifiedType,
89107
PatternKind,
90108
SelfAccessKind,
91109
ReferenceOwnership,
@@ -116,6 +134,7 @@ namespace swift {
116134
ValueDecl *TheValueDecl;
117135
Type TypeVal;
118136
TypeRepr *TyR;
137+
FullyQualified<Type> FullyQualifiedTypeVal;
119138
PatternKind PatternKindVal;
120139
SelfAccessKind SelfAccessKindVal;
121140
ReferenceOwnership ReferenceOwnershipVal;
@@ -172,6 +191,10 @@ namespace swift {
172191
: Kind(DiagnosticArgumentKind::TypeRepr), TyR(T) {
173192
}
174193

194+
DiagnosticArgument(FullyQualified<Type> FQT)
195+
: Kind(DiagnosticArgumentKind::FullyQualifiedType),
196+
FullyQualifiedTypeVal(FQT) {}
197+
175198
DiagnosticArgument(const TypeLoc &TL) {
176199
if (TypeRepr *tyR = TL.getTypeRepr()) {
177200
Kind = DiagnosticArgumentKind::TypeRepr;
@@ -268,7 +291,12 @@ namespace swift {
268291
assert(Kind == DiagnosticArgumentKind::TypeRepr);
269292
return TyR;
270293
}
271-
294+
295+
FullyQualified<Type> getAsFullyQualifiedType() const {
296+
assert(Kind == DiagnosticArgumentKind::FullyQualifiedType);
297+
return FullyQualifiedTypeVal;
298+
}
299+
272300
PatternKind getAsPatternKind() const {
273301
assert(Kind == DiagnosticArgumentKind::PatternKind);
274302
return PatternKindVal;

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,8 @@ NOTE(invalid_redecl_implicit_wrapper,none,
802802
ERROR(ambiguous_type_base,none,
803803
"%0 is ambiguous for type lookup in this context", (DeclNameRef))
804804
ERROR(invalid_member_type,none,
805-
"%0 is not a member type of %1", (DeclNameRef, Type))
805+
"%0 is not a member type of %1 %2",
806+
(DeclNameRef, DescriptiveDeclKind, FullyQualified<Type>))
806807
ERROR(invalid_member_type_suggest,none,
807808
"%0 does not have a member type named %1; did you mean %2?",
808809
(Type, DeclNameRef, DeclName))

include/swift/Runtime/RuntimeFunctions.def

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1489,14 +1489,24 @@ FUNCTION(TaskDealloc,
14891489
ARGS(SwiftTaskPtrTy, Int8PtrTy),
14901490
ATTRS(NoUnwind, ArgMemOnly))
14911491

1492-
// void swift_task_dealloc(AsyncTask *task, void *ptr);
1492+
// void swift_task_cancel(AsyncTask *task);
14931493
FUNCTION(TaskCancel,
14941494
swift_task_cancel, SwiftCC,
14951495
ConcurrencyAvailability,
14961496
RETURNS(VoidTy),
14971497
ARGS(SwiftTaskPtrTy),
14981498
ATTRS(NoUnwind, ArgMemOnly))
14991499

1500+
// AsyncTaskAndContext swift_task_create_f(
1501+
// size_t flags, AsyncTask *task, AsyncFunctionType<void()> *function,
1502+
// size_t initialContextSize);
1503+
FUNCTION(TaskCreateFunc,
1504+
swift_task_create_f, SwiftCC,
1505+
ConcurrencyAvailability,
1506+
RETURNS(AsyncTaskAndContextTy),
1507+
ARGS(SizeTy, SwiftTaskPtrTy, TaskContinuationFunctionPtrTy, SizeTy),
1508+
ATTRS(NoUnwind, ArgMemOnly))
1509+
15001510
#undef RETURNS
15011511
#undef ARGS
15021512
#undef ATTRS

include/swift/SIL/SILBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1969,7 +1969,7 @@ class SILBuilder {
19691969

19701970
ReturnInst *createReturn(SILLocation Loc, SILValue ReturnValue) {
19711971
return insertTerminator(new (getModule()) ReturnInst(
1972-
getSILDebugLocation(Loc), ReturnValue));
1972+
getFunction(), getSILDebugLocation(Loc), ReturnValue));
19731973
}
19741974

19751975
ThrowInst *createThrow(SILLocation Loc, SILValue errorValue) {

include/swift/SIL/SILInstruction.h

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7369,16 +7369,25 @@ class ReturnInst
73697369
{
73707370
friend SILBuilder;
73717371

7372+
/// We store the ownership kind in the return inst, but we do not consider the
7373+
/// underlying return inst to be forwarding. This is because its ownership is
7374+
/// tied to the function signature and thus should be static.
7375+
ValueOwnershipKind ownershipKind;
7376+
73727377
/// Constructs a ReturnInst representing a return.
73737378
///
7374-
/// \param DebugLoc The backing AST location.
7375-
///
7376-
/// \param ReturnValue The value to be returned.
7377-
///
7378-
ReturnInst(SILDebugLocation DebugLoc, SILValue ReturnValue)
7379-
: UnaryInstructionBase(DebugLoc, ReturnValue) {}
7379+
/// \param func The function we are returning from. Used to compute the
7380+
/// preferred ownership kind.
7381+
/// \param debugLoc The backing AST location.
7382+
/// \param returnValue The value to be returned.
7383+
ReturnInst(SILFunction &func, SILDebugLocation debugLoc,
7384+
SILValue returnValue);
73807385

73817386
public:
7387+
/// Return the ownership kind for this instruction if we had any direct
7388+
/// results.
7389+
ValueOwnershipKind getOwnershipKind() const { return ownershipKind; }
7390+
73827391
SuccessorListTy getSuccessors() {
73837392
// No Successors.
73847393
return SuccessorListTy();

include/swift/Sema/ConstraintGraph.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,13 @@ class ConstraintGraph {
228228
/// The constraints in this component.
229229
TinyPtrVector<Constraint *> constraints;
230230

231-
public:
232231
/// The set of components that this component depends on, such that
233232
/// the partial solutions of the those components need to be available
234233
/// before this component can be solved.
235234
///
236-
/// FIXME: Use a TinyPtrVector here.
237-
std::vector<unsigned> dependsOn;
235+
SmallVector<unsigned, 2> dependencies;
238236

237+
public:
239238
Component(unsigned solutionIndex) : solutionIndex(solutionIndex) { }
240239

241240
/// Whether this component represents an orphaned constraint.
@@ -250,6 +249,11 @@ class ConstraintGraph {
250249
return constraints;
251250
}
252251

252+
/// Records a component which this component depends on.
253+
void recordDependency(const Component &component);
254+
255+
ArrayRef<unsigned> getDependencies() const { return dependencies; }
256+
253257
unsigned getNumDisjunctions() const { return numDisjunctions; }
254258
};
255259

lib/AST/Builtins.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,25 @@ static ValueDecl *getCancelAsyncTask(ASTContext &ctx, Identifier id) {
13501350
id, { ctx.TheNativeObjectType }, ctx.TheEmptyTupleType);
13511351
}
13521352

1353+
Type swift::getAsyncTaskAndContextType(ASTContext &ctx) {
1354+
TupleTypeElt resultTupleElements[2] = {
1355+
ctx.TheNativeObjectType, // task,
1356+
ctx.TheRawPointerType // initial context
1357+
};
1358+
1359+
return TupleType::get(resultTupleElements, ctx);
1360+
}
1361+
1362+
static ValueDecl *getCreateAsyncTask(ASTContext &ctx, Identifier id) {
1363+
auto extInfo = ASTExtInfoBuilder().withAsync().withThrows().build();
1364+
return getBuiltinFunction(
1365+
id,
1366+
{ ctx.getIntDecl()->getDeclaredInterfaceType(),
1367+
OptionalType::get(ctx.TheNativeObjectType),
1368+
FunctionType::get({ }, ctx.TheEmptyTupleType, extInfo) },
1369+
getAsyncTaskAndContextType(ctx));
1370+
}
1371+
13531372
static ValueDecl *getPoundAssert(ASTContext &Context, Identifier Id) {
13541373
auto int1Type = BuiltinIntegerType::get(1, Context);
13551374
auto optionalRawPointerType = BoundGenericEnumType::get(
@@ -2482,6 +2501,9 @@ ValueDecl *swift::getBuiltinValueDecl(ASTContext &Context, Identifier Id) {
24822501
case BuiltinValueKind::CancelAsyncTask:
24832502
return getCancelAsyncTask(Context, Id);
24842503

2504+
case BuiltinValueKind::CreateAsyncTask:
2505+
return getCreateAsyncTask(Context, Id);
2506+
24852507
case BuiltinValueKind::PoundAssert:
24862508
return getPoundAssert(Context, Id);
24872509

lib/AST/DiagnosticEngine.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -526,21 +526,30 @@ static void formatDiagnosticArgument(StringRef Modifier,
526526
Out << FormatOpts.ClosingQuotationMark;
527527
break;
528528

529+
case DiagnosticArgumentKind::FullyQualifiedType:
529530
case DiagnosticArgumentKind::Type: {
530531
assert(Modifier.empty() && "Improper modifier for Type argument");
531532

532533
// Strip extraneous parentheses; they add no value.
533-
auto type = Arg.getAsType()->getWithoutParens();
534+
Type type;
535+
bool needsQualification = false;
536+
537+
if (Arg.getKind() == DiagnosticArgumentKind::Type) {
538+
type = Arg.getAsType()->getWithoutParens();
539+
needsQualification = typeSpellingIsAmbiguous(type, Args);
540+
} else {
541+
assert(Arg.getKind() == DiagnosticArgumentKind::FullyQualifiedType);
542+
type = Arg.getAsFullyQualifiedType().getType()->getWithoutParens();
543+
needsQualification = true;
544+
}
534545

535546
// If a type has an unresolved type, print it with syntax sugar removed for
536547
// clarity. For example, print `Array<_>` instead of `[_]`.
537548
if (type->hasUnresolvedType()) {
538549
type = type->getWithoutSyntaxSugar();
539550
}
540551

541-
bool isAmbiguous = typeSpellingIsAmbiguous(type, Args);
542-
543-
if (isAmbiguous && isa<OpaqueTypeArchetypeType>(type.getPointer())) {
552+
if (needsQualification && isa<OpaqueTypeArchetypeType>(type.getPointer())) {
544553
auto opaqueTypeDecl = type->castTo<OpaqueTypeArchetypeType>()->getDecl();
545554

546555
llvm::SmallString<256> NamingDeclText;
@@ -562,7 +571,7 @@ static void formatDiagnosticArgument(StringRef Modifier,
562571

563572
} else {
564573
auto printOptions = PrintOptions();
565-
printOptions.FullyQualifiedTypes = isAmbiguous;
574+
printOptions.FullyQualifiedTypes = needsQualification;
566575
std::string typeName = type->getString(printOptions);
567576

568577
if (shouldShowAKA(type, typeName)) {

0 commit comments

Comments
 (0)