Skip to content

Commit

Permalink
deploy: 0444b00
Browse files Browse the repository at this point in the history
  • Loading branch information
Gohla committed Sep 20, 2023
1 parent 7d51b01 commit 0e75a03
Show file tree
Hide file tree
Showing 30 changed files with 127 additions and 118 deletions.
10 changes: 5 additions & 5 deletions 1_programmability/2_non_incremental/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ <h1 id="non-incremental-context"><a class="header" href="#non-incremental-contex
<h2 id="context-module"><a class="header" href="#context-module">Context module</a></h2>
<p>Since we will be implementing three different contexts in this tutorial, we will separate them in different modules.
Create the <code>context</code> module by adding a module to <code>pie/src/lib.rs</code>:</p>
<div id="diff2html_0"></div>
<div class="diff2html" id="diff2html_0"></div>
<script>
document.addEventListener('DOMContentLoaded', function () {
let diff = String.raw`--- pie/src/lib.rs
Expand Down Expand Up @@ -300,7 +300,7 @@ <h2 id="simple-test"><a class="header" href="#simple-test">Simple Test</a></h2>
<p>Run the test by running <code>cargo test</code>.
The output should look something like:</p>
<pre><code class="language-shell "> Compiling pie v0.1.0 (/pie)
Finished test [unoptimized + debuginfo] target(s) in 0.44s
Finished test [unoptimized + debuginfo] target(s) in 0.47s
Running unittests src/lib.rs (/pie/target/debug/deps/pie-6c9d55a7ef727e00)

running 1 test
Expand Down Expand Up @@ -341,7 +341,7 @@ <h2 id="simple-test"><a class="header" href="#simple-test">Simple Test</a></h2>
<h2 id="test-with-multiple-tasks"><a class="header" href="#test-with-multiple-tasks">Test with Multiple Tasks</a></h2>
<p>Our first test only tests a single task that does not use the context, so let's write a test with two tasks where one requires the other to increase our test coverage.
Add the following test:</p>
<div id="diff2html_1"></div>
<div class="diff2html" id="diff2html_1"></div>
<script>
document.addEventListener('DOMContentLoaded', function () {
let diff = String.raw`--- pie/src/context/non_incremental.rs
Expand Down Expand Up @@ -415,7 +415,7 @@ <h2 id="test-with-multiple-tasks"><a class="header" href="#test-with-multiple-ta
<p>The problem is that <code>execute</code> of <code>ToLowerCase</code> takes a <code>Context&lt;Self&gt;</code>, so in <code>impl Task for ToLowerCase</code> it takes a <code>Context&lt;ToLowerCase&gt;</code>, while we're trying to require <code>&amp;ReturnHelloWorld</code> through the context.
This doesn't work as <code>Context&lt;ToLowerCase&gt;::require_task</code> only takes a <code>&amp;ToLowerCase</code> as input.</p>
<p>We could change <code>execute</code> of <code>ToLowerCase</code> to take <code>Context&lt;ReturnHelloWorld&gt;</code>:</p>
<div id="diff2html_2"></div>
<div class="diff2html" id="diff2html_2"></div>
<script>
document.addEventListener('DOMContentLoaded', function () {
let diff = String.raw`--- pie/src/context/non_incremental.rs
Expand Down Expand Up @@ -487,7 +487,7 @@ <h2 id="test-with-multiple-tasks"><a class="header" href="#test-with-multiple-ta
</details>
<p>For now, we will solve this by just using a single task type which is an enumeration of the different possible tasks.
Replace the test with the following:</p>
<div id="diff2html_3"></div>
<div class="diff2html" id="diff2html_3"></div>
<script>
document.addEventListener('DOMContentLoaded', function () {
let diff = String.raw`--- original
Expand Down
8 changes: 4 additions & 4 deletions 2_incrementality/1_require_file/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ <h1 id="requiring-files"><a class="header" href="#requiring-files">Requiring Fil
<p>Since build systems frequently interact with files, and changes to files can affect tasks, we need to keep track of file dependencies.
Therefore, we will extend the <code>Context</code> API with methods to <em>require files</em>, enabling tasks to specify dynamic dependencies to files.</p>
<p>Add a method to the <code>Context</code> trait in <code>pie/src/lib.rs</code>:</p>
<div id="diff2html_0"></div>
<div class="diff2html" id="diff2html_0"></div>
<script>
document.addEventListener('DOMContentLoaded', function () {
let diff = String.raw`--- pie/src/lib.rs
Expand Down Expand Up @@ -257,7 +257,7 @@ <h1 id="requiring-files"><a class="header" href="#requiring-files">Requiring Fil
<p>Now we need to implement this method for <code>NonIncrementalContext</code>.
However, because we will be performing similar file system operations in the incremental context as well, we will create some utility functions for this first.</p>
<p>Add the <code>fs</code> module to <code>pie/src/lib.rs</code>:</p>
<div id="diff2html_1"></div>
<div class="diff2html" id="diff2html_1"></div>
<script>
document.addEventListener('DOMContentLoaded', function () {
let diff = String.raw`--- pie/src/lib.rs
Expand Down Expand Up @@ -384,7 +384,7 @@ <h1 id="requiring-files"><a class="header" href="#requiring-files">Requiring Fil
└── Cargo.toml
</code></pre>
<p>To access these utility functions in the <code>pie</code> crate, add a dependency to <code>dev_shared</code> in <code>pie/Cargo.toml</code> along with another create that will help testing:</p>
<div id="diff2html_2"></div>
<div class="diff2html" id="diff2html_2"></div>
<script>
document.addEventListener('DOMContentLoaded', function () {
let diff = String.raw`--- pie/Cargo.toml
Expand Down Expand Up @@ -490,7 +490,7 @@ <h1 id="requiring-files"><a class="header" href="#requiring-files">Requiring Fil
</details>
<p>Now we are done unwinding our stack and have filesystem and testing utilities.
Make the non-incremental context compatible by changing <code>pie/src/context/non_incremental.rs</code>:</p>
<div id="diff2html_3"></div>
<div class="diff2html" id="diff2html_3"></div>
<script>
document.addEventListener('DOMContentLoaded', function () {
let diff = String.raw`--- pie/src/context/non_incremental.rs
Expand Down
12 changes: 6 additions & 6 deletions 2_incrementality/2_stamp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ <h1 id="stamps"><a class="header" href="#stamps">Stamps</a></h1>
A dependency is inconsistent if after stamping, the new stamp is different from the old stamp.
Therefore, we will implement a <code>FileStamper</code> that stamps files and produces a <code>FileStamp</code>, and an <code>OutputStamper</code> that stamps task outputs and produces an <code>OutputStamp</code>.</p>
<p>Add the <code>stamp</code> module to <code>pie/src/lib.rs</code>:</p>
<div id="diff2html_0"></div>
<div class="diff2html" id="diff2html_0"></div>
<script>
document.addEventListener('DOMContentLoaded', function () {
let diff = String.raw`--- pie/src/lib.rs
Expand Down Expand Up @@ -386,7 +386,7 @@ <h2 id="testing-with-file-modified-time-correctly"><a class="header" href="#test
Even worse, our test can be flaky, sometimes succeeding if we write in between those milliseconds, sometimes failing if we write within a millisecond.</p>
<p>To solve this, add a function to the filesystem testing utility crate.
Change <code>dev_shared/src/lib.rs</code>:</p>
<div id="diff2html_1"></div>
<div class="diff2html" id="diff2html_1"></div>
<script>
document.addEventListener('DOMContentLoaded', function () {
let diff = String.raw`--- dev_shared/src/lib.rs
Expand Down Expand Up @@ -446,7 +446,7 @@ <h2 id="testing-with-file-modified-time-correctly"><a class="header" href="#test
</script>
<p>The <code>write_until_modified</code> function writes to the file, but ensures its modified time will change.
Now change the tests in <code>pie/src/stamp.rs</code> to use this function:</p>
<div id="diff2html_2"></div>
<div class="diff2html" id="diff2html_2"></div>
<script>
document.addEventListener('DOMContentLoaded', function () {
let diff = String.raw`--- pie/src/stamp.rs
Expand Down Expand Up @@ -528,7 +528,7 @@ <h2 id="stamps-in-context"><a class="header" href="#stamps-in-context">Stamps in
However, stampers are constructed by users of the library that author tasks, and they need to pass in these stampers when creating dependencies.
Therefore, we need to update the <code>Context</code> trait to allow passing in these stampers.</p>
<p>Change <code>Context</code> in <code>pie/src/lib.rs</code>:</p>
<div id="diff2html_3"></div>
<div class="diff2html" id="diff2html_3"></div>
<script>
document.addEventListener('DOMContentLoaded', function () {
let diff = String.raw`--- pie/src/lib.rs
Expand Down Expand Up @@ -602,7 +602,7 @@ <h2 id="stamps-in-context"><a class="header" href="#stamps-in-context">Stamps in
We add a default implementation for <code>require_file</code> that passes in a default stamper.
The default is provided by <code>default_require_file_stamper</code> which can be overridden by context implementations.</p>
<p>Now apply the same to tasks, changing <code>Context</code> again in <code>pie/src/lib.rs</code>:</p>
<div id="diff2html_4"></div>
<div class="diff2html" id="diff2html_4"></div>
<script>
document.addEventListener('DOMContentLoaded', function () {
let diff = String.raw`--- pie/src/lib.rs
Expand Down Expand Up @@ -639,7 +639,7 @@ <h2 id="stamps-in-context"><a class="header" href="#stamps-in-context">Stamps in
});
</script>
<p>Update <code>NonIncrementalContext</code> in <code>src/context/non_incremental.rs</code> to implement the new methods:</p>
<div id="diff2html_5"></div>
<div class="diff2html" id="diff2html_5"></div>
<script>
document.addEventListener('DOMContentLoaded', function () {
let diff = String.raw`--- pie/src/context/non_incremental.rs
Expand Down
2 changes: 1 addition & 1 deletion 2_incrementality/3_dependency/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ <h1 id="dynamic-dependencies"><a class="header" href="#dynamic-dependencies">Dyn
To that end, we will implement the <code>FileDependency</code> and <code>TaskDependency</code> types with methods for consistency checking.
We will also implement a <code>Dependency</code> type that abstracts over <code>FileDependency</code> and <code>TaskDependency</code>, which we will need for the dependency graph implementation in the next chapter.</p>
<p>Add the <code>dependency</code> module to <code>pie/src/lib.rs</code>:</p>
<div id="diff2html_0"></div>
<div class="diff2html" id="diff2html_0"></div>
<script>
document.addEventListener('DOMContentLoaded', function () {
let diff = String.raw`--- pie/src/lib.rs
Expand Down
8 changes: 4 additions & 4 deletions 2_incrementality/4_store/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ <h1 id="dependency-graph-store"><a class="header" href="#dependency-graph-store"
</div>
</details>
<p>Add the <code>pie_graph</code> dependency to <code>pie/Cargo.toml</code>:</p>
<div id="diff2html_0"></div>
<div class="diff2html" id="diff2html_0"></div>
<script>
document.addEventListener('DOMContentLoaded', function () {
let diff = String.raw`--- pie/Cargo.toml
Expand Down Expand Up @@ -225,7 +225,7 @@ <h1 id="dependency-graph-store"><a class="header" href="#dependency-graph-store"
</script>
<h2 id="store-basics"><a class="header" href="#store-basics">Store basics</a></h2>
<p>Add the <code>store</code> module to <code>pie/src/lib.rs</code>:</p>
<div id="diff2html_1"></div>
<div class="diff2html" id="diff2html_1"></div>
<script>
document.addEventListener('DOMContentLoaded', function () {
let diff = String.raw`--- pie/src/lib.rs
Expand Down Expand Up @@ -315,7 +315,7 @@ <h2 id="graph-nodes"><a class="header" href="#graph-nodes">Graph nodes</a></h2>
<p>To ensure unique nodes, we need to maintain the reverse mapping from <code>PathBuf</code> and <code>T</code> to <code>Node</code> ourselves, which we will do with <code>HashMap</code>s.
This is also the reason for the <code>Eq</code> and <code>Hash</code> trait bounds on the <code>Task</code> trait, so we can use them as keys in <code>HashMap</code>s.</p>
<p>Change <code>pie/src/store.rs</code> to add hash maps to map between these things:</p>
<div id="diff2html_2"></div>
<div class="diff2html" id="diff2html_2"></div>
<script>
document.addEventListener('DOMContentLoaded', function () {
let diff = String.raw`--- pie/src/store.rs
Expand Down Expand Up @@ -371,7 +371,7 @@ <h2 id="graph-nodes"><a class="header" href="#graph-nodes">Graph nodes</a></h2>
});
</script>
<p>To prevent accidentally using a file node as a task node, and vice versa, change <code>pie/src/store.rs</code> to add specific types of nodes:</p>
<div id="diff2html_3"></div>
<div class="diff2html" id="diff2html_3"></div>
<script>
document.addEventListener('DOMContentLoaded', function () {
let diff = String.raw`--- pie/src/store.rs
Expand Down
22 changes: 11 additions & 11 deletions 2_incrementality/5_context/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ <h1 id="top-down-context"><a class="header" href="#top-down-context">Top-down Co
Now we will create the <code>TopDownContext</code> type which implements the <code>Context</code> trait in an incremental way. </p>
<h2 id="top-down-context-basics"><a class="header" href="#top-down-context-basics">Top-down context basics</a></h2>
<p>Add the <code>top_down</code> module to <code>pie/src/context/mod.rs</code>:</p>
<div id="diff2html_0"></div>
<div class="diff2html" id="diff2html_0"></div>
<script>
document.addEventListener('DOMContentLoaded', function () {
let diff = String.raw`--- pie/src/context/mod.rs
Expand Down Expand Up @@ -241,7 +241,7 @@ <h2 id="requiring-files"><a class="header" href="#requiring-files">Requiring fil
This dependency will go from the <em>current executing task</em> to the file.
Therefore, we will need to keep track of the current executing task.</p>
<p>Change <code>pie/src/context/mod.rs</code> to add a field for tracking the current executing task, and use it in <code>require_file_with_stamper</code>:</p>
<div id="diff2html_1"></div>
<div class="diff2html" id="diff2html_1"></div>
<script>
document.addEventListener('DOMContentLoaded', function () {
let diff = String.raw`--- pie/src/context/top_down.rs
Expand Down Expand Up @@ -297,7 +297,7 @@ <h2 id="requiring-files"><a class="header" href="#requiring-files">Requiring fil
In <code>require_file_with_stamper</code> we're now getting the current executing task.
If there is no current executing task, which only happens if a user directly calls <code>require_file</code> on a context, we don't make a dependency and just open the file.</p>
<p>Now we need to add the file dependency, change <code>pie/src/context/mod.rs</code> to do this: </p>
<div id="diff2html_2"></div>
<div class="diff2html" id="diff2html_2"></div>
<script>
document.addEventListener('DOMContentLoaded', function () {
let diff = String.raw`--- pie/src/context/top_down.rs
Expand Down Expand Up @@ -336,7 +336,7 @@ <h2 id="requiring-tasks"><a class="header" href="#requiring-tasks">Requiring tas
A task should be executed either if it's new (it does not have an output stored yet), or if at least one of its dependencies is inconsistent.
If we don't execute it, then it must have an output value and all its dependencies are consistent, so we just return its output value.</p>
<p>Change <code>pie/src/context/mod.rs</code> to implement this logic:</p>
<div id="diff2html_3"></div>
<div class="diff2html" id="diff2html_3"></div>
<script>
document.addEventListener('DOMContentLoaded', function () {
let diff = String.raw`--- pie/src/context/top_down.rs
Expand Down Expand Up @@ -385,7 +385,7 @@ <h2 id="requiring-tasks"><a class="header" href="#requiring-tasks">Requiring tas
Otherwise, we get the output of the task from the store, which cannot panic because <code>should_execute_task</code> ensures that the task has an output if it returns false.
Finally, we return the output.</p>
<p>We still need to create a task dependency. Change <code>pie/src/context/mod.rs</code> to add the dependency:</p>
<div id="diff2html_4"></div>
<div class="diff2html" id="diff2html_4"></div>
<script>
document.addEventListener('DOMContentLoaded', function () {
let diff = String.raw`--- pie/src/context/top_down.rs
Expand Down Expand Up @@ -468,7 +468,7 @@ <h2 id="requiring-tasks"><a class="header" href="#requiring-tasks">Requiring tas
<h2 id="checking-tasks"><a class="header" href="#checking-tasks">Checking tasks</a></h2>
<p>The final piece to our puzzle is the <code>should_execute_task</code> implementation.</p>
<p>Add the following code to <code>pie/src/context/top_down.rs</code>:</p>
<div id="diff2html_5"></div>
<div class="diff2html" id="diff2html_5"></div>
<script>
document.addEventListener('DOMContentLoaded', function () {
let diff = String.raw`--- pie/src/context/top_down.rs
Expand Down Expand Up @@ -583,7 +583,7 @@ <h2 id="checking-tasks"><a class="header" href="#checking-tasks">Checking tasks<
We've ignored the case where <code>dependency.is_inconsistent</code> returns <code>Err</code>.
When dependency checking result in an error, we should store the error for the user to investigate, and assume the dependency is inconsistent.</p>
<p>Change <code>pie/src/context/mod.rs</code> to store dependency check errors and give users access to it:</p>
<div id="diff2html_6"></div>
<div class="diff2html" id="diff2html_6"></div>
<script>
document.addEventListener('DOMContentLoaded', function () {
let diff = String.raw`--- pie/src/context/top_down.rs
Expand Down Expand Up @@ -625,7 +625,7 @@ <h2 id="checking-tasks"><a class="header" href="#checking-tasks">Checking tasks<
});
</script>
<p>And then change <code>pie/src/context/mod.rs</code> to store these errors:</p>
<div id="diff2html_7"></div>
<div class="diff2html" id="diff2html_7"></div>
<script>
document.addEventListener('DOMContentLoaded', function () {
let diff = String.raw`--- pie/src/context/top_down.rs
Expand Down Expand Up @@ -805,7 +805,7 @@ <h3 id="exploring-incrementality"><a class="header" href="#exploring-incremental
You should see the <code>println!</code> in <code>ReadStringFromFile</code> appear in your console as the incremental context correctly determines that this task is new (i.e., has no output) and must be executed.
It should look something like:</p>
<pre><code> Compiling pie v0.1.0 (/pie)
Finished dev [unoptimized + debuginfo] target(s) in 1.38s
Finished dev [unoptimized + debuginfo] target(s) in 1.42s
Running `/pie/target/debug/examples/incremental`
A) New task: expect `read_task` to execute
Reading from input.txt with Modified stamper
Expand All @@ -821,7 +821,7 @@ <h4 id="reuse"><a class="header" href="#reuse">Reuse</a></h4>
</code></pre>
<p>Running with <code>cargo run --example incremental</code> should produce output like:</p>
<pre><code> Compiling pie v0.1.0 (/pie)
Finished dev [unoptimized + debuginfo] target(s) in 0.66s
Finished dev [unoptimized + debuginfo] target(s) in 0.69s
Running `/pie/target/debug/examples/incremental`
A) New task: expect `read_task` to execute
Reading from input.txt with Modified stamper
Expand Down Expand Up @@ -974,7 +974,7 @@ <h4 id="same-file-different-stampers"><a class="header" href="#same-file-differe
<p>Of course, using an <code>Exists</code> stamper for <code>ReadStringFromFile</code> does not make a lot of sense, but this is for demonstration purposes only.</p>
<p>Running <code>cargo run --example incremental</code> now should produce output like:</p>
<pre><code> Compiling pie v0.1.0 (/pie)
Finished dev [unoptimized + debuginfo] target(s) in 0.78s
Finished dev [unoptimized + debuginfo] target(s) in 0.81s
Running `/pie/target/debug/examples/incremental`
A) New task: expect `read_task` to execute
Reading from input.txt with Modified stamper
Expand Down
Loading

0 comments on commit 0e75a03

Please sign in to comment.