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

New modname module #23

Merged
merged 31 commits into from
May 4, 2023
Merged

New modname module #23

merged 31 commits into from
May 4, 2023

Conversation

dinosaure
Copy link
Contributor

This PR wants to solve the issue #14 and provide a new module: Modname which is basically a module to implement module names. As explained into the issue, the type is no longer a simple string but an abstract type to keep and enforce assertions about module names.

Currently, only one test remains wrong from this deep change. Implications from this PR on tests are reference by the prefix [test]. We denote 2 big changes:

  1. the type Modname.t becomes abstract, we need to use Modname.to_string sometimes but the propagation of this type is not full. To keep the PR clear, I have only dwelt on the most important details and there are places where we could go further in the spread.
  2. The Namespaced.t type has 2 views that are useful in many contexts, one view as a module path and one view as a file path. I decided to decouple these views (with a new "file" field) to differentiate between when you want a module path and a file path.

Finally, I haven't updated bundle_refs (see this issue: #21).

This is a draft but it is already a good step to clarify the information handled by codept throughout the resolution process. After this RP, it will be a matter of:

  1. further propagate the Modname.t type
  2. Abstract Namespace.t and Path.t

lib/module.ml Outdated Show resolved Hide resolved
lib/modname.ml Outdated Show resolved Hide resolved
lib/modname.mli Outdated Show resolved Hide resolved
@dinosaure dinosaure force-pushed the modname branch 3 times, most recently from e725764 to d690075 Compare February 27, 2023 15:19
@dinosaure
Copy link
Contributor Author

I did the introduction of the new module Unitname to keep the bijection about the modulize function and use it into the Namespaced module instead of:

  • adding a new field into the type Namespaced.t
  • losing an information about the path of the module

Tests did not change (but one test still is commented), just the dependencies graph was updated with the insertion of the new module. Again, I did not propagate the Unitname.t everywhere - I'm waiting to merge this PR first and do this job then. From my perspective and regardless the commented test, it's ready to merge.

This PR integrates #26 too and it will probably be nice to merge #25 before this one. Especially when I updated the implementation of Namespaced.module_path_of_filename and Namespaced.filepath_of_filename.

@dinosaure dinosaure marked this pull request as ready for review February 27, 2023 16:16
lib/namespaced.ml Outdated Show resolved Hide resolved
lib/paths.ml Show resolved Hide resolved
@Octachron
Copy link
Owner

I have pushed few fixes, and one change in behavior in Modulize to avoid rewriting names.

Copy link
Contributor Author

@dinosaure dinosaure left a comment

Choose a reason for hiding this comment

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

Seems really good even if we some conflicts now!

dinosaure added 17 commits May 4, 2023 15:05
Only for debugging, this function helps to knows which are the caller
for an unexpected value, for instance.
The Modname module is like the Name but with an abstract type. The idea
behind is to provide a nice API and codept as a library. The abstraction
lets us to keep some invariants described into the documentation.

The goal is to use this abstract type for any module names instead of
the Name.t which can refers to several things (path, namespace, module
path, etc.)
The order of dependencies is updated. We probably should implement and
use a compare function for Modname.t and Namespaced.t instead of to use
Stdlib.compare. Regardless the order, the reference still is the same.
The semantic of the Namespaced.t changes a bit. It has 2 views:
- as a module path with x.namespace and x.name (Modname.t)
- as a file path with x.file

This patch update the way to construct Namespaced.t values according to
these views and what we give to:
- Namespaced.make
- Namespaced.of_path
…n.ml

The codept solver returns module names instead of a basic strings. To
compare results and what we abstract, we must cast results to strings
(due to the fact that Modname.t is an abstract type now). The comparison
is also updated due to the new definition of Namespaced.t. We must use
Namespaced.compare instead of Stdlib.(=) to select only one view of a
namespace (the module path view instead of the file path view).
Due to the insertion and the usage of Modname, several modules have new
dependencies. We update them according to the new module Modname.
Due to the Modname.t, we follow the module path view instead of the file
path view. On the serialization process, solver.mli becomes Solver.
The objective of Unitname is to keep the path of a given module. Due to
the namespaced view, it's possible that a path has a signification for
the solver (as a part of the module path). To ensure the bijection on
some elements, we must keep the file path for any modules which are
concretized by a file. Unitname offers two views:
- the module name (introduced by the Modname module)
- the file path used to construct the Unitname

By this way, we ensure the bijection on Unitname elements and we provide
these views depending on the context.
This function, due to the transformation, is integrated into the
Unitname module which keeps the file path given to construct the Modname
value.
To concretize the goal of Unitname, we replace the usage of Modname by
the Unitname module, especially for the Namespaced module to keep the
file path view at some place.

For the Namespaced module, the file record is not needed anymore
because Unitname keeps this information internally.
Instead to have the file path view directly into the Namespaced module,
we use the opportunity to handle extensions into the Unitname module. By
this way, we factorize a bit the Namespaced module by the usage of
Unitname.change_file_extension.
@Octachron Octachron merged commit a6591b6 into Octachron:master May 4, 2023
@dinosaure dinosaure deleted the modname branch May 4, 2023 13:55
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