-
Notifications
You must be signed in to change notification settings - Fork 56
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
Remove KclValue::SketchGroup variant #3446
Conversation
QA Wolf here! As you write new code it's important that your test coverage is keeping up. |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice im stoked
a653b86
to
fb28993
Compare
Codecov ReportAttention: Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this 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.
68c5940
to
386ae08
Compare
0d030ae
to
4a43a2e
Compare
There was a problem hiding this 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)
016df94
to
c99847a
Compare
c5a1643
to
a580d3a
Compare
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.` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
* 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]>
f8b9ebb
to
dada9f8
Compare
5da5afb
to
ed16e62
Compare
2ff3c50
to
50af13b
Compare
We can store Rust types like
SketchGroup
as their own variant ofKclValue
, or asKclValue::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.