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

Splitting/Grouping channels using patterns #7

Open
np opened this issue Oct 8, 2015 · 0 comments
Open

Splitting/Grouping channels using patterns #7

np opened this issue Oct 8, 2015 · 0 comments

Comments

@np
Copy link
Owner

np commented Oct 8, 2015

The process language and type system was designed to keep the burden of where/when splitting tensors & pars really low.

Channel splitting

This means that channel splittings can be done early and freely ordered.
However we could directly name the sessions deeply and automate these splittings.

Example:

pattern_example = proc[ a : !Int, [: b : !Int, c : !Int :], { d : [!Int, !Int], e : {?Int, ?Int} } ]
   (send a 1 | send b 2. send c 3 | fwd [!Int,!Int] (d,e))

Which should desugar to:

pattern_example_expanded =
  proc(abcde : [!Int, [: !Int, !Int :], { [!Int, !Int], {?Int, ?Int} } ])
    abcde[a, bc, de]
    bc[: b, c :]
    de{d, e}
    (send a 1 | send b 2. send c 3 | fwd [!Int,!Int] (d,e))

Splitting patterns are not only for processes-as-terms but should be allowed for normal splitting as well:

pattern_example_2 = proc(abcde)
   abcde[ a : !Int, [: b, c :], { d, e } ]
   (send a 1 | send b 2. send c 3 | fwd [!Int,!Int] (d,e))

This example also recalls that session annotations are optional.

Patterns for grouping

[Grouping has been implemented in commit 72a3388]

When injecting a term as a process one must pass in some channels.
For instance consider we want to inject the term above in another process where the protocol is equivalent up-to some permutations.

-- notice how various parts gets commuted
test_pat =
  proc[ [: b : !Int, c : !Int :], a : !Int, { e : {?Int, ?Int}, d : [!Int, !Int] } ]
  @pattern_example[a, [: b, c :], {d, e}]

Alternatively with pattern splitting expanded:

test_pat_expanded_splitting =
  proc(bcaed : [[: !Int, !Int :], !Int, { {?Int, ?Int}, [!Int, !Int] } ])
    bcaed[bc, a, ed]
    bc[: b, c :]
    ed{e, d}
  @pattern_example_expanded[a, [: b, c :], {d, e}]

These grouping patterns can be expanded away as well. While we need to have this expansion in place eventually it is better to check the process un-expanded.

The expansion of grouping patterns for our example is:

test_pat_expanded_grouping =
  proc[ [: b : !Int, c : !Int :], a : !Int, { e : {?Int, ?Int}, d : [!Int, !Int] } ]
  new(f, g)
  ( @pattern_example(f)
  | g[a, [: b, c :], {d, e}])

So expansion of grouping patterns rely on the expansion of splitting patterns.

Syntax of Patterns

[also in commit 72a3388]

After the keyword proc we change `"(" ChanDecs ")", into TopPatt.

TPOld. TopPatt ::= "(" [Patt] ")" ;
TPPar. TopPatt ::= "{" [Patt] "}" ;
TPTen. TopPatt ::= "[" [Patt] "]" ;
TPOrd. TopPatt ::= "[:" [Patt] ":]" ;

PaVar. Patt ::= Name ":" Session ;
PaPar. Patt ::= "{" [Patt] "}" ;
PaTen. Patt ::= "[" [Patt] "]" ;
PaOrd. Patt ::= "[:" [Patt] ":]" ;

Implementation sketch

@np np added the enhancement label Oct 8, 2015
@np np changed the title Splitting channels using patterns Splitting/Grouping channels using patterns Oct 25, 2015
np added a commit that referenced this issue May 6, 2016
Related to #7

Either deep patterns are expanded away to shallow patterns
or we need to support deep patterns in:
* Check.Core
* Compile.C
* Fuse
* Sequential
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant