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 candidates method as CURI recommendation manager #1125

Closed
wants to merge 7 commits into from
Closed

Add candidates method as CURI recommendation manager #1125

wants to merge 7 commits into from

Conversation

ugexe
Copy link
Member

@ugexe ugexe commented Jul 30, 2017

Add method candidates - All distribution searching/resolving go
through this new method. This gives developers insight into how a
CURI resolves a module request, which was not possible with .resolve
(since it would chain to the next CUR, and only returned a single
result). Many NYI s22 features will require something like this, and
.candidates is indeed mentioned in s22
https://design.perl6.org/S22.html#candidates

!matching-dist is now backed by .candidates, but also caches a single
'best match' so it acts similar to before.

.candidates (i.e. !matching-dist) now returns a Distribution object
and not ($dist-id, $dist-data). This is possible because of a role
that allows our lazy distribution to avoid yet additional costly IO
calls to obtain meta data. Previously this was done by passing around
a hash internally, but now we dogfood our Distribution interface
throughout CURI.

Avoid io after setting up various directories once.

Removes .script, and reverts to using just .files - .script was just
a fast path of .files under certain conditions and lacked the ability
to filter by name. Now .files can provide the faster path for other
files automatically. Additionally this fixes an issue where .script
would invoke older version bin/ scripts from ~/.perl6

Adds :$api field wherever it was missing for consistency.

Add `method candidates` - All distribution searching/resolving go
through this new method. This gives developers insight into how a
CURI resolves a module request, which was not possible with .resolve
(since it would chain to the next CUR, and only returned a single
result). Many NYI s22 features will require something like this, and
.candidates is indeed mentioned in s22 https://design.perl6.org/S22.html#candidates

!matching-dist is now backed by .candidates, but also caches a single
'best match' so it acts similar to before.

.candidates (i.e. !matching-dist) now returns a Distribution object
and not ($dist-id, $dist-data). This is possible because of a role
that allows our lazy distribution to avoid yet additional costly IO
calls to obtain meta data. Previously this was done by passing around
a hash internally, but now we dogfood our Distribution interface
throughout CURI.

Avoid io after setting up various directories once.

Removes .script, and reverts to using just .files - .script was just
a fast path of .files under certain conditions and lacked the ability
to filter by name. Now .files can provide the faster path for other
files automatically. Additionally this fixes an issue where .script
would invoke older version bin/ scripts from ~/.perl6

Adds :$api field wherever it was missing for consistency.
:version($dist<ver>),
:auth($dist<auth> // Str),
:version(.meta<ver>),
:auth(.meta<auth> // Str),
Copy link
Member Author

Choose a reason for hiding this comment

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

I wonder: does CompUnit still need :version and :auth now that these can be provided via $cu.distribution.meta<ver>? Or maybe we should use the distribution, if provided, to provide default values for those fields?

@niner
Copy link
Collaborator

niner commented Aug 5, 2017

My standard benchmark (require GTK::Simple) does not show any change outside the margin of error :)

@niner
Copy link
Collaborator

niner commented Aug 5, 2017

But this is not good :(

nine@sphinx:~> zef
Use of uninitialized value of type Any in string context.
Methods .^name, .perl, .gist, or .say can be used to stringify it to something meaningful.
  in sub MAIN at /home/nine/rakudo/install/share/perl6/site/bin/zef line 2
Use of uninitialized value of type Any in string context.
Methods .^name, .perl, .gist, or .say can be used to stringify it to something meaningful.
  in sub MAIN at /home/nine/rakudo/install/share/perl6/site/bin/zef line 2
Could not find /home/nine/.perl6/resources in:
    /home/nine/.perl6
    /home/nine/rakudo/install/share/perl6/site
    /home/nine/rakudo/install/share/perl6/vendor
    /home/nine/rakudo/install/share/perl6
    CompUnit::Repository::AbsolutePath<29344704>
    CompUnit::Repository::NQP<32911168>
    CompUnit::Repository::Perl5<32911208>
  in sub MAIN at /home/nine/rakudo/install/share/perl6/site/bin/zef line 2
  in block <unit> at /home/nine/rakudo/install/share/perl6/site/bin/zef line 2

Happens to a zef installed on nom after switching rakudo to your branch.

It made sense for the .files/.candidates api to take an explicit
bin/ (if looking for bin/foo). It could make sense for this
.run-script + wrapper, but it also make sense without since the
method name implies the name-path prefix is a bin/ script.

Since a rakudo installation can be upgraded with distributions
(i.e. bin/ scripts) already installed we should continue to use
the current behavior of an implicit bin/ prefix.
Even if this doesn't result in a obvious speed increase, it has
the ability to. Consider that a lazy Distribution may eventually
end up parsing json (its slow path) to fill out the rest of its
fields (anything that isn't name/auth/ver/source/checksum) - once
this happens we may as well serve all future requests with those
fields so they don't have to do another parse.
Sometimes the lookup file may not contain the source id. In these
cases we need to fall back to the slower json-parsing code path.
This also revealed a bug where old meta data was being returned
for a LazyDistribution after the first json parsing.
ugexe added a commit that referenced this pull request Aug 17, 2017
See #1125 for .candidates details

Creates full Distribution for both -I. and -Ilib, where the later will use the directory recursion it was already doing (to determine id) to automatically populate meta data for provides and files (bin/, resources/).

Makes it possible to do `sub MAIN("version") { $*REPO.need("My::Module").distribution.meta<ver> }` to allow scripts to give the right version regardless of CURI or CURFS being used to load it.
@ugexe ugexe changed the base branch from nom to master October 27, 2017 00:31
ugexe added a commit to Raku/roast that referenced this pull request Nov 1, 2017
If a distribution is not found then do not cache the value. This allows run time module installations to be found with resolve/candidates.
Name meta data variables $meta instead of $dist
@ugexe ugexe closed this Nov 24, 2017
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