Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Commit

Permalink
Merge tag '0.12.5' into bump/0.12.5
Browse files Browse the repository at this point in the history
  • Loading branch information
nielstron committed Apr 15, 2023
2 parents 2660ed0 + 9b5b162 commit 39e945b
Show file tree
Hide file tree
Showing 16 changed files with 1,308 additions and 261 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ script:
coverage run -a --source=hebi -m hebi compile_pluto examples/smart_contracts/assert_sum.py
- >
coverage run -a --source=hebi -m hebi build examples/smart_contracts/assert_sum.py
# all smart contracts
- >
for i in $(find examples -type f -name "*.py" -not \( -name "broken*" -o -name "extract*" -o -name "__*" \)); do
echo "$i"
Expand Down
3 changes: 3 additions & 0 deletions docs/hebi/compiler.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ <h1 class="title">Module <code>hebi.compiler</code></h1>

from .optimize.optimize_remove_comments import OptimizeRemoveDeadconstants
from .rewrite.rewrite_forbidden_overwrites import RewriteForbiddenOverwrites
from .rewrite.rewrite_guaranteed_variables import RewriteGuaranteedVariables
from .rewrite.rewrite_import import RewriteImport
from .rewrite.rewrite_import_dataclasses import RewriteImportDataclasses
from .rewrite.rewrite_import_hashlib import RewriteImportHashlib
Expand Down Expand Up @@ -774,6 +775,7 @@ <h1 class="title">Module <code>hebi.compiler</code></h1>
RewriteImportDataclasses(),
RewriteInjectBuiltins(),
RewriteDuplicateAssignment(),
RewriteGuaranteedVariables(),
# The type inference needs to be run after complex python operations were rewritten
AggressiveTypeInferencer(),
# Rewrites that circumvent the type inference or use its results
Expand Down Expand Up @@ -838,6 +840,7 @@ <h2 class="section-title" id="header-functions">Functions</h2>
RewriteImportDataclasses(),
RewriteInjectBuiltins(),
RewriteDuplicateAssignment(),
RewriteGuaranteedVariables(),
# The type inference needs to be run after complex python operations were rewritten
AggressiveTypeInferencer(),
# Rewrites that circumvent the type inference or use its results
Expand Down
2 changes: 1 addition & 1 deletion docs/hebi/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ <h3 id="supporters">Supporters</h3>

import warnings

__version__ = &#34;0.1.1.0.12.4&#34;
__version__ = &#34;0.1.1.0.12.5&#34;
__author__ = &#34;nielstron&#34;
__author_email__ = &#34;n.muendler@web.de&#34;
__copyright__ = &#34;Copyright (C) 2023 nielstron&#34;
Expand Down
23 changes: 17 additions & 6 deletions docs/hebi/optimize/optimize_remove_deadvars.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ <h1 class="title">Module <code>hebi.optimize.optimize_remove_deadvars</code></h1

from ..util import CompilingNodeVisitor, CompilingNodeTransformer
from ..type_inference import INITIAL_SCOPE
from ..typed_ast import TypedAnnAssign

&#34;&#34;&#34;
Removes assignments to variables that are never read
Expand Down Expand Up @@ -132,7 +133,9 @@ <h1 class="title">Module <code>hebi.optimize.optimize_remove_deadvars</code></h1
loaded_vars = None
# names that are guaranteed to be available to the current node
# this acts differently to the type inferencer! in particular, ite/while/for all produce their own scope
guaranteed_avail_names = [list(INITIAL_SCOPE.keys())]
guaranteed_avail_names = [
list(INITIAL_SCOPE.keys()) + [&#34;isinstance&#34;, &#34;Union&#34;, &#34;Dict&#34;, &#34;List&#34;]
]

def guaranteed(self, name: str) -&gt; bool:
name = name
Expand Down Expand Up @@ -222,13 +225,15 @@ <h1 class="title">Module <code>hebi.optimize.optimize_remove_deadvars</code></h1
return self.generic_visit(node)
return Pass()

def visit_AnnAssign(self, node: AnnAssign):
def visit_AnnAssign(self, node: TypedAnnAssign):
if (
not isinstance(node.target, Name)
or node.target.id in self.loaded_vars
or not SafeOperationVisitor(sum(self.guaranteed_avail_names, [])).visit(
node.value
)
# only upcasts are safe!
or not node.target.typ &gt;= node.value.typ
):
assert isinstance(
node.target, Name
Expand Down Expand Up @@ -422,7 +427,9 @@ <h3>Methods</h3>
loaded_vars = None
# names that are guaranteed to be available to the current node
# this acts differently to the type inferencer! in particular, ite/while/for all produce their own scope
guaranteed_avail_names = [list(INITIAL_SCOPE.keys())]
guaranteed_avail_names = [
list(INITIAL_SCOPE.keys()) + [&#34;isinstance&#34;, &#34;Union&#34;, &#34;Dict&#34;, &#34;List&#34;]
]

def guaranteed(self, name: str) -&gt; bool:
name = name
Expand Down Expand Up @@ -512,13 +519,15 @@ <h3>Methods</h3>
return self.generic_visit(node)
return Pass()

def visit_AnnAssign(self, node: AnnAssign):
def visit_AnnAssign(self, node: TypedAnnAssign):
if (
not isinstance(node.target, Name)
or node.target.id in self.loaded_vars
or not SafeOperationVisitor(sum(self.guaranteed_avail_names, [])).visit(
node.value
)
# only upcasts are safe!
or not node.target.typ &gt;= node.value.typ
):
assert isinstance(
node.target, Name
Expand Down Expand Up @@ -637,21 +646,23 @@ <h3>Methods</h3>
<div class="desc inherited"><p>Visit a node.</p></div>
</dd>
<dt id="hebi.optimize.optimize_remove_deadvars.OptimizeRemoveDeadvars.visit_AnnAssign"><code class="name flex">
<span>def <span class="ident">visit_AnnAssign</span></span>(<span>self, node: _ast.AnnAssign)</span>
<span>def <span class="ident">visit_AnnAssign</span></span>(<span>self, node: <a title="hebi.typed_ast.TypedAnnAssign" href="../typed_ast.html#hebi.typed_ast.TypedAnnAssign">TypedAnnAssign</a>)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def visit_AnnAssign(self, node: AnnAssign):
<pre><code class="python">def visit_AnnAssign(self, node: TypedAnnAssign):
if (
not isinstance(node.target, Name)
or node.target.id in self.loaded_vars
or not SafeOperationVisitor(sum(self.guaranteed_avail_names, [])).visit(
node.value
)
# only upcasts are safe!
or not node.target.typ &gt;= node.value.typ
):
assert isinstance(
node.target, Name
Expand Down
12 changes: 5 additions & 7 deletions docs/hebi/prelude.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,12 @@ <h1 class="title">Module <code>hebi.prelude</code></h1>
&#34;&#34;&#34;
attached_datum = txout.datum
if isinstance(attached_datum, SomeOutputDatumHash):
res = tx_info.data[attached_datum.datum_hash]
return tx_info.data[attached_datum.datum_hash]
elif isinstance(attached_datum, SomeOutputDatum):
res = attached_datum.datum
return attached_datum.datum
else:
# no datum attached
assert False, &#34;No datum was attached to the given transaction output&#34;
return res


def resolve_datum(
Expand Down Expand Up @@ -285,13 +284,12 @@ <h2 class="section-title" id="header-functions">Functions</h2>
&#34;&#34;&#34;
attached_datum = txout.datum
if isinstance(attached_datum, SomeOutputDatumHash):
res = tx_info.data[attached_datum.datum_hash]
return tx_info.data[attached_datum.datum_hash]
elif isinstance(attached_datum, SomeOutputDatum):
res = attached_datum.datum
return attached_datum.datum
else:
# no datum attached
assert False, &#34;No datum was attached to the given transaction output&#34;
return res</code></pre>
assert False, &#34;No datum was attached to the given transaction output&#34;</code></pre>
</details>
</dd>
<dt id="hebi.prelude.resolve_spent_utxo"><code class="name flex">
Expand Down
5 changes: 5 additions & 0 deletions docs/hebi/rewrite/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ <h2 class="section-title" id="header-submodules">Sub-modules</h2>
<dd>
<div class="desc"></div>
</dd>
<dt><code class="name"><a title="hebi.rewrite.rewrite_guaranteed_variables" href="rewrite_guaranteed_variables.html">hebi.rewrite.rewrite_guaranteed_variables</a></code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt><code class="name"><a title="hebi.rewrite.rewrite_import" href="rewrite_import.html">hebi.rewrite.rewrite_import</a></code></dt>
<dd>
<div class="desc"></div>
Expand Down Expand Up @@ -197,6 +201,7 @@ <h1>Index</h1>
<ul>
<li><code><a title="hebi.rewrite.rewrite_duplicate_assignment" href="rewrite_duplicate_assignment.html">hebi.rewrite.rewrite_duplicate_assignment</a></code></li>
<li><code><a title="hebi.rewrite.rewrite_forbidden_overwrites" href="rewrite_forbidden_overwrites.html">hebi.rewrite.rewrite_forbidden_overwrites</a></code></li>
<li><code><a title="hebi.rewrite.rewrite_guaranteed_variables" href="rewrite_guaranteed_variables.html">hebi.rewrite.rewrite_guaranteed_variables</a></code></li>
<li><code><a title="hebi.rewrite.rewrite_import" href="rewrite_import.html">hebi.rewrite.rewrite_import</a></code></li>
<li><code><a title="hebi.rewrite.rewrite_import_dataclasses" href="rewrite_import_dataclasses.html">hebi.rewrite.rewrite_import_dataclasses</a></code></li>
<li><code><a title="hebi.rewrite.rewrite_import_hashlib" href="rewrite_import_hashlib.html">hebi.rewrite.rewrite_import_hashlib</a></code></li>
Expand Down
Loading

0 comments on commit 39e945b

Please sign in to comment.