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

Remove KclValue::SketchGroup variant #3446

Merged
merged 9 commits into from
Aug 21, 2024

Conversation

adamchalmers
Copy link
Collaborator

@adamchalmers adamchalmers commented Aug 15, 2024

We can store Rust types like SketchGroup as their own variant of KclValue, or as KclValue::UserVal. Sometimes we store in one and try to read from the other, which fails. This causes bugs, like #3338.

Instead, we should use either ::SketchGroup or ::UserVal, and stop using the other. If we stopped using ::UserVal, we'd need a new variant for every Rust type we wanted to build, including user-defined types. So I don't think that's practical.

Instead, we should store every KCL value by de/serializing it into UserVal. This is a first step along that path, removing just the SketchGroup variants. If it goes well, we can remove the other specialized variants too.

My only concern is there might be performance implications from how frequently we convert between serde_json::Value and Rust types via Serde. But I'm not too worried -- there's no parsing JSON strings, just traversing serde_json::Value trees. This isn't great for performance but I think it'll probably be miniscule in comparison to doing all the API calls. I'll benchmark it and see.

@adamchalmers adamchalmers requested review from jtran and jessfraz August 15, 2024 03:20
Copy link

qa-wolf bot commented Aug 15, 2024

QA Wolf here! As you write new code it's important that your test coverage is keeping up.
Click here to request test coverage for this PR!

Copy link

vercel bot commented Aug 15, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
modeling-app ✅ Ready (Inspect) Visit Preview Aug 21, 2024 3:57pm

Copy link
Contributor

@jessfraz jessfraz left a comment

Choose a reason for hiding this comment

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

nice im stoked

@adamchalmers adamchalmers force-pushed the achalmers/no-more-kcl-sketchgroup-variants branch from a653b86 to fb28993 Compare August 15, 2024 03:42
Copy link

codecov bot commented Aug 15, 2024

Codecov Report

Attention: Patch coverage is 96.50000% with 7 lines in your changes missing coverage. Please review.

Project coverage is 87.92%. Comparing base (682590d) to head (50af13b).
Report is 1 commits behind head on main.

Files Patch % Lines
src/wasm-lib/kcl/src/executor.rs 92.85% 6 Missing ⚠️
src/wasm-lib/kcl/src/std/args.rs 92.85% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3446      +/-   ##
==========================================
+ Coverage   87.83%   87.92%   +0.08%     
==========================================
  Files          66       66              
  Lines       25963    26003      +40     
==========================================
+ Hits        22805    22863      +58     
+ Misses       3158     3140      -18     
Flag Coverage Δ
wasm-lib 87.92% <96.50%> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@jtran jtran left a comment

Choose a reason for hiding this comment

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

What you said about giving up nominal typing is going to haunt me. But until the language has a way to have user-defined types, I think structural typing is the way to go.

Copy link
Collaborator

@Irev-Dev Irev-Dev left a comment

Choose a reason for hiding this comment

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

Looks good to me.

(aside from the fact that some of the JS unit tests will need adjusting)

src/lang/wasm.ts Outdated
const actualType = obj?.value?.type ?? obj?.type
if (actualType) {
return new Error(
`Expected ${varName} to be a sketchGroup, but it ${actualType} instead.`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
`Expected ${varName} to be a sketchGroup, but it ${actualType} instead.`
`Expected ${varName} to be a sketchGroup, but it was ${actualType} instead.`

kclManager.programMemory.get(sketchVar),
sketchVar
)
if (trap(sketchGroup)) return
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think trap will throw up a toast, just a heads up in case that isn't the intended behavior, since I saw you use err elsewhere.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The problem is that switching to err would silently swallow the error. Do we have another function that prints to the console but doesn't show a toast?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Seems like we can use trap with suppress = true for that.

We can store Rust types like `SketchGroup` as their own variant of
`KclValue`, or as `KclValue::UserVal`. Sometimes we store in one and
try to read from the other, which fails. This causes bugs, like #3338.

Instead, we should use either ::SketchGroup or ::UserVal, and stop using
the other. If we stopped using ::UserVal, we'd need a new variant for
every Rust type we wanted to build, including user-defined types. So I
don't think that's practical.

Instead, we should store every KCL value by de/serializing it into
UserVal. This is a first step along that path, removing just the
SketchGroup variants. If it goes well, we can remove the other
specialized variants too.

My only concern is there might be performance implications from how
frequently we convert between serde_json::Value and Rust types via Serde.
But I'm not too worried -- there's no parsing JSON strings, just
traversing serde_json::Value trees. This isn't great for performance but
I think it'll probably be miniscule in comparison to doing all the API
calls. I'll benchmark it and see.
adamchalmers and others added 3 commits August 21, 2024 09:59
* Move error-handling into the getter function, ty @vipyne

* Update src/lang/wasm.ts

Co-authored-by: Jonathan Tran <[email protected]>

---------

Co-authored-by: Jonathan Tran <[email protected]>
@adamchalmers adamchalmers force-pushed the achalmers/no-more-kcl-sketchgroup-variants branch from f8b9ebb to dada9f8 Compare August 21, 2024 14:59
@adamchalmers adamchalmers force-pushed the achalmers/no-more-kcl-sketchgroup-variants branch from 5da5afb to ed16e62 Compare August 21, 2024 15:17
@adamchalmers adamchalmers force-pushed the achalmers/no-more-kcl-sketchgroup-variants branch from 2ff3c50 to 50af13b Compare August 21, 2024 16:06
@adamchalmers adamchalmers merged commit d656a38 into main Aug 21, 2024
42 of 53 checks passed
@adamchalmers adamchalmers deleted the achalmers/no-more-kcl-sketchgroup-variants branch August 21, 2024 16:06
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.

5 participants