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

Support go to definition for the standard library #1592

Merged
merged 7 commits into from
Oct 19, 2022

Conversation

paulcadman
Copy link
Collaborator

@paulcadman paulcadman commented Oct 18, 2022

The fundamental change in this PR is that the standard library is now read from disk instead of being read from an in memory representation.

When the compiler pipeline is run, the standard library that is embedded in the juvix binary is written to .juvix-build/stdlib in the Juvix project. When the standard library is used, it is read from this location.

Implementation

topModulePathToFilePath' now obtains the absolute path of a top module from the Files effect instead of constructing the path using the root directory of the Juvix project. The Files effect knows which modules are in the standard library and so can return the relevant path to the caller.

getAbsPath (topModulePathToRelativeFilePath ext "" (</>) mp)

Loc construction

The mkLoc function used to have the root path of the Juvix project passed in to construct the location file path from the megaparsec SourcePosition. However the sourceName field of the SourcePosition is already absolute, so the path construction was no-op and could be removed.

https://github.com/anoma/juvix/pull/1592/files#diff-407b13d649a9b0e8da32f30d91394ce87893373b6b9c3db4bcd76c58897fc14dR40

Updating .juvix-build/stdlib

.juvix-build/stdlib is recreated whenever the versionTag (version + commit hash) of the Juvix binary changes. The current version of the standard library is stored in a file .juvix-build/stdlib/.version.

Using a custom stdlib

Instead of using the pre-bundled standard library you can specify --stdlib-path PATH on the CLI to use an existing checkout of the standard library instead.

The custom stdlib flag can also be set as an emacs Juvix-mode customisation variable juvix-stdlib-path

New dependencies

Both path and path-io dependencies are added to implement the getFilesRecursive function:

getFilesRecursive :: FilePath -> IO [FilePath]

I'm not 100% certain but I think the only new transitive dependency this adds is dlist.

Closes #1470

@paulcadman paulcadman added enhancement New feature or request standard-library labels Oct 18, 2022
@paulcadman paulcadman added this to the 0.2.6 milestone Oct 18, 2022
@paulcadman paulcadman self-assigned this Oct 18, 2022
@paulcadman paulcadman force-pushed the root-from-files-effect branch from 7e835d0 to 67ca7df Compare October 18, 2022 13:38
ParserParams is only used to record the root of the project, which is
used to prefix source file paths. However source file paths are always
absolute so this is not required.
The Files effect is not responsible for resolving a relative module
path into an absolute path on disk. This will allow us to resolve
relative module paths to alternative paths, for example to point to the
standard library on disk.
library

This means that the standard library can exist on disk at a different
location to the Juvix project.

A command line flag --stdlib-path can be specified to point to a
standard library, otherwise the embedded standard library is written to
disk at $PROJ_DIR/.juvix-build/stdlib and this is used instead.
@paulcadman paulcadman force-pushed the root-from-files-effect branch from 652d224 to c69410f Compare October 19, 2022 14:29
Copy link
Collaborator

@janmasrovira janmasrovira left a comment

Choose a reason for hiding this comment

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

🥇

@paulcadman paulcadman merged commit 9e7a8a9 into main Oct 19, 2022
@paulcadman paulcadman deleted the root-from-files-effect branch October 19, 2022 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request standard-library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support go to definition for the standard library
2 participants