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

Fix not without dependencies #613

Merged
merged 5 commits into from
Nov 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions src/runtime/join.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export interface ProposalProvider {
// Check if a prefix of solved variables is a valid potential solution
// for this provider. SolvingFor is used to ignore accept calls that
// aren't related to variables the provider is solving for.
accept(index: MultiIndex, prefix: any[], solvingFor: Variable, force?: boolean): boolean
accept(index: MultiIndex, prefix: any[], solvingFor: Variable, force?: boolean, prejoin?: boolean): boolean
}

//---------------------------------------------------------------------
Expand Down Expand Up @@ -497,8 +497,18 @@ export class NotScan {
propose() { return; }
resolveProposal() { throw new Error("Resolving a not proposal"); }

accept(multiIndex: MultiIndex, prefix, solvingFor, force?) {
if(!force && !this.internalVars[solvingFor.id] && this.internalVars.length || !fullyResolved(this.args, prefix)) return true;
accept(multiIndex: MultiIndex, prefix, solvingFor, force?, prejoin?) {
// if we're in the prejoin phase and this not has no args, then we need
// to evaluate the not to see if we should run. If we didn't do this, arg-less
// nots won't get evaluated during Generic Join since we're never solving for a
// variable that this scan cares about.
if((!prejoin || this.args.length)
// if we aren't forcing and not solving for the current variable, then we just accept
// as it is
&& (!force && !this.internalVars[solvingFor.id] && this.internalVars.length)
// we also blind accept if we have args that haven't been filled in yet, as we don't
// have the dependencies necessary to make a decision
|| !fullyResolved(this.args, prefix)) return true;
Copy link
Contributor

Choose a reason for hiding this comment

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

I find this conditional to be pretty hard to parse due to its density. It might be worth commenting about the other early acceptance cases or trying to refactor it to split it up.

This is subjective so I don't know that it's blocking.

let resolved = this.resolve(prefix);
let notPrefix = [];
let ix = 0;
Expand Down Expand Up @@ -825,13 +835,22 @@ function preJoinAccept(multiIndex: MultiIndex, providers : ProposalProvider[], v
if(value !== undefined && vars[ix] !== undefined) {
presolved++;
for(let provider of providers) {
if(!provider.accept(multiIndex, prefix, solvingFor)) {
if(!provider.accept(multiIndex, prefix, solvingFor, false, true)) {
return {accepted: false, presolved};
}
}
}
ix++;
}
// we still need to do a single prejoin pass to make sure that any nots
// that may have no external dependencies are given a chance to end this
// evaluation
let fakeVar = new Variable(0);
for(let provider of providers) {
if(provider instanceof NotScan && !provider.accept(multiIndex, prefix, fakeVar, false, true)) {
return {accepted: false, presolved};
}
}
return {accepted: true, presolved};
}

Expand Down
23 changes: 23 additions & 0 deletions test/join.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2647,6 +2647,29 @@ test("not can't provide a variable for an attribute access", (assert) => {
assert.end();
})

test("not without dependencies filters correctly", (assert) => {
let expected = {
insert: [[1, "tag", "foo"]],
remove: [],
};
evaluate(assert, expected, `
add some stuff
~~~
commit
[#foo]
~~~

foo bar
~~~
search
not([#foo])
bind
[#bar]
~~~
`);
assert.end();
})


test("indirect constant equality in if", (assert) => {
let expected = {
Expand Down