【问题标题】:Updating a program in a CompUnit::PrecompilationStore?更新 CompUnit::PrecompilationStore 中的程序?
【发布时间】:2018-12-12 04:34:35
【问题描述】:

我正在处理由 Rakudo Perl 编译的文档,这些文档可以得到更新。
我将文档存储在 CompUnit::PrecompilationStore::File

如何将旧版本更改为新版本?

以下程序产生相同的输出,就好像新版本没有存储在 CompUnit 中一样。我做错了什么?

use v6.c;
use nqp;
'cache'.IO.unlink if 'cache'.IO ~~ e;
my $precomp-store = CompUnit::PrecompilationStore::File.new(prefix=>'cache'.IO);
my $precomp = CompUnit::PrecompilationRepository::Default.new(store=> $precomp-store );
my $key = nqp::sha1('test.pod6');

'test.pod6'.IO.spurt(q:to/--END--/);
    =begin pod
    =TITLE More and more

    Some text

    =end pod
    --END--
$precomp.precompile('test.pod6'.IO, $key, :force);
my $handle = $precomp.load( $key )[0];
my $resurrected = nqp::atkey($handle.unit,'$=pod')[0];
say $resurrected.contents[1].contents[0];


'test.pod6'.IO.spurt(q:to/--END--/);
    =begin pod
    =TITLE More and more

    Some more text added

    =end pod
    --END--
# $precomp-store.unlock;
# fails with:
# Attempt to unlock mutex by thread not holding it
#  in block <unit> at comp-test.p6 line 30

$precomp.precompile('test.pod6'.IO, $key, :force);
my $new-handle = $precomp.load($key)[0];
my $new-resurrected = nqp::atkey($new-handle.unit,'$=pod')[0];
say $new-resurrected.contents[1].contents[0];

输出总是:

Some text
Some text

更新:我最初的问题是“$handle”而不是“$new-handle”,其中定义了“$new-resurrected”。输出没有变化。

【问题讨论】:

  • 嗨,理查德,我刚刚在另一个 SO 上给您写了一条评论,要求您查看您的问题和现有答案,并可能接受其中一个。这同样适用于所有问题。如果其中一个答案似乎在正确的轨道上,那么对该答案的评论可能会帮助我们集体结束。如果没有一个接近提问者的需求,那么也许在问题中添加评论或编辑它会让我们到达那里。请考虑查看您的所有问题,看看您是否可以以这种方式处理它们。 TIA。

标签: raku


【解决方案1】:

我认为答案可能是in the answer to other, similar question of yours here 通常,CompUnits 旨在不可变。如果对象改变,目标也需要改变。正如@ugexe 所说,

$key 旨在表示一个不可变的名称,以便它始终指向相同的内容。

因此,您实际上可能正在寻找类似 precomp 的行为,但您可能不想使用实际的 CompUnits 来执行此操作。

【讨论】:

  • 我又重新阅读了@ugexe 的答案。我没有考虑不变性的程度。似乎有一些方法可以从缓存中删除内容(称为删除和从缓存中删除的方法)。那么 :force 的目的是什么,如果没有什么可以强制的呢?
  • 您正在强制预编译,但似乎希望它也会强制加载以破坏缓存。这是两个不同的东西。预编译后重新启动程序,以便加载发生在空缓存上,您将看到更新。
【解决方案2】:

正如提到的previouslyload 方法缓存,而不是对precomp 的方法调用。您期望方法precompile 的参数:force 会影响以后对方法load 的调用——这是不正确的。通过跳过对load 的第一次调用并查看对load 的最终调用是否显示更新后的结果,我们可以轻松证明:force预编译 中按预期工作:

use v6.c;
use nqp;
'cache'.IO.unlink if 'cache'.IO ~~ e;
my $precomp-store = CompUnit::PrecompilationStore::File.new(prefix=>'cache'.IO);
my $precomp = CompUnit::PrecompilationRepository::Default.new(store=> $precomp-store );
my $key = nqp::sha1('test.pod6');

'test.pod6'.IO.spurt(q:to/--END--/);
    =begin pod
    =TITLE More and more

    Some text

    =end pod
    --END--
$precomp.precompile('test.pod6'.IO, $key, :force);


'test.pod6'.IO.spurt(q:to/--END--/);
    =begin pod
    =TITLE More and more

    Some more text added

    =end pod
    --END--
# $precomp-store.unlock;
# fails with:
# Attempt to unlock mutex by thread not holding it
#  in block <unit> at comp-test.p6 line 30

$precomp.precompile('test.pod6'.IO, $key, :force);
my $new-handle = $precomp.load($key)[0];
my $new-resurrected = nqp::atkey($new-handle.unit,'$=pod')[0];
say $new-resurrected.contents[1].contents[0];

给出:Some more text added

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-28
    • 1970-01-01
    相关资源
    最近更新 更多