-
Notifications
You must be signed in to change notification settings - Fork 18
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
Examples #40
Examples #40
Conversation
Happy to see this commit. This looks like a good start. We should consider adding some even larger examples, I know I recently saw an Ascent version of https://github.com/plast-lab/doop-mirror/blob/master/souffle-logic/analyses/micro/self-contained.dl, which comes complete with some sizable EDBs. It is a very small version of DOOP (not using more complex analysis features, but a suitable basis). I am also interested in adding a few more complex examples of program analyses in Ascent that we could contribute to the examples folder if this is approved. |
Absolutely! The lack of available Datalog source code is a major hurdle when getting started with the language, imho. In pretty much every other major language there is more openly available source code available than one could reasonably read in a lifetime. Yet for Datalog you're likely to reach the end (of the stuff that's easily available/discoverable) by the end of the day, unless you descend into scientific journal papers and stuff. So every example is worth its weight in gold. |
@regexident Thanks for the PR, this is great work! |
ascent/examples/fizz_buzz.rs
Outdated
fn main() { | ||
let mut prog = AscentProgram::default(); | ||
|
||
prog.number = vec![ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we generate this from a range instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure!
I'm not sure if FizzBuzz (and this specific implementation in particular) is much of a great example for ascent to begin with, as in it isn't really a particularly interesting problem, but since it's a well-known yet simple one I figured why not include it.
(I also tried implementing the Sieve of Eratosthenes but failed miserably. 😅)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, Sieve of Eratosthenes doesn't look like a good fit for Datalog (it may be doable with lattices, but I don't think it would end up being a good example).
BTW, you may have forgotten to generate prog.number
from a range here!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, you may have forgotten to generate
prog.number
from a range here!
I did! Fixed.
relation len(Rc<List<char>>, usize); | ||
|
||
len(nil!(), 0); | ||
len(Rc::clone(&l), n + 1) <-- char(c), len(r, n), let l = cons!(c.clone(), r.clone()), list(Rc::clone(&l)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would also work:
len(l, n + 1) <-- char(c), len(r, n), let l = cons!(c.clone(), r.clone()), list(&l);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite, unfortunately:
error[E0507]: cannot move out of `l`, a captured variable in an `FnMut` closure
--> ascent/examples/lists_using_recursive_enums.rs:58:9
|
58 | ...en(l, n + 1) <-- char(c), len(r, n), let l = cons!(c.clone(), r.clone()), list(&...
| ^ - ---- captured by this `FnMut` closure
| | |
| | captured outer variable
| move occurs because `l` has type `Rc<List<char>>`, which does not implement the `Copy` trait
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, ok. I'll have to look into it. Meanwhile, this should work:
len(l.clone(), n + 1) <-- char(c), len(r, n), let l = cons!(c.clone(), r.clone()), list(&l);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works! Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I see why that wouldn't work. The last clause could have multiple matches in general (not the case here), so we can't take ownership of the value in the head clause.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that makes a lot of sense.
ascent/examples/fizz_buzz.rs
Outdated
fn main() { | ||
let mut prog = AscentProgram::default(); | ||
|
||
prog.number = vec![ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, Sieve of Eratosthenes doesn't look like a good fit for Datalog (it may be doable with lattices, but I don't think it would end up being a good example).
BTW, you may have forgotten to generate prog.number
from a range here!
5f28e26
to
6917e9a
Compare
|
||
// The rule above could alternatively also be written | ||
// using the following short-hand syntax: | ||
// some(y) <-- option(?Some(y)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it'd be better to uncomment this. This would be a redundant rule, but I think it's fine for an example showing Ascent features.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
It's much easier to start using ascent (and especially its custom DSL) if there is a list of examples for both, individual language features, as well as more complete use-cases.
This PR aims to plant a first seed for such an extensive pool of examples with an initial set of …
Examples focussing on individual language features of ascent:
ascent_for_in_clause.rs
ascent_agg_clause.rs
ascent_disjunction_clause.rs
ascent_generic_program.rs
ascent_if_clause.rs
ascent_if_let_clause.rs
ascent_lattice.rs
ascent_let_clause.rs
ascent_macros_rule.rs
ascent_negation_clause.rs
Examples showcasing simple yet well-known algorithms:
fibonacci.rs
fizz_buzz.rs
transitive_graph_closure.rs
Examples showcasing real-world use-cases:
context_sensitive_flow_graph_with_records.rs
context_sensitive_flow_graph.rs
def_use_chains.rs
sequences_using_recursive_records.rs
var_points_to.rs