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

Add new record completion operator #1375

Merged
merged 12 commits into from
Oct 11, 2019
Merged

Add new record completion operator #1375

merged 12 commits into from
Oct 11, 2019

Conversation

Gabriella439
Copy link
Collaborator

... as standardized in dhall-lang/dhall-lang#767

@Gabriella439
Copy link
Collaborator Author

Note that this requires a few other changes to be merged so that this can be updated to use the corresponding dhall-lang submodule commit and then pass tests. Once tests pass I'll fix downstream packages

dhall/src/Dhall/Diff.hs Outdated Show resolved Hide resolved
dhall/src/Dhall/Diff.hs Outdated Show resolved Hide resolved
dhall/src/Dhall/Diff.hs Outdated Show resolved Hide resolved
@@ -689,6 +689,8 @@ eval !env t0 =
vCombineTypes (eval env t) (eval env u)
Prefer t u ->
vPrefer env (eval env t) (eval env u)
RecordCompletion t u ->
eval env (Annot (Prefer (Field t "default") u) (Field t "Type"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Given that we know that eval ignores the type annotation, can we just skip adding it here?

Suggested change
eval env (Annot (Prefer (Field t "default") u) (Field t "Type"))
eval env (Prefer (Field t "default") u)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In this case I prefer to pedantically follow the standard given that we don't have any benchmarks showing that this is a measurable optimization

dhall/src/Dhall/Parser/Expression.hs Outdated Show resolved Hide resolved
dhall/src/Dhall/Parser/Expression.hs Outdated Show resolved Hide resolved
dhall/src/Dhall/Pretty/Internal.hs Outdated Show resolved Hide resolved
@@ -178,7 +178,10 @@ instance Arbitrary Directory where
instance (Arbitrary s, Arbitrary a) => Arbitrary (Expr s a) where
arbitrary =
Test.QuickCheck.suchThat
(Generic.Random.genericArbitraryRecG customGens weights)
(Generic.Random.withBaseCase
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe this is good, but I don't actually quite understand why. Can you help me?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This fixes an infinite loop. Adding one more constructor caused the weights to generate an infinitely growing expression tree. Using withBaseCase ensures that the random generator can still cap the recursion depth when this happens so that we don't have to be so diligent with weights.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh! This sounds like a bug in generic-random. Should we report this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure it is a bug. The documentation from withBaseCase seems to suggest that this behavior is expected if you don't use withBaseCase

@Gabriella439 Gabriella439 merged commit 4b8b8cd into master Oct 11, 2019
@Gabriella439 Gabriella439 deleted the gabriel/override_2 branch October 11, 2019 15:26
@Gabriella439 Gabriella439 changed the title Add new override operator Add new record completion operator Oct 17, 2019
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.

None yet

2 participants