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

datalog foreign function interface prototype #228

Merged
merged 8 commits into from
Nov 19, 2024
Merged

datalog foreign function interface prototype #228

merged 8 commits into from
Nov 19, 2024

Conversation

divarvel
Copy link
Collaborator

@divarvel divarvel commented Oct 2, 2024

This allows using external functions in datalog.

This makes it easy to provide custom logic without extending the spec for every use-case, at the expense of portability: behaviour is no longer guaranteed to be consistent cross languages, and some languages won’t be able to support it at all (for instance JS as of now).

Copy link

codspeed-hq bot commented Oct 2, 2024

CodSpeed Performance Report

Merging #228 will not alter performance

Comparing ffi (a179587) with v5 (e59f41d)

Summary

✅ 12 untouched benchmarks

Copy link

codecov bot commented Oct 2, 2024

Codecov Report

Attention: Patch coverage is 75.54180% with 79 lines in your changes missing coverage. Please review.

Project coverage is 65.44%. Comparing base (796ba5d) to head (a179587).
Report is 9 commits behind head on v5.

Files with missing lines Patch % Lines
biscuit-parser/src/builder.rs 0.00% 34 Missing ⚠️
biscuit-auth/src/token/builder.rs 86.76% 18 Missing ⚠️
biscuit-auth/src/format/convert.rs 74.13% 15 Missing ⚠️
biscuit-auth/src/token/authorizer.rs 25.00% 6 Missing ⚠️
biscuit-auth/src/datalog/expression.rs 90.90% 4 Missing ⚠️
biscuit-auth/examples/testcases.rs 93.10% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##               v5     #228      +/-   ##
==========================================
+ Coverage   64.82%   65.44%   +0.62%     
==========================================
  Files          25       25              
  Lines        6502     6729     +227     
==========================================
+ Hits         4215     4404     +189     
- Misses       2287     2325      +38     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@divarvel divarvel force-pushed the ffi branch 5 times, most recently from 4f68cf3 to 949d273 Compare October 4, 2024 08:21
@divarvel divarvel force-pushed the ffi branch 6 times, most recently from c9a91d0 to 7d1297d Compare October 25, 2024 13:20
@divarvel divarvel force-pushed the ffi branch 4 times, most recently from 2daa976 to 90c6ca3 Compare November 12, 2024 08:20
@divarvel divarvel force-pushed the ffi branch 3 times, most recently from ff6d1f4 to 99c0718 Compare November 13, 2024 09:30
@divarvel divarvel marked this pull request as ready for review November 19, 2024 10:48
@divarvel divarvel changed the title wip: datalog foreign function interface prototype datalog foreign function interface prototype Nov 19, 2024
@divarvel divarvel requested a review from Geal November 19, 2024 10:51
biscuit-auth/examples/testcases.rs Outdated Show resolved Hide resolved
biscuit-auth/src/datalog/mod.rs Outdated Show resolved Hide resolved
biscuit-auth/src/token/builder.rs Show resolved Hide resolved
This allows using external functions in datalog.

This makes it easy to provide custom logic without extending the spec for every use-case, at the expense of portability: behaviour is no longer guaranteed to be consistent cross languages, and some languages won’t be able to support it at all (for instance JS as of now).

Todo:
- stricter conversions from datalog
- feature-gating if possible

Open questions:
- enum index for the FFI variants (contiguous or not?)
- how to provide functions (right now, function pointers: prevent mutability and closing over arguments)
- how to provide arguments (right now, datalog::Term, so symbols have to be resolved, and functions returning strings have to register new symbols)
- using boxed functions instead of function pointers allow capturing the environment
- using builder terms instead of datalog terms remove the need for manual symbol management
Instead of storing strings directly in the ops, do as we do for everything else and use the symbol table.

This required duplicating `biscuit_parser::builder::Binary` and `Unary` in the `biscuit_auth::builder` module (which previously used the definitions from the `datalog` module directly). There is a lot of duplication between `biscuit_parser::builder` and `biscuit_auth::builder`, with a circular-ish dependency (biscuit_auth depends on biscuit parser, but code generated by the `ToTokens` impl blocks in biscuit parser depend on `biscuit_auth::builder`).
This ensures consistent evaluation of functions and removes the need of storing them in `RunLimits`
@Geal
Copy link
Contributor

Geal commented Nov 19, 2024

that will be a great tool for future experimentation

@divarvel divarvel merged commit 4556320 into v5 Nov 19, 2024
7 checks passed
@divarvel divarvel deleted the ffi branch November 19, 2024 21:03
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