Skip to content

feat: first-class RT-safe callable contracts for function pointers - #1310

Merged
godofecht merged 13 commits into
mainfrom
feat-rt-safe-indirect-calls-2191090288977208181
Oct 4, 2026
Merged

godofecht merged 13 commits into
mainfrom
feat-rt-safe-indirect-calls-2191090288977208181

Conversation

@godofecht

Copy link
Copy Markdown
Contributor

Implements the requested capability to add a compile-time callable contract that lets the checker prove that an indirect callable is callback-safe. This implements the contract for function pointers via the effect row, leaving closures and trait methods out of scope for this PR.

  • Modified sem_check.flow and typecheck.flow to understand rt_safe on function pointer types.
  • Extended the model to enforce the safety graph on binding.
  • Fixed the effect row parser skip behavior for rt_safe.
  • Added end-to-end tests inside tests/lang.

PR created automatically by Jules for task 2191090288977208181 started by @godofecht

@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

google-labs-jules Bot and others added 2 commits October 3, 2026 21:55
Adds the ability to declare an `rt_safe` contract on function pointer types
using the effect row syntax (e.g., `(i32) -> i32 with rt_safe`).
The semantic checker enforces that calls through such pointers do not emit
an `__unresolved_dynamic_call` failure on an RT-safe path, and binding
a function to an `rt_safe` function pointer type verifies its call graph.

Part of #766

Co-authored-by: godofecht <[email protected]>
@cursor
cursor Bot force-pushed the feat-rt-safe-indirect-calls-2191090288977208181 branch from a7e8604 to 9a2e7a3 Compare October 3, 2026 22:00
godofecht and others added 11 commits October 4, 2026 00:21
Resolve bootstrap binary conflict by taking current main; the generated C
will be regenerated after the remaining compiler/src rt_safe fixes.

Co-authored-by: Abhishek Shivakumar <[email protected]>
`effect` is a reserved word and cannot be used as a parameter name.
Rename it to `eff_name` so flowc can compile compiler/src.

Co-authored-by: Abhishek Shivakumar <[email protected]>
Fixed-point emit after merging current main and renaming the reserved
`effect` parameter so compiler/src compiles under flowc.

Co-authored-by: Abhishek Shivakumar <[email protected]>
Treat a function-typed variable without an `rt_safe` contract as an
unresolved dynamic call. Move compile-fail cases to typecheck_rules
because tests/lang cannot express expected type errors.

Co-authored-by: Abhishek Shivakumar <[email protected]>
tests/lang/test_typecheck_overload_integration.flow imports
compiler/src/typecheck.flow, so its recorded MLIR digest changes with
the rt_safe contract checks.

Co-authored-by: Abhishek Shivakumar <[email protected]>
…-calls-2191090288977208181

Co-authored-by: Abhishek Shivakumar <[email protected]>
@godofecht
godofecht merged commit 5d97890 into main Oct 4, 2026
37 checks passed
cursor Bot pushed a commit that referenced this pull request Oct 4, 2026
Include first-class RT-safe callable contracts from #1310 (5d97890)
while keeping AST_GPU_FRAME parser/typecheck. Take main's bootstrap C
so it can be regenerated from the merged compiler/src.

Co-authored-by: Abhishek Shivakumar <[email protected]>
cursor Bot pushed a commit that referenced this pull request Oct 4, 2026
Self-emit from the merged compiler/src until the C reaches a fixed
point at gen2 so bootstrap_from_c.sh --verify matches AST_GPU_FRAME
and the #1310 rt_safe callable-contract work.

Co-authored-by: Abhishek Shivakumar <[email protected]>
cursor Bot pushed a commit that referenced this pull request Oct 4, 2026
tests/lang/test_typecheck_overload_integration.flow imports
compiler/src/typecheck.flow, so its normalized MLIR digest changes
when AST_GPU_FRAME and the #1310 rt_safe row checks sit together.
Update that one corpus entry only.

Co-authored-by: Abhishek Shivakumar <[email protected]>
godofecht added a commit that referenced this pull request Oct 4, 2026
* feat(gpu): Add parsing support for `gpu frame` AST block

This PR adds the `AST_GPU_FRAME` node to the Flow compiler's AST and implements parsing for `gpu frame { ... }` blocks in the `flowc` parser. The blocks are correctly passed through to the type checker to resolve statements within the frame block. This forms the foundation for representing render and compute passes natively in Flow, allowing multi-pass GPU programs to execute without host-side choreography.

Part of #812

Co-authored-by: godofecht <[email protected]>

* fix: regenerate bootstrap C after gpu frame AST rebase

Co-authored-by: Abhishek Shivakumar <[email protected]>

* fix: regenerate bootstrap C after gpu frame AST merge

Self-emit from the merged compiler/src until the C reaches a fixed
point at gen2 so bootstrap_from_c.sh --verify matches AST_GPU_FRAME.

Co-authored-by: Abhishek Shivakumar <[email protected]>

* fix: update MLIR corpus goldens for AST_GPU_FRAME

Programs that import compiler/src now include the gpu-frame AST node
and parser, so their normalized MLIR digests change. Update those 28
corpus entries only.

Co-authored-by: Abhishek Shivakumar <[email protected]>

* fix: regenerate bootstrap C after gpu frame + rt_safe merge

Self-emit from the merged compiler/src until the C reaches a fixed
point at gen2 so bootstrap_from_c.sh --verify matches AST_GPU_FRAME
and the #1310 rt_safe callable-contract work.

Co-authored-by: Abhishek Shivakumar <[email protected]>

* fix: update MLIR corpus digest after gpu frame + rt_safe merge

tests/lang/test_typecheck_overload_integration.flow imports
compiler/src/typecheck.flow, so its normalized MLIR digest changes
when AST_GPU_FRAME and the #1310 rt_safe row checks sit together.
Update that one corpus entry only.

Co-authored-by: Abhishek Shivakumar <[email protected]>

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: godofecht <[email protected]>
Co-authored-by: Cursor Agent <[email protected]>
godofecht added a commit that referenced this pull request Oct 7, 2026
Extend the #1310 `with rt_safe` function-pointer contract so a
callback-safe higher-order function can accept a proven-safe named
function or closure and reject an allocating one.

Closures get a compile-time summary: the body is walked into the existing
pointer/span captures are rejected, and diagnostics name the closure and
the unsafe op. The contract is erased before codegen.

Stop `with E1, E2` on a nested function type from swallowing the next
parameter (`f: (T) -> R with rt_safe, x: i32`). Trait-method contracts
remain a documented gap.

Part of #766.

Co-authored-by: Abhishek Shivakumar <[email protected]>
godofecht added a commit that referenced this pull request Oct 7, 2026
Extend the #1310 `with rt_safe` function-pointer contract so a
callback-safe higher-order function can accept a proven-safe named
function or closure and reject an allocating one.

Closures get a compile-time summary: the body is walked into the existing
pointer/span captures are rejected, and diagnostics name the closure and
the unsafe op. The contract is erased before codegen.

Stop `with E1, E2` on a nested function type from swallowing the next
parameter (`f: (T) -> R with rt_safe, x: i32`). Trait-method contracts
remain a documented gap.

Part of #766.

Co-authored-by: Abhishek Shivakumar <[email protected]>
godofecht added a commit that referenced this pull request Oct 8, 2026
Extend the #1310 `with rt_safe` function-pointer contract so a
callback-safe higher-order function can accept a proven-safe named
function or closure and reject an allocating one.

Closures get a compile-time summary: the body is walked into the existing
pointer/span captures are rejected, and diagnostics name the closure and
the unsafe op. The contract is erased before codegen.

Stop `with E1, E2` on a nested function type from swallowing the next
parameter (`f: (T) -> R with rt_safe, x: i32`). Trait-method contracts
remain a documented gap.

Part of #766.

Co-authored-by: Abhishek Shivakumar <[email protected]>
godofecht added a commit that referenced this pull request Oct 8, 2026
Extend the #1310 `with rt_safe` function-pointer contract so a
callback-safe higher-order function can accept a proven-safe named
function or closure and reject an allocating one.

Closures get a compile-time summary: the body is walked into the existing
pointer/span captures are rejected, and diagnostics name the closure and
the unsafe op. The contract is erased before codegen.

Stop `with E1, E2` on a nested function type from swallowing the next
parameter (`f: (T) -> R with rt_safe, x: i32`). Trait-method contracts
remain a documented gap.

Part of #766.

Co-authored-by: Abhishek Shivakumar <[email protected]>
godofecht added a commit that referenced this pull request Oct 8, 2026
Extend the #1310 `with rt_safe` function-pointer contract so a
callback-safe higher-order function can accept a proven-safe named
function or closure and reject an allocating one.

Closures get a compile-time summary: the body is walked into the existing
pointer/span captures are rejected, and diagnostics name the closure and
the unsafe op. The contract is erased before codegen.

Stop `with E1, E2` on a nested function type from swallowing the next
parameter (`f: (T) -> R with rt_safe, x: i32`). Trait-method contracts
remain a documented gap.

Part of #766.

Co-authored-by: Abhishek Shivakumar <[email protected]>
godofecht added a commit that referenced this pull request Oct 8, 2026
Extend the #1310 `with rt_safe` function-pointer contract so a
callback-safe higher-order function can accept a proven-safe named
function or closure and reject an allocating one.

Closures get a compile-time summary: the body is walked into the existing
pointer/span captures are rejected, and diagnostics name the closure and
the unsafe op. The contract is erased before codegen.

Stop `with E1, E2` on a nested function type from swallowing the next
parameter (`f: (T) -> R with rt_safe, x: i32`). Trait-method contracts
remain a documented gap.

Part of #766.

Co-authored-by: Abhishek Shivakumar <[email protected]>
godofecht added a commit that referenced this pull request Oct 8, 2026
Extend the #1310 `with rt_safe` function-pointer contract so a
callback-safe higher-order function can accept a proven-safe named
function or closure and reject an allocating one.

Closures get a compile-time summary: the body is walked into the existing
pointer/span captures are rejected, and diagnostics name the closure and
the unsafe op. The contract is erased before codegen.

Stop `with E1, E2` on a nested function type from swallowing the next
parameter (`f: (T) -> R with rt_safe, x: i32`). Trait-method contracts
remain a documented gap.

Part of #766.

Co-authored-by: Abhishek Shivakumar <[email protected]>
godofecht added a commit that referenced this pull request Oct 8, 2026
Extend the #1310 `with rt_safe` function-pointer contract so a
callback-safe higher-order function can accept a proven-safe named
function or closure and reject an allocating one.

Closures get a compile-time summary: the body is walked into the existing
pointer/span captures are rejected, and diagnostics name the closure and
the unsafe op. The contract is erased before codegen.

Stop `with E1, E2` on a nested function type from swallowing the next
parameter (`f: (T) -> R with rt_safe, x: i32`). Trait-method contracts
remain a documented gap.

Part of #766.

Co-authored-by: Abhishek Shivakumar <[email protected]>
godofecht added a commit that referenced this pull request Oct 8, 2026
Extend the #1310 `with rt_safe` function-pointer contract so a
callback-safe higher-order function can accept a proven-safe named
function or closure and reject an allocating one.

Closures get a compile-time summary: the body is walked into the existing
pointer/span captures are rejected, and diagnostics name the closure and
the unsafe op. The contract is erased before codegen.

Stop `with E1, E2` on a nested function type from swallowing the next
parameter (`f: (T) -> R with rt_safe, x: i32`). Trait-method contracts
remain a documented gap.

Part of #766.

Co-authored-by: Abhishek Shivakumar <[email protected]>
@godofecht
godofecht deleted the feat-rt-safe-indirect-calls-2191090288977208181 branch October 12, 2026 23:02
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