Skip to content

Commit

Permalink
deploy: 52ea69f
Browse files Browse the repository at this point in the history
  • Loading branch information
raviqqe committed Feb 18, 2024
1 parent 8700f26 commit 95d407e
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 73 deletions.
24 changes: 14 additions & 10 deletions src/melior_macro/dialect/generation/operation_builder.rs.html
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@
<a href="#195" id="195">195</a>
<a href="#196" id="196">196</a>
<a href="#197" id="197">197</a>
<a href="#198" id="198">198</a>
<a href="#199" id="199">199</a>
</pre></div><pre class="rust"><code><span class="kw">use </span><span class="kw">crate</span>::dialect::{
error::Error,
operation::{OperationBuilder, OperationField},
Expand All @@ -205,11 +207,15 @@
<span class="kw">use </span>quote::{format_ident, quote};

<span class="kw">pub fn </span>generate_operation_builder(builder: <span class="kw-2">&amp;</span>OperationBuilder) -&gt; <span class="prelude-ty">Result</span>&lt;TokenStream, Error&gt; {
<span class="kw">let </span>result_fns = builder
.operation()
.results()
.map(|result| generate_field_fn(builder, result))
.collect::&lt;Vec&lt;<span class="kw">_</span>&gt;&gt;();
<span class="kw">let </span>result_fns = <span class="kw">if </span>builder.operation().can_infer_type() {
Default::default()
} <span class="kw">else </span>{
builder
.operation()
.results()
.map(|result| generate_field_fn(builder, result))
.collect::&lt;Vec&lt;<span class="kw">_</span>&gt;&gt;()
};
<span class="kw">let </span>operand_fns = builder
.operation()
.operands()
Expand Down Expand Up @@ -268,7 +274,7 @@
<span class="kw">let </span>identifier = field.singular_identifier();
<span class="kw">let </span>parameter_type = field.parameter_type();
<span class="kw">let </span>argument = <span class="macro">quote! </span>{ #identifier: #parameter_type };
<span class="kw">let </span>add = <span class="macro">format_ident!</span>(<span class="string">"add_{}"</span>, field.plural_kind_identifier());
<span class="kw">let </span>add_identifier = <span class="macro">format_ident!</span>(<span class="string">"add_{}"</span>, field.plural_kind_identifier());

<span class="comment">// Argument types can be singular and variadic. But `add` functions in Melior
// are always variadic, so we need to create a slice or `Vec` for singular
Expand All @@ -281,13 +287,11 @@
<span class="macro">quote! </span>{
<span class="kw">impl</span>&lt;<span class="lifetime">'c</span>, #(#parameters),<span class="kw-2">*</span>&gt; #builder_identifier&lt;<span class="lifetime">'c</span>, #(#parameters),<span class="kw-2">*</span>&gt; {
<span class="kw">pub fn </span>#identifier(<span class="kw-2">mut </span><span class="self">self</span>, #argument) -&gt; #builder_identifier&lt;<span class="lifetime">'c</span>, #(#parameters),<span class="kw-2">*</span>&gt; {
<span class="self">self</span>.builder = <span class="self">self</span>.builder.#add(#add_arguments);
<span class="self">self</span>.builder = <span class="self">self</span>.builder.#add_identifier(#add_arguments);
<span class="self">self
</span>}
}
}
} <span class="kw">else if </span>field.is_result() &amp;&amp; builder.operation().can_infer_type() {
<span class="macro">quote!</span>()
} <span class="kw">else </span>{
<span class="kw">let </span>parameters = builder.type_state().parameters_without(field.name());
<span class="kw">let </span>arguments_set = builder.type_state().arguments_set(field.name(), <span class="bool-val">true</span>);
Expand All @@ -298,7 +302,7 @@
<span class="kw">pub fn </span>#identifier(<span class="self">self</span>, #argument) -&gt; #builder_identifier&lt;<span class="lifetime">'c</span>, #(#arguments_set),<span class="kw-2">*</span>&gt; {
#builder_identifier {
context: <span class="self">self</span>.context,
builder: <span class="self">self</span>.builder.#add(#add_arguments),
builder: <span class="self">self</span>.builder.#add_identifier(#add_arguments),
_state: Default::default(),
}
}
Expand Down
32 changes: 15 additions & 17 deletions src/melior_macro/dialect/operation.rs.html
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,6 @@
<a href="#373" id="373">373</a>
<a href="#374" id="374">374</a>
<a href="#375" id="375">375</a>
<a href="#376" id="376">376</a>
</pre></div><pre class="rust"><code><span class="kw">mod </span>attribute;
<span class="kw">mod </span>builder;
<span class="kw">mod </span>operand;
Expand Down Expand Up @@ -516,20 +515,6 @@
sanitize_documentation(<span class="self">self</span>.definition.str_value(<span class="string">"description"</span>)<span class="question-mark">?</span>)
}

<span class="kw">pub fn </span>fields(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; <span class="kw">impl </span>Iterator&lt;Item = <span class="kw-2">&amp;</span><span class="kw">dyn </span>OperationField&gt; {
<span class="kw">fn </span>convert(field: <span class="kw-2">&amp;</span><span class="kw">impl </span>OperationField) -&gt; <span class="kw-2">&amp;</span><span class="kw">dyn </span>OperationField {
field
}

<span class="self">self</span>.results
.iter()
.map(convert)
.chain(<span class="self">self</span>.operands.iter().map(convert))
.chain(<span class="self">self</span>.regions.iter().map(convert))
.chain(<span class="self">self</span>.successors.iter().map(convert))
.chain(<span class="self">self</span>.attributes().map(convert))
}

<span class="kw">pub fn </span>operands(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; <span class="kw">impl </span>Iterator&lt;Item = <span class="kw-2">&amp;</span>Operand&lt;<span class="lifetime">'a</span>&gt;&gt; + Clone {
<span class="self">self</span>.operands.iter()
}
Expand Down Expand Up @@ -559,8 +544,21 @@
}

<span class="kw">pub fn </span>required_fields(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; <span class="kw">impl </span>Iterator&lt;Item = <span class="kw-2">&amp;</span><span class="kw">dyn </span>OperationField&gt; {
<span class="self">self</span>.fields()
.filter(|field| (!field.is_result() || !<span class="self">self</span>.can_infer_type) &amp;&amp; !field.is_optional())
<span class="kw">fn </span>convert(field: <span class="kw-2">&amp;</span><span class="kw">impl </span>OperationField) -&gt; <span class="kw-2">&amp;</span><span class="kw">dyn </span>OperationField {
field
}

(<span class="kw">if </span><span class="self">self</span>.can_infer_type {
Default::default()
} <span class="kw">else </span>{
<span class="self">self</span>.results.iter()
})
.map(convert)
.chain(<span class="self">self</span>.operands.iter().map(convert))
.chain(<span class="self">self</span>.regions.iter().map(convert))
.chain(<span class="self">self</span>.successors.iter().map(convert))
.chain(<span class="self">self</span>.attributes().map(convert))
.filter(|field| !field.is_optional())
}

<span class="kw">fn </span>collect_successors(definition: Record&lt;<span class="lifetime">'a</span>&gt;) -&gt; <span class="prelude-ty">Result</span>&lt;Vec&lt;Successor&gt;, Error&gt; {
Expand Down
8 changes: 0 additions & 8 deletions src/melior_macro/dialect/operation/attribute.rs.html
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,6 @@
<a href="#166" id="166">166</a>
<a href="#167" id="167">167</a>
<a href="#168" id="168">168</a>
<a href="#169" id="169">169</a>
<a href="#170" id="170">170</a>
<a href="#171" id="171">171</a>
<a href="#172" id="172">172</a>
</pre></div><pre class="rust"><code><span class="kw">use </span><span class="kw">crate</span>::dialect::{
error::Error,
operation::operation_field::OperationField,
Expand Down Expand Up @@ -328,10 +324,6 @@
<span class="self">self</span>.is_optional() || <span class="self">self</span>.has_default_value()
}

<span class="kw">fn </span>is_result(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; bool {
<span class="bool-val">false
</span>}

<span class="kw">fn </span>add_arguments(<span class="kw-2">&amp;</span><span class="self">self</span>, name: <span class="kw-2">&amp;</span>Ident) -&gt; TokenStream {
<span class="kw">let </span>name_string = <span class="kw-2">&amp;</span><span class="self">self</span>.name;

Expand Down
8 changes: 0 additions & 8 deletions src/melior_macro/dialect/operation/operand.rs.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@
<a href="#88" id="88">88</a>
<a href="#89" id="89">89</a>
<a href="#90" id="90">90</a>
<a href="#91" id="91">91</a>
<a href="#92" id="92">92</a>
<a href="#93" id="93">93</a>
<a href="#94" id="94">94</a>
</pre></div><pre class="rust"><code><span class="kw">use super</span>::{OperationElement, OperationField, VariadicKind};
<span class="kw">use </span><span class="kw">crate</span>::dialect::{
error::Error,
Expand Down Expand Up @@ -165,10 +161,6 @@
<span class="self">self</span>.r#type.is_optional()
}

<span class="kw">fn </span>is_result(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; bool {
<span class="bool-val">false
</span>}

<span class="kw">fn </span>add_arguments(<span class="kw-2">&amp;</span><span class="self">self</span>, name: <span class="kw-2">&amp;</span>Ident) -&gt; TokenStream {
<span class="kw">if </span><span class="self">self</span>.r#type.is_variadic() {
<span class="macro">quote! </span>{ #name }
Expand Down
6 changes: 0 additions & 6 deletions src/melior_macro/dialect/operation/operation_field.rs.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
<a href="#10" id="10">10</a>
<a href="#11" id="11">11</a>
<a href="#12" id="12">12</a>
<a href="#13" id="13">13</a>
<a href="#14" id="14">14</a>
<a href="#15" id="15">15</a>
</pre></div><pre class="rust"><code><span class="kw">use </span>proc_macro2::{Ident, TokenStream};
<span class="kw">use </span>syn::Type;

Expand All @@ -25,8 +22,5 @@
<span class="kw">fn </span>return_type(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; Type;
<span class="kw">fn </span>is_optional(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; bool;
<span class="kw">fn </span>add_arguments(<span class="kw-2">&amp;</span><span class="self">self</span>, name: <span class="kw-2">&amp;</span>Ident) -&gt; TokenStream;

<span class="comment">// TODO Remove this.
</span><span class="kw">fn </span>is_result(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; bool;
}
</code></pre></div></section></main></body></html>
8 changes: 0 additions & 8 deletions src/melior_macro/dialect/operation/region.rs.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@
<a href="#73" id="73">73</a>
<a href="#74" id="74">74</a>
<a href="#75" id="75">75</a>
<a href="#76" id="76">76</a>
<a href="#77" id="77">77</a>
<a href="#78" id="78">78</a>
<a href="#79" id="79">79</a>
</pre></div><pre class="rust"><code><span class="kw">use </span><span class="kw">super</span>::OperationField;
<span class="kw">use </span><span class="kw">crate</span>::dialect::{
error::Error,
Expand Down Expand Up @@ -145,10 +141,6 @@
<span class="bool-val">false
</span>}

<span class="kw">fn </span>is_result(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; bool {
<span class="bool-val">false
</span>}

<span class="kw">fn </span>add_arguments(<span class="kw-2">&amp;</span><span class="self">self</span>, name: <span class="kw-2">&amp;</span>Ident) -&gt; TokenStream {
<span class="kw">if </span><span class="self">self</span>.is_variadic() {
<span class="macro">quote! </span>{ #name }
Expand Down
8 changes: 0 additions & 8 deletions src/melior_macro/dialect/operation/result.rs.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@
<a href="#90" id="90">90</a>
<a href="#91" id="91">91</a>
<a href="#92" id="92">92</a>
<a href="#93" id="93">93</a>
<a href="#94" id="94">94</a>
<a href="#95" id="95">95</a>
<a href="#96" id="96">96</a>
</pre></div><pre class="rust"><code><span class="kw">use super</span>::{OperationElement, OperationField, VariadicKind};
<span class="kw">use </span><span class="kw">crate</span>::dialect::{
error::Error,
Expand Down Expand Up @@ -169,10 +165,6 @@
<span class="self">self</span>.r#type.is_optional()
}

<span class="kw">fn </span>is_result(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; bool {
<span class="bool-val">true
</span>}

<span class="kw">fn </span>add_arguments(<span class="kw-2">&amp;</span><span class="self">self</span>, name: <span class="kw-2">&amp;</span>Ident) -&gt; TokenStream {
<span class="kw">if </span><span class="self">self</span>.r#type.is_unfixed() &amp;&amp; !<span class="self">self</span>.r#type.is_optional() {
<span class="macro">quote! </span>{ #name }
Expand Down
8 changes: 0 additions & 8 deletions src/melior_macro/dialect/operation/successor.rs.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@
<a href="#73" id="73">73</a>
<a href="#74" id="74">74</a>
<a href="#75" id="75">75</a>
<a href="#76" id="76">76</a>
<a href="#77" id="77">77</a>
<a href="#78" id="78">78</a>
<a href="#79" id="79">79</a>
</pre></div><pre class="rust"><code><span class="kw">use </span><span class="kw">super</span>::OperationField;
<span class="kw">use </span><span class="kw">crate</span>::dialect::{
error::Error,
Expand Down Expand Up @@ -145,10 +141,6 @@
<span class="bool-val">false
</span>}

<span class="kw">fn </span>is_result(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; bool {
<span class="bool-val">false
</span>}

<span class="kw">fn </span>add_arguments(<span class="kw-2">&amp;</span><span class="self">self</span>, name: <span class="kw-2">&amp;</span>Ident) -&gt; TokenStream {
<span class="kw">if </span><span class="self">self</span>.is_variadic() {
<span class="macro">quote! </span>{ #name }
Expand Down

0 comments on commit 95d407e

Please sign in to comment.