Skip to content

[concurrency] SILGen: emit hop_to_executor instructions #34540

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 4, 2020

Conversation

eeckstein
Copy link
Contributor

@eeckstein eeckstein commented Nov 2, 2020

Emit hop_to_executor instruction in the prolog of actor-isolated async functions and after all async calls in such functions.

rdar://problem/70299168

Copy link
Contributor

@slavapestov slavapestov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we also need to emit hop_to_executor after an apply instruction, don't we? I was thinking it would be better to do this in a mandatory SIL pass, since SILGen emits applies in various places that would all need this handling, such as protocol witness thunks. The only bit of plumbing required then would be storing the actor isolation kind in the SILFunction instead of pulling it out of the Decl.

@@ -449,6 +449,24 @@ void SILGenFunction::emitProlog(CaptureInfo captureInfo,
}
}
}

if (auto *funcDecl = dyn_cast_or_null<AbstractFunctionDecl>(FunctionDC->getAsDecl())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're going to keep doing this in SILGen, how about passing this down as a parameter to emitProlog()? The caller knows the function being emitted, and I'd like to remove FunctionDC eventually since it's used for various hacks that should go away.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I leave this up to you? emitProlog is called from multiple places (which I'm not familiar with) and I don't want to introduce a bug with this refactoring.

@eeckstein
Copy link
Contributor Author

I think we also need to emit hop_to_executor after an apply instruction, don't we? I was thinking it would be better to do this in a mandatory SIL pass, since SILGen emits applies in various places that would all need this handling, such as protocol witness thunks.

That's a good point. Yes, we need hop_to_executor after each async apply (just async applies) - and only in functions, which actually need to be actor isolated, e.g. because they access an actor property. I assume that this is not the case for all the thunks we generate.
Anyway, it's easy to emit the after-apply hop_to_executors in a mandatory pass. The main thing of this PR is to set up the prolog (which would be hard outside SILGen).

@eeckstein
Copy link
Contributor Author

@swift-ci test

@swift-ci
Copy link
Contributor

swift-ci commented Nov 3, 2020

Build failed
Swift Test Linux Platform
Git Sha - 523840a834303189feb1e8a8a99b7365af7d0255

Emit hop_to_executor instruction in the prolog of actor-isolated async functions and after all async calls in such functions.

rdar://problem/70299168
@eeckstein
Copy link
Contributor Author

@swift-ci smoke test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants