Skip to content

Commit

Permalink
Merge 5741103 into 5085545
Browse files Browse the repository at this point in the history
  • Loading branch information
xunilrj authored Jul 23, 2024
2 parents 5085545 + 5741103 commit 421d20c
Show file tree
Hide file tree
Showing 61 changed files with 2,476 additions and 217 deletions.
784 changes: 784 additions & 0 deletions a.txt

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions forc-plugins/forc-doc/src/render/item/type_anchor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ pub(crate) fn render_type_anchor(
: format!("; {}]", len.val());
})
}
TypeInfo::Slice(ty_arg) => {
let inner = render_type_anchor(
(*render_plan.engines.te().get(ty_arg.type_id)).clone(),
render_plan,
current_module_info,
)?;
Ok(box_html! {
: "__slice[";
: inner;
: "]";
})
}
TypeInfo::Tuple(ty_args) => {
let mut rendered_args: Vec<_> = Vec::new();
for ty_arg in ty_args {
Expand Down
6 changes: 6 additions & 0 deletions sway-ast/src/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ pub enum Intrinsic {
EncodeBufferEmpty, // let buffer: (raw_ptr, u64, u64) = __encode_buffer_empty()
EncodeBufferAppend, // let buffer: (raw_ptr, u64, u64) = __encode_buffer_append(buffer, primitive data type)
EncodeBufferAsRawSlice, // let slice: raw_slice = __encode_buffer_as_raw_slice(buffer)
Slice, // let ref_to_slice = __slice(array or ref to slice, inclusive_start_index, exclusive_end_index)
SliceElem, // let ref_to_item = __slice_elem(ref to slice, index)
}

impl fmt::Display for Intrinsic {
Expand Down Expand Up @@ -85,6 +87,8 @@ impl fmt::Display for Intrinsic {
Intrinsic::EncodeBufferEmpty => "encode_buffer_empty",
Intrinsic::EncodeBufferAppend => "encode_buffer_append",
Intrinsic::EncodeBufferAsRawSlice => "encode_buffer_as_raw_slice",
Intrinsic::Slice => "slice",
Intrinsic::SliceElem => "slice_elem",
};
write!(f, "{s}")
}
Expand Down Expand Up @@ -133,6 +137,8 @@ impl Intrinsic {
"__encode_buffer_empty" => EncodeBufferEmpty,
"__encode_buffer_append" => EncodeBufferAppend,
"__encode_buffer_as_raw_slice" => EncodeBufferAsRawSlice,
"__slice" => Slice,
"__slice_elem" => SliceElem,
_ => return None,
})
}
Expand Down
8 changes: 8 additions & 0 deletions sway-core/src/abi_generation/abi_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ impl TypeId {
};
format!("[{}; {}]", inner_type, count.val())
}
(TypeInfo::Slice(type_arg), TypeInfo::Slice(_)) => {
let inner_type = if ctx.abi_with_fully_specified_types {
type_engine.get(type_arg.type_id).abi_str(ctx, engines)
} else {
"_".to_string()
};
format!("[{}]", inner_type)
}
(TypeInfo::Custom { .. }, _) => {
format!("generic {}", self_abi_str)
}
Expand Down
1 change: 1 addition & 0 deletions sway-core/src/abi_generation/evm_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ fn get_type_str(type_id: &TypeId, engines: &Engines, resolved_type_id: TypeId) -
assert_eq!(count.val(), resolved_count.val());
format!("[_; {}]", count.val())
}
(TypeInfo::Slice(_), TypeInfo::Slice(_)) => "__slice[_]".into(),
(TypeInfo::Custom { .. }, _) => {
format!("generic {}", abi_str(&type_engine.get(*type_id), engines))
}
Expand Down
41 changes: 41 additions & 0 deletions sway-core/src/abi_generation/fuel_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,47 @@ impl TypeId {
unreachable!();
}
}
TypeInfo::Slice(..) => {
if let TypeInfo::Slice(elem_ty) = &*type_engine.get(resolved_type_id) {
// The `program_abi::TypeDeclaration`s needed for the slice element type
let elem_abi_ty = program_abi::TypeDeclaration {
type_id: elem_ty.initial_type_id.index(),
type_field: elem_ty.initial_type_id.get_abi_type_str(
&ctx.to_str_context(engines, false),
engines,
elem_ty.type_id,
),
components: elem_ty.initial_type_id.get_abi_type_components(
ctx,
engines,
types,
elem_ty.type_id,
),
type_parameters: elem_ty.initial_type_id.get_abi_type_parameters(
ctx,
engines,
types,
elem_ty.type_id,
),
};
types.push(elem_abi_ty);

// Generate the JSON data for the array. This is basically a single
// `program_abi::TypeApplication` for the array element type
Some(vec![program_abi::TypeApplication {
name: "__slice_element".to_string(),
type_id: elem_ty.initial_type_id.index(),
type_arguments: elem_ty.initial_type_id.get_abi_type_arguments(
ctx,
engines,
types,
elem_ty.type_id,
),
}])
} else {
unreachable!();
}
}
TypeInfo::Tuple(_) => {
if let TypeInfo::Tuple(fields) = &*type_engine.get(resolved_type_id) {
// A list of all `program_abi::TypeDeclaration`s needed for the tuple fields
Expand Down
1 change: 1 addition & 0 deletions sway-core/src/asm_generation/fuel/data_section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ impl Entry {
name,
padding,
),
ConstantValue::Slice(_) => todo!(),
ConstantValue::Struct(_) => Entry::new_collection(
constant
.struct_fields_with_padding(context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ impl<'ir, 'eng> MidenVMAsmBuilder<'ir, 'eng> {
B256(_) => todo!(),
String(_) => todo!(),
Array(_) => todo!(),
Slice(_) => todo!(),
Struct(_) => todo!(),
Reference(_) => todo!(),
RawUntypedSlice(_) => todo!(),
Expand Down
52 changes: 24 additions & 28 deletions sway-core/src/control_flow_analysis/dead_code_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,9 @@ fn get_struct_type_info_from_type_id(
TypeInfo::Array(type_arg, _) => {
get_struct_type_info_from_type_id(type_engine, decl_engine, type_arg.type_id)
}
TypeInfo::Slice(type_arg) => {
get_struct_type_info_from_type_id(type_engine, decl_engine, type_arg.type_id)
}
_ => Ok(None),
}
}
Expand Down Expand Up @@ -1792,35 +1795,28 @@ fn connect_expression<'eng: 'cfg, 'cfg>(
elem_type: _,
contents,
} => {
let mut element_diverge = false;
let nodes = contents
.iter()
.map(|elem| {
if !element_diverge
&& type_engine
.get(elem.return_type)
.is_uninhabited(engines.te(), engines.de())
{
element_diverge = true
}
connect_expression(
engines,
&elem.expression,
graph,
leaves,
exit_node,
"",
tree_type,
elem.span.clone(),
options,
)
})
.collect::<Result<Vec<_>, _>>()?;
if element_diverge {
Ok(vec![])
} else {
Ok(nodes.concat())
let mut last = leaves.to_vec();

for elem in contents.iter() {
last = connect_expression(
engines,
&elem.expression,
graph,
last.as_slice(),
None,
"",
tree_type,
elem.span.clone(),
options,
)?;

// If an element diverges, break the connections and return nothing
if last.is_empty() {
break;
}
}

Ok(last)
}
ArrayIndex { prefix, index } => {
let prefix_idx = connect_expression(
Expand Down
14 changes: 7 additions & 7 deletions sway-core/src/ir_generation/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{

use super::{
const_eval::{compile_const_decl, LookupEnv},
convert::convert_resolved_typeid,
convert::convert_resolved_type_id,
function::FnCompiler,
CompiledFunctionCache,
};
Expand Down Expand Up @@ -298,11 +298,11 @@ pub(crate) fn compile_configurables(
{
let decl = engines.de().get(decl_id);

let ty = convert_resolved_typeid(
let ty = convert_resolved_type_id(
engines.te(),
engines.de(),
context,
&decl.type_ascription.type_id,
decl.type_ascription.type_id,
&decl.type_ascription.span,
)
.unwrap();
Expand Down Expand Up @@ -520,11 +520,11 @@ fn compile_fn(
.iter()
.map(|param| {
// Convert to an IR type.
convert_resolved_typeid(
convert_resolved_type_id(
type_engine,
decl_engine,
context,
&param.type_argument.type_id,
param.type_argument.type_id,
&param.type_argument.span,
)
.map(|ty| {
Expand All @@ -544,11 +544,11 @@ fn compile_fn(
.collect::<Result<Vec<_>, CompileError>>()
.map_err(|err| vec![err])?;

let ret_type = convert_resolved_typeid(
let ret_type = convert_resolved_type_id(
type_engine,
decl_engine,
context,
&return_type.type_id,
return_type.type_id,
&return_type.span,
)
.map_err(|err| vec![err])?;
Expand Down
Loading

0 comments on commit 421d20c

Please sign in to comment.