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

feat(hog): importing modules in hog #25796

Merged
merged 26 commits into from
Oct 25, 2024
Merged

feat(hog): importing modules in hog #25796

merged 26 commits into from
Oct 25, 2024

Conversation

mariusandra
Copy link
Collaborator

@mariusandra mariusandra commented Oct 24, 2024

Problem

Splitting up #25719

  • PR 2 - hog work
    • Add a system to synchronously import bytecode/files/code/functions in Hog
    • Pass loaded code around in the vmState
    • Tests
    • Backport to Python HogVM
    • Release new version

Changes

  • Instead of passing bytecode to the HogVM, you can now pass an object of bytecodes ({filename: {bytecode, globals}}), and import them with import('filename') from your code.
  • Whatever is returned at the end of the script is the return value of import()
  • The default bytecode is root.
  • In TS you can either pass in an object of bytecodes, or use the new importBytecode: (module: string) => BytecodeEntry callback option to dynamically load them.
  • In Python you must pass in all the bytecodes at the start. We can easily extend this to support dynamic imports if ever relevant.

Code like this works now:

ret = lambda string: {"bytecode": ["_H", 1, op.STRING, string, op.RETURN]}
call = lambda chunk: {"bytecode": ["_H", 1, op.STRING, chunk, op.CALL_GLOBAL, "import", 1, op.RETURN]}
res = execute_bytecode(
    {
        "root": call("code2"),
        "code2": call("code3"),
        "code3": call("code4"),
        "code4": call("code5"),
        "code5": ret("tomato"),
    }
)
assert res.result == "tomato"

This will be used in the messaging product to call the right sendEmail function.

How did you test this code?

Updated/added tests.

@mariusandra mariusandra marked this pull request as ready for review October 25, 2024 07:48
Copy link
Contributor

github-actions bot commented Oct 25, 2024

Size Change: 0 B

Total Size: 1.15 MB

ℹ️ View Unchanged
Filename Size
frontend/dist/toolbar.js 1.15 MB

compressed-size-action

@mariusandra mariusandra requested a review from MarconLP October 25, 2024 09:56
@PostHog PostHog deleted a comment from posthog-bot Oct 25, 2024
@PostHog PostHog deleted a comment from posthog-bot Oct 25, 2024
@PostHog PostHog deleted a comment from posthog-bot Oct 25, 2024
@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

3 snapshot changes in total. 0 added, 3 modified, 0 deleted:

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@mariusandra mariusandra enabled auto-merge (squash) October 25, 2024 10:58
@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

3 snapshot changes in total. 0 added, 3 modified, 0 deleted:

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

3 snapshot changes in total. 0 added, 3 modified, 0 deleted:

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

2 snapshot changes in total. 0 added, 2 modified, 0 deleted:

  • chromium: 0 added, 2 modified, 0 deleted (diff for shard 1)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@mariusandra mariusandra merged commit c09b1de into master Oct 25, 2024
94 checks passed
@mariusandra mariusandra deleted the messaging-part-2 branch October 25, 2024 12:21
timgl pushed a commit that referenced this pull request Oct 25, 2024
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
@mariusandra mariusandra mentioned this pull request Oct 25, 2024
42 tasks
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.

3 participants