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

fix: style relation checker using substance variables #1239

Merged
merged 8 commits into from Jan 18, 2023
Merged

Conversation

liangyiliang
Copy link
Contributor

@liangyiliang liangyiliang commented Jan 18, 2023

Description

Related issue/PR: #1123

This PR fixes the uncaught error in the Style compiler when selector relations refer to a variable not declared in the selector, but exists in the substance program. It now throws an error. We added a test case on this error. Finally, we improved upon how the "suggested" variables in the error message distinguish between Style and Substance variables.

Implementation strategy and design decisions

The style compiler checks through the relations in the where clause, primarily using functions within the Substance checker, which checks the consistency of expressions with respect to a SubstanceEnv. In particular, it checks that each variable referred in the expressions are declared inside SubstanceEnv.

In order to call the Substance checker, we would need to provide a SubstanceEnv that contains all the variables that we want the relations to be able to access. Previously, we just take the current SubstanceEnv (as used in the Substance program), and add all the variables declared in the style header. The problem is that now this SubstanceEnv contains both variables declared in the style header (which we want to be able to access) and variables not declared in the style header but exists in the substance program.

The solution is simply to create a new, empty SubstanceEnv and add in the variables declared in the style header.

Examples with steps to reproduce them

This is the same example as used in the original issue, running in the version in this PR. Previously, this did not trigger an error, and only fails silently under the browser console. Now it does trigger a sensible error.

Checklist

  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new ESLint warnings
  • I have reviewed any generated registry diagram changes

@cloudflare-pages
Copy link

cloudflare-pages bot commented Jan 18, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3dcb5cf
Status: ✅  Deploy successful!
Preview URL: https://e6a96a2e.penrose-72l.pages.dev
Branch Preview URL: https://merging-envs.penrose-72l.pages.dev

View logs

@github-actions
Copy link

github-actions bot commented Jan 18, 2023

± Registry diff

📊 Performance

Key

Note that each bar component rounds up to the nearest 100ms, so each full bar is an overestimate by up to 400ms.

     0s   1s   2s   3s   4s   5s   6s   7s   8s   9s
     |    |    |    |    |    |    |    |    |    |
name ▝▀▀▀▀▀▀▀▀▀▀▀▚▄▄▄▄▄▄▄▄▄▞▀▀▀▀▀▀▀▀▀▀▀▀▚▄▄▄▄▄▄▄▄▄▖
      compilation labelling optimization rendering

Data

                                        0s   1s   2s   3s   4s   5s   6s   7s
                                        |    |    |    |    |    |    |    |
3d-projection-fake-3d-linear-algebra    ▝▞▖
allShapes-allShapes                     ▝▚▚▄
arrowheads-arrowheads                   ▝▞▖
caffeine-structural-formula             ▝▀▀▞▚
center-shrink-circle-animation          ▝▞▖
circle-example-euclidean                ▝▀▞▀▀▖
collinear-euclidean                     ▝▀▞▖
congruent-triangles-euclidean           ▝▀▀▞▖
continuousmap-continuousmap             ▝▞▖
cubic-bezier-cubic-bezier               ▝▚▀▀▖
full-moon-full-moon                     ▝▀▀▀▚▀▀▚
glutamine-molecules-basic               ▝▀▞▖
half-adder-distinctive-shape            ▝▚▚
hypergraph-hypergraph                   ▝▀▀▚▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▖
incenter-triangle-euclidean             ▝▀▞▖
lagrange-bases-lagrange-bases           ▝▚▚
midsegment-triangles-euclidean          ▝▀▞▖
mobius-mobius                           ▝▞▖
non-convex-non-convex                   ▝▀▞▖
one-water-molecule-atoms-and-bonds      ▝▚▚
parallel-lines-euclidean                ▝▀▞▖
persistent-homology-persistent-homology ▝▀▀▞▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▖
points-around-line-shape-distance       ▝▀▞▖
points-around-polyline-shape-distance   ▝▀▀▞▖
points-around-star-shape-distance       ▝▀▀▀▞▖
siggraph-teaser-euclidean-teaser        ▝▀▞▖
small-graph-disjoint-rect-line-horiz    ▝▀▚▚
small-graph-disjoint-rects              ▝▞▖
small-graph-disjoint-rects-large-canvas ▝▞▖
small-graph-disjoint-rects-small-canvas ▝▚▚
tree-tree                               ▝▀▞▖
tree-venn                               ▝▀▚▚
tree-venn-3d                            ▝▀▞▄▖
two-vectors-perp-vectors-dashed         ▝▀▞▖
vector-wedge-exterior-algebra           ▝▞▖
wet-floor-atoms-and-bonds               ▝▚▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▚
word-cloud-example-word-cloud           ▝▀▞▖
wos-laplace-estimator-walk-on-spheres   ▝▀▚▀▖
wos-nested-estimator-walk-on-spheres    ▝▀▀▞▀▀▀▀▀▀▚
wos-offcenter-estimator-walk-on-spheres ▝▀▚▀▀▀▚
wos-poisson-estimator-walk-on-spheres   ▝▀▚▀▚

@codecov
Copy link

codecov bot commented Jan 18, 2023

Codecov Report

Merging #1239 (e2a1079) into main (2109ee8) will increase coverage by 0.32%.
The diff coverage is 20.00%.

@@            Coverage Diff             @@
##             main    #1239      +/-   ##
==========================================
+ Coverage   63.13%   63.45%   +0.32%     
==========================================
  Files          60       61       +1     
  Lines        7061     7170     +109     
  Branches     1646     1664      +18     
==========================================
+ Hits         4458     4550      +92     
- Misses       2519     2537      +18     
+ Partials       84       83       -1     
Impacted Files Coverage Δ
packages/core/src/utils/Error.ts 28.01% <0.00%> (-1.14%) ⬇️
packages/core/src/compiler/Style.ts 68.00% <60.00%> (+0.04%) ⬆️
packages/core/src/contrib/Functions.ts 27.09% <0.00%> (-0.65%) ⬇️
packages/core/src/renderer/Line.ts 2.85% <0.00%> (ø)
packages/core/src/contrib/Constraints.ts 82.88% <0.00%> (ø)
...e/src/contrib/__testfixtures__/TestShapes.input.ts 100.00% <0.00%> (ø)
packages/core/src/contrib/CurveConstraints.ts 100.00% <0.00%> (ø)
packages/core/src/engine/Autodiff.ts 91.05% <0.00%> (+1.21%) ⬆️
packages/core/src/contrib/Objectives.ts 21.59% <0.00%> (+4.51%) ⬆️
packages/core/src/contrib/Utils.ts 51.35% <0.00%> (+9.53%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@liangyiliang liangyiliang requested review from samestep and wodeni and removed request for wodeni January 18, 2023 21:00
@samestep
Copy link
Collaborator

Just to clarify, does #1123 become fixed via this PR? If so, could you modify your PR description autoclose it using GitHub's special syntax? https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue

@liangyiliang
Copy link
Contributor Author

Just to clarify, does #1123 become fixed via this PR? If so, could you modify your PR description autoclose it using GitHub's special syntax? https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue

Done!

@samestep
Copy link
Collaborator

Done!

Thanks! And in future you can do this by just saying "Closes #1123" instead of "Related issue/PR: #1123". Actually, @wodeni do you think we should change this in .github/PULL_REQUEST_TEMPLATE.md? I've seen a bunch of people get tripped up by this in the past.

Copy link
Collaborator

@samestep samestep left a comment

Choose a reason for hiding this comment

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

Looks great, thanks Leo! Just one minor comment.

packages/core/src/compiler/Style.ts Outdated Show resolved Hide resolved
packages/core/src/compiler/Style.ts Outdated Show resolved Hide resolved
packages/core/src/compiler/Style.ts Outdated Show resolved Hide resolved
liangyiliang and others added 2 commits January 18, 2023 16:16
Co-authored-by: Sam Estep <sam@samestep.com>
Co-authored-by: Sam Estep <sam@samestep.com>
@liangyiliang liangyiliang merged commit 2e7de5e into main Jan 18, 2023
@liangyiliang liangyiliang deleted the merging-envs branch January 23, 2023 20:21
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.

Uncaught error in the Style compiler when selector relations refer to nonexistent variables
3 participants