-
Notifications
You must be signed in to change notification settings - Fork 205
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
interfaces: Prevent circular and non-closed requirements. #12073
Conversation
Updates the haskell side to be more strict about requirements: - requirements must be transitively closed, so if A requires B, and B requires C, then A requires C. - no circular requirements allowed The logic for circular requirements is a bit duplicated to get a better error message. Part of #11978 changelog_begin changelog_end
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.
nice, thank you!
Co-authored-by: Moritz Kiefer <moritz.kiefer@purelyfunctional.org>
whenJust (listToMaybe (S.toList missing)) $ \missingIfaceId -> | ||
throwWithContext (ENotClosedInterfaceRequires (intName iface) requiredIfaceId missingIfaceId) |
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.
Perhaps it would be better to show all missing required interfaces in one go? I think this should do the trick:
whenJust (listToMaybe (S.toList missing)) $ \missingIfaceId -> | |
throwWithContext (ENotClosedInterfaceRequires (intName iface) requiredIfaceId missingIfaceId) | |
whenJust (nonEmpty (S.toList missing)) $ \missingIfaceIds -> | |
throwWithContext (ENotClosedInterfaceRequires (intName iface) requiredIfaceId missingIfaceIds) |
(together with the corresponding change for ENotClosedInterfaceRequires
)
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.
good idea, changed the error to take a list!
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.
nice, thank you!
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.
nothing else to add, thank you!
forM_ (intRequires iface) $ \requiredIfaceId -> do | ||
requiredIface <- inWorld (lookupInterface requiredIfaceId) | ||
when (tcon `S.member` intRequires requiredIface) $ | ||
throwWithContext (ECircularInterfaceRequires (intName iface) (Just requiredIfaceId)) |
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 a big issue, but we actually does not need this case.
If you require the requires is transitively closed, you just need to check that an interface does not require itself (done at line 840).
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.
Yep, that's why I said it's only done to get a better error message.
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.
Fair enough.
It is true that error messages in the compiler are more important than the one in the interpreter.
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 agree. I think it's better for the check to be simpler in the interpreter. The compiler is more user-facing.
* interfaces: Prevent circular and non-closed reqs Updates the haskell side to be more strict about requirements: - requirements must be transitively closed, so if A requires B, and B requires C, then A requires C. - no circular requirements allowed The logic for circular requirements is a bit duplicated to get a better error message. Part of #11978 changelog_begin changelog_end * Update compiler/daml-lf-tools/src/DA/Daml/LF/TypeChecker/Check.hs Co-authored-by: Moritz Kiefer <moritz.kiefer@purelyfunctional.org> * take a list in NotClosed error Co-authored-by: Moritz Kiefer <moritz.kiefer@purelyfunctional.org>
Updates the haskell side to be more strict about requirements:
then A requires C.
The logic for circular requirements is a bit duplicated to get a better
error message.
(Also refactored the typechecker a little bit to use
whenJust
instead of pattern matching where appropriate.)Part of #11978
changelog_begin
changelog_end
Pull Request Checklist
CHANGELOG_BEGIN
andCHANGELOG_END
tagsNOTE: CI is not automatically run on non-members pull-requests for security
reasons. The reviewer will have to comment with
/AzurePipelines run
totrigger the build.