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(hydroflow_plus, stageleft)!: allow cluster self ID to be referenced as a global constant #1574

Merged
merged 1 commit into from
Nov 21, 2024

Conversation

shadaj
Copy link
Member

@shadaj shadaj commented Nov 19, 2024

This eliminates the need to store cluster.self_id() in a local variable first, instead you can directly reference CLUSTER_SELF_ID.

Stack created with Sapling. Best reviewed with ReviewStack.

Copy link

cloudflare-workers-and-pages bot commented Nov 19, 2024

Deploying hydroflow with  Cloudflare Pages  Cloudflare Pages

Latest commit: a865b44
Status: ✅  Deploy successful!
Preview URL: https://5e5014c4.hydroflow.pages.dev
Branch Preview URL: https://pr1574.hydroflow.pages.dev

View logs

…ced as a global constant

This eliminates the need to store `cluster.self_id()` in a local variable first, instead you can directly reference `CLUSTER_SELF_ID`.
@shadaj
Copy link
Member Author

shadaj commented Nov 21, 2024

Guide for review. The first big change is to stageleft, where we create a richer version of Quoted that takes a Ctx type parameter. The idea is that Ctx captures some metadata about where the quoted snippet will be spliced, which can be used to augment how free variables are made available inside the quoted snippet.

In Hydroflow+, the context for UDFs is the location for the stream, so this allows us to have a general global CLUSTER_SELF_ID value which when used as a free variable will return the appropriate ClusterId based on the provided context. This preserves the type safety guarantees, but avoids needing to call cluster.self_id(). In fact, this API was previously unsafe, since you could call c1.self_id() and reference that in a UDF on c2, which would result in malformed generated code. Now, because we rely on the context, we know that the spliced free variable will always be well-formed.

Copy link
Member

@MingweiSamuel MingweiSamuel left a comment

Choose a reason for hiding this comment

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

Is CLUSTER_SELF_ID just a magic name? In the future probably best to namespace it to something, ctx.CLUSTER_SELF_ID, if/when we add other magic names

stageleft/src/runtime_support.rs Show resolved Hide resolved
@shadaj
Copy link
Member Author

shadaj commented Nov 21, 2024

Is CLUSTER_SELF_ID just a magic name? In the future probably best to namespace it to something, ctx.CLUSTER_SELF_ID, if/when we add other magic names

Ah no, it's actually defined as a const CLUSTER_SELF_ID in the cluster module!

@shadaj shadaj merged commit a93a5e5 into main Nov 21, 2024
29 checks passed
@shadaj shadaj deleted the pr1574 branch November 21, 2024 20:28
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.

2 participants