8000 add coroutine behavior for generators by kvc0 · Pull Request #3178 · adafruit/circuitpython · GitHub
[go: up one dir, main page]

Skip to content

add coroutine behavior for generators #3178

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 an 8000 d privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 24, 2020

Conversation

kvc0
Copy link
@kvc0 kvc0 commented Jul 21, 2020

coroutines don't have next; they also call themselves coroutines.
This does not change the fact that async def methods are generators,
but it does make them behave more like CPython.

This also turns on async in mpy-cross so tests will pass, though the exception thrown by the mpy-cross byte code is not very helpful.

Copy link
Member
@tannewt tannewt left a comment

Choose a reason for hiding this comment

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

This looks great! Thank you!

The tests are a bit unhappy. I think you need to add a skip condition to the test.

@tannewt
Copy link
Member
tannewt commented Jul 22, 2020

What do you think about async only being enabled on non-m0?

@dhalbert
Copy link
Collaborator

What do you think about async only being enabled on non-m0?

I could imagine async being used for simple multi-task timing projects even on a Trinket M0, say. I think a simple task library would fit.

Is the problem with the bast pro mini that it has more pins than other small boards like trinket and gemma?

@dhalbert
Copy link
Collaborator

While looking at #3190, I realized that both py/gc.o and py/vm.o are compiled -O3 by default. We have turned that off for GC on small builds (SUPEROPT_GC =0), but not for vm.o. Compiling vm.o as -O2 instead of -O3 gains back 416 bytes on a trinket_m0 build.

@tannewt
Copy link
Member
tannewt commented Jul 23, 2020

What do you think about async only being enabled on non-m0?

I could imagine async being used for simple multi-task timing projects even on a Trinket M0, say. I think a simple task library would fit.

Sure, but that doesn't mean we need it enabled. There are lots of things that could be useful on an M0.

Is the problem with the bast pro mini that it has more pins than other small boards like trinket and gemma?

Yes, I think so.

While looking at #3190, I realized that both py/gc.o and py/vm.o are compiled -O3 by default. We have turned that off for GC on small builds (SUPEROPT_GC =0), but not for vm.o. Compiling vm.o as -O2 instead of -O3 gains back 416 bytes on a trinket_m0 build.

Nice! That'll do. How much do we gain with -Os? I wonder what the speed loss is. GCC10 will also make builds smaller.

@dhalbert
Copy link
Collaborator

I could imagine async being used for simple multi-task timing projects even on a Trinket M0, say. I think a simple task library would fit.

Sure, but that doesn't mean we need it enabled. There are lots of things that could be useful on an M0.

I was just thinking that if it was really easy to use, it could be used in simple blinky and NeoPixel programs, etc.

While looking at #3190, I realized that both py/gc.o and py/vm.o are compiled -O3 by default. We have turned that off for GC on small builds (SUPEROPT_GC =0), but not for vm.o. Compiling vm.o as -O2 instead of -O3 gains back 416 bytes on a trinket_m0 build.

Nice! That'll do. How much do we gain with -Os? I wonder what the speed loss is. GCC10 will also make builds smaller.

Well, that's weird: -Os should be the best, but it's not:

CSUPEROPT (affects vm.o build) bytes free on trinket_m0 build
-Os 2292
-O2 2412
-O3 1996

@kvc0
Copy link
Author
kvc0 commented Jul 24, 2020

What do you think about async only being enabled on non-m0?

Async is useful everywhere; right now it's nowhere. There's no great loss if it's not available on m0 at the outset.

It might be a problem in the future, as it's a core language feature, but on the short-to-medium term it seems fine. Right now I'm happy to disable any target that does not easily build (given that there is a pretty healthy crop of boards that do build). If there is demand on those tiny boards the problems can be solved.

kvc0 added 4 commits July 23, 2020 20:40
8000
coroutines don't have __next__; they also call themselves coroutines.
This does not change the fact that `async def` methods are generators,
but it does make them behave more like CPython.
@kvc0 kvc0 force-pushed the async_def_coroutine_sim branch from a6322ed to e9b4e0b Compare July 24, 2020 03:52
@kvc0
Copy link
Author
kvc0 commented Jul 24, 2020

Let's try a rebase and see what shakes loose

@kvc0
Copy link
Author
kvc0 commented Jul 24, 2020

@tannewt okay, this passes after a rebase so the can is kicked one commit further down the road.

Copy link
Member
@tannewt tannewt left a comment

Choose a reason for hiding this comment

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

Looks good to me! Thank you!

@tannewt tannewt merged commit a6e0486 into adafruit:main Jul 24, 2020
jepler pushed a commit that referenced this pull request May 8, 2021
Fixes issues #3178 and #5220.

Tests are added, including all the cases mentioned in both bugs.
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.

3 participants
0