-
Notifications
You must be signed in to change notification settings - Fork 115
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
DSL parsing derefs protocols instead of refering to the class of the protocol #429
Comments
Unfortunately I don't think the question of how to behave here is entirely straightforward. I suspect that users who use a protocol as a type may be expecting the conditions to match on facts that extend the protocol, not just facts that implement the Java interface directly. So if this proposal is implemented, the first case below would match a MarkerProtocol condition but the second would not.
At first glance the resolution could involve using the extenders function to find all types implementing the protocol, but this is potentially problematic if the types implementing the protocol were to change after the session was created though. However, this wouldn't be an entirely new problem since the default :ancestors-fn is seems likely to be susceptible to such issues when it works against Clojure's type hierarchy created via derive rather than the JVM's. I don't know how frequently that part of Clara's type dispatch is currently used in practice though. For any change like this we'd have to be careful of performance impacts, but since the get-alphas-fn that performs this dispatch is cached I think it would be OK from that point of view. I'd need to spend a bit more time reasoning through how this would be implemented but it seems like we could take a "snapshot" of the extenders at the time the session was created. Another question: If we do want behaviour like this should it be opt-in or by default? Having a protocol map as an actual type in the rules seems like strange enough behaviour that I'd be tempted to either throw or log a warning if it occurs without the user having set their own :fact-type-fn and maybe :ancestors-fn, and then the users could choose what to do. |
Overall, I consider using a The That said, I think I'm not sure about caching protocol implementors etc. I know |
Quick comment from mobile: "but then it would not be dynamic for a session and that may also be weird. Meaning, a later extend wouldn't be respected by the pre-created session". Changes in the fact type dispatch during the scope of a rules session could have arbitrary behavior analogous to that when facts are mutated after being inserted into the session. For example, suppose a fact doesn't match a condition, the rules are fired, and then the type hierarchy changes so that it does match it. So I don't think trying to support that kind of dynamism is likely a good path. |
@WilliamParker yeah that’s a fair point on the dynamism part. I guess that’s already sort of a possible restriction. |
Per a discussion in the clara slack, there is an interesting behavior when a production tries to leverage a protocol as its
fact-type
.For example,
The execution of the session does not fail, this is because the way that the dsl resolves
fact-types
seen here. The protocol will resolve to a var, thus the parser will deref it into its map representation. Meaning that theancestors
call on thetype
of(->SomeFact)
will not match the rule.So, there is an open question here:
cc. @mrrodriguez @WilliamParker
The text was updated successfully, but these errors were encountered: