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

Add [fence-effects=""] to stop effect propagation #388

Merged
merged 2 commits into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions src/Meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export default class Meta extends Builder {
span.appendChild(node.firstChild);
}
node.replaceWith(span);
} else {
// Nothing to render, strip it.
node.replaceWith(...node.childNodes);
}
}
}
37 changes: 25 additions & 12 deletions src/Xref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,34 @@ export default class Xref extends Builder {
shouldPropagateEffect(effectName: string) {
if (!this.isInvocation) return false;
if (this.clause) {
// Xrefs nested inside Abstract Closures should not propagate the
// user-code effect, since those are effectively nested functions.
// Xrefs should not propagate past explicit fences in parent steps. Fences
// must be at the beginning of steps.
//
// Abstract Closures are considered automatic fences for the user-code
// effect, since those are effectively nested functions.
//
// Calls to Abstract Closures that can call user code must be explicitly
// marked as such with <emu-meta effects="user-code">...</emu-meta>.
if (effectName === 'user-code') {
for (let node = this.node; node.parentElement; node = node.parentElement) {
const parent = node.parentElement;
// This is super hacky. It's checking the output of ecmarkdown.
if (
parent.tagName === 'LI' &&
parent.textContent?.includes('be a new Abstract Closure')
) {
return false;
}
for (let node = this.node; node.parentElement; node = node.parentElement) {
const parent = node.parentElement;
// This is super hacky. It's checking the output of ecmarkdown.
if (parent.tagName !== 'LI') continue;

if (
effectName === 'user-code' &&
parent.textContent?.includes('be a new Abstract Closure')
) {
return false;
}

if (
parent
.getAttribute('fence-effects')
?.split(',')
.map(s => s.trim())
.includes(effectName)
syg marked this conversation as resolved.
Show resolved Hide resolved
) {
return false;
}
}
if (!this.clause.canHaveEffect(effectName)) {
Expand Down
12 changes: 12 additions & 0 deletions test/baselines/generated-reference/effect-user-code.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,16 @@ <h1><span class="secnum">20</span> ResultOfEvaluating()</h1>
<p>The abstract operation ResultOfEvaluating takes no arguments. The phrase "the result of evaluating Foo" is automatically considered as can call user code. It performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>res</var> be the result of <span class="e-user-code">evaluating <emu-nt>Foo</emu-nt></span>.</li></ol></emu-alg>
</emu-clause>

<emu-clause id="sec-fenced-effects" type="abstract operation" aoid="FencedEffects">
<h1><span class="secnum">21</span> FencedEffects()</h1>
<p>The abstract operation FencedEffects takes no arguments. Effects don't propagate past fences in parent steps. A fence must be at the beginning of a step. It performs the following steps when called:</p>
<emu-alg><ol><li fence-effects="user-code">Fence.<ol><li><emu-xref aoid="UserCode" id="_ref_18"><a href="#sec-user-code" class="e-user-code">UserCode</a></emu-xref>().</li></ol></li></ol></emu-alg>
</emu-clause>

<emu-clause id="sec-call-fenced-effects" type="abstract operation" aoid="CallFencedEffects">
<h1><span class="secnum">22</span> CallFencedEffects()</h1>
<p>The abstract operation CallFencedEffects takes no arguments. Effects don't propagate past fences in parent steps. It performs the following steps when called:</p>
<emu-alg><ol><li><emu-xref aoid="FencedEffects" id="_ref_19"><a href="#sec-fenced-effects">FencedEffects</a></emu-xref>().</li></ol></emu-alg>
</emu-clause>
</div></body>
23 changes: 23 additions & 0 deletions test/baselines/sources/effect-user-code.html
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,26 @@ <h1>ResultOfEvaluating()</h1>
1. Let _res_ be the result of evaluating |Foo|.
</emu-alg>
</emu-clause>

<emu-clause id="sec-fenced-effects" type="abstract operation">
<h1>FencedEffects()</h1>
<dl class="header">
<dt>description</dt>
<dd>Effects don't propagate past fences in parent steps. A fence must be at the beginning of a step.</dd>
</dl>
<emu-alg>
1. [fence-effects="user-code"] Fence.
1. UserCode().
</emu-alg>
</emu-clause>

<emu-clause id="sec-call-fenced-effects" type="abstract operation">
<h1>CallFencedEffects()</h1>
<dl class="header">
<dt>description</dt>
<dd>Effects don't propagate past fences in parent steps.</dd>
</dl>
<emu-alg>
1. FencedEffects().
</emu-alg>
</emu-clause>