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 380 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
380 commits
Select commit Hold shift + click to select a range
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
addf65e
be more diligent with positions
Simn May 16, 2025
f265286
fix more optimization problems
Simn May 16, 2025
51047e8
[WIP] Stack traces continued (#82)
Simn May 16, 2025
0d84324
Try a new stack trace approach (#84)
Simn May 20, 2025
8e8834c
Merge branch 'development' into kt_coro
Simn May 21, 2025
3f81db4
Make Context immutable (#87)
Simn May 21, 2025
1da7db6
remove -D coroutine.throw (#89)
Simn May 23, 2025
e372bcf
disable optimizations for now
Simn May 23, 2025
4db1813
deal with branching expressions in value places
Simn May 23, 2025
572bef9
Merge branch 'development' into kt_coro
Simn May 23, 2025
9500c74
Merge branch 'development' into kt_coro
Simn May 23, 2025
cc67f42
assign suspension calls in value places to local
Simn May 25, 2025
50831ed
Revert "assign suspension calls in value places to local"
Simn May 25, 2025
57fba12
awkwardly deal with stack suspend problem
Simn May 25, 2025
8b85443
Don't use the typers current module for manged class names
Aidan63 May 26, 2025
f86927d
Merge pull request #95 from Aidan63/cont_name_clash
Aidan63 May 26, 2025
4dcf2b3
per class anon function counter
Aidan63 May 26, 2025
8cd46d0
Merge pull request #96 from Aidan63/stable_anon_naming
Aidan63 May 26, 2025
02bc2e8
fix transformer bug and add more tests
Simn May 28, 2025
5de06f9
change context data structure to linked list (#100)
Simn May 30, 2025
de0f244
Structured Concurrency with Task/Scope (#97)
Simn May 30, 2025
36fab78
unset children when they completed
Simn May 30, 2025
b61bd62
add some micro benchmarks
Simn May 30, 2025
7229572
Add some virtual time scheduler tests
Aidan63 May 30, 2025
e470be7
scheduler functions can be cancelled
Aidan63 May 30, 2025
606339f
fix complex wrapper expressions
Simn May 30, 2025
bd11390
Callback on abstract task for cancellation
Aidan63 May 30, 2025
8bd337b
handle for stopping cancellation callback
Aidan63 May 30, 2025
4dd5536
Cancellation token approach
Aidan63 May 30, 2025
239e014
add Context.add
Simn May 31, 2025
17e5ddf
walk event loop from both ends
Simn May 31, 2025
fce8266
Merge branch 'kt_coro' into prompt-cancellation
Aidan63 May 31, 2025
d780a79
Cancellation token key
Aidan63 May 31, 2025
3921347
static no-op cancellation handle
Aidan63 May 31, 2025
55a3e3f
lazy initialise cancellation callback and children array
Aidan63 May 31, 2025
33679d9
lets get fancy after all
Aidan63 May 31, 2025
85c164b
Add hxcoro.ds.Channel (#107)
Simn May 31, 2025
af70636
clean up a little and document random things
Simn May 31, 2025
10fa5eb
document new interfaces
Aidan63 May 31, 2025
503b833
Merge pull request #110 from Aidan63/prompt-cancellation
Aidan63 May 31, 2025
837afbc
timeout implementation
Aidan63 May 31, 2025
a284b99
Add some tests
Aidan63 May 31, 2025
3c4db57
separate (#117)
Simn Jun 1, 2025
8030146
generate continuation stack traces only in debug mode
Simn Jun 1, 2025
9a10df2
avoid more array allocations
Simn Jun 1, 2025
3a23f96
Extra test
Aidan63 Jun 1, 2025
7651be1
Document timeout
Aidan63 Jun 1, 2025
fe40a93
Merge branch 'kt_coro' into timeout
Aidan63 Jun 1, 2025
3f77fc3
Merge pull request #116 from Aidan63/timeout
Aidan63 Jun 1, 2025
d22d4c6
Bring back the event loop mutexes
Aidan63 Jun 1, 2025
13bd66d
implement awaitChildren (#123)
Simn Jun 1, 2025
a1a97fc
release future lock before calling the function
Aidan63 Jun 1, 2025
25b8534
Merge remote-tracking branch 'origin/kt_coro' into kt_coro
Aidan63 Jun 1, 2025
7640316
don't hold onto zeroMutex while we're running
Simn Jun 1, 2025
16797fe
also remove double loop because run itself is run in a loop
Simn Jun 1, 2025
f8a6447
Don't reschedule BaseContinuation.resume (#118)
Simn Jun 1, 2025
063f867
disable linux lua because this is annoying
Simn Jun 1, 2025
734e72b
Merge branch 'development' into kt_coro
Simn Jun 1, 2025
1eee9f8
even less lua
Simn Jun 1, 2025
c144b15
go away...
Simn Jun 1, 2025
2bdafc9
move task stuff to hxcoro.task
Simn Jun 1, 2025
629fc0b
add some API to PagedDeque
Simn Jun 1, 2025
790af88
add produce sample as a test because it happens to work right now
Simn Jun 1, 2025
4e8a273
Don't have RacingContinuation hold onto its mutex for so long (#127)
Simn Jun 2, 2025
7c37f2e
Add CoroMutex (#112)
Simn Jun 3, 2025
386bcbe
make task context lazy and avoid some retention
Simn Jun 3, 2025
bc49261
add CoroTask.putOnHold and call it from CoroSemaphore
Simn Jun 3, 2025
d990c4a
make some more context retention adjustments
Simn Jun 3, 2025
e6e5531
enable optimizations again to see if we have broken anything in the m…
Simn Jun 3, 2025
3c648d6
ignoring failing eval call stack test
Simn Jun 3, 2025
3a90640
fix some potential null problems
Simn Jun 3, 2025
ed5c64e
Cancelling suspend (#129)
Aidan63 Jun 4, 2025
88fb8ca
Merge branch 'development' into kt_coro
Simn Jun 4, 2025
b423301
Merge branch 'development' into kt_coro
Simn Jun 4, 2025
b32e465
Prompt channels (#126)
Aidan63 Jun 4, 2025
ec32886
finally add an id to tasks
Simn Jun 4, 2025
5c33d39
optimize common CancellationHandle.close case
Simn Jun 4, 2025
87ba073
make Key interface nicer
Simn Jun 4, 2025
a87fbb1
don't use @:native
Simn Jun 4, 2025
cf06f67
add hxcoro.components.CoroName
Simn Jun 4, 2025
b6e73fa
get the old generator tests working
Simn Jun 5, 2025
68372c5
add Coro.supervisor
Simn Jun 5, 2025
4001e00
add C type parameter to tasks (#135)
Simn Jun 5, 2025
cc7586d
move parent back to AbstractTask
Simn Jun 5, 2025
b99a63c
Add INodeStrategy (#136)
Simn Jun 6, 2025
99d8444
Add hxcoro.util.Convenience (#134)
Simn Jun 6, 2025
5b712f2
Merge branch 'development' into kt_coro
Simn Jun 6, 2025
275ce53
refine some toString
Simn Jun 6, 2025
171e81d
Merge branch 'development' into kt_coro
Simn Jun 6, 2025
b3f19f6
fix double suspension_result wrapping
Simn Jun 6, 2025
587480b
fix some field hosts
Simn Jun 6, 2025
71dfe05
Schedulers use Int64 ms everywhere
Aidan63 Jun 6, 2025
bcdd261
Change float literal
Aidan63 Jun 6, 2025
c955f20
Int64 literal to make some targets happy
Aidan63 Jun 6, 2025
6a0f294
i64 literal here as well, for paranoia's sake
Aidan63 Jun 6, 2025
e8f87b5
Private access Int64.toString to make some targets happy
Aidan63 Jun 6, 2025
d143096
spell things out for HL
Simn Jun 6, 2025
45e6928
spell it out for every other target too
Simn Jun 6, 2025
f973f93
Add ILocalContext (#137)
Simn Jun 6, 2025
a91350b
Merge pull request #140 from Aidan63/milliseconds
Aidan63 Jun 6, 2025
d350cce
add initialState to AbstractTask constructor and `start` automaticall…
Simn Jun 7, 2025
e42b37e
[mad science] Get rid of explicit .key expressions (#141)
Simn Jun 7, 2025
c97c15e
add Channel benchmark
Simn Jun 7, 2025
c94afc4
remove expression mapping that doesn't seem to be needed anymore
Simn Jun 7, 2025
a0d42f2
bring back some mapping that was needed after all
Simn Jun 7, 2025
7cb4f71
re-enabled virtual time scheduler tests
Aidan63 Jun 7, 2025
1b9b493
Implement yield as delay 0
Aidan63 Jun 7, 2025
e6847c6
don't ignore RLocal when mapping complex expressions
Simn Jun 7, 2025
d74109f
Remove private access int64 workaround
Aidan63 Jun 7, 2025
12b9668
Clean up _hx_tmp handling (#145)
Simn Jun 7, 2025
bf84fa8
clean up result handling a little
Simn Jun 8, 2025
1cabf72
make most Context functions inline
Simn Jun 8, 2025
2658453
add missing return
Simn Jun 8, 2025
a35165c
Add IScheduleObject (#143)
Simn Jun 8, 2025
d4b9be3
go back to Array context because that's simply faster
Simn Jun 8, 2025
7f59452
reduce BaseContinuation data a little more
Simn Jun 8, 2025
4616e57
Merge branch 'development' into kt_coro
Simn Jun 10, 2025
efe880a
Merge branch 'development' into kt_coro
Simn Jun 12, 2025
60dac0d
eval has atomics now
Simn Jun 12, 2025
abe7ebd
Change isCancellationRequested to cancellationException (#147)
Simn Jun 12, 2025
2eb12ae
Make internal coroutine initialization lazy (#151)
Simn Jun 13, 2025
ebd097e
Merge branch 'development' into kt_coro
Simn Jun 14, 2025
d852661
Add PagedDeque.remove (#154)
Simn Jun 16, 2025
21d53ce
Merge branch 'development' into kt_coro
Simn Jun 18, 2025
aeaf98a
Merge branch 'HaxeFoundation:development' into kt_coro
Aidan63 Jul 1, 2025
f52e467
Follow away abstracts before getting the default value
Aidan63 Jul 5, 2025
51949f0
Add test
Aidan63 Jul 5, 2025
cb1c65b
Add an assert
Aidan63 Jul 5, 2025
1bd1604
Merge pull request #161 from Aidan63/follow_for_default
Aidan63 Jul 6, 2025
ccfb373
treat {} as the special case that it is
Simn Jul 9, 2025
34cffd3
Merge branch 'development' into kt_coro
Simn Jul 9, 2025
46eebed
haxelib
Simn Jul 9, 2025
293640d
[tests] fix server tests (#164)
kLabz Jul 9, 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
9 changes: 2 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,12 @@ jobs:
strategy:
fail-fast: false
matrix:
target: [macro, js, hl, cpp, jvm, php, python, lua, flash, neko]
target: [macro, js, hl, cpp, jvm, php, python, flash, neko]
include:
- target: hl
APT_PACKAGES: cmake ninja-build libturbojpeg-dev
- target: cpp
APT_PACKAGES: gcc-multilib g++-multilib
- target: lua
APT_PACKAGES: ncurses-dev
- target: flash
APT_PACKAGES: libglib2.0-0 libgtk2.0-0 libfreetype6 xvfb
steps:
Expand Down Expand Up @@ -470,10 +468,7 @@ jobs:
strategy:
fail-fast: false
matrix:
target: [macro, js, cpp, jvm, php, python, lua, neko]
include:
- target: lua
APT_PACKAGES: ncurses-dev
target: [macro, js, cpp, jvm, php, python, neko]
steps:
- uses: actions/checkout@main
with:
Expand Down
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 [./LICENSE](./LICENSE).

## 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
2 changes: 1 addition & 1 deletion extra/haxelib_src
Submodule haxelib_src updated 2 files
+85 −5 CHANGES.md
+ run.n
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
20 changes: 20 additions & 0 deletions src/context/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -790,9 +790,16 @@ 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 = lazy (fun _ -> die "Could not locate abstract Coroutine<T> (was it redefined?)" __LOC__);
continuation = lazy (mk_mono());
suspension_result_class = lazy null_class;
}
};
std = null_class;
file_keys = new file_keys;
Expand Down Expand Up @@ -923,6 +930,13 @@ 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 = lazy (fun _ -> die "Could not locate abstract Coroutine<T> (was it redefined?)" __LOC__);
continuation = lazy (mk_mono());
suspension_result_class = lazy null_class;
};
};
local_wrapper = LocalWrapper.null_wrapper;
std = null_class;
Expand Down Expand Up @@ -1134,6 +1148,12 @@ 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,Lazy.force basic.tcoro.continuation)] in
let ret = if ExtType.is_void (follow ret) then basic.tunit else ret in
let c = Lazy.force basic.tcoro.suspension_result_class in
(args,TInst(c,[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
11 changes: 10 additions & 1 deletion src/core/tType.ml
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,12 @@ and build_state =

exception Type_exception of t

type coro_types = {
mutable tcoro : ((string * bool * t) list -> t -> t) Lazy.t;
mutable continuation : t Lazy.t;
mutable suspension_result_class : tclass Lazy.t;
}

type basic_types = {
mutable tvoid : t;
mutable tany : t;
Expand All @@ -491,7 +497,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
37 changes: 37 additions & 0 deletions src/coro/contTypes.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
open Type

type continuation_api = {
base_continuation_class : tclass;
immediate_suspension_result_class : tclass;
suspension_state : Type.t;
suspension_result : t -> t;
suspension_result_class : tclass;
continuation : Type.t;
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 base_continuation_class immediate_suspension_result_class suspension_state suspension_result_class continuation immediate_result immediate_error state result error completion context goto_label recursing = {
base_continuation_class;
immediate_suspension_result_class;
suspension_state;
suspension_result = (fun t -> TInst(suspension_result_class,[t]));
suspension_result_class;
continuation;
immediate_result;
immediate_error;
state;
result;
error;
completion;
context;
goto_label;
recursing;
}
Loading
Loading