Commit a56376fe authored by Jeff Smits's avatar Jeff Smits

Thoughts while writing the blog post

parent 6d72c976
Specification([Signature([Constructors([ExtOpDecl("Nil",ConstType(Sort("List",[SortVar("a")])))])]),Strategies([SDefT("main_0_0",[],[],Scope(["c_0","d_0"],Seq(Match(Var("c_0")),Seq(Build(Anno(Str("Expected behaviour: failure"),Op("Nil",[]))),Seq(CallT(SVar("debug_0_0"),[],[]),Seq(Build(Var("c_0")),Let([SDefT("e_0",[],[],Seq(Match(Var("d_0")),Fail))],GuardedLChoice(CallT(SVar("e_0"),[],[]),Id,Seq(Build(Var("d_0")),CallT(SVar("debug_1_0"),[Build(Anno(Str("Well, it succeeded.. b was: "),Op("Nil",[])))],[])))))))))),ExtSDef("debug_0_0",[],[]),ExtSDef("debug_1_0",[VarDec("r_13",FunType([ConstType(Sort("ATerm",[]))],ConstType(Sort("ATerm",[]))))],[])])])
\ No newline at end of file
module backtrack
imports libstratego-lib
strategies
// EXPECTED BEHAVIOUR: program fails at runtime because of unbound b
// EXPECTED BEHAVIOUR: program fails at runtime when f is inlined, because the closure gets made inside the guarded choice
// f always fails, but it binds b before that. In a guarded choice, the binding to b needs to be undone. But if you
// compile this program with -O 0 (no optimisations), f stays a separate strategy and becomes a closure inside the
// execution environment. Interaction between closures and backtracking can be trick, hence this "test".
main = where(<debug> "Expected behaviour: failure"); {b: let f = ?b; fail in f <+ !b; debug(!"Well, it succeeded.. b was: ") end }
// execution environment. Interaction between closures and backtracking can be tricky, hence this "test".
main = where(<debug> "Expected behaviour: b binding stays"); {b: let f = ?b; fail in f <+ !b; debug(!"Well, it succeeded.. b was: ") end }
......@@ -347,6 +347,7 @@ impl<'a> ::std::hash::Hash for C<'a> {
fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) {}
}
// TODO: Refactor into separate tree walks to 1) check for variables 2) do size estimate/transform
type SizeEstimate = Option<usize>;
fn add_estimates(first: SizeEstimate, second: SizeEstimate) -> SizeEstimate {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment