Compare commits
10 Commits
kcl-test-s
...
franknoiro
Author | SHA1 | Date | |
---|---|---|---|
1a9a2ef51e | |||
b283f027de | |||
7967b44508 | |||
04d21774cc | |||
3bd4fa6674 | |||
f68ed9997b | |||
a52a3bdd0e | |||
8d710e0e92 | |||
23c09dc4df | |||
04781abbb5 |
95
.github/workflows/build-test-publish-apps.yml
vendored
95
.github/workflows/build-test-publish-apps.yml
vendored
@ -72,18 +72,6 @@ jobs:
|
||||
- id: export_version
|
||||
run: echo "version=`cat package.json | jq -r '.version'`" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Prepare electron-builder.yml file for nightly
|
||||
if: ${{ github.event_name == 'schedule' }}
|
||||
run: |
|
||||
yq -i '.publish[0].url = "https://dl.zoo.dev/releases/modeling-app/nightly"' electron-builder.yml
|
||||
|
||||
- uses: actions/upload-artifact@v3
|
||||
if: ${{ github.event_name == 'schedule' }}
|
||||
with:
|
||||
name: prepared-files-nightly
|
||||
path: |
|
||||
electron-builder.yml
|
||||
|
||||
- id: export_notes
|
||||
run: echo "notes=`cat release-notes.md'`" >> "$GITHUB_OUTPUT"
|
||||
|
||||
@ -93,7 +81,6 @@ jobs:
|
||||
yq -i '.publish[0].url = "https://dl.zoo.dev/releases/modeling-app/updater-test-release-notes"' electron-builder.yml
|
||||
|
||||
- uses: actions/upload-artifact@v3
|
||||
if: ${{ env.CUT_RELEASE_PR == 'true' }}
|
||||
with:
|
||||
name: prepared-files-updater-test
|
||||
path: |
|
||||
@ -105,13 +92,7 @@ jobs:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: macos-14
|
||||
platform: mac
|
||||
- os: windows-2022
|
||||
platform: win
|
||||
- os: ubuntu-22.04
|
||||
platform: linux
|
||||
os: [macos-14, windows-2022, ubuntu-22.04]
|
||||
runs-on: ${{ matrix.os }}
|
||||
env:
|
||||
APPLE_ID: ${{ secrets.APPLE_ID }}
|
||||
@ -140,16 +121,6 @@ jobs:
|
||||
cp prepared-files/src/wasm-lib/pkg/wasm_lib* src/wasm-lib/pkg
|
||||
cp prepared-files/release-notes.md release-notes.md
|
||||
|
||||
- uses: actions/download-artifact@v3
|
||||
if: ${{ github.event_name == 'schedule' }}
|
||||
name: prepared-files-nightly
|
||||
|
||||
- name: Copy updated electron-builder.yml file for nightly build
|
||||
if: ${{ github.event_name == 'schedule' }}
|
||||
run: |
|
||||
ls -R prepared-files-nightly
|
||||
cp prepared-files-nightly/electron-builder.yml electron-builder.yml
|
||||
|
||||
- name: Sync node version and setup cache
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
@ -194,27 +165,9 @@ jobs:
|
||||
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: out-arm64-${{ matrix.platform }}
|
||||
# first two will pick both Zoo Modeling App-$VERSION-arm64-win.exe and Zoo Modeling App-$VERSION-win.exe
|
||||
path: |
|
||||
out/*-${{ env.VERSION_NO_V }}-win.*
|
||||
out/*-${{ env.VERSION_NO_V }}-arm64-win.*
|
||||
out/*-arm64-mac.*
|
||||
out/*-arm64-linux.*
|
||||
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: out-x64-${{ matrix.platform }}
|
||||
path: |
|
||||
out/*-x64-win.*
|
||||
out/*-x64-mac.*
|
||||
out/*-x86_64-linux.*
|
||||
|
||||
- uses: actions/upload-artifact@v3
|
||||
if: ${{ env.CUT_RELEASE_PR == 'true' }}
|
||||
with:
|
||||
name: out-yml
|
||||
name: out-${{ matrix.os }}
|
||||
path: |
|
||||
out/Zoo*.*
|
||||
out/latest*.yml
|
||||
|
||||
# TODO: add the 'Build for Mac TestFlight (nightly)' stage back
|
||||
@ -236,20 +189,10 @@ jobs:
|
||||
- uses: actions/upload-artifact@v3
|
||||
if: ${{ env.CUT_RELEASE_PR == 'true' }}
|
||||
with:
|
||||
name: updater-test-arm64-${{ matrix.platform }}
|
||||
name: updater-test-${{ matrix.os }}
|
||||
path: |
|
||||
out/*-arm64-win.exe
|
||||
out/*-arm64-mac.dmg
|
||||
out/*-arm64-linux.AppImage
|
||||
|
||||
- uses: actions/upload-artifact@v3
|
||||
if: ${{ env.CUT_RELEASE_PR == 'true' }}
|
||||
with:
|
||||
name: updater-test-x64-${{ matrix.platform }}
|
||||
path: |
|
||||
out/*-x64-win.exe
|
||||
out/*-x64-mac.dmg
|
||||
out/*-x86_64-linux.AppImage
|
||||
out/Zoo*.*
|
||||
out/latest*.yml
|
||||
|
||||
|
||||
publish-apps-release:
|
||||
@ -271,37 +214,17 @@ jobs:
|
||||
|
||||
- uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: out-arm64-win
|
||||
name: out-windows-2022
|
||||
path: out
|
||||
|
||||
- uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: out-x64-win
|
||||
name: out-macos-14
|
||||
path: out
|
||||
|
||||
- uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: out-arm64-mac
|
||||
path: out
|
||||
|
||||
- uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: out-x64-mac
|
||||
path: out
|
||||
|
||||
- uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: out-arm64-linux
|
||||
path: out
|
||||
|
||||
- uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: out-x64-linux
|
||||
path: out
|
||||
|
||||
- uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: out-yml
|
||||
name: out-ubuntu-22.04
|
||||
path: out
|
||||
|
||||
- name: Generate the download static endpoint
|
||||
|
22
README.md
22
README.md
@ -158,29 +158,11 @@ The PR may then serve as a place to discuss the human-readable changelog and ext
|
||||
|
||||
#### 3. Manually test artifacts from the Cut Release PR
|
||||
|
||||
##### Release builds
|
||||
|
||||
The release builds can be found under the `out-{platform}` zip, at the very bottom of the `build-publish-apps` summary page for each commit on this branch.
|
||||
The release builds can be find under the `artifact` zip, at the very bottom of the `ci` action page for each commit on this branch.
|
||||
|
||||
Manually test against this [list](https://github.com/KittyCAD/modeling-app/issues/3588) across Windows, MacOS, Linux and posting results as comments in the Cut Release PR.
|
||||
|
||||
##### Updater-test builds
|
||||
|
||||
The other `build-publish-apps` output in Cut Release PRs is `updater-test-{platform}`. As we don't have a way to test this fully automatically, we have a semi-automated process. For macOS, Windows, and Linux, download the corresponding updater-test artifact file, install the app, run it, expect an updater prompt to a dummy v0.255.255, install it and check that the app comes back at that version.
|
||||
|
||||
The only difference with these builds is that they point to a different update location on the release bucket, with this dummy v0.255.255 always available. This helps ensuring that the version we release will be able to update to the next one available.
|
||||
|
||||
If the prompt doesn't show up, start the app in command line to grab the electron-updater logs. This is likely an issue with the current build that needs addressing (or the updater-test location in the storage bucket).
|
||||
```
|
||||
# Windows (PowerShell)
|
||||
& 'C:\Program Files\Zoo Modeling App\Zoo Modeling App.exe'
|
||||
|
||||
# macOS
|
||||
/Applications/Zoo\ Modeling\ App.app/Contents/MacOS/Zoo\ Modeling\ App
|
||||
|
||||
# Linux
|
||||
./Zoo Modeling App-{version}-{arch}-linux.AppImage
|
||||
```
|
||||
The other `ci` output in Cut Release PRs is `updater-test`, because we don't have a way to test this fully automated, we have a semi-automated process. Download updater-test zip file, install the app, run it, expect an updater prompt to a dummy v0.99.99, install it and check that the app comes back at that version (on both macOS and Windows).
|
||||
|
||||
#### 4. Merge the Cut Release PR
|
||||
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 39 KiB After Width: | Height: | Size: 39 KiB |
@ -259,7 +259,7 @@ export const FileMachineProvider = ({
|
||||
// Refresh the route selected above because it's possible we're on
|
||||
// the same path on the navigate, which doesn't cause anything to
|
||||
// refresh, leaving a stale execution state.
|
||||
navigate(0)
|
||||
navigate('.')
|
||||
return {
|
||||
message: 'No more files in project, created main.kcl',
|
||||
}
|
||||
|
4
src/wasm-lib/Cargo.lock
generated
4
src/wasm-lib/Cargo.lock
generated
@ -1542,7 +1542,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "kcl-lib"
|
||||
version = "0.2.22"
|
||||
version = "0.2.21"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"approx 0.5.1",
|
||||
@ -1617,7 +1617,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "kcl-test-server"
|
||||
version = "0.1.14"
|
||||
version = "0.1.13"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"hyper 0.14.30",
|
||||
|
@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "kcl-test-server"
|
||||
description = "A test server for KCL"
|
||||
version = "0.1.14"
|
||||
version = "0.1.13"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "kcl-lib"
|
||||
description = "KittyCAD Language implementation and tools"
|
||||
version = "0.2.22"
|
||||
version = "0.2.21"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
repository = "https://github.com/KittyCAD/modeling-app"
|
||||
|
@ -13,6 +13,7 @@ use parse_display::{Display, FromStr};
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value as JValue;
|
||||
use sha2::{Digest as DigestTrait, Sha256};
|
||||
use tower_lsp::lsp_types::{
|
||||
CompletionItem, CompletionItemKind, DocumentSymbol, FoldingRange, FoldingRangeKind, Range as LspRange, SymbolKind,
|
||||
};
|
||||
@ -32,12 +33,12 @@ use crate::{
|
||||
};
|
||||
|
||||
mod condition;
|
||||
pub(crate) mod digest;
|
||||
pub(crate) mod execute;
|
||||
mod literal_value;
|
||||
mod none;
|
||||
|
||||
use digest::Digest;
|
||||
/// Position-independent digest of the AST node.
|
||||
pub type Digest = [u8; 32];
|
||||
|
||||
pub enum Definition<'a> {
|
||||
Variable(&'a VariableDeclarator),
|
||||
@ -58,7 +59,40 @@ pub struct Program {
|
||||
pub digest: Option<Digest>,
|
||||
}
|
||||
|
||||
macro_rules! compute_digest {
|
||||
(|$slf:ident, $hasher:ident| $body:block) => {
|
||||
/// Compute a digest over the AST node.
|
||||
pub fn compute_digest(&mut self) -> Digest {
|
||||
if let Some(node_digest) = self.digest {
|
||||
return node_digest;
|
||||
}
|
||||
|
||||
let mut $hasher = Sha256::new();
|
||||
|
||||
#[allow(unused_mut)]
|
||||
let mut $slf = self;
|
||||
|
||||
$hasher.update(std::any::type_name::<Self>());
|
||||
|
||||
$body
|
||||
|
||||
let node_digest: Digest = $hasher.finalize().into();
|
||||
$slf.digest = Some(node_digest);
|
||||
node_digest
|
||||
}
|
||||
};
|
||||
}
|
||||
pub(crate) use compute_digest;
|
||||
|
||||
impl Program {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.body.len().to_ne_bytes());
|
||||
for body_item in slf.body.iter_mut() {
|
||||
hasher.update(body_item.compute_digest());
|
||||
}
|
||||
hasher.update(slf.non_code_meta.compute_digest());
|
||||
});
|
||||
|
||||
/// Is the last body item an expression?
|
||||
pub fn ends_with_expr(&self) -> bool {
|
||||
let Some(ref last) = self.body.last() else {
|
||||
@ -456,6 +490,15 @@ pub enum BodyItem {
|
||||
}
|
||||
|
||||
impl BodyItem {
|
||||
pub fn compute_digest(&mut self) -> Digest {
|
||||
match self {
|
||||
BodyItem::ImportStatement(s) => s.compute_digest(),
|
||||
BodyItem::ExpressionStatement(es) => es.compute_digest(),
|
||||
BodyItem::VariableDeclaration(vs) => vs.compute_digest(),
|
||||
BodyItem::ReturnStatement(rs) => rs.compute_digest(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn start(&self) -> usize {
|
||||
match self {
|
||||
BodyItem::ImportStatement(stmt) => stmt.start(),
|
||||
@ -511,6 +554,30 @@ pub enum Expr {
|
||||
}
|
||||
|
||||
impl Expr {
|
||||
pub fn compute_digest(&mut self) -> Digest {
|
||||
match self {
|
||||
Expr::Literal(lit) => lit.compute_digest(),
|
||||
Expr::Identifier(id) => id.compute_digest(),
|
||||
Expr::TagDeclarator(tag) => tag.compute_digest(),
|
||||
Expr::BinaryExpression(be) => be.compute_digest(),
|
||||
Expr::FunctionExpression(fe) => fe.compute_digest(),
|
||||
Expr::CallExpression(ce) => ce.compute_digest(),
|
||||
Expr::PipeExpression(pe) => pe.compute_digest(),
|
||||
Expr::PipeSubstitution(ps) => ps.compute_digest(),
|
||||
Expr::ArrayExpression(ae) => ae.compute_digest(),
|
||||
Expr::ArrayRangeExpression(are) => are.compute_digest(),
|
||||
Expr::ObjectExpression(oe) => oe.compute_digest(),
|
||||
Expr::MemberExpression(me) => me.compute_digest(),
|
||||
Expr::UnaryExpression(ue) => ue.compute_digest(),
|
||||
Expr::IfExpression(e) => e.compute_digest(),
|
||||
Expr::None(_) => {
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.update(b"Value::None");
|
||||
hasher.finalize().into()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_lsp_folding_range(&self) -> Option<FoldingRange> {
|
||||
let recasted = self.recast(&FormatOptions::default(), 0, false);
|
||||
// If the code only has one line then we don't need to fold it.
|
||||
@ -734,6 +801,18 @@ impl From<&BinaryPart> for SourceRange {
|
||||
}
|
||||
|
||||
impl BinaryPart {
|
||||
pub fn compute_digest(&mut self) -> Digest {
|
||||
match self {
|
||||
BinaryPart::Literal(lit) => lit.compute_digest(),
|
||||
BinaryPart::Identifier(id) => id.compute_digest(),
|
||||
BinaryPart::BinaryExpression(be) => be.compute_digest(),
|
||||
BinaryPart::CallExpression(ce) => ce.compute_digest(),
|
||||
BinaryPart::UnaryExpression(ue) => ue.compute_digest(),
|
||||
BinaryPart::MemberExpression(me) => me.compute_digest(),
|
||||
BinaryPart::IfExpression(e) => e.compute_digest(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the constraint level.
|
||||
pub fn get_constraint_level(&self) -> ConstraintLevel {
|
||||
match self {
|
||||
@ -853,6 +932,29 @@ impl From<&NonCodeNode> for SourceRange {
|
||||
}
|
||||
|
||||
impl NonCodeNode {
|
||||
compute_digest!(|slf, hasher| {
|
||||
match &slf.value {
|
||||
NonCodeValue::Shebang { value } => {
|
||||
hasher.update(value);
|
||||
}
|
||||
NonCodeValue::InlineComment { value, style } => {
|
||||
hasher.update(value);
|
||||
hasher.update(style.digestable_id());
|
||||
}
|
||||
NonCodeValue::BlockComment { value, style } => {
|
||||
hasher.update(value);
|
||||
hasher.update(style.digestable_id());
|
||||
}
|
||||
NonCodeValue::NewLineBlockComment { value, style } => {
|
||||
hasher.update(value);
|
||||
hasher.update(style.digestable_id());
|
||||
}
|
||||
NonCodeValue::NewLine => {
|
||||
hasher.update(b"\r\n");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
pub fn contains(&self, pos: usize) -> bool {
|
||||
self.start <= pos && pos <= self.end
|
||||
}
|
||||
@ -1025,6 +1127,20 @@ impl<'de> Deserialize<'de> for NonCodeMeta {
|
||||
}
|
||||
|
||||
impl NonCodeMeta {
|
||||
compute_digest!(|slf, hasher| {
|
||||
let mut keys = slf.non_code_nodes.keys().copied().collect::<Vec<_>>();
|
||||
keys.sort();
|
||||
|
||||
for key in keys.into_iter() {
|
||||
hasher.update(key.to_ne_bytes());
|
||||
let nodes = slf.non_code_nodes.get_mut(&key).unwrap();
|
||||
hasher.update(nodes.len().to_ne_bytes());
|
||||
for node in nodes.iter_mut() {
|
||||
hasher.update(node.compute_digest());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
pub fn insert(&mut self, i: usize, new: NonCodeNode) {
|
||||
self.non_code_nodes.entry(i).or_default().push(new);
|
||||
}
|
||||
@ -1059,6 +1175,18 @@ pub struct ImportItem {
|
||||
impl_value_meta!(ImportItem);
|
||||
|
||||
impl ImportItem {
|
||||
compute_digest!(|slf, hasher| {
|
||||
let name = slf.name.name.as_bytes();
|
||||
hasher.update(name.len().to_ne_bytes());
|
||||
hasher.update(name);
|
||||
if let Some(alias) = &mut slf.alias {
|
||||
hasher.update([1]);
|
||||
hasher.update(alias.compute_digest());
|
||||
} else {
|
||||
hasher.update([0]);
|
||||
}
|
||||
});
|
||||
|
||||
pub fn identifier(&self) -> &str {
|
||||
match &self.alias {
|
||||
Some(alias) => &alias.name,
|
||||
@ -1111,6 +1239,15 @@ pub struct ImportStatement {
|
||||
impl_value_meta!(ImportStatement);
|
||||
|
||||
impl ImportStatement {
|
||||
compute_digest!(|slf, hasher| {
|
||||
for item in &mut slf.items {
|
||||
hasher.update(item.compute_digest());
|
||||
}
|
||||
let path = slf.path.as_bytes();
|
||||
hasher.update(path.len().to_ne_bytes());
|
||||
hasher.update(path);
|
||||
});
|
||||
|
||||
pub fn get_constraint_level(&self) -> ConstraintLevel {
|
||||
ConstraintLevel::Full {
|
||||
source_ranges: vec![self.into()],
|
||||
@ -1151,6 +1288,12 @@ pub struct ExpressionStatement {
|
||||
|
||||
impl_value_meta!(ExpressionStatement);
|
||||
|
||||
impl ExpressionStatement {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.expression.compute_digest());
|
||||
});
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, Bake)]
|
||||
#[databake(path = kcl_lib::ast::types)]
|
||||
#[ts(export)]
|
||||
@ -1185,6 +1328,15 @@ impl CallExpression {
|
||||
})
|
||||
}
|
||||
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.callee.compute_digest());
|
||||
hasher.update(slf.arguments.len().to_ne_bytes());
|
||||
for argument in slf.arguments.iter_mut() {
|
||||
hasher.update(argument.compute_digest());
|
||||
}
|
||||
hasher.update(if slf.optional { [1] } else { [0] });
|
||||
});
|
||||
|
||||
/// Is at least one argument the '%' i.e. the substitution operator?
|
||||
pub fn has_substitution_arg(&self) -> bool {
|
||||
self.arguments
|
||||
@ -1359,6 +1511,15 @@ impl From<&VariableDeclaration> for Vec<CompletionItem> {
|
||||
impl_value_meta!(VariableDeclaration);
|
||||
|
||||
impl VariableDeclaration {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.declarations.len().to_ne_bytes());
|
||||
for declarator in &mut slf.declarations {
|
||||
hasher.update(declarator.compute_digest());
|
||||
}
|
||||
hasher.update(slf.visibility.digestable_id());
|
||||
hasher.update(slf.kind.digestable_id());
|
||||
});
|
||||
|
||||
pub fn new(declarations: Vec<VariableDeclarator>, visibility: ItemVisibility, kind: VariableKind) -> Self {
|
||||
Self {
|
||||
start: 0,
|
||||
@ -1591,6 +1752,11 @@ impl VariableDeclarator {
|
||||
}
|
||||
}
|
||||
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.id.compute_digest());
|
||||
hasher.update(slf.init.compute_digest());
|
||||
});
|
||||
|
||||
pub fn get_constraint_level(&self) -> ConstraintLevel {
|
||||
self.init.get_constraint_level()
|
||||
}
|
||||
@ -1622,6 +1788,10 @@ impl Literal {
|
||||
}
|
||||
}
|
||||
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.value.digestable_id());
|
||||
});
|
||||
|
||||
/// Get the constraint level for this literal.
|
||||
/// Literals are always not constrained.
|
||||
pub fn get_constraint_level(&self) -> ConstraintLevel {
|
||||
@ -1677,6 +1847,12 @@ impl Identifier {
|
||||
}
|
||||
}
|
||||
|
||||
compute_digest!(|slf, hasher| {
|
||||
let name = slf.name.as_bytes();
|
||||
hasher.update(name.len().to_ne_bytes());
|
||||
hasher.update(name);
|
||||
});
|
||||
|
||||
/// Get the constraint level for this identifier.
|
||||
/// Identifier are always fully constrained.
|
||||
pub fn get_constraint_level(&self) -> ConstraintLevel {
|
||||
@ -1779,6 +1955,12 @@ impl TagDeclarator {
|
||||
}
|
||||
}
|
||||
|
||||
compute_digest!(|slf, hasher| {
|
||||
let name = slf.name.as_bytes();
|
||||
hasher.update(name.len().to_ne_bytes());
|
||||
hasher.update(name);
|
||||
});
|
||||
|
||||
/// Get the constraint level for this identifier.
|
||||
/// TagDeclarator are always fully constrained.
|
||||
pub fn get_constraint_level(&self) -> ConstraintLevel {
|
||||
@ -1834,6 +2016,10 @@ impl PipeSubstitution {
|
||||
digest: None,
|
||||
}
|
||||
}
|
||||
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(b"PipeSubstitution");
|
||||
});
|
||||
}
|
||||
|
||||
impl Default for PipeSubstitution {
|
||||
@ -1881,6 +2067,13 @@ impl ArrayExpression {
|
||||
}
|
||||
}
|
||||
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.elements.len().to_ne_bytes());
|
||||
for value in slf.elements.iter_mut() {
|
||||
hasher.update(value.compute_digest());
|
||||
}
|
||||
});
|
||||
|
||||
pub fn replace_value(&mut self, source_range: SourceRange, new_value: Expr) {
|
||||
for element in &mut self.elements {
|
||||
element.replace_value(source_range, new_value.clone());
|
||||
@ -1957,6 +2150,11 @@ impl ArrayRangeExpression {
|
||||
}
|
||||
}
|
||||
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.start_element.compute_digest());
|
||||
hasher.update(slf.end_element.compute_digest());
|
||||
});
|
||||
|
||||
pub fn replace_value(&mut self, source_range: SourceRange, new_value: Expr) {
|
||||
self.start_element.replace_value(source_range, new_value.clone());
|
||||
self.end_element.replace_value(source_range, new_value.clone());
|
||||
@ -2014,6 +2212,13 @@ impl ObjectExpression {
|
||||
}
|
||||
}
|
||||
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.properties.len().to_ne_bytes());
|
||||
for prop in slf.properties.iter_mut() {
|
||||
hasher.update(prop.compute_digest());
|
||||
}
|
||||
});
|
||||
|
||||
pub fn replace_value(&mut self, source_range: SourceRange, new_value: Expr) {
|
||||
for property in &mut self.properties {
|
||||
property.value.replace_value(source_range, new_value.clone());
|
||||
@ -2073,6 +2278,11 @@ pub struct ObjectProperty {
|
||||
impl_value_meta!(ObjectProperty);
|
||||
|
||||
impl ObjectProperty {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.key.compute_digest());
|
||||
hasher.update(slf.value.compute_digest());
|
||||
});
|
||||
|
||||
pub fn get_lsp_symbols(&self, code: &str) -> Vec<DocumentSymbol> {
|
||||
let source_range: SourceRange = self.clone().into();
|
||||
let inner_source_range: SourceRange = self.key.clone().into();
|
||||
@ -2112,6 +2322,13 @@ pub enum MemberObject {
|
||||
}
|
||||
|
||||
impl MemberObject {
|
||||
pub fn compute_digest(&mut self) -> Digest {
|
||||
match self {
|
||||
MemberObject::MemberExpression(me) => me.compute_digest(),
|
||||
MemberObject::Identifier(id) => id.compute_digest(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a hover value that includes the given character position.
|
||||
pub fn get_hover_value_for_position(&self, pos: usize, code: &str) -> Option<Hover> {
|
||||
match self {
|
||||
@ -2159,6 +2376,13 @@ pub enum LiteralIdentifier {
|
||||
}
|
||||
|
||||
impl LiteralIdentifier {
|
||||
pub fn compute_digest(&mut self) -> Digest {
|
||||
match self {
|
||||
LiteralIdentifier::Identifier(id) => id.compute_digest(),
|
||||
LiteralIdentifier::Literal(lit) => lit.compute_digest(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn start(&self) -> usize {
|
||||
match self {
|
||||
LiteralIdentifier::Identifier(identifier) => identifier.start,
|
||||
@ -2203,6 +2427,12 @@ pub struct MemberExpression {
|
||||
impl_value_meta!(MemberExpression);
|
||||
|
||||
impl MemberExpression {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.object.compute_digest());
|
||||
hasher.update(slf.property.compute_digest());
|
||||
hasher.update(if slf.computed { [1] } else { [0] });
|
||||
});
|
||||
|
||||
/// Get the constraint level for a member expression.
|
||||
/// This is always fully constrained.
|
||||
pub fn get_constraint_level(&self) -> ConstraintLevel {
|
||||
@ -2273,6 +2503,12 @@ impl BinaryExpression {
|
||||
}
|
||||
}
|
||||
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.operator.digestable_id());
|
||||
hasher.update(slf.left.compute_digest());
|
||||
hasher.update(slf.right.compute_digest());
|
||||
});
|
||||
|
||||
pub fn replace_value(&mut self, source_range: SourceRange, new_value: Expr) {
|
||||
self.left.replace_value(source_range, new_value.clone());
|
||||
self.right.replace_value(source_range, new_value);
|
||||
@ -2454,6 +2690,11 @@ impl UnaryExpression {
|
||||
}
|
||||
}
|
||||
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.operator.digestable_id());
|
||||
hasher.update(slf.argument.compute_digest());
|
||||
});
|
||||
|
||||
pub fn replace_value(&mut self, source_range: SourceRange, new_value: Expr) {
|
||||
self.argument.replace_value(source_range, new_value);
|
||||
}
|
||||
@ -2537,6 +2778,14 @@ impl PipeExpression {
|
||||
}
|
||||
}
|
||||
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.body.len().to_ne_bytes());
|
||||
for value in slf.body.iter_mut() {
|
||||
hasher.update(value.compute_digest());
|
||||
}
|
||||
hasher.update(slf.non_code_meta.compute_digest());
|
||||
});
|
||||
|
||||
pub fn replace_value(&mut self, source_range: SourceRange, new_value: Expr) {
|
||||
for value in &mut self.body {
|
||||
value.replace_value(source_range, new_value.clone());
|
||||
@ -2635,6 +2884,32 @@ pub enum FnArgType {
|
||||
},
|
||||
}
|
||||
|
||||
impl FnArgType {
|
||||
pub fn compute_digest(&mut self) -> Digest {
|
||||
let mut hasher = Sha256::new();
|
||||
|
||||
match self {
|
||||
FnArgType::Primitive(prim) => {
|
||||
hasher.update(b"FnArgType::Primitive");
|
||||
hasher.update(prim.digestable_id())
|
||||
}
|
||||
FnArgType::Array(prim) => {
|
||||
hasher.update(b"FnArgType::Array");
|
||||
hasher.update(prim.digestable_id())
|
||||
}
|
||||
FnArgType::Object { properties } => {
|
||||
hasher.update(b"FnArgType::Object");
|
||||
hasher.update(properties.len().to_ne_bytes());
|
||||
for prop in properties.iter_mut() {
|
||||
hasher.update(prop.compute_digest());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hasher.finalize().into()
|
||||
}
|
||||
}
|
||||
|
||||
/// Parameter of a KCL function.
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, ts_rs::TS, JsonSchema, Bake)]
|
||||
#[databake(path = kcl_lib::ast::types)]
|
||||
@ -2653,6 +2928,22 @@ pub struct Parameter {
|
||||
pub digest: Option<Digest>,
|
||||
}
|
||||
|
||||
impl Parameter {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.identifier.compute_digest());
|
||||
match &mut slf.type_ {
|
||||
Some(arg) => {
|
||||
hasher.update(b"Parameter::type_::Some");
|
||||
hasher.update(arg.compute_digest())
|
||||
}
|
||||
None => {
|
||||
hasher.update(b"Parameter::type_::None");
|
||||
}
|
||||
}
|
||||
hasher.update(if slf.optional { [1] } else { [0] })
|
||||
});
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, Bake)]
|
||||
#[databake(path = kcl_lib::ast::types)]
|
||||
#[ts(export)]
|
||||
@ -2687,6 +2978,23 @@ impl FunctionExpression {
|
||||
}
|
||||
}
|
||||
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.params.len().to_ne_bytes());
|
||||
for param in slf.params.iter_mut() {
|
||||
hasher.update(param.compute_digest());
|
||||
}
|
||||
hasher.update(slf.body.compute_digest());
|
||||
match &mut slf.return_type {
|
||||
Some(rt) => {
|
||||
hasher.update(b"FunctionExpression::return_type::Some");
|
||||
hasher.update(rt.compute_digest());
|
||||
}
|
||||
None => {
|
||||
hasher.update(b"FunctionExpression::return_type::None");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
pub fn required_and_optional_params(
|
||||
&self,
|
||||
) -> Result<(&[Parameter], &[Parameter]), RequiredParamAfterOptionalParam> {
|
||||
@ -2756,6 +3064,12 @@ pub struct ReturnStatement {
|
||||
|
||||
impl_value_meta!(ReturnStatement);
|
||||
|
||||
impl ReturnStatement {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.argument.compute_digest());
|
||||
});
|
||||
}
|
||||
|
||||
/// Describes information about a hover.
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
|
@ -1,6 +1,13 @@
|
||||
use crate::errors::KclError;
|
||||
use crate::executor::BodyType;
|
||||
use crate::executor::ExecState;
|
||||
use crate::executor::ExecutorContext;
|
||||
use crate::executor::KclValue;
|
||||
use crate::executor::Metadata;
|
||||
use crate::executor::SourceRange;
|
||||
use crate::executor::StatementKind;
|
||||
|
||||
use super::compute_digest;
|
||||
use super::impl_value_meta;
|
||||
use super::ConstraintLevel;
|
||||
use super::Hover;
|
||||
@ -8,6 +15,7 @@ use super::{Digest, Expr};
|
||||
use databake::*;
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sha2::{Digest as DigestTrait, Sha256};
|
||||
|
||||
// TODO: This should be its own type, similar to Program,
|
||||
// but guaranteed to have an Expression as its final item.
|
||||
@ -48,6 +56,14 @@ impl_value_meta!(IfExpression);
|
||||
impl_value_meta!(ElseIf);
|
||||
|
||||
impl IfExpression {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.cond.compute_digest());
|
||||
hasher.update(slf.then_val.compute_digest());
|
||||
for else_if in &mut slf.else_ifs {
|
||||
hasher.update(else_if.compute_digest());
|
||||
}
|
||||
hasher.update(slf.final_else.compute_digest());
|
||||
});
|
||||
fn source_ranges(&self) -> Vec<SourceRange> {
|
||||
vec![SourceRange::from(self)]
|
||||
}
|
||||
@ -85,12 +101,63 @@ impl From<&ElseIf> for Metadata {
|
||||
}
|
||||
|
||||
impl ElseIf {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.cond.compute_digest());
|
||||
hasher.update(slf.then_val.compute_digest());
|
||||
});
|
||||
#[allow(dead_code)]
|
||||
fn source_ranges(&self) -> Vec<SourceRange> {
|
||||
vec![SourceRange([self.start, self.end])]
|
||||
}
|
||||
}
|
||||
|
||||
// Execution
|
||||
|
||||
impl IfExpression {
|
||||
#[async_recursion::async_recursion]
|
||||
pub async fn get_result(&self, exec_state: &mut ExecState, ctx: &ExecutorContext) -> Result<KclValue, KclError> {
|
||||
// Check the `if` branch.
|
||||
let cond = ctx
|
||||
.execute_expr(&self.cond, exec_state, &Metadata::from(self), StatementKind::Expression)
|
||||
.await?
|
||||
.get_bool()?;
|
||||
if cond {
|
||||
let block_result = ctx.inner_execute(&self.then_val, exec_state, BodyType::Block).await?;
|
||||
// Block must end in an expression, so this has to be Some.
|
||||
// Enforced by the parser.
|
||||
// See https://github.com/KittyCAD/modeling-app/issues/4015
|
||||
return Ok(block_result.unwrap());
|
||||
}
|
||||
|
||||
// Check any `else if` branches.
|
||||
for else_if in &self.else_ifs {
|
||||
let cond = ctx
|
||||
.execute_expr(
|
||||
&else_if.cond,
|
||||
exec_state,
|
||||
&Metadata::from(self),
|
||||
StatementKind::Expression,
|
||||
)
|
||||
.await?
|
||||
.get_bool()?;
|
||||
if cond {
|
||||
let block_result = ctx
|
||||
.inner_execute(&else_if.then_val, exec_state, BodyType::Block)
|
||||
.await?;
|
||||
// Block must end in an expression, so this has to be Some.
|
||||
// Enforced by the parser.
|
||||
// See https://github.com/KittyCAD/modeling-app/issues/4015
|
||||
return Ok(block_result.unwrap());
|
||||
}
|
||||
}
|
||||
|
||||
// Run the final `else` branch.
|
||||
ctx.inner_execute(&self.final_else, exec_state, BodyType::Block)
|
||||
.await
|
||||
.map(|expr| expr.unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
// IDE support and refactors
|
||||
|
||||
impl IfExpression {
|
||||
@ -141,3 +208,8 @@ impl ElseIf {
|
||||
self.then_val.rename_identifiers(old_name, new_name);
|
||||
}
|
||||
}
|
||||
|
||||
// Linting
|
||||
|
||||
impl IfExpression {}
|
||||
impl ElseIf {}
|
||||
|
@ -1,391 +0,0 @@
|
||||
use sha2::{Digest as DigestTrait, Sha256};
|
||||
|
||||
use super::{
|
||||
ArrayExpression, ArrayRangeExpression, BinaryExpression, BinaryPart, BodyItem, CallExpression, ElseIf, Expr,
|
||||
ExpressionStatement, FnArgType, FunctionExpression, Identifier, IfExpression, ImportItem, ImportStatement, Literal,
|
||||
LiteralIdentifier, MemberExpression, MemberObject, NonCodeMeta, NonCodeNode, NonCodeValue, ObjectExpression,
|
||||
ObjectProperty, Parameter, PipeExpression, PipeSubstitution, Program, ReturnStatement, TagDeclarator,
|
||||
UnaryExpression, VariableDeclaration, VariableDeclarator,
|
||||
};
|
||||
|
||||
/// Position-independent digest of the AST node.
|
||||
pub type Digest = [u8; 32];
|
||||
|
||||
macro_rules! compute_digest {
|
||||
(|$slf:ident, $hasher:ident| $body:block) => {
|
||||
/// Compute a digest over the AST node.
|
||||
pub fn compute_digest(&mut self) -> Digest {
|
||||
if let Some(node_digest) = self.digest {
|
||||
return node_digest;
|
||||
}
|
||||
|
||||
let mut $hasher = Sha256::new();
|
||||
|
||||
#[allow(unused_mut)]
|
||||
let mut $slf = self;
|
||||
|
||||
$hasher.update(std::any::type_name::<Self>());
|
||||
|
||||
$body
|
||||
|
||||
let node_digest: Digest = $hasher.finalize().into();
|
||||
$slf.digest = Some(node_digest);
|
||||
node_digest
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl ImportItem {
|
||||
compute_digest!(|slf, hasher| {
|
||||
let name = slf.name.name.as_bytes();
|
||||
hasher.update(name.len().to_ne_bytes());
|
||||
hasher.update(name);
|
||||
if let Some(alias) = &mut slf.alias {
|
||||
hasher.update([1]);
|
||||
hasher.update(alias.compute_digest());
|
||||
} else {
|
||||
hasher.update([0]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
impl ImportStatement {
|
||||
compute_digest!(|slf, hasher| {
|
||||
for item in &mut slf.items {
|
||||
hasher.update(item.compute_digest());
|
||||
}
|
||||
let path = slf.path.as_bytes();
|
||||
hasher.update(path.len().to_ne_bytes());
|
||||
hasher.update(path);
|
||||
});
|
||||
}
|
||||
|
||||
impl Program {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.body.len().to_ne_bytes());
|
||||
for body_item in slf.body.iter_mut() {
|
||||
hasher.update(body_item.compute_digest());
|
||||
}
|
||||
hasher.update(slf.non_code_meta.compute_digest());
|
||||
});
|
||||
}
|
||||
|
||||
impl BodyItem {
|
||||
pub fn compute_digest(&mut self) -> Digest {
|
||||
match self {
|
||||
BodyItem::ImportStatement(s) => s.compute_digest(),
|
||||
BodyItem::ExpressionStatement(es) => es.compute_digest(),
|
||||
BodyItem::VariableDeclaration(vs) => vs.compute_digest(),
|
||||
BodyItem::ReturnStatement(rs) => rs.compute_digest(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Expr {
|
||||
pub fn compute_digest(&mut self) -> Digest {
|
||||
match self {
|
||||
Expr::Literal(lit) => lit.compute_digest(),
|
||||
Expr::Identifier(id) => id.compute_digest(),
|
||||
Expr::TagDeclarator(tag) => tag.compute_digest(),
|
||||
Expr::BinaryExpression(be) => be.compute_digest(),
|
||||
Expr::FunctionExpression(fe) => fe.compute_digest(),
|
||||
Expr::CallExpression(ce) => ce.compute_digest(),
|
||||
Expr::PipeExpression(pe) => pe.compute_digest(),
|
||||
Expr::PipeSubstitution(ps) => ps.compute_digest(),
|
||||
Expr::ArrayExpression(ae) => ae.compute_digest(),
|
||||
Expr::ArrayRangeExpression(are) => are.compute_digest(),
|
||||
Expr::ObjectExpression(oe) => oe.compute_digest(),
|
||||
Expr::MemberExpression(me) => me.compute_digest(),
|
||||
Expr::UnaryExpression(ue) => ue.compute_digest(),
|
||||
Expr::IfExpression(e) => e.compute_digest(),
|
||||
Expr::None(_) => {
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.update(b"Value::None");
|
||||
hasher.finalize().into()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl BinaryPart {
|
||||
pub fn compute_digest(&mut self) -> Digest {
|
||||
match self {
|
||||
BinaryPart::Literal(lit) => lit.compute_digest(),
|
||||
BinaryPart::Identifier(id) => id.compute_digest(),
|
||||
BinaryPart::BinaryExpression(be) => be.compute_digest(),
|
||||
BinaryPart::CallExpression(ce) => ce.compute_digest(),
|
||||
BinaryPart::UnaryExpression(ue) => ue.compute_digest(),
|
||||
BinaryPart::MemberExpression(me) => me.compute_digest(),
|
||||
BinaryPart::IfExpression(e) => e.compute_digest(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl MemberObject {
|
||||
pub fn compute_digest(&mut self) -> Digest {
|
||||
match self {
|
||||
MemberObject::MemberExpression(me) => me.compute_digest(),
|
||||
MemberObject::Identifier(id) => id.compute_digest(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl LiteralIdentifier {
|
||||
pub fn compute_digest(&mut self) -> Digest {
|
||||
match self {
|
||||
LiteralIdentifier::Identifier(id) => id.compute_digest(),
|
||||
LiteralIdentifier::Literal(lit) => lit.compute_digest(),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl FnArgType {
|
||||
pub fn compute_digest(&mut self) -> Digest {
|
||||
let mut hasher = Sha256::new();
|
||||
|
||||
match self {
|
||||
FnArgType::Primitive(prim) => {
|
||||
hasher.update(b"FnArgType::Primitive");
|
||||
hasher.update(prim.digestable_id())
|
||||
}
|
||||
FnArgType::Array(prim) => {
|
||||
hasher.update(b"FnArgType::Array");
|
||||
hasher.update(prim.digestable_id())
|
||||
}
|
||||
FnArgType::Object { properties } => {
|
||||
hasher.update(b"FnArgType::Object");
|
||||
hasher.update(properties.len().to_ne_bytes());
|
||||
for prop in properties.iter_mut() {
|
||||
hasher.update(prop.compute_digest());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hasher.finalize().into()
|
||||
}
|
||||
}
|
||||
impl Parameter {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.identifier.compute_digest());
|
||||
match &mut slf.type_ {
|
||||
Some(arg) => {
|
||||
hasher.update(b"Parameter::type_::Some");
|
||||
hasher.update(arg.compute_digest())
|
||||
}
|
||||
None => {
|
||||
hasher.update(b"Parameter::type_::None");
|
||||
}
|
||||
}
|
||||
hasher.update(if slf.optional { [1] } else { [0] })
|
||||
});
|
||||
}
|
||||
|
||||
impl FunctionExpression {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.params.len().to_ne_bytes());
|
||||
for param in slf.params.iter_mut() {
|
||||
hasher.update(param.compute_digest());
|
||||
}
|
||||
hasher.update(slf.body.compute_digest());
|
||||
match &mut slf.return_type {
|
||||
Some(rt) => {
|
||||
hasher.update(b"FunctionExpression::return_type::Some");
|
||||
hasher.update(rt.compute_digest());
|
||||
}
|
||||
None => {
|
||||
hasher.update(b"FunctionExpression::return_type::None");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
impl ReturnStatement {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.argument.compute_digest());
|
||||
});
|
||||
}
|
||||
|
||||
impl NonCodeNode {
|
||||
compute_digest!(|slf, hasher| {
|
||||
match &slf.value {
|
||||
NonCodeValue::Shebang { value } => {
|
||||
hasher.update(value);
|
||||
}
|
||||
NonCodeValue::InlineComment { value, style } => {
|
||||
hasher.update(value);
|
||||
hasher.update(style.digestable_id());
|
||||
}
|
||||
NonCodeValue::BlockComment { value, style } => {
|
||||
hasher.update(value);
|
||||
hasher.update(style.digestable_id());
|
||||
}
|
||||
NonCodeValue::NewLineBlockComment { value, style } => {
|
||||
hasher.update(value);
|
||||
hasher.update(style.digestable_id());
|
||||
}
|
||||
NonCodeValue::NewLine => {
|
||||
hasher.update(b"\r\n");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
impl NonCodeMeta {
|
||||
compute_digest!(|slf, hasher| {
|
||||
let mut keys = slf.non_code_nodes.keys().copied().collect::<Vec<_>>();
|
||||
keys.sort();
|
||||
|
||||
for key in keys.into_iter() {
|
||||
hasher.update(key.to_ne_bytes());
|
||||
let nodes = slf.non_code_nodes.get_mut(&key).unwrap();
|
||||
hasher.update(nodes.len().to_ne_bytes());
|
||||
for node in nodes.iter_mut() {
|
||||
hasher.update(node.compute_digest());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
impl ExpressionStatement {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.expression.compute_digest());
|
||||
});
|
||||
}
|
||||
|
||||
impl VariableDeclaration {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.declarations.len().to_ne_bytes());
|
||||
for declarator in &mut slf.declarations {
|
||||
hasher.update(declarator.compute_digest());
|
||||
}
|
||||
hasher.update(slf.visibility.digestable_id());
|
||||
hasher.update(slf.kind.digestable_id());
|
||||
});
|
||||
}
|
||||
|
||||
impl VariableDeclarator {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.id.compute_digest());
|
||||
hasher.update(slf.init.compute_digest());
|
||||
});
|
||||
}
|
||||
|
||||
impl Literal {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.value.digestable_id());
|
||||
});
|
||||
}
|
||||
|
||||
impl Identifier {
|
||||
compute_digest!(|slf, hasher| {
|
||||
let name = slf.name.as_bytes();
|
||||
hasher.update(name.len().to_ne_bytes());
|
||||
hasher.update(name);
|
||||
});
|
||||
}
|
||||
|
||||
impl TagDeclarator {
|
||||
compute_digest!(|slf, hasher| {
|
||||
let name = slf.name.as_bytes();
|
||||
hasher.update(name.len().to_ne_bytes());
|
||||
hasher.update(name);
|
||||
});
|
||||
}
|
||||
|
||||
impl PipeSubstitution {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(b"PipeSubstitution");
|
||||
});
|
||||
}
|
||||
|
||||
impl ArrayExpression {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.elements.len().to_ne_bytes());
|
||||
for value in slf.elements.iter_mut() {
|
||||
hasher.update(value.compute_digest());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
impl ArrayRangeExpression {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.start_element.compute_digest());
|
||||
hasher.update(slf.end_element.compute_digest());
|
||||
});
|
||||
}
|
||||
|
||||
impl ObjectExpression {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.properties.len().to_ne_bytes());
|
||||
for prop in slf.properties.iter_mut() {
|
||||
hasher.update(prop.compute_digest());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
impl ObjectProperty {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.key.compute_digest());
|
||||
hasher.update(slf.value.compute_digest());
|
||||
});
|
||||
}
|
||||
|
||||
impl MemberExpression {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.object.compute_digest());
|
||||
hasher.update(slf.property.compute_digest());
|
||||
hasher.update(if slf.computed { [1] } else { [0] });
|
||||
});
|
||||
}
|
||||
|
||||
impl BinaryExpression {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.operator.digestable_id());
|
||||
hasher.update(slf.left.compute_digest());
|
||||
hasher.update(slf.right.compute_digest());
|
||||
});
|
||||
}
|
||||
|
||||
impl UnaryExpression {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.operator.digestable_id());
|
||||
hasher.update(slf.argument.compute_digest());
|
||||
});
|
||||
}
|
||||
|
||||
impl PipeExpression {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.body.len().to_ne_bytes());
|
||||
for value in slf.body.iter_mut() {
|
||||
hasher.update(value.compute_digest());
|
||||
}
|
||||
hasher.update(slf.non_code_meta.compute_digest());
|
||||
});
|
||||
}
|
||||
|
||||
impl CallExpression {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.callee.compute_digest());
|
||||
hasher.update(slf.arguments.len().to_ne_bytes());
|
||||
for argument in slf.arguments.iter_mut() {
|
||||
hasher.update(argument.compute_digest());
|
||||
}
|
||||
hasher.update(if slf.optional { [1] } else { [0] });
|
||||
});
|
||||
}
|
||||
|
||||
impl IfExpression {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.cond.compute_digest());
|
||||
hasher.update(slf.then_val.compute_digest());
|
||||
for else_if in &mut slf.else_ifs {
|
||||
hasher.update(else_if.compute_digest());
|
||||
}
|
||||
hasher.update(slf.final_else.compute_digest());
|
||||
});
|
||||
}
|
||||
impl ElseIf {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.cond.compute_digest());
|
||||
hasher.update(slf.then_val.compute_digest());
|
||||
});
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
use super::{
|
||||
human_friendly_type, ArrayExpression, ArrayRangeExpression, BinaryExpression, BinaryOperator, BinaryPart,
|
||||
CallExpression, Expr, IfExpression, LiteralIdentifier, LiteralValue, MemberExpression, MemberObject,
|
||||
ObjectExpression, TagDeclarator, UnaryExpression, UnaryOperator,
|
||||
CallExpression, Expr, LiteralIdentifier, LiteralValue, MemberExpression, MemberObject, ObjectExpression,
|
||||
TagDeclarator, UnaryExpression, UnaryOperator,
|
||||
};
|
||||
use crate::{
|
||||
errors::{KclError, KclErrorDetails},
|
||||
@ -738,48 +738,3 @@ pub fn json_as_bool(j: &serde_json::Value) -> Option<bool> {
|
||||
JValue::Object(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
impl IfExpression {
|
||||
#[async_recursion]
|
||||
pub async fn get_result(&self, exec_state: &mut ExecState, ctx: &ExecutorContext) -> Result<KclValue, KclError> {
|
||||
// Check the `if` branch.
|
||||
let cond = ctx
|
||||
.execute_expr(&self.cond, exec_state, &Metadata::from(self), StatementKind::Expression)
|
||||
.await?
|
||||
.get_bool()?;
|
||||
if cond {
|
||||
let block_result = ctx.inner_execute(&self.then_val, exec_state, BodyType::Block).await?;
|
||||
// Block must end in an expression, so this has to be Some.
|
||||
// Enforced by the parser.
|
||||
// See https://github.com/KittyCAD/modeling-app/issues/4015
|
||||
return Ok(block_result.unwrap());
|
||||
}
|
||||
|
||||
// Check any `else if` branches.
|
||||
for else_if in &self.else_ifs {
|
||||
let cond = ctx
|
||||
.execute_expr(
|
||||
&else_if.cond,
|
||||
exec_state,
|
||||
&Metadata::from(self),
|
||||
StatementKind::Expression,
|
||||
)
|
||||
.await?
|
||||
.get_bool()?;
|
||||
if cond {
|
||||
let block_result = ctx
|
||||
.inner_execute(&else_if.then_val, exec_state, BodyType::Block)
|
||||
.await?;
|
||||
// Block must end in an expression, so this has to be Some.
|
||||
// Enforced by the parser.
|
||||
// See https://github.com/KittyCAD/modeling-app/issues/4015
|
||||
return Ok(block_result.unwrap());
|
||||
}
|
||||
}
|
||||
|
||||
// Run the final `else` branch.
|
||||
ctx.inner_execute(&self.final_else, exec_state, BodyType::Block)
|
||||
.await
|
||||
.map(|expr| expr.unwrap())
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user