-
Notifications
You must be signed in to change notification settings - Fork 287
Fail hashing if components are ambiguously ordered. #6007
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
base: trunk
Are you sure you want to change the base?
Conversation
b925b4b to
b94a51c
Compare
| verifyTermFormatHash :: ComponentHash -> TermFormat.HashTermFormat -> Maybe HashValidationError | ||
| verifyTermFormatHash (ComponentHash hash) (TermFormat.Term (TermFormat.LocallyIndexedComponent elements)) = toMaybe $ do |
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.
This is the change that allows Share to catch these.
…ng them in the `errors` directory
|
@ChrisPenner Not sure why this would be an issue when they're not top level definitions |
Even if not top-level definitions they still need to be hashed, and AFAIK we treat top-level bindings just as one big let-rec. I think it won't run into quite the same problems, since I'd guess that the variable names are going to be the same on every hash since they're baked in, and you can't have external references into that let-rec, so that problem doesn't apply. The one thing would be that this implies if you load a term, then change a variable name, the hash could change (if you had a 3 element component where element ordering matters), which would be annoying, but not entirely problematic. I'll fix this test, but I don't think we should change the behaviour. |
Overview
A temporary measure to prevent components with ambiguous element orderings from propagating through the ecosystem; particularly in Share.
More context on this issue: #2787
This doesn't fix the issue, but it does prevent the problematic situation caused by a single hash having multiple semantically different definitions; which would cause completely erroneous behaviour in certain cases.
I analyzed Share and no such definitions are in the ecosystem at the moment, this change should keep it that way.
@aryairani we'd talked about different approaches for implementing this without making large changes to the codebase;
you seemed hesitant to thread errors all the way through only to (hopefully) remove them later, so instead I inserted calls to
error, which should have the same effect but with a slightly worse user experience.Here's what happens if you write a component like this:
It prevents the user from adding/updating such a component, which accomplishes the goal, but in a bit of a scary way.
Implementation approach and notes
Interesting/controversial decisions
There's some nuance, we could choose allow components where all elements are identical, since those don't technically cause any problems, but it's somewhat annoying and difficult to check if this is the case for non-trivial components, and AFAIK there's never a good reason to write such a component since you could just recurse instead.
This also is the first introduction of the idea that hashing a component could fail; which is undesirable.
We plan to lift this restriction by introducing a complete ordering of component elements in the future, but it involves implementing a whole new component ordering algorithm. (see #2787 )
Test coverage
Loose ends
It would be nice to properly resolve this issue by implementing a complete element ordering algorithm.