Skip to content

[work in progress] Coroutines the Third #12168

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

Open
wants to merge 247 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
247 commits
Select commit Hold shift + click to select a range
86cebca
try a different approach
Simn Feb 6, 2024
bbd726b
fix
Simn Feb 6, 2024
ffd5860
Merge branch 'development' into coroutines_2024
Simn Feb 8, 2024
4126322
Merge branch 'development' into coroutines_2024
Simn Feb 9, 2024
de3e495
Merge branch 'development' into coroutines_2024
Simn Feb 14, 2024
b327ecd
merge
Simn Feb 14, 2024
3a49bf2
remove analyzer changes
Simn Feb 14, 2024
cfe1b31
clean up next state setting
Simn Feb 14, 2024
5a394b0
turn coro state into a record
Simn Feb 14, 2024
e8e19b8
most importantly: dot graphs
Simn Feb 14, 2024
b963967
get something working on JVM
Simn Feb 14, 2024
fb857ab
somehow make suspend work on JVM
Simn Feb 14, 2024
0ff8e29
run it on eval too
Simn Feb 14, 2024
913e74a
add expand_coro_type
Simn Feb 14, 2024
04d73eb
introduce haxe.coro package
Simn Feb 14, 2024
6d986dc
add haxe.coro.Continuation
Simn Feb 14, 2024
5698a41
just @:keep for now
Simn Feb 14, 2024
2d9ba3a
don't put Void in result
Simn Feb 14, 2024
e09e259
run on C++, mostly
Simn Feb 14, 2024
de7e54c
use asys branch for now
Simn Feb 14, 2024
0e2f532
use custom branch
Simn Feb 14, 2024
2ae66e8
no .exe
Simn Feb 14, 2024
b8d8e6f
deal with `this` properly
Simn Feb 15, 2024
60c8e64
add some unreachable block sanity checks
Simn Feb 15, 2024
e857bbe
give blocks IDs and track fall-through connections
Simn Feb 15, 2024
3e91fcd
track all CFG edges
Simn Feb 15, 2024
679c7cc
use block IDs as state IDs
Simn Feb 15, 2024
9b30386
skip forwarding states
Simn Feb 15, 2024
62bdf66
ignore next after unconditional termination
Simn Feb 15, 2024
9f0238f
add yield tests from https://github.com/nadako/haxe-coroutines/pull/6
Simn Feb 15, 2024
9ff9964
add Coroutine special case to gencpp visit_type
Simn Feb 15, 2024
7377cc3
invert do try to try do
Simn Feb 15, 2024
28fdaa4
still replace `this` inside TFunction
Simn Feb 15, 2024
d1d01fe
set rethrow state before rethrowing
Simn Feb 16, 2024
22dfa2e
deal with `this`, again
Simn Feb 16, 2024
d509e86
implement simon-exceptions
Simn Feb 16, 2024
a71536b
Warnings
kLabz Feb 16, 2024
d75e37d
[macro] get build order into control
kLabz Feb 16, 2024
bf3d81a
[tests] use coroutines for server tests
kLabz Feb 16, 2024
72a202c
[ci] use utest fork coro branch for now
kLabz Feb 16, 2024
b0796e1
add build-hl.hxml
Simn Feb 16, 2024
4213732
don't assign e_no_value
Simn Feb 16, 2024
f430997
Merge branch 'coroutines_2024' into coroutines_2024_server_tests
Simn Feb 16, 2024
d52d1b6
Merge branch 'development' into coroutines_2024
Simn Feb 16, 2024
ba7604b
Merge branch 'coroutines_2024_server_tests' into coroutines_2024
Simn Feb 16, 2024
54dfcad
try a different input data design
Simn Feb 23, 2024
a29eb99
avoid callback code duplication
Simn Feb 26, 2024
92214ba
Merge branch 'development' into coroutines_2025
Simn Feb 26, 2024
fd21ee9
some work on updating the state machine scaffolding
Aidan63 Apr 4, 2025
36b3b96
Fix some dodgy function type building
Aidan63 Apr 4, 2025
7c0ff11
Set the constructor as the constructor...
Aidan63 Apr 4, 2025
e35e9d1
proper module path
Aidan63 Apr 4, 2025
4d3e2fe
Fix missing assignment
Aidan63 Apr 4, 2025
e697b43
set initial state to 1
Aidan63 Apr 4, 2025
19b4a79
capture this for non static coroutines
Aidan63 Apr 5, 2025
20cd54b
Implemented scheduler resuming
Aidan63 Apr 5, 2025
be6f71b
some initial dealing with args
Aidan63 Apr 5, 2025
50752f5
implement intrinsic to get current completion
Aidan63 Apr 5, 2025
cf45a62
Don't make assumptions about the initial state id
Aidan63 Apr 5, 2025
2609145
Initial hoisting of variables used across states
Aidan63 Apr 5, 2025
ff04597
pass in variable ids not allowed to be hoisted
Aidan63 Apr 5, 2025
5896f9a
hoist function arguments into the continuation if used across states
Aidan63 Apr 6, 2025
50ca8b8
Make coroutine suspend target generic
Aidan63 Apr 6, 2025
b4981eb
Only mangle names of generated variables
Aidan63 Apr 6, 2025
5c9ce1c
Merge branch 'development' into kt_coro_rebase
Simn Apr 7, 2025
ba371dc
fix merge botch
Simn Apr 8, 2025
b2fb3bc
fix JVM coro signature
Simn Apr 8, 2025
af527dd
Add scheduleIn function
Aidan63 Apr 9, 2025
6c3484c
Life another coro from non coro restriction
Aidan63 Apr 9, 2025
fa370cc
Add delay and yield functions to Coroutine
Aidan63 Apr 9, 2025
3b67906
Rename safe continuation to racing continuation
Aidan63 Apr 9, 2025
caa7024
expand static function coro fields to fix jvm crash
Aidan63 Apr 9, 2025
512a9de
Add basic run function which blocks
Aidan63 Apr 9, 2025
c4fd7b4
Move the racing continuation into the continuations package
Aidan63 Apr 9, 2025
0f9d67b
don't use the typer curfield for args and return type
Aidan63 Apr 11, 2025
57e8b7d
clean up, or a different sort of mess?
Aidan63 Apr 11, 2025
e610549
Restore working member coroutines
Aidan63 Apr 11, 2025
abcf80f
finally working local func coroutines
Aidan63 Apr 11, 2025
4603388
Merge branch 'development' into kt_coro
Simn Apr 12, 2025
0bd4a32
adapt to development
Simn Apr 12, 2025
ace8c22
support unnamed local coroutines
Simn Apr 12, 2025
e329f8e
Check for a result before blocking
Aidan63 Apr 12, 2025
0ad88a9
make typer emit var `this = this when we're in a coro
Simn Apr 12, 2025
3625d42
Restore most of the coroutine tests
Aidan63 Apr 12, 2025
d55b0ae
fix HL continuation typing
Simn Apr 12, 2025
91dd0f7
bring back big TTry for now
Simn Apr 12, 2025
a25a46b
Fix wrong type for captured field access
Aidan63 Apr 12, 2025
3e1d153
fix another wrong type
Simn Apr 12, 2025
47ac434
Rework variable hoisting and add some tests. fixes #13
Aidan63 Apr 13, 2025
d6c6662
Why do I suddenly need a cast here to get it to compile?
Aidan63 Apr 13, 2025
e7be0a2
reduce some noise
Simn Apr 13, 2025
e857d99
fix more types
Simn Apr 13, 2025
fbc7a7e
accept more meta after @:coroutine
Simn Apr 13, 2025
f0d22bf
don't copy field, pass in pertinent information instead
Simn Apr 13, 2025
b44e5e6
remove hoisted default init
Simn Apr 13, 2025
f02724e
bring back hx_error check and throw the right thing
Simn Apr 13, 2025
a363572
only try-wrap if there's a catch
Simn Apr 13, 2025
3cf13be
More hoisting tests
Aidan63 Apr 13, 2025
2ce06c7
Add tests for resuming with and error
Aidan63 Apr 13, 2025
c08db1c
Add anonymous local coroutine function test
Aidan63 Apr 13, 2025
f4e4e82
Add misc tests with debug coroutine metadata test
Aidan63 Apr 13, 2025
59bc4e2
Give the continuation variable of lambda coroutines a unique name
Aidan63 Apr 13, 2025
34647d4
Don't put the original lambda arguments on the captured function type
Aidan63 Apr 13, 2025
2623fec
Remove un-needed suffix code
Aidan63 Apr 13, 2025
af5a7c5
Support recursive coroutines
Aidan63 Apr 13, 2025
845dfc8
banish tcoro things to their own record type
Simn Apr 14, 2025
7eeddc8
track continuation class because we need it
Simn Apr 14, 2025
c14d9be
use correct field for cf_recursing
Simn Apr 14, 2025
d2430ed
use hxcpp master and comment out failing exception test again
Simn Apr 14, 2025
4a0c4eb
delete more things
Simn Apr 14, 2025
5b1c7af
introduce inside/outside to deal with type parameters
Simn Apr 14, 2025
c9576ca
convenience
Simn Apr 14, 2025
83e6ce0
Add a cast before checking the recursive field
Aidan63 Apr 14, 2025
12c2b7a
use correct class for recursing access
Simn Apr 14, 2025
03c264c
Initial attempt at creating js friendly continuations and event loops
Aidan63 Apr 14, 2025
50aff08
don't clone fields
Simn Apr 14, 2025
79cd60c
don't leak IContinuation.T
Simn Apr 14, 2025
e3494c3
avoid sys package rule problem
Simn Apr 14, 2025
b8187c7
Switch back to bog standard utest
Aidan63 Apr 14, 2025
9b59dca
restore gencpp coroutine parameter visiting for forward declarations
Aidan63 Apr 14, 2025
24cba39
delete eval's EventLoop
Simn Apr 14, 2025
2bdce3b
Don't transition to the -1 state on throw
Aidan63 Apr 14, 2025
c5db5be
Revert "delete eval's EventLoop"
Simn Apr 14, 2025
014dab9
Fix for inline constructors bug #12149 (#12169)
basro Apr 13, 2025
82eb6e5
[generics] Ensure type substitution happens for closures too. (#12173)
Apprentice-Alchemist Apr 14, 2025
60b4186
awkwardly work around @:multiType problem
Simn Apr 14, 2025
cfa641c
Ensure the error is set to the current result before we throw the error
Aidan63 Apr 14, 2025
0240875
clone type parameters with correct host
Simn Apr 15, 2025
362b310
group TWhile cases
Simn Apr 15, 2025
31a4d6f
demonstrate insanity
Simn Apr 15, 2025
d4431e4
fix inference insanity
Simn Apr 15, 2025
9e60f0e
use standard name for captured `this`
Simn Apr 15, 2025
d46b667
activate js promise tests
Simn Apr 15, 2025
2106f6d
Merge branch 'development' into kt_coro
Simn Apr 15, 2025
0d741d8
don't lose block elements when skipping initial block
Simn Apr 15, 2025
171c66e
gimme a windows build
Aidan63 Apr 15, 2025
1607710
reset recursing flag before resuming
Aidan63 Apr 15, 2025
69a21a3
Bin a bunch of no-longer needed code
Aidan63 Apr 15, 2025
e2e2053
Merge branch 'base_continuation' into kt_coro
Aidan63 Apr 15, 2025
f7d851f
make haxe fast again
Simn Apr 16, 2025
deb3d0f
put some links in readme so I know where to find them
Simn Apr 16, 2025
723583a
learn to markdown...
Simn Apr 16, 2025
43259f1
rename some prefixes that always confuse me
Simn Apr 16, 2025
ce45d4c
more convenience
Simn Apr 16, 2025
aae4e13
factor out continuation API
Simn Apr 16, 2025
9fff336
add tvar to LocalFunc
Simn Apr 16, 2025
e965138
Merge branch 'development' into kt_coro
Simn Apr 16, 2025
fbb0c18
add override flag
Simn Apr 16, 2025
2ed1b41
follow coros and expand arguments when building cppia scaffolding
Aidan63 Apr 16, 2025
03d6437
Deal with sys (#28)
Simn Apr 16, 2025
f96160d
split up BaseContinuation
Simn Apr 16, 2025
8b29845
bring back ContinuationControl
Simn Apr 16, 2025
f048166
fix name
Simn Apr 16, 2025
3e4e1cc
Remove now un-needed nested functions for the local function case
Aidan63 Apr 16, 2025
194b4a5
start injecting things
Simn Apr 16, 2025
be3b499
Merge branch 'kt_coro' into kt_coro_tag
Simn Apr 16, 2025
67dc665
it's mostly broken but some tests pass
Simn Apr 16, 2025
02d79af
do what Aidan says
Simn Apr 16, 2025
1b181ea
remove debug print
Simn Apr 16, 2025
94d1a11
try different approach to typing
Simn Apr 16, 2025
6aa6179
turn getOrThrow into a coro
Simn Apr 16, 2025
7522787
getOrThrow shouldn't be a coro
Simn Apr 16, 2025
1f12f9e
get something working with some hacks
Simn Apr 17, 2025
4720d7b
avoid hxcpp problem
Simn Apr 17, 2025
c8b5031
update HL
Simn Apr 17, 2025
3606866
redesign RacingContinuation
Simn Apr 17, 2025
59455cb
disable failing tests for now
Simn Apr 17, 2025
d9efbe0
disable misc test that fails for silly reasons
Simn Apr 17, 2025
a1f75e2
Merge branch 'kt_coro' into kt_coro_tag
Simn Apr 17, 2025
0c40bac
Merge branch 'development' into kt_coro
Simn Apr 17, 2025
26949a7
clean up a bit
Simn Apr 17, 2025
085d0a4
Merge branch 'kt_coro' into kt_coro_tag
Simn Apr 17, 2025
cc1832c
let's see if we can run HL
Simn Apr 17, 2025
adc2f34
expand coroutine function types for proper forward declarations
Aidan63 Apr 17, 2025
60a89ba
Merge pull request #33 from Aidan63/kt_coro_tag
Aidan63 Apr 17, 2025
4edc66a
add @:coroutine.transformed (#39)
Simn Apr 17, 2025
f2abdd9
add delay test
Simn Apr 18, 2025
6f520a4
get neko working
Simn Apr 19, 2025
0e938e6
make test output file consistent
Simn Apr 19, 2025
2190de7
apparently python just works
Simn Apr 19, 2025
9031079
Run tests on php and lua (#43)
Simn Apr 19, 2025
cfb5747
Merge branch 'development' into kt_coro
Simn Apr 19, 2025
cad4cb5
Merge branch 'development' into kt_coro
Simn Apr 19, 2025
3ce6c15
remove invalid extra type parameter
Simn Apr 19, 2025
e380bb4
Make coros exception-free (#40)
Simn Apr 20, 2025
4be29e2
Add type parameters to BaseContinuation and ContinuationResult (#45)
Simn Apr 20, 2025
6145652
Copy js' custom event loop, but add mutexes
Aidan63 Apr 20, 2025
227e673
Merge pull request #47 from Aidan63/custom-eval-loop
Aidan63 Apr 20, 2025
f4f8df0
cache continuation_api on typer globals
Simn Apr 21, 2025
69350bb
remove some API types that we don't need
Simn Apr 21, 2025
69d7b70
pass texprs as record type
Simn Apr 21, 2025
629da09
clean up some outdated comments
Simn Apr 21, 2025
ed9e01c
remove some unused internal data
Simn Apr 21, 2025
cf69c2e
Optimize CFG a bit (#48)
Simn Apr 21, 2025
d1b4e09
implement TCO (#49)
Simn Apr 22, 2025
d54501b
add _hx_tmp local to deal with intermediate values (#53)
Simn Apr 22, 2025
d335638
don't forward blocks if their cb_catch differs
Simn Apr 22, 2025
b537899
rework error resume, again
Simn Apr 22, 2025
aa0612c
actually we don't need the cb_catch check now, I think
Simn Apr 22, 2025
7c9bd69
Add -D coroutine.throw for eager throws (#52)
Simn Apr 22, 2025
70f30ab
Keep waiting if we haven't got a result but the loop reports no more …
Aidan63 Apr 22, 2025
b1b5511
set next state later
Simn Apr 23, 2025
822740f
use Unit instead of Void
Simn Apr 23, 2025
74c65c9
change how we run JVM tests on CI
Simn Apr 23, 2025
9990b00
try a new way of expression building
Simn Apr 23, 2025
57a2850
move local handling to own function
Simn Apr 23, 2025
08654ac
Merge branch 'development' into kt_coro
Simn Apr 23, 2025
df57c5d
rename some things
Simn Apr 23, 2025
ead207b
update resume-flag when forwarding blocks
Simn Apr 23, 2025
fe53ce3
Remove unreachable block (#60)
Simn Apr 24, 2025
fba9d58
pull structural changes from call-stacks branch
Simn Apr 25, 2025
d09f95d
Merge branch 'development' into kt_coro
Simn Apr 25, 2025
438c278
pull null_pos changes from call-stacks branch
Simn Apr 26, 2025
ac188a7
always use the mangled name with the variable id
Aidan63 Apr 26, 2025
35461f9
no more _hx_ prefixes for core classes / interfaces
Aidan63 Apr 26, 2025
af6ab43
Merge pull request #62 from Aidan63/prefixes-and-collisions
Aidan63 Apr 26, 2025
2fc6638
Merge branch 'development' into kt_coro
Simn Apr 26, 2025
7f4333d
Merge branch 'development' into kt_coro
Simn Apr 27, 2025
92ae10f
Call stacks (#50)
Aidan63 Apr 28, 2025
4d7b13b
interfaces seemingly working
Aidan63 May 11, 2025
b3fd904
Add test
Aidan63 May 11, 2025
7d82c52
number issue properly
Aidan63 May 11, 2025
f58859d
Add an assert.pass
Aidan63 May 11, 2025
a83de93
Fix coroutine overload resolution in jvm
Aidan63 May 11, 2025
b4157c5
Expand coroutine arguments for php
Aidan63 May 11, 2025
a51d19a
Merge pull request #70 from Aidan63/interfaces
Aidan63 May 11, 2025
8dd3086
[std/hl] move some position for customStack and set_stack (#12217)
yuxiaomao Apr 28, 2025
5871a2d
send all types to analyzer for purity inference
Simn May 4, 2025
a27c6bb
Test for #12224 (#12227)
RblSb May 5, 2025
10c83fe
Test for #11909 (#12218)
RblSb May 5, 2025
e63991a
[nullsafety] Allow statics init in main (#12211)
RblSb May 5, 2025
363fb3f
Update TestStrict.hx (#12228)
RblSb May 6, 2025
4f4cb08
4.3.7 changelog
kLabz May 9, 2025
a56f411
Merge branch 'development' into kt_coro
Simn May 13, 2025
94554af
get call stack test passing on HL
Simn May 13, 2025
1593970
fix test
Simn May 13, 2025
23cd2f8
rename state to gotoLabel and control to state (#73)
Simn May 13, 2025
7fc3f45
never mind
Simn May 13, 2025
2f84158
haxe/coro: add Mutex typedef for threaded targets, and stub for non (…
PXshadow May 13, 2025
59cb791
don't try to optimize resume states
Simn May 13, 2025
b07d714
avoid null issue
Simn May 13, 2025
cd77894
also avoid JVM issue
Simn May 13, 2025
9a3696b
use ctx.type_params for type params
Simn May 14, 2025
d3d1916
Merge branch 'development' into kt_coro
Simn May 15, 2025
ca1d049
Extensible context (#78)
Simn May 15, 2025
c1b1e0f
assign value blocks to temp var
Simn May 15, 2025
bbafb56
change Element to IElement (#80)
Simn May 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,4 @@ lib.sexp
src/compiler/version.ml
tests/party
tests/misc/projects/Issue10863/error.log
tests/misc/coroutines/dump
108 changes: 9 additions & 99 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,99 +1,9 @@
<p align="center">
<a href="https://haxe.org/" title="haxe.org"><img src="extra/images/Readme.png" /></a>
</p>

<p align="center">
<a href="https://github.com/HaxeFoundation/haxe/actions"><img src="https://github.com/HaxeFoundation/haxe/workflows/CI/badge.svg" alt="GitHub Build Status"></a>
<a href="https://saucelabs.com/u/haxe"><img src="https://saucelabs.com/buildstatus/haxe" alt="SauceLabs Test Status"></a>
<a href="https://gitter.im/HaxeFoundation/haxe?utm_source=badge&amp;utm_medium=badge&amp;utm_campaign=pr-badge"><img src="https://badges.gitter.im/Join%20Chat.svg" alt="Gitter"></a>
<a href="https://discordapp.com/invite/0uEuWH3spjck73Lo"><img src="https://img.shields.io/discord/162395145352904705.svg?logo=discord" alt="Discord"></a>
</p>

#

Haxe is an open source toolkit that allows you to easily build cross-platform tools and applications that target many mainstream platforms. The Haxe toolkit includes:

* **The Haxe programming language**, a modern, high-level, strictly-typed programming language
* **The Haxe cross-compiler**, a state-of-the-art, lightning-speed compiler for many targets
* **The Haxe standard library**, a complete, cross-platform library of common functionality

Haxe allows you to compile for the following targets:

* JavaScript
* C++
* JVM
* Lua
* PHP 7
* Python 3
* [HashLink](https://hashlink.haxe.org/)
* [NekoVM](https://nekovm.org/)
* Flash (SWF Bytecode)
* And its own [interpreter](https://haxe.org/blog/eval/)

You can try Haxe directly from your browser at [try.haxe.org](https://try.haxe.org)!

For more information about Haxe, head to the [official Haxe website](https://haxe.org).

## License

The Haxe project has several licenses, covering different parts of the projects.

* The Haxe compiler is released under the GNU General Public License version 2 or any later version.
* The Haxe standard library is released under the MIT license.
* The Neko virtual machine is released under the MIT license. Its bundled runtime libraries (ndll) and tools are released under open source licenses as described in https://github.com/HaxeFoundation/neko/blob/master/LICENSE

For the complete Haxe licenses, please see https://haxe.org/foundation/open-source.html or [extra/LICENSE.txt](extra/LICENSE.txt).

## Installing Haxe

The latest stable release is available at [https://haxe.org/download/](https://haxe.org/download/). Pre-built binaries are available for your platform:

* **[Windows installer](https://haxe.org/download/file/latest/haxe-latest-win.exe/)**
* **[Windows binaries](https://haxe.org/download/file/latest/haxe-latest-win.zip/)**
* **[OSX installer](https://haxe.org/download/file/latest/haxe-latest-osx-installer.pkg/)**
* **[OSX binaries](https://haxe.org/download/file/latest/haxe-latest-osx.tar.gz/)**
* **[Linux Software Packages](https://haxe.org/download/linux/)**
* **[Linux 32-bit binaries](https://haxe.org/download/file/latest/haxe-latest-linux32.tar.gz/)**
* **[Linux 64-bit binaries](https://haxe.org/download/file/latest/haxe-latest-linux64.tar.gz/)**

Automated development builds are available from [build.haxe.org](http://build.haxe.org).

## Building from source

See [extra/BUILDING.md](extra/BUILDING.md).

## Using Haxe

For information on using Haxe, consult the [Haxe documentation](https://haxe.org/documentation/):

* [Haxe Introduction](https://haxe.org/documentation/introduction/), an introduction to the Haxe toolkit
* [The Haxe Manual](https://haxe.org/manual/), the reference manual for the Haxe language
* [Haxe Code Cookbook](https://code.haxe.org), code snippets / learning resource
* [Haxe API](https://api.haxe.org), documentation for the Haxe standard and native APIs
* [Haxelib](https://lib.haxe.org), Haxelib is the package manager for the Haxe Toolkit.

## Community

You can get help and talk with fellow Haxers from around the world via:

* [Haxe Community Forum](http://community.haxe.org)
* [Haxe on Stack Overflow](https://stackoverflow.com/questions/tagged/haxe)
* [Haxe Gitter chatroom](https://gitter.im/HaxeFoundation/haxe/)
* [Haxe Discord server](https://discordapp.com/invite/0uEuWH3spjck73Lo)

:+1: Get notified of the latest Haxe news, don't forget to read the [Haxe roundups](https://haxe.io/).

## Version compatibility

Haxe | Neko | SWF | Python | HL | PHP | Lua |
--------------- | ----- | ----- | ------ | ---- | ---- | --- |
2.* | 1.* | 8-10 | - | - | - | - |
3.0.0 | 2.0.0 | | - | - | 5.1+ | - |
3.2.0 | | 12-14 | 3.2+ | - | | - |
3.3.0 | 2.1.0 | 21 | | - | | 5.1, 5.2, 5.3, LuaJIT 2.0, 2.1 |
3.4.0 | | | | 1.1 | 5.4+ and 7.0+ (with `-D php7`) | |
4.0.0 | 2.3.0 | | | 1.11 | 7.0+ | |

## Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md) for more. Thank you!
* First PR: https://github.com/HaxeFoundation/haxe/pull/10128
* Second PR: https://github.com/HaxeFoundation/haxe/pull/11554
* Third PR: https://github.com/HaxeFoundation/haxe/pull/12168

* Original design repo: https://github.com/nadako/haxe-coroutines/
* Related Kotlin document: https://github.com/Kotlin/KEEP/blob/master/proposals/coroutines.md
* Coroutines under the hood: https://kt.academy/article/cc-under-the-hood
* Design of Kotlin coroutines: https://www.droidcon.com/2022/09/22/design-of-kotlin-coroutines/
* Mega document: https://github.com/JetBrains/kotlin/blob/master/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/coroutines-codegen.md
12 changes: 12 additions & 0 deletions src-json/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@
"targets": ["TAbstract"],
"links": ["https://haxe.org/manual/types-abstract-core-type.html"]
},
{
"name": "Coroutine",
"metadata": ":coroutine",
"doc": "Transform function into a coroutine",
"targets": ["TClassField"]
},
{
"name": "CoroutineTransformed",
"metadata": ":coroutine.transformed",
"doc": "Marks a field as being a coroutine that has already been transformed",
"targets": ["TClassField"]
},
{
"name": "CppFileCode",
"metadata": ":cppFileCode",
Expand Down
12 changes: 10 additions & 2 deletions src/codegen/fixOverrides.ml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ let fix_override com c f fd =
let f2 = (try Some (find_field com c f) with Not_found -> None) in
match f2,fd with
| Some (f2), Some(fd) ->
let targs, tret = (match follow f2.cf_type with TFun (args,ret) -> args, ret | _ -> die "" __LOC__) in
let targs, tret =
match follow_with_coro f2.cf_type with
| Coro (args,ret) -> Common.expand_coro_type com.basic args ret
| NotCoro (TFun(args, ret)) -> args, ret
| _ -> die "" __LOC__ in
let changed_args = ref [] in
let prefix = "_tmp_" in
let nargs = List.map2 (fun ((v,ct) as cur) (_,_,t2) ->
Expand Down Expand Up @@ -86,7 +90,11 @@ let fix_override com c f fd =
f.cf_expr <- Some { fde with eexpr = TFunction fd2 };
f.cf_type <- TFun(targs,tret);
| Some(f2), None when (has_class_flag c CInterface) ->
let targs, tret = (match follow f2.cf_type with TFun (args,ret) -> args, ret | _ -> die "" __LOC__) in
let targs, tret =
match follow_with_coro f2.cf_type with
| Coro (args,ret) -> Common.expand_coro_type com.basic args ret
| NotCoro (TFun(args, ret)) -> args, ret
| _ -> die "" __LOC__ in
f.cf_type <- TFun(targs,tret)
| _ ->
()
Expand Down
27 changes: 27 additions & 0 deletions src/context/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -754,9 +754,20 @@ let create timer_ctx compilation_step cs version args display_mode =
tfloat = mk_mono();
tbool = mk_mono();
tstring = mk_mono();
texception = mk_mono();
tnull = (fun _ -> die "Could use locate abstract Null<T> (was it redefined?)" __LOC__);
tarray = (fun _ -> die "Could not locate class Array<T> (was it redefined?)" __LOC__);
titerator = (fun _ -> die "Could not locate typedef Iterator<T> (was it redefined?)" __LOC__);
tunit = mk_mono();
tcoro = {
tcoro = (fun _ -> die "Could not locate abstract Coroutine<T> (was it redefined?)" __LOC__);
continuation = mk_mono();
base_continuation_class = null_class;
suspension_state = mk_mono();
suspension_result = (fun _ -> die "Could not locate class ContinuationResult<T> (was it redefined?)" __LOC__);
suspension_result_class = null_class;
immediate_suspension_result_class = null_class;
}
};
std = null_class;
file_keys = new file_keys;
Expand Down Expand Up @@ -887,6 +898,17 @@ let clone com is_macro_context =
tnull = (fun _ -> die "Could use locate abstract Null<T> (was it redefined?)" __LOC__);
tarray = (fun _ -> die "Could not locate class Array<T> (was it redefined?)" __LOC__);
titerator = (fun _ -> die "Could not locate typedef Iterator<T> (was it redefined?)" __LOC__);
texception = mk_mono();
tunit = mk_mono();
tcoro = {
tcoro = (fun _ -> die "Could not locate abstract Coroutine<T> (was it redefined?)" __LOC__);
continuation = mk_mono();
base_continuation_class = null_class;
suspension_state = mk_mono();
suspension_result = (fun _ -> die "Could not locate class ContinuationResult<T> (was it redefined?)" __LOC__);
suspension_result_class = null_class;
immediate_suspension_result_class = null_class;
};
};
std = null_class;
module_to_file = new hashtbl_lookup;
Expand Down Expand Up @@ -1097,6 +1119,11 @@ let get_entry_point com =
(snd path, c, e)
) com.main.main_path

let expand_coro_type basic args ret =
let args = args @ [("_hx_continuation",false,basic.tcoro.continuation)] in
let ret = if ExtType.is_void (follow ret) then basic.tunit else ret in
(args,basic.tcoro.suspension_result ret)

let make_unforced_lazy t_proc f where =
let r = ref (lazy_available t_dynamic) in
r := lazy_wait (fun() ->
Expand Down
7 changes: 6 additions & 1 deletion src/context/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ type typer_pass_tasks = {

type function_mode =
| FunFunction
| FunCoroutine
| FunNotFunction

type typer_globals = {
Expand All @@ -113,6 +114,7 @@ type typer_globals = {
mutable delayed_display : DisplayTypes.display_exception_kind option;
root_typer : typer;
(* api *)
mutable continuation_api : ContTypes.continuation_api option;
do_macro : typer -> macro_mode -> path -> string -> expr list -> pos -> macro_result;
do_load_macro : typer -> bool -> path -> string -> pos -> ((string * bool * t) list * t * tclass * Type.tclass_field);
do_load_module : ?origin:module_dep_origin -> typer -> path -> pos -> module_def;
Expand Down Expand Up @@ -288,8 +290,11 @@ module TyperManager = struct
let e = create_ctx_e ctx.e.curfun FunNotFunction in
create ctx ctx.m ctx.c f e PTypeField ctx.type_params

let is_coroutine_context ctx =
ctx.e.function_mode = FunCoroutine

let is_function_context ctx = match ctx.e.function_mode with
| FunFunction ->
| FunFunction | FunCoroutine ->
true
| FunNotFunction ->
false
Expand Down
15 changes: 15 additions & 0 deletions src/core/tFunctions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,21 @@ let rec follow_lazy_and_mono t = match t with
| _ ->
t

type maybe_coro =
| Coro of tsignature
| NotCoro of t

let follow_with_coro t = match follow t with
| TAbstract({a_path = (["haxe";"coro"],"Coroutine")},[t]) ->
begin match follow t with
| TFun(args,ret) ->
Coro (args,ret)
| t ->
NotCoro t
end
| t ->
NotCoro t

let rec ambiguate_funs t =
match follow t with
| TFun _ -> TFun ([], t_dynamic)
Expand Down
17 changes: 16 additions & 1 deletion src/core/tType.ml
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,18 @@ and build_state =

exception Type_exception of t

(* TODO: Most of this can probably be moved to the typer context
with lazy initialization from the coro code. *)
type coro_types = {
mutable tcoro : (string * bool * t) list -> t -> t;
mutable continuation : t;
mutable base_continuation_class : tclass;
mutable suspension_state : t;
mutable suspension_result : t -> t;
mutable suspension_result_class : tclass;
mutable immediate_suspension_result_class : tclass;
}

type basic_types = {
mutable tvoid : t;
mutable tany : t;
Expand All @@ -490,7 +502,10 @@ type basic_types = {
mutable tnull : t -> t;
mutable tstring : t;
mutable tarray : t -> t;
mutable titerator : t -> t
mutable texception : t;
mutable titerator : t -> t;
mutable tunit : t;
mutable tcoro : coro_types;
}

type class_field_scope =
Expand Down
18 changes: 18 additions & 0 deletions src/core/texpr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,24 @@ let for_remap basic v etype e1 e2 p =
mk (TWhile((mk (TParenthesis ehasnext) ehasnext.etype ehasnext.epos),ebody,NormalWhile)) basic.tvoid e1.epos;
]) basic.tvoid p

let not_while_true_to_while_true basic e1 e2 flag t p =
let e_break = mk TBreak t_dynamic p in
let e_not = mk (TUnop(Not,Prefix,Builder.mk_parent e1)) e1.etype e1.epos in
let e_if eo = mk (TIf(e_not,e_break,eo)) basic.tvoid p in
let rec map_continue e = match e.eexpr with
| TContinue ->
duplicate_tvars e_identity (e_if (Some e))
| TWhile _ ->
e
| _ ->
map_expr map_continue e
in
let e2 = if flag = NormalWhile then e2 else map_continue e2 in
let e_if = e_if None in
let e_block = if flag = NormalWhile then concat e_if e2 else concat e2 e_if in
let e_true = mk (TConst (TBool true)) basic.tbool p in
mk (TWhile(e_true,e_block,NormalWhile)) t p

(* -------------------------------------------------------------------------- *)
(* BUILD META DATA OBJECT *)

Expand Down
25 changes: 25 additions & 0 deletions src/coro/contTypes.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
open Type

type continuation_api = {
state : tclass_field;
result : tclass_field;
error : tclass_field;
completion : tclass_field;
context : tclass_field;
goto_label : tclass_field;
recursing : tclass_field;
immediate_result : texpr -> texpr;
immediate_error : texpr -> Type.t -> texpr;
}

let create_continuation_api immediate_result immediate_error state result error completion context goto_label recursing = {
immediate_result;
immediate_error;
state;
result;
error;
completion;
context;
goto_label;
recursing;
}
Loading
Loading