Skip to content

Commit

Permalink
vec build on top on slice
Browse files Browse the repository at this point in the history
  • Loading branch information
xunilrj committed Jul 19, 2024
1 parent 4aa03d5 commit 1a25649
Show file tree
Hide file tree
Showing 99 changed files with 10,035 additions and 438 deletions.
784 changes: 784 additions & 0 deletions a.txt

Large diffs are not rendered by default.

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
18 changes: 9 additions & 9 deletions sway-core/src/ir_generation/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
};

use super::{
convert::{convert_literal_to_constant, convert_resolved_typeid},
convert::{convert_literal_to_constant, convert_resolved_type_id},
function::FnCompiler,
types::*,
};
Expand Down Expand Up @@ -1036,11 +1036,11 @@ fn const_eval_intrinsic(
}
Intrinsic::SizeOfType => {
let targ = &intrinsic.type_arguments[0];
let ir_type = convert_resolved_typeid(
let ir_type = convert_resolved_type_id(
lookup.engines.te(),
lookup.engines.de(),
lookup.context,
&targ.type_id,
targ.type_id,
&targ.span,
)
.map_err(|_| ConstEvalError::CompileError)?;
Expand All @@ -1052,11 +1052,11 @@ fn const_eval_intrinsic(
Intrinsic::SizeOfVal => {
let val = &intrinsic.arguments[0];
let type_id = val.return_type;
let ir_type = convert_resolved_typeid(
let ir_type = convert_resolved_type_id(
lookup.engines.te(),
lookup.engines.de(),
lookup.context,
&type_id,
type_id,
&val.span,
)
.map_err(|_| ConstEvalError::CompileError)?;
Expand All @@ -1067,11 +1067,11 @@ fn const_eval_intrinsic(
}
Intrinsic::SizeOfStr => {
let targ = &intrinsic.type_arguments[0];
let ir_type = convert_resolved_typeid(
let ir_type = convert_resolved_type_id(
lookup.engines.te(),
lookup.engines.de(),
lookup.context,
&targ.type_id,
targ.type_id,
&targ.span,
)
.map_err(|_| ConstEvalError::CompileError)?;
Expand All @@ -1084,11 +1084,11 @@ fn const_eval_intrinsic(
}
Intrinsic::AssertIsStrArray => {
let targ = &intrinsic.type_arguments[0];
let ir_type = convert_resolved_typeid(
let ir_type = convert_resolved_type_id(
lookup.engines.te(),
lookup.engines.de(),
lookup.context,
&targ.type_id,
targ.type_id,
&targ.span,
)
.map_err(|_| ConstEvalError::CompileError)?;
Expand Down
64 changes: 36 additions & 28 deletions sway-core/src/ir_generation/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,32 +52,29 @@ pub(super) fn convert_literal_to_constant(
}
}

pub(super) fn convert_resolved_typeid(
pub(super) fn convert_resolved_type_id(
type_engine: &TypeEngine,
decl_engine: &DeclEngine,
context: &mut Context,
ast_type: &TypeId,
ast_type: TypeId,
span: &Span,
) -> Result<Type, CompileError> {
let t = &type_engine
.to_typeinfo(*ast_type, span)
.map_err(|_| CompileError::TypeMustBeKnownAtThisPoint { span: span.clone() })?;

convert_resolved_type(type_engine, decl_engine, context, t, span)
let t = type_engine.get(ast_type);
convert_resolved_type_info(type_engine, decl_engine, context, &*t, span)
}

pub(super) fn convert_resolved_typeid_no_span(
type_engine: &TypeEngine,
decl_engine: &DeclEngine,
context: &mut Context,
ast_type: &TypeId,
ast_type: TypeId,
) -> Result<Type, CompileError> {
let msg = "unknown source location";
let span = crate::span::Span::from_string(msg.to_string());
convert_resolved_typeid(type_engine, decl_engine, context, ast_type, &span)
convert_resolved_type_id(type_engine, decl_engine, context, ast_type, &span)
}

fn convert_resolved_type(
fn convert_resolved_type_info(
type_engine: &TypeEngine,
decl_engine: &DeclEngine,
context: &mut Context,
Expand All @@ -87,10 +84,10 @@ fn convert_resolved_type(
// A handy macro for rejecting unsupported types.
macro_rules! reject_type {
($name_str:literal) => {{
return Err(CompileError::Internal(
concat!($name_str, " type cannot be resolved in IR."),
span.clone(),
));
return Err(CompileError::TypeMustBeKnownAtThisPoint {
span: span.clone(),
internal: $name_str.into(),
});
}};
}

Expand Down Expand Up @@ -125,25 +122,16 @@ fn convert_resolved_type(
&decl_engine.get_enum(decl_ref).variants,
)?,
TypeInfo::Array(elem_type, length) => {
let elem_type = convert_resolved_typeid(
let elem_type = convert_resolved_type_id(
type_engine,
decl_engine,
context,
&elem_type.type_id,
elem_type.type_id,
span,
)?;
Type::new_array(context, elem_type, length.val() as u64)
}
TypeInfo::Slice(elem_type) => {
let elem_type = convert_resolved_typeid(
type_engine,
decl_engine,
context,
&elem_type.type_id,
span,
)?;
Type::get_typed_slice(context, elem_type)
}

TypeInfo::Tuple(fields) => {
if fields.is_empty() {
// XXX We've removed Unit from the core compiler, replaced with an empty Tuple.
Expand All @@ -159,11 +147,31 @@ fn convert_resolved_type(
TypeInfo::RawUntypedSlice => Type::get_slice(context),
TypeInfo::Ptr(_) => Type::get_uint64(context),
TypeInfo::Alias { ty, .. } => {
convert_resolved_typeid(type_engine, decl_engine, context, &ty.type_id, span)?
convert_resolved_type_id(type_engine, decl_engine, context, ty.type_id, span)?
}
// refs to slice are actually fat pointers,
// all others refs are thin pointers.
TypeInfo::Ref {
referenced_type, ..
} => {
if let Some(slice_elem) = type_engine.get(referenced_type.type_id).as_slice() {
let elem_ir_type = convert_resolved_type_id(
type_engine,
decl_engine,
context,
slice_elem.type_id,
span,
)?;
Type::get_typed_slice(context, elem_ir_type)
} else {
Type::get_uint64(context)
}
}
TypeInfo::Ref { .. } => Type::get_uint64(context),
TypeInfo::Never => Type::get_never(context),

// Unsized types
TypeInfo::Slice(_) => reject_type!("unsized"),

// Unsupported types which shouldn't exist in the AST after type checking and
// monomorphisation.
TypeInfo::Custom { .. } => reject_type!("Custom"),
Expand Down
Loading

0 comments on commit 1a25649

Please sign in to comment.