Skip to content
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

[RFC] Parallelism #83

Open
mertyildiran opened this issue Dec 16, 2020 · 2 comments
Open

[RFC] Parallelism #83

mertyildiran opened this issue Dec 16, 2020 · 2 comments
Assignees
Labels
feature request New feature or request
Projects

Comments

@mertyildiran
Copy link
Member

mertyildiran commented Dec 16, 2020

Implement parallelism using async keyword on function calls:

void def iterate_and_print(num list a)
    foreach a as i
        print i
    end
end

async iterate_and_print([1, 2, 3, 4, 5])
print "Print me in the mean time"

The output should look like:

1
2
Print me in the mean time
3
4
5

The async should also be assignable so that using the wait keyword the execution can wait until the function called by async finishes:

num def iterate_print_and_return_last(num list a)
    foreach a as i
        print i
    end
    num r = a[-1]
    return r
end

ptr call = async iterate_print_and_return_last([1, 2, 3, 4, 5])
print "Print me in the mean time"
wait [num a = call]

echo "Last element: "
print a

wait keyword should be able to accept a num list:

num def iterate_print_and_return_last(num list a)
    foreach a as i
        print i
    end
    num r = a[-1]
    return r
end

ptr call1 = async iterate_print_and_return_last([1, 2, 3, 4, 5])
ptr call2 = async iterate_print_and_return_last([6, 7, 8, 9, 10])
print "Print me in the mean time"
wait [num a = call1, num b = call2]

echo "Last elements: "
echo a
echo ", "
print b

such that the output will look like:

1
2
6
3
Print me in the mean time
8
4
9
5
10
Last elements: 5, 10
@mertyildiran mertyildiran added the feature request New feature or request label Dec 16, 2020
@mertyildiran mertyildiran added this to To do in Chaos via automation Dec 16, 2020
@mertyildiran mertyildiran self-assigned this Dec 16, 2020
@dumblob
Copy link

dumblob commented Oct 22, 2021

Interesting - basically you're turning the "traditional async" approach on its head into a futures semantics. Shall be quite performant and actually avoid many (most?) of the pitfalls of the "traditional" async (most notably your approach seems to solve the stdlib of double size and mutually incompatible "function colors" split).

Though admittedly I'm curious how you want to implement this under the hood. The only implementation semantically resembling yours is the one in Dao which though uses plain os-level threads. But you seem to indicate that you want to have it single-threaded which would mean either you need to distinguish between return and yield (which I can't find anywhere in your description) or simply insert yield points automatically in compile time (which I also can't find anywhere in your description 😉). Or I'm missing some other option... IDK

Dare to elaborate 😉?

@mertyildiran
Copy link
Member Author

@dumblob it's just a syntax proposal at this point. I've no idea how are we going to implement it. Also the current state of master far from making parallelism possible. Right now, I'm focused on making the language JIT compiled. So this RFC is kind of on hold.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
Chaos
  
To do
Development

No branches or pull requests

2 participants