Skip to content

Commit 1a2c903

Browse files
committed
Merge branch 'vaivaswatha/sroa_gep_fix' of github.com:FuelLabs/sway into vaivaswatha/sroa_gep_fix
2 parents b075541 + 3bd5994 commit 1a2c903

File tree

95 files changed

+1298
-1144
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+1298
-1144
lines changed

forc-plugins/forc-doc/src/doc/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl Documentation {
8484
let primitive_docs: Vec<_> = impl_traits
8585
.par_iter()
8686
.filter_map(|(impl_trait, module_info)| {
87-
let impl_for_type = engines.te().get(impl_trait.implementing_for.type_id());
87+
let impl_for_type = engines.te().get(impl_trait.implementing_for.type_id);
8888
if let Ok(Descriptor::Documentable(doc)) =
8989
Descriptor::from_type_info(impl_for_type.as_ref(), engines, module_info.clone())
9090
{

forc-plugins/forc-doc/src/render/item/context.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl Renderable for Context {
6161
for field in fields {
6262
let struct_field_id = format!("structfield.{}", field.name.as_str());
6363
let type_anchor = render_type_anchor(
64-
(*render_plan.engines.te().get(field.type_argument.type_id())).clone(),
64+
(*render_plan.engines.te().get(field.type_argument.type_id)).clone(),
6565
&render_plan,
6666
&self.module_info,
6767
);
@@ -89,7 +89,7 @@ impl Renderable for Context {
8989
for field in fields {
9090
let storage_field_id = format!("storagefield.{}", field.name.as_str());
9191
let type_anchor = render_type_anchor(
92-
(*render_plan.engines.te().get(field.type_argument.type_id())).clone(),
92+
(*render_plan.engines.te().get(field.type_argument.type_id)).clone(),
9393
&render_plan,
9494
&self.module_info,
9595
);
@@ -117,11 +117,7 @@ impl Renderable for Context {
117117
for variant in variants {
118118
let enum_variant_id = format!("variant.{}", variant.name.as_str());
119119
let type_anchor = render_type_anchor(
120-
(*render_plan
121-
.engines
122-
.te()
123-
.get(variant.type_argument.type_id()))
124-
.clone(),
120+
(*render_plan.engines.te().get(variant.type_argument.type_id)).clone(),
125121
&render_plan,
126122
&self.module_info,
127123
);

forc-plugins/forc-doc/src/render/item/type_anchor.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub(crate) fn render_type_anchor(
2323
match type_info {
2424
TypeInfo::Array(ty_arg, len) => {
2525
let inner = render_type_anchor(
26-
(*render_plan.engines.te().get(ty_arg.type_id())).clone(),
26+
(*render_plan.engines.te().get(ty_arg.type_id)).clone(),
2727
render_plan,
2828
current_module_info,
2929
)?;
@@ -36,7 +36,7 @@ pub(crate) fn render_type_anchor(
3636
}
3737
TypeInfo::Slice(ty_arg) => {
3838
let inner = render_type_anchor(
39-
(*render_plan.engines.te().get(ty_arg.type_id())).clone(),
39+
(*render_plan.engines.te().get(ty_arg.type_id)).clone(),
4040
render_plan,
4141
current_module_info,
4242
)?;
@@ -50,7 +50,7 @@ pub(crate) fn render_type_anchor(
5050
let mut rendered_args: Vec<_> = Vec::new();
5151
for ty_arg in ty_args {
5252
rendered_args.push(render_type_anchor(
53-
(*render_plan.engines.te().get(ty_arg.type_id())).clone(),
53+
(*render_plan.engines.te().get(ty_arg.type_id)).clone(),
5454
render_plan,
5555
current_module_info,
5656
)?);

forc-plugins/forc-migrate/src/migrations/new_hashing.rs

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use sway_core::{
1717
ty::{TyExpression, TyStorageField, TyStructDecl},
1818
CallPath,
1919
},
20-
Engines, GenericArgument, TypeId, TypeInfo, TypeParameter,
20+
Engines, TypeId, TypeInfo, TypeParameter,
2121
};
2222
use sway_error::formatting::{plural_s, sequence_to_str, Enclosing};
2323
use sway_types::Spanned;
@@ -203,10 +203,8 @@ fn review_existing_usages_of_storage_map_sha256_and_keccak256(
203203
TypeInfo::Enum(decl_id) => {
204204
let enum_decl = engines.de().get_enum(decl_id);
205205
for variant in enum_decl.variants.iter() {
206-
if let GenericArgument::Type(ta) = &variant.type_argument {
207-
if let Some(is_affected) = is_affected_type_impl(visitor, engines, original_type_name, ta.type_id, depth + 1) {
208-
return Some(is_affected);
209-
}
206+
if let Some(is_affected) = is_affected_type_impl(visitor, engines, original_type_name, variant.type_argument.type_id, depth + 1) {
207+
return Some(is_affected);
210208
}
211209
}
212210
None
@@ -219,21 +217,17 @@ fn review_existing_usages_of_storage_map_sha256_and_keccak256(
219217
review_affected_type(original_type_name, &engines.help_out(type_id).to_string(), depth)
220218
} else {
221219
for field in struct_decl.fields.iter() {
222-
if let GenericArgument::Type(ta) = &field.type_argument {
223-
if let Some(is_affected) = is_affected_type_impl(visitor, engines, original_type_name, ta.type_id, depth + 1) {
224-
return Some(is_affected);
225-
}
220+
if let Some(is_affected) = is_affected_type_impl(visitor, engines, original_type_name, field.type_argument.type_id, depth + 1) {
221+
return Some(is_affected);
226222
}
227223
}
228224
None
229225
}
230226
},
231227
TypeInfo::Tuple(generic_arguments) => {
232228
for generic_argument in generic_arguments.iter() {
233-
if let GenericArgument::Type(ta) = generic_argument {
234-
if let Some(is_affected) = is_affected_type_impl(visitor, engines, original_type_name, ta.type_id, depth + 1) {
235-
return Some(is_affected);
236-
}
229+
if let Some(is_affected) = is_affected_type_impl(visitor, engines, original_type_name, generic_argument.type_id, depth + 1) {
230+
return Some(is_affected);
237231
}
238232
}
239233
None
@@ -246,11 +240,7 @@ fn review_existing_usages_of_storage_map_sha256_and_keccak256(
246240
// Still, we will handle the type itself, to be on the safe side.
247241
| TypeInfo::Slice(generic_argument)
248242
| TypeInfo::Alias { ty: generic_argument, .. }
249-
| TypeInfo::Ref { referenced_type: generic_argument, .. } => match generic_argument {
250-
GenericArgument::Type(ta) => is_affected_type_impl(visitor, engines, original_type_name, ta.type_id, depth + 1),
251-
GenericArgument::Const(_) => None,
252-
},
253-
243+
| TypeInfo::Ref { referenced_type: generic_argument, .. } => is_affected_type_impl(visitor, engines, original_type_name, generic_argument.type_id, depth + 1),
254244
// Trait type.
255245
TypeInfo::TraitType { implemented_in, .. } => is_affected_type_impl(visitor, engines, original_type_name, *implemented_in, depth + 1),
256246
}
@@ -597,12 +587,7 @@ fn review_existing_usages_of_storage_map_sha256_and_keccak256(
597587
ty_storage_field: Option<&TyStorageField>,
598588
output: &mut Vec<Occurrence>,
599589
) -> Result<InvalidateTypedElement> {
600-
if let Some(ty_field_type) = ty_storage_field.and_then(|ty_storage_field| {
601-
match &ty_storage_field.type_argument {
602-
GenericArgument::Type(ty) => Some(ty.type_id),
603-
GenericArgument::Const(_) => None,
604-
}
605-
}) {
590+
if let Some(ty_field_type) = ty_storage_field.map(|x| x.type_argument.type_id) {
606591
let Some(help_message) =
607592
self.is_affected_storage_field_type(ctx.engines, ty_field_type)
608593
else {

forc-plugins/forc-migrate/src/migrations/try_from_bytes_for_b256.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ fn replace_bytes_into_b256_with_try_into_b256_step(
164164
let method_return_type = ctx
165165
.engines
166166
.te()
167-
.get(ty_method_call_info.fn_decl.return_type.type_id());
167+
.get(ty_method_call_info.fn_decl.return_type.type_id);
168168
let method_target_is_bytes_struct = match ctx
169169
.engines
170170
.te()

justfile

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,30 +36,37 @@ collect-gas-usage:
3636
cargo r -p test --release -- --verbose --forc-test-only | ./scripts/compare-gas-usage/extract-gas-usage.sh
3737

3838
# This recipe should be used on snapshot tests that contains gas usage from `forc test`,
39-
# because it will extract gas usage from all versions of the file and generate an html interactive report.
39+
# because it will extract gas usage from all versions of the file
40+
# revision_range: as used in git to select the versions of the file that gas will be extracted
4041
# path: path to file to extract gas usage
41-
# open: "-o" will open the default browser showing the report
42+
# report: csv or html
43+
# open: for "html", "-o" will open the report in the default browser
4244
[linux]
4345
[group('benchmark')]
44-
collect-historic-gas-usage path open:
46+
collect-historic-gas-usage revision_range path report open="":
4547
#! /bin/bash
4648
mkdir -p target
47-
rm target/a.csv
48-
rm target/a.html
49+
rm target/a.csv &>> /dev/null
50+
rm target/a.html &>> /dev/null
4951
echo "test,gas,commit" > target/a.csv
50-
for HASH in `git log --format='%H' -- {{path}}`; do
52+
for HASH in `git log --format='%H' {{revision_range}} -- {{path}}`; do
5153
TIMESTAMP=$(git show -s --format='%as-%ct-%H' "$HASH")
5254
git --no-pager show "$HASH:{{path}}" | bash -c "scripts/compare-gas-usage/extract-gas-usage.sh $TIMESTAMP" >> target/a.csv
5355
done
54-
./scripts/csv2html/csv2html.sh target/a.csv >> target/a.html
55-
if [ -n "{{open}}" ]; then
56-
if which xdg-open &>> /dev/null
57-
then
58-
xdg-open target/a.html
59-
elif which gnome-open &>> /dev/null
60-
then
61-
gnome-open target/a.html
56+
57+
if [ "{{report}}" = "html" ]; then
58+
./scripts/csv2html/csv2html.sh target/a.csv >> target/a.html
59+
if [ -n "{{open}}" ]; then
60+
if which xdg-open &>> /dev/null
61+
then
62+
xdg-open target/a.html
63+
elif which gnome-open &>> /dev/null
64+
then
65+
gnome-open target/a.html
66+
fi
6267
fi
68+
else
69+
clipivot max target/a.csv --rows=test --cols=commit --val=gas > target/b.csv
6370
fi
6471

6572
[group('build')]

scripts/csv2html/csv2html.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,4 @@ tail -n +2 "$1" | sed -e 's/^/<tr><td>/' -e 's/,/<\/td><td>/g' -e 's/$/<\/td><\/
5757
echo " </tbody>
5858
</table>
5959
<body>
60-
</html>"
60+
</html>"

sway-core/src/abi_generation/abi_str.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
use crate::{
2+
ast_elements::type_argument::GenericTypeArgument, language::CallPath, transform, Engines,
3+
TypeId, TypeInfo,
4+
};
15
use sway_error::handler::{ErrorEmitted, Handler};
26
use sway_types::{integer_bits::IntegerBits, Ident, Named};
37

4-
use crate::{language::CallPath, transform, Engines, GenericArgument, TypeId, TypeInfo};
5-
68
#[derive(Clone)]
79
pub struct AbiStrContext {
810
pub program_name: String,
@@ -35,18 +37,17 @@ impl TypeId {
3537
| (TypeInfo::Custom { .. }, TypeInfo::Enum { .. }) => type_engine
3638
.get(resolved_type_id)
3739
.abi_str(handler, ctx, engines, true),
38-
(_, TypeInfo::Alias { ty, .. }) => {
39-
ty.type_id()
40-
.get_abi_type_str(handler, ctx, engines, ty.type_id())
41-
}
40+
(_, TypeInfo::Alias { ty, .. }) => ty
41+
.type_id
42+
.get_abi_type_str(handler, ctx, engines, ty.type_id),
4243
(TypeInfo::Tuple(fields), TypeInfo::Tuple(resolved_fields)) => {
4344
assert_eq!(fields.len(), resolved_fields.len());
4445
let field_strs = resolved_fields
4546
.iter()
4647
.map(|f| {
4748
if ctx.abi_with_fully_specified_types {
4849
type_engine
49-
.get(f.type_id())
50+
.get(f.type_id)
5051
.abi_str(handler, ctx, engines, false)
5152
} else {
5253
Ok("_".to_string())
@@ -65,7 +66,7 @@ impl TypeId {
6566
);
6667
let inner_type = if ctx.abi_with_fully_specified_types {
6768
type_engine
68-
.get(type_arg.type_id())
69+
.get(type_arg.type_id)
6970
.abi_str(handler, ctx, engines, false)?
7071
} else {
7172
"_".to_string()
@@ -79,7 +80,7 @@ impl TypeId {
7980
(TypeInfo::Slice(type_arg), TypeInfo::Slice(_)) => {
8081
let inner_type = if ctx.abi_with_fully_specified_types {
8182
type_engine
82-
.get(type_arg.type_id())
83+
.get(type_arg.type_id)
8384
.abi_str(handler, ctx, engines, false)?
8485
} else {
8586
"_".to_string()
@@ -255,7 +256,7 @@ fn call_path_display(ctx: &AbiStrContext, call_path: &CallPath) -> String {
255256
buf
256257
}
257258

258-
impl GenericArgument {
259+
impl GenericTypeArgument {
259260
pub(self) fn abi_str(
260261
&self,
261262
handler: &Handler,
@@ -265,7 +266,7 @@ impl GenericArgument {
265266
) -> Result<String, ErrorEmitted> {
266267
engines
267268
.te()
268-
.get(self.type_id())
269+
.get(self.type_id)
269270
.abi_str(handler, ctx, engines, is_root)
270271
}
271272
}

sway-core/src/abi_generation/evm_abi.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ use sway_types::{integer_bits::IntegerBits, Named};
22

33
use crate::{
44
asm_generation::EvmAbiResult,
5+
ast_elements::type_argument::GenericTypeArgument,
56
decl_engine::DeclId,
67
language::ty::{TyFunctionDecl, TyProgram, TyProgramKind},
7-
Engines, GenericArgument, TypeId, TypeInfo,
8+
Engines, TypeId, TypeInfo,
89
};
910

1011
pub fn generate_abi_program(program: &TyProgram, engines: &Engines) -> EvmAbiResult {
@@ -171,20 +172,20 @@ pub fn abi_param_type(type_info: &TypeInfo, engines: &Engines) -> ethabi::ParamT
171172
Tuple(fields) => ethabi::ParamType::Tuple(
172173
fields
173174
.iter()
174-
.map(|f| abi_param_type(&type_engine.get(f.type_id()), engines))
175+
.map(|f| abi_param_type(&type_engine.get(f.type_id), engines))
175176
.collect::<Vec<ethabi::ParamType>>(),
176177
),
177178
Struct(decl_ref) => {
178179
let decl = decl_engine.get_struct(decl_ref);
179180
ethabi::ParamType::Tuple(
180181
decl.fields
181182
.iter()
182-
.map(|f| abi_param_type(&type_engine.get(f.type_argument.type_id()), engines))
183+
.map(|f| abi_param_type(&type_engine.get(f.type_argument.type_id), engines))
183184
.collect::<Vec<ethabi::ParamType>>(),
184185
)
185186
}
186187
Array(elem_ty, ..) => ethabi::ParamType::Array(Box::new(abi_param_type(
187-
&type_engine.get(elem_ty.type_id()),
188+
&type_engine.get(elem_ty.type_id),
188189
engines,
189190
))),
190191
_ => panic!("cannot convert type to Solidity ABI param type: {type_info:?}",),
@@ -205,9 +206,9 @@ fn generate_abi_function(
205206
name: x.name.to_string(),
206207
kind: ethabi::ParamType::Address,
207208
internal_type: Some(get_type_str(
208-
&x.type_argument.type_id(),
209+
&x.type_argument.type_id,
209210
engines,
210-
x.type_argument.type_id(),
211+
x.type_argument.type_id,
211212
)),
212213
})
213214
.collect::<Vec<_>>();
@@ -217,9 +218,9 @@ fn generate_abi_function(
217218
name: String::default(),
218219
kind: ethabi::ParamType::Address,
219220
internal_type: Some(get_type_str(
220-
&fn_decl.return_type.type_id(),
221+
&fn_decl.return_type.type_id,
221222
engines,
222-
fn_decl.return_type.type_id(),
223+
fn_decl.return_type.type_id,
223224
)),
224225
};
225226

@@ -234,6 +235,6 @@ fn generate_abi_function(
234235
})
235236
}
236237

237-
fn abi_str_type_arg(type_arg: &GenericArgument, engines: &Engines) -> String {
238-
abi_str(&engines.te().get(type_arg.type_id()), engines)
238+
fn abi_str_type_arg(type_arg: &GenericTypeArgument, engines: &Engines) -> String {
239+
abi_str(&engines.te().get(type_arg.type_id), engines)
239240
}

0 commit comments

Comments
 (0)