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

Reject custom contexts that are ill-formed #259

Merged
merged 4 commits into from
Feb 15, 2018
Merged

Conversation

Gabriella439
Copy link
Collaborator

Fixes #253

This protects typeWith to reject any custom-context that might trigger a
type-checking loop

Fixes #253

This protects `typeWith` to reject any custom-context that might trigger a
type-checking loop
{-| This function verifies that a custom context is well-formed so that
type-checking will not loop
-}
checkContext :: Context (Expr s X) -> Either (TypeError s X) ()
Copy link
Member

Choose a reason for hiding this comment

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

I think you meant to export this. If not, please export it 😄

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually, I intentionally did not export it since typeWith calls it once before entering the type-checking loop. This avoids the performance issue since it's not called on every iteration of the loop

@ocharles
Copy link
Member

ocharles commented Feb 13, 2018 via email

@Gabriella439
Copy link
Collaborator Author

Oh, whoops! You're right that there is one unnecessary call to checkContext since it already uses typeWith which already uses checkContext. I'll fix that

I'll also go ahead and export it, too

@ocharles
Copy link
Member

Oh, I actually meant https://hackage.haskell.org/package/dhall-1.9.1/docs/src/Dhall-Import.html#loadWithContext which calls typeWith, so we end up validating the context twice if you do import resolution and then final type checking. It's hardly the end of the world though.

@Gabriella439
Copy link
Collaborator Author

Imports are type-checked twice anyway even without custom contexts. This is normal to ensure that imports are closed and also to localize error messages better.

@ocharles
Copy link
Member

Sure, it's just a pinch more overhead. But I think it's inconsequential

@Gabriella439
Copy link
Collaborator Author

I'll go ahead and merge this, then, since I think I've addressed your requests

@Gabriella439 Gabriella439 merged commit fbac034 into master Feb 15, 2018
@Gabriella439 Gabriella439 deleted the gabriel/253 branch February 15, 2018 02:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants