Skip to content

Simple module/import implementation#293

Merged
mergify[bot] merged 7 commits intomainfrom
brprice/modules
Mar 13, 2022
Merged

Simple module/import implementation#293
mergify[bot] merged 7 commits intomainfrom
brprice/modules

Conversation

@brprice
Copy link
Copy Markdown
Contributor

@brprice brprice commented Mar 7, 2022

We enable Primer programs to import modules. This is achieved by adding a progImports :: [Module] field to Prog. (We also move the current progDefs and progTypes into a Module.) The imported modules are each immutable, and one can only add more modules to the imported set. This immutability is ensured by having all the actions only operate on the one "current" module (that comprises the old progDefs and progTypes).

For now we don't have any namespacing, we just lookup references in all modules and assume unique names. We leave adding hierarchical names for future work. We also leave having multiple editable modules for future work. This work should also address the fact that we look up global terms by ID which "should be unique" (we should probably scope this so IDs only need to be unique in one given module).

@brprice
Copy link
Copy Markdown
Contributor Author

brprice commented Mar 7, 2022

Notes for reviewers: (edited) I added a few comments about temporary TODOs that will be resolved later in this patchset. Unfortunately I rebased the PR after I did so -- I think that github has lost the connection with which commit they came from. It would be worth keeping this in mind when reviewing commit-by-commit.

This PR is an alternative to #263. Note that the bulk of the changes are pretty mechanical.

Comment thread primer/src/Primer/App.hs Outdated
Comment thread primer/src/Primer/App.hs
@brprice brprice linked an issue Mar 7, 2022 that may be closed by this pull request
Comment thread primer/src/Primer/App.hs Outdated
Comment thread primer/src/Primer/Action.hs Outdated
Comment thread primer/src/Primer/Action.hs Outdated
@brprice brprice marked this pull request as ready for review March 7, 2022 18:59
@brprice brprice requested a review from a team March 7, 2022 19:02
@brprice
Copy link
Copy Markdown
Contributor Author

brprice commented Mar 8, 2022

The test suite failure is mostly (4 tests) due to serialisation changes which I didn't notice because of #294. There is one that needs more investigation though: -p '/prim con scope ast/'

Comment thread primer/src/Primer/App.hs
@georgefst
Copy link
Copy Markdown
Contributor

There is one that needs more investigation though: -p '/prim con scope ast/'

Looks like that's been broken by changes to checkTypeDefs in the final commit. Perhaps splitting out the "refactor" part of that commit would make the issue clearer?

Copy link
Copy Markdown
Contributor

@georgefst georgefst left a comment

Choose a reason for hiding this comment

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

Looks good! Once tests pass, of course.

@brprice brprice force-pushed the brprice/fix-defaultPrimsProg branch from 59d07e6 to 32e1cae Compare March 10, 2022 10:40
brprice added 7 commits March 10, 2022 17:15
This is in preparation for having a Prog include imported modules.

BREAKING CHANGE: this change requires a database migration, as it
changes the representation of `Prog`. However, since this is just
serialised to json and stored as a blob in the DB, it requires no schema
changes. Since we have no programs we need to preserve, we decided not
to bother with a migration. This means that DBs created before this
commit will not load with a primer containing this commit.
We will shortly want to import Primer.Core(defID), and want to avoid CI
failures due to -Werror -Wname-shadowing.
We enable Primer programs to import modules. This is achieved by adding
a `progImports :: [Module]` field to `Prog`. The imported modules are
each immutable (via the api). This immutability is ensured by having all
the actions only operate on the one "current" module (that comprises the
old `progDefs` and `progTypes`). (For now, the set itself is also
immutable via the api.)

For now we don't have any namespacing, we just lookup references in all
modules and assume unique names. We leave adding hierarchical names for
future work. We also leave having multiple editable modules for future
work.

BREAKING CHANGE: this change requires a database migration, as it
changes the representation of `Prog`. However, since this is just
serialised to json and stored as a blob in the DB, it requires no schema
changes. Since we have no programs we need to preserve, we decided not
to bother with a migration. This means that DBs created before this
commit will not load with a primer containing this commit.
This is basically an action, except we don't expose it in the API. We
will delay doing so until we have a nice way for a frontend to refer to
a module. I.e. we would like to say
"import the User1.ProjectFoo.ModuleBar" module, rather than having to
explicitly give the code contained within the module.

This utility does not check that imported modules have disjointly-named
contents. We intend to shortly require a hierarchical naming scheme
which will address this concern. At that point we will also address the
issue of disjoint IDs of contents, and our freshness guarantees.

The reason we delay worrying about disjointness/uniqueness is that both
it and being able to expose this nicely in the API require the notion of
a module having some short name, rather than having to explicitly pass
around all the code contained in the module.
@brprice
Copy link
Copy Markdown
Contributor Author

brprice commented Mar 10, 2022

@dhess: this is ready to merge, once #292 is in.

@brprice brprice mentioned this pull request Mar 10, 2022
@dhess dhess added the Ready to merge Ready to merge label Mar 13, 2022
Base automatically changed from brprice/fix-defaultPrimsProg to main March 13, 2022 13:12
@dhess
Copy link
Copy Markdown
Member

dhess commented Mar 13, 2022

@Mergifyio refresh

@mergify
Copy link
Copy Markdown

mergify Bot commented Mar 13, 2022

refresh

✅ Pull request refreshed

@dhess dhess added Ready to merge Ready to merge and removed Ready to merge Ready to merge labels Mar 13, 2022
@dhess
Copy link
Copy Markdown
Member

dhess commented Mar 13, 2022

@Mergifyio refresh

@mergify
Copy link
Copy Markdown

mergify Bot commented Mar 13, 2022

refresh

✅ Pull request refreshed

@dhess
Copy link
Copy Markdown
Member

dhess commented Mar 13, 2022

@Mergifyio refresh

@mergify
Copy link
Copy Markdown

mergify Bot commented Mar 13, 2022

refresh

✅ Pull request refreshed

mergify Bot added a commit that referenced this pull request Mar 13, 2022
@dhess
Copy link
Copy Markdown
Member

dhess commented Mar 13, 2022

Note: I couldn’t figure out why this wasn’t building in Mergify. It’s because it had unresolved comments, but that wasn’t clear from the GitHub status for Mergify. That seems like a bug to me. Anyway, for future reference, if a PR is stuck, maintainers can go to https://dashboard.mergify.com/github/hackworthltd/repo/primer/config-editor?repositoryName=primer and use the “Check my configuration on pull request #” functionality for a real-time check.

@mergify mergify Bot merged commit ccef87d into main Mar 13, 2022
@mergify mergify Bot deleted the brprice/modules branch March 13, 2022 13:43
Comment thread primer/src/Primer/App.hs

-- | Get all type definitions from all modules (including imports)
allTypes :: Prog -> [TypeDef]
allTypes = moduleTypes . progModule
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I missed this at the time of review - why does allTypes look at imports when allDefs does not? This seems to contradict its comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks! This is a bug, see #327

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready to merge Ready to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Simple module/import mechanism (backend only)

3 participants