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

Reduction semantics #109

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

dhil
Copy link
Member

@dhil dhil commented Jan 22, 2025

This patch populates the "Execution" section of the Explainer document with the reduction rules for stack switching.

Resolves #91.

This patch populates the "Execution" section of the Explainer document
with the reduction rules for stack switching.
@dhil dhil requested review from rossberg and tlively January 22, 2025 10:19
Copy link
Member

@rossberg rossberg left a comment

Choose a reason for hiding this comment

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

Would also make sense to have Maxime take a look, since he's mechanising this right now.

@@ -833,6 +833,126 @@ events and only `(on $e switch)` handlers can handle `switch`
events. The handler search continues past handlers for the wrong kind
of event, even if they use the correct tag.

#### Store extensions

* A store component `tags` for allocated tags (from the exception
Copy link
Member

Choose a reason for hiding this comment

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

Since the exception handling proposal is already merged, I think we can consider taginsts and their store component given.

- `ref.cont a : [] -> [(ref $ct)]`
- iff `S.conts[a] = epsilon \/ S.conts[a] = (E : n)`
- and `$ct ~~ cont $ft`
- and `$ft ~~ [t1^n] -> [t2*]`
Copy link
Member

@rossberg rossberg Jan 22, 2025

Choose a reason for hiding this comment

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

This would also need to require that E returns t2*. I think we want to factor both out into a separate typing rule for continuations, which is just invoked here. That rule would be something like

(E : n) : t1^n → t2*
- iff s ⊢ E[val^n] : t2*
- and (s ⊢ val : t1)^n 

- and `$ft ~~ [t1^n] -> [t2*]`

* `(prompt{<hdl>*} <instr>* end)` represents an active handler
- `(prompt{((a $l) | (b switch))*}? instr* end) : [t1*] -> [t2*]`
Copy link
Member

Choose a reason for hiding this comment

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

This is a bit too cute. A disjunction under an iteration does not really work, since the dimensions of a* and b* wouldn't really make sense then. So I'd suggest

Suggested change
- `(prompt{((a $l) | (b switch))*}? instr* end) : [t1*] -> [t2*]`
- `(prompt{hdl*} instr* end) : [t1*] -> [t2*]`

and then have auxiliary rules for typing hdl, like for syntactic handlers.


The administrative structure `hdl` is defined as.
```
hdl ::= (<tagaddr> $l) hdl | (<tagaddr> switch)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
hdl ::= (<tagaddr> $l) hdl | (<tagaddr> switch)
hdl ::= (<tagaddr> $l) | (<tagaddr> switch)

label_n{instr*} H^ea end
frame_n{F} H^ea end
catch{...} H^ea end
prompt{hdl*} H^ea end (iff ea notin ea'*)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
prompt{hdl*} H^ea end (iff ea notin ea'*)
prompt{hdl*} H^ea end (iff ea notin tagaddr(hdl*))


* `S; F; v^m (ref.cont ca) (resume_throw $ct $e hdl*) --> S'; F; prompt{hdl*} E[v^m (throw $e)] end`
- iff `S.conts[ca] = (E : n)`
- and `(ea = F.tags[$t])*`
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

- and `S.tags[F.tags[$e]].type ~~ [t1^m] -> [t2*]`
- and `S' = S with conts[ca] = epsilon`

* `S; F; (prompt{(e $l)*}? v* end) --> S; F; v*`
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* `S; F; (prompt{(e $l)*}? v* end) --> S; F; v*`
* `S; F; (prompt{hdl*} v* end) --> S; F; v*`


* `S; F; (prompt{(e $l)*}? v* end) --> S; F; v*`

* `S; F; (prompt H^ea[(suspend $e)] end) --> S; F; trap`
Copy link
Member

Choose a reason for hiding this comment

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

It looks like this rule was for barrier, so is obsolete?

- iff `ea = F.tags[$e]`

* `S; F; (prompt{hdl1* (ea $l) hdl2*} H^ea[v^n (suspend $e)] end) --> S'; F; v^n (ref.cont |S.conts|) (br $l)`
- iff `ea notin ea1*`
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- iff `ea notin ea1*`
- iff `ea notin tagaddr(hdl1*)`

* `S; F; (prompt{hdl1* (ea switch) hdl2*} H^ea[v^n (ref.cont ca) (switch $ct $e)] end) --> S''; F; prompt{hdl1* (ea switch) hdl2*} E[v^n (ref.cont |S.conts|)] end`
- iff `S.conts[ca] = (E : n')`
- and `n' = 1 + n`
- and `ea notin ea1*`
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- and `ea notin ea1*`
- and `ea notin tagaddr(hdl1*)`

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.

Put the reduction rules in the explainer
2 participants