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

[css-values] Short-circuit if() evaluation #11500

Open
andruud opened this issue Jan 14, 2025 · 2 comments
Open

[css-values] Short-circuit if() evaluation #11500

andruud opened this issue Jan 14, 2025 · 2 comments

Comments

@andruud
Copy link
Member

andruud commented Jan 14, 2025

In a world where huge trees of custom function calls and inline if()s need to be evaluated, it would be nice if we could stop evaluating once a matching condition is found:

 if(cheap-test1(): 10px;
    cheap-test2(): 42px;
    else: --expensive())

In the above, we don't want to evaluate (substitute) --expensive() if an earlier branch will do.

Relatedly, a var() function also has up to two branches: the main value produced by the custom property being referenced, and optionally the fallback value. As specified currently, we can not short-circuit this "evaluation", since we need to look for cycles in the fallback value:

--valid: 1px;
--x: var(--valid, var(--y)); /* Cycle; IACVT */
--y: var(--valid, var(--x)); /* Cycle; IACVT */

--x and --y are in a cycle above, even though the fallback paths are not taken. By default, I'd expect this to extend to the branches not taken for if() as well, otherwise we'd miss the cycle in a case like:

--x: if(test-which-is-true(): 10px;
        else: var(--y));
--y: var(--x);

So:

  • Should we specify this short-circuiting behavior for if()?
  • Should we avoid looking for cycles in the fallback part of var() when it's not taken? (Requires compat investigation.)
  • Should we generally avoid looking for cycles in a branch not taken during any substitution? (E.g. attr()).
@andruud
Copy link
Member Author

andruud commented Jan 27, 2025

Should we generally avoid looking for cycles in a branch not taken during any substitution? (E.g. attr()).

This would extend to custom functions as well; none of the following functions are in a cycle:

@function --x() {
  @media (false) {
    result: --x();
  }
  result: 1px;
}
@function --y() {
  @if (false) { /* If added in the future */
    result: --y();
  }
  result: 1px;
}
@function --z() {
  --unused: var(--unused);
  result: 1px;
}

This probably does place --w() in a cycle, however, since we can't leave the locals unevaluated due to dynamic scoping (#10954):

@function --w() {
  --unused: --w();
  result: 1px;
}

EDIT: Added --w() example.

@tabatkins
Copy link
Member

Yes, --x() and --y() should be non-cyclic; --z() has a cycle inside of itself (--unused is cyclic) but the function itself isn't cyclic; and --w() is cyclic.

@astearns astearns moved this from Friday morning to Friday afternoon in CSSWG January 2025 meeting Jan 31, 2025
aarongable pushed a commit to chromium/chromium that referenced this issue Feb 4, 2025
This is now fairly easy to do by extending the CycleElem type
introduced in CL:6176920.

Both attributes (used by attr()) and locals need the AtomicString type;
we can distinguish between the two cases using a StrongAlias.

Note that this CL follows the behavior described in Issue 11500,
not what the spec currently says. Therefore, the test is marked
as tentative.

w3c/csswg-drafts#11500

Bug: 325504770
Change-Id: I5a00e03175f0446a0ec6e6ba771253b4ea5f48e6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6190327
Commit-Queue: Anders Hartvoll Ruud <[email protected]>
Reviewed-by: Munira Tursunova <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1415484}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Feb 4, 2025
This is now fairly easy to do by extending the CycleElem type
introduced in CL:6176920.

Both attributes (used by attr()) and locals need the AtomicString type;
we can distinguish between the two cases using a StrongAlias.

Note that this CL follows the behavior described in Issue 11500,
not what the spec currently says. Therefore, the test is marked
as tentative.

w3c/csswg-drafts#11500

Bug: 325504770
Change-Id: I5a00e03175f0446a0ec6e6ba771253b4ea5f48e6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6190327
Commit-Queue: Anders Hartvoll Ruud <[email protected]>
Reviewed-by: Munira Tursunova <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1415484}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Feb 4, 2025
This is now fairly easy to do by extending the CycleElem type
introduced in CL:6176920.

Both attributes (used by attr()) and locals need the AtomicString type;
we can distinguish between the two cases using a StrongAlias.

Note that this CL follows the behavior described in Issue 11500,
not what the spec currently says. Therefore, the test is marked
as tentative.

w3c/csswg-drafts#11500

Bug: 325504770
Change-Id: I5a00e03175f0446a0ec6e6ba771253b4ea5f48e6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6190327
Commit-Queue: Anders Hartvoll Ruud <[email protected]>
Reviewed-by: Munira Tursunova <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1415484}
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Feb 7, 2025
…variables, a=testonly

Automatic update from web-platform-tests
[functions] Detect cycles between local variables

This is now fairly easy to do by extending the CycleElem type
introduced in CL:6176920.

Both attributes (used by attr()) and locals need the AtomicString type;
we can distinguish between the two cases using a StrongAlias.

Note that this CL follows the behavior described in Issue 11500,
not what the spec currently says. Therefore, the test is marked
as tentative.

w3c/csswg-drafts#11500

Bug: 325504770
Change-Id: I5a00e03175f0446a0ec6e6ba771253b4ea5f48e6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6190327
Commit-Queue: Anders Hartvoll Ruud <[email protected]>
Reviewed-by: Munira Tursunova <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1415484}

--

wpt-commits: c5dda19e7580e26e7f5e538af095fdff241c9301
wpt-pr: 50483
i3roly pushed a commit to i3roly/firefox-dynasty that referenced this issue Feb 7, 2025
…variables, a=testonly

Automatic update from web-platform-tests
[functions] Detect cycles between local variables

This is now fairly easy to do by extending the CycleElem type
introduced in CL:6176920.

Both attributes (used by attr()) and locals need the AtomicString type;
we can distinguish between the two cases using a StrongAlias.

Note that this CL follows the behavior described in Issue 11500,
not what the spec currently says. Therefore, the test is marked
as tentative.

w3c/csswg-drafts#11500

Bug: 325504770
Change-Id: I5a00e03175f0446a0ec6e6ba771253b4ea5f48e6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6190327
Commit-Queue: Anders Hartvoll Ruud <[email protected]>
Reviewed-by: Munira Tursunova <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1415484}

--

wpt-commits: c5dda19e7580e26e7f5e538af095fdff241c9301
wpt-pr: 50483
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Friday afternoon
Development

No branches or pull requests

2 participants