@@ -832,6 +832,15 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
832832 valueDescription + " cannot apply to a function type" );
833833 }
834834
835+ // / Require the operand to be `$Optional<Builtin.Executor>`.
836+ void requireOptionalExecutorType (SILValue value, const Twine &what) {
837+ auto type = value->getType ();
838+ require (type.isObject (), what + " must be an object type" );
839+ auto objectType = type.getASTType ().getOptionalObjectType ();
840+ require (objectType && objectType == M->getASTContext ().TheExecutorType ,
841+ what + " must be Optional<Builtin.Executor>" );
842+ }
843+
835844 // / Assert that two types are equal.
836845 void requireSameType (Type type1, Type type2, const Twine &complaint) {
837846 _require (type1->isEqual (type2), complaint,
@@ -1822,6 +1831,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
18221831 }
18231832
18241833 auto builtinKind = BI->getBuiltinKind ();
1834+ auto arguments = BI->getArguments ();
18251835
18261836 // Check that 'getCurrentAsyncTask' only occurs within an async function.
18271837 if (builtinKind == BuiltinValueKind::GetCurrentAsyncTask) {
@@ -1832,7 +1842,6 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
18321842
18331843 if (builtinKind == BuiltinValueKind::InitializeDefaultActor ||
18341844 builtinKind == BuiltinValueKind::DestroyDefaultActor) {
1835- auto arguments = BI->getArguments ();
18361845 require (arguments.size () == 1 ,
18371846 " default-actor builtin can only operate on a single object" );
18381847 auto argType = arguments[0 ]->getType ().getASTType ();
@@ -1844,23 +1853,32 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
18441853 return ;
18451854 }
18461855
1856+ // Check that 'getCurrentAsyncTask' only occurs within an async function.
1857+ if (builtinKind == BuiltinValueKind::GetCurrentExecutor) {
1858+ require (F.isAsync (),
1859+ " getCurrentExecutor can only be used in an async function" );
1860+ require (arguments.empty (), " getCurrentExecutor takes no arguments" );
1861+ requireOptionalExecutorType (BI, " result of getCurrentExecutor" );
1862+ return ;
1863+ }
1864+
18471865 if (builtinKind == BuiltinValueKind::BuildOrdinarySerialExecutorRef ||
18481866 builtinKind == BuiltinValueKind::BuildDefaultActorExecutorRef) {
1849- requireObjectType (BuiltinExecutorType, BI,
1850- " result of building a serial executor" );
1851- auto arguments = BI->getArguments ();
18521867 require (arguments.size () == 1 ,
18531868 " builtin expects one argument" );
18541869 require (arguments[0 ]->getType ().isObject (),
18551870 " operand of builtin should have object type" );
1871+ requireObjectType (BuiltinExecutorType, BI,
1872+ " result of build*ExecutorRef" );
1873+ return ;
18561874 }
18571875
18581876 if (builtinKind == BuiltinValueKind::BuildMainActorExecutorRef) {
1859- requireObjectType (BuiltinExecutorType, BI,
1860- " result of buildSerialExecutorRef" );
1861- auto arguments = BI->getArguments ();
18621877 require (arguments.size () == 0 ,
18631878 " buildMainActorExecutorRef expects no arguments" );
1879+ requireObjectType (BuiltinExecutorType, BI,
1880+ " result of build*ExecutorRef" );
1881+ return ;
18641882 }
18651883 }
18661884
@@ -4792,9 +4810,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
47924810 void checkHopToExecutorInst (HopToExecutorInst *HI) {
47934811 auto executor = HI->getTargetExecutor ();
47944812 if (HI->getModule ().getStage () == SILStage::Lowered) {
4795- requireObjectType (BuiltinExecutorType, executor->getType (),
4796- " hop_to_executor instruction must take a "
4797- " Builtin.Executor in lowered SIL" );
4813+ requireOptionalExecutorType (executor,
4814+ " hop_to_executor operand in lowered SIL" );
47984815 }
47994816 }
48004817
0 commit comments