quantified-uncertainty / squiggle

An estimation language
https://squiggle-language.com
MIT License
148 stars 22 forks source link

Serialize AST with normalization #3271

Closed berekuk closed 3 weeks ago

berekuk commented 1 month ago

This PR implements the proper serialization of AST - the part that was missing from #3158.

AST is already JSON-compatible, so in #3158 I didn't normalize it. That could cause N^2 amount of JSON when we serialized expressions.

Pseudo-code example:

expression: {
  type: "Call",
  fn: ...,
  arg1: { // this is a nested expression
    ...,
    ast: ast1, // this is AST for the nested expression
  },
  arg2: {
    ...,
    ast: ast2,
  },
  ast: { // this is AST for the outer expression
    type: "Call",
    arg1: ast1, // as you can see, ast1 is duplicated
    arg2: ast2,
  }

This branch is done on top of #3268, for merging convenience.

PS: The reduction of expression-related data in the produced JSON bundle, in case of GUCEM codebase, is at least 2x (but might be 5x, hard to tell exactly).

changeset-bot[bot] commented 1 month ago

🦋 Changeset detected

Latest commit: 8a7332b4b0246cf0aea39cfe0a01775dff84e8e3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages | Name | Type | | ----------------------------------- | ----- | | @quri/squiggle-lang | Patch | | @quri/squiggle-components | Patch | | @quri/prettier-plugin-squiggle | Patch | | @quri/versioned-squiggle-components | Patch | | vscode-squiggle | Patch | | @quri/squiggle-textmate-grammar | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

vercel[bot] commented 1 month ago

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

4 Ignored Deployments | Name | Status | Preview | Updated (UTC) | | :--- | :----- | :------ | :------ | | **quri-hub** | ⬜️ Ignored ([Inspect](https://vercel.com/quantified-uncertainty/quri-hub/Hdm6Rr5AasTvN5PLtpyWSeC3a5Uj)) | [Visit Preview](https://quri-hub-git-serialize-ast-quantified-uncertainty.vercel.app) | May 21, 2024 3:22pm | | **quri-ui** | ⬜️ Ignored ([Inspect](https://vercel.com/quantified-uncertainty/quri-ui/AHkdgmcR8pqxm7WPu4PZtyjR5b61)) | [Visit Preview](https://quri-ui-git-serialize-ast-quantified-uncertainty.vercel.app) | May 21, 2024 3:22pm | | **squiggle-components** | ⬜️ Ignored ([Inspect](https://vercel.com/quantified-uncertainty/squiggle-components/3pd7F4bYuQbYUQdTXbS694Drqi9x)) | [Visit Preview](https://squiggle-components-git-serialize-ast-quantified-uncertainty.vercel.app) | May 21, 2024 3:22pm | | **squiggle-website** | ⬜️ Ignored ([Inspect](https://vercel.com/quantified-uncertainty/squiggle-website/3S3GgLVM6smjRe852VcqKY5gAKdW)) | [Visit Preview](https://squiggle-website-git-serialize-ast-quantified-uncertainty.vercel.app) | May 21, 2024 3:22pm |