Skip to content

Migrate updateName and addSources to use expr modifier #820

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

Closed
wants to merge 145 commits into from
Closed

Migrate updateName and addSources to use expr modifier #820

wants to merge 145 commits into from

Conversation

JordanMartinez
Copy link
Contributor

@JordanMartinez JordanMartinez commented Sep 16, 2021

Implements what I proposed in this comment:

Add a PR that migrates addRawDeps, addSourcePaths, and updateName to use the Dhall expression updater in Make spago install work when more advanced Dhall expressions are used #815

Since this builds off of #815, you can view this diff rather than the one presented in this PR. The first commit starts with the message, "Extract list text values in more modular way."

Also, I ran out of time today, so I'll have to see how the tests are affected by these changes later.

Here's an explanation of this PR. I migrated these by doing the following:

  • dropping the need for addRawDeps as that has been superceded by addDependencies.
  • reimplementing updateName so that it copies addDependencies but updates just the name
  • implementing the first usage of addSourcePaths by defining a new config modification called MigrateFromV1Config as that's how addSourcePaths was used in this usage
  • reimplementing the second usage of addSourcePaths to not use it at all. Since the dependencies key is always present in v1 configs and v2 configs, the usage was unnecessary.
  • removing all code that is now unused and commenting out the rest for historical reasons

Ideally, the config modification updates would be batched together, so that the spago.dhall file is only updated once. This change does each atomically for simplicity. This is also likely why some tests will fail despite otherwise working correctly (e.g. error messages are different now).

Remaining work:

  • The usage of MigrateFromV1Config should be checked to verify it produces the expected config value if parsed. I haven't done that yet.
  • Verifying that tests pass (and updating any that need to be updated)

Control flow before this commit would do all the lookup work and get
the needed values, only to fail if the packages that are trying to be
added don't exist in the package set.

This commit does the check first.
In this commit, I moved the code that checks whether
the user-requested packges exist in the package set
into the `withRawConfigAST`, so that the new
`Spago.Config.AST` module doesn't introduce a cyclial dependency with
the `Spago.Config` module.

I also provide both the raw and normalized AST expressions
as it's the only way to correctly determine which packages
haven't yet been installed.
This change enables us to pass the keystack
back up to the let binding expression that defines
the value for the binding. However, since the
key stack might be empty, we can no longer use
`NonEmpty Text`. Unfortunately, this change
means `SearchingforField`'s arg must also be updated
and by implication, `WithinField` and `SearchingForField` are
conceptually the same thing.
To maintain the previous behavior, a let binding
should only allow a `VariableName` to propagate to its parent expression
if its own level is not an empty key stack (which means
we're at the field we need to update). Otherwise,
we will traverse outside of the current expression,
and introduce a side-effect if we update the
actual let binding's value.
To support the Right version of Project, we would
need to traverse type-level constructors
in the Dhall Expr type.
Previously, we were checking whether we should only
update the `updateExpr` and only then falling back to updating
either the `updateExpr` or the `recordExpr`.
If the `updateExpr` was an exact match of the remaining
fields we were seaching for, we would go down that path.
Otherwise (i.e. the `updateExpr` was a partial match), we would try
updating the `updateExpr` and then the `recordExpr` if the former failed
By removing the "full" updateExpr case, we get the same execution but without
the redundant code
While the immediate Var updates won't be as nice stylistically,
they are always correct.
When 2+ config AST updates occur, the second one does not have access
to the result of the first config update. Thus,
the `isSemanticallyEquivalent` check fails because
the second config update's expectec config
does not contain the updates done in the first one.
For example, if we update the name and then add dependencies,
the dependencies ast update check does not have
the new name in the 'expectedConfig' value.

Moreover, in the process of doing this change,
I discovered that I could remove the 'sortDependencies' part of the
publishConfig check by just verifying that the
keys in each maps are the same since that's all
the error really cards about: missing keys.
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.

1 participant