Skip to content

Commit

Permalink
Remove byte type and associated literal (FuelLabs#2976)
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-trunov authored Oct 8, 2022
1 parent e8a28b5 commit 2e32477
Show file tree
Hide file tree
Showing 18 changed files with 29 additions and 126 deletions.
2 changes: 1 addition & 1 deletion docs/src/basics/built_in_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ All other types in Sway are built up of these primitive types, or references to

## Numeric Types

All of the unsigned integer types are numeric types, and the `byte` type can also be viewed as an 8-bit unsigned integer.
All of the unsigned integer types are numeric types.

Numbers can be declared with binary syntax, hexadecimal syntax, base-10 syntax, and underscores for delineation. Let's take a look at the following valid numeric primitives:

Expand Down
1 change: 0 additions & 1 deletion sway-core/src/convert_parse_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,6 @@ fn type_name_to_type_info_opt(name: &Ident) -> Option<TypeInfo> {
"u64" => Some(TypeInfo::UnsignedInteger(IntegerBits::SixtyFour)),
"bool" => Some(TypeInfo::Boolean),
"unit" => Some(TypeInfo::Tuple(Vec::new())),
"byte" => Some(TypeInfo::Byte),
"b256" => Some(TypeInfo::B256),
"Self" | "self" => Some(TypeInfo::SelfType),
"Contract" => Some(TypeInfo::Contract),
Expand Down
4 changes: 2 additions & 2 deletions sway-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,8 @@ pub enum CompileError {
)]
InternalOwned(String, Span),
#[error(
"Byte literal had length of {byte_length}. Byte literals must be either one byte long (8 \
binary digits or 2 hex digits) or 32 bytes long (256 binary digits or 64 hex digits)"
"Byte literal had length of {byte_length}. Byte literals must be 32 bytes long \
(256 binary digits or 64 hex digits)"
)]
InvalidByteLiteralLength { byte_length: usize, span: Span },
#[error("Expected an expression to follow operator \"{op}\"")]
Expand Down
5 changes: 2 additions & 3 deletions sway-core/src/ir_generation/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub(super) fn convert_literal_to_value(context: &mut Context, ast_literal: &Lite
// consistent and doesn't tolerate mising integers of different width, so for now, until we
// do introduce explicit `as` casting, all integers are `u64` as far as the IR is
// concerned.
Literal::U8(n) | Literal::Byte(n) => Constant::get_uint(context, 64, *n as u64),
Literal::U8(n) => Constant::get_uint(context, 64, *n as u64),
Literal::U16(n) => Constant::get_uint(context, 64, *n as u64),
Literal::U32(n) => Constant::get_uint(context, 64, *n as u64),
Literal::U64(n) => Constant::get_uint(context, 64, *n),
Expand All @@ -31,7 +31,7 @@ pub(super) fn convert_literal_to_value(context: &mut Context, ast_literal: &Lite
pub(super) fn convert_literal_to_constant(ast_literal: &Literal) -> Constant {
match ast_literal {
// All integers are `u64`. See comment above.
Literal::U8(n) | Literal::Byte(n) => Constant::new_uint(64, *n as u64),
Literal::U8(n) => Constant::new_uint(64, *n as u64),
Literal::U16(n) => Constant::new_uint(64, *n as u64),
Literal::U32(n) => Constant::new_uint(64, *n as u64),
Literal::U64(n) => Constant::new_uint(64, *n),
Expand Down Expand Up @@ -86,7 +86,6 @@ fn convert_resolved_type(
TypeInfo::UnsignedInteger(_) => Type::Uint(64),
TypeInfo::Numeric => Type::Uint(64),
TypeInfo::Boolean => Type::Bool,
TypeInfo::Byte => Type::Uint(64),
TypeInfo::B256 => Type::B256,
TypeInfo::Str(n) => Type::String(*n),
TypeInfo::Struct { fields, .. } => super::types::get_aggregate_for_types(
Expand Down
11 changes: 1 addition & 10 deletions sway-core/src/language/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ pub enum Literal {
String(span::Span),
Numeric(u64),
Boolean(bool),
Byte(u8),
B256([u8; 32]),
}

Expand Down Expand Up @@ -56,12 +55,8 @@ impl Hash for Literal {
state.write_u8(7);
x.hash(state);
}
Byte(x) => {
state.write_u8(8);
x.hash(state);
}
B256(x) => {
state.write_u8(9);
state.write_u8(8);
x.hash(state);
}
}
Expand All @@ -81,7 +76,6 @@ impl PartialEq for Literal {
(Self::String(l0), Self::String(r0)) => *l0.as_str() == *r0.as_str(),
(Self::Numeric(l0), Self::Numeric(r0)) => l0 == r0,
(Self::Boolean(l0), Self::Boolean(r0)) => l0 == r0,
(Self::Byte(l0), Self::Byte(r0)) => l0 == r0,
(Self::B256(l0), Self::B256(r0)) => l0 == r0,
_ => false,
}
Expand All @@ -98,7 +92,6 @@ impl fmt::Display for Literal {
Literal::Numeric(content) => content.to_string(),
Literal::String(content) => content.as_str().to_string(),
Literal::Boolean(content) => content.to_string(),
Literal::Byte(content) => content.to_string(),
Literal::B256(content) => content
.iter()
.map(|x| x.to_string())
Expand All @@ -121,7 +114,6 @@ impl Literal {
Numeric(_) => ResolvedType::UnsignedInteger(IntegerBits::SixtyFour),
String(inner) => ResolvedType::Str(inner.as_str().len() as u64),
Boolean(_) => ResolvedType::Boolean,
Byte(_) => ResolvedType::Byte,
B256(_) => ResolvedType::B256,
}
}
Expand Down Expand Up @@ -160,7 +152,6 @@ impl Literal {
Literal::U32(_) => TypeInfo::UnsignedInteger(IntegerBits::ThirtyTwo),
Literal::U64(_) => TypeInfo::UnsignedInteger(IntegerBits::SixtyFour),
Literal::Boolean(_) => TypeInfo::Boolean,
Literal::Byte(_) => TypeInfo::Byte,
Literal::B256(_) => TypeInfo::B256,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,37 +269,6 @@ impl ConstructorFactory {
Pattern::Boolean(true)
}
}
Pattern::Byte(range) => {
let mut ranges = vec![range];
for pat in rest.into_iter() {
match pat {
Pattern::Byte(range) => ranges.push(range),
_ => {
errors.push(CompileError::Internal(
"expected all patterns to be of the same type",
span.clone(),
));
return err(warnings, errors);
}
}
}
let unincluded: PatStack = check!(
Range::find_exclusionary_ranges(ranges, Range::u8(), span),
return err(warnings, errors),
warnings,
errors
)
.into_iter()
.map(Pattern::Byte)
.collect::<Vec<_>>()
.into();
check!(
Pattern::from_pat_stack(unincluded, span),
return err(warnings, errors),
warnings,
errors
)
}
Pattern::Struct(struct_pattern) => {
let fields = struct_pattern
.fields()
Expand Down Expand Up @@ -508,22 +477,6 @@ impl ConstructorFactory {
}
Range::do_ranges_equal_range(ranges, Range::u64(), span)
}
Pattern::Byte(range) => {
let mut ranges = vec![range];
for pat in rest.into_iter() {
match pat {
Pattern::Byte(range) => ranges.push(range),
_ => {
errors.push(CompileError::Internal(
"expected all patterns to be of the same type",
span.clone(),
));
return err(warnings, errors);
}
}
}
Range::do_ranges_equal_range(ranges, Range::u8(), span)
}
Pattern::Numeric(range) => {
let mut ranges = vec![range];
for pat in rest.into_iter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ pub(crate) enum Pattern {
U64(Range<u64>),
B256([u8; 32]),
Boolean(bool),
Byte(Range<u8>),
Numeric(Range<u64>),
String(String),
Struct(StructPattern),
Expand Down Expand Up @@ -188,7 +187,6 @@ impl Pattern {
Literal::U64(x) => Pattern::U64(Range::from_single(x)),
Literal::B256(x) => Pattern::B256(x),
Literal::Boolean(b) => Pattern::Boolean(b),
Literal::Byte(x) => Pattern::Byte(Range::from_single(x)),
Literal::Numeric(x) => Pattern::Numeric(Range::from_single(x)),
Literal::String(s) => Pattern::String(s.as_str().to_string()),
}
Expand Down Expand Up @@ -376,16 +374,6 @@ impl Pattern {
}
Pattern::Boolean(*b)
}
Pattern::Byte(range) => {
if !args.is_empty() {
errors.push(CompileError::Internal(
"malformed constructor request",
span.clone(),
));
return err(warnings, errors);
}
Pattern::Byte(range.clone())
}
Pattern::Numeric(range) => {
if !args.is_empty() {
errors.push(CompileError::Internal(
Expand Down Expand Up @@ -522,7 +510,6 @@ impl Pattern {
Pattern::U64(_) => 0,
Pattern::B256(_) => 0,
Pattern::Boolean(_) => 0,
Pattern::Byte(_) => 0,
Pattern::Numeric(_) => 0,
Pattern::String(_) => 0,
Pattern::Struct(StructPattern { fields, .. }) => fields.len(),
Expand Down Expand Up @@ -570,7 +557,6 @@ impl Pattern {
(Pattern::U64(a), Pattern::U64(b)) => a == b,
(Pattern::B256(a), Pattern::B256(b)) => a == b,
(Pattern::Boolean(a), Pattern::Boolean(b)) => a == b,
(Pattern::Byte(a), Pattern::Byte(b)) => a == b,
(Pattern::Numeric(a), Pattern::Numeric(b)) => a == b,
(Pattern::String(a), Pattern::String(b)) => a == b,
(
Expand Down Expand Up @@ -692,13 +678,12 @@ impl Pattern {
Pattern::U64(_) => 4,
Pattern::B256(_) => 5,
Pattern::Boolean(_) => 6,
Pattern::Byte(_) => 7,
Pattern::Numeric(_) => 8,
Pattern::String(_) => 9,
Pattern::Struct(_) => 10,
Pattern::Enum(_) => 11,
Pattern::Tuple(_) => 12,
Pattern::Or(_) => 13,
Pattern::Numeric(_) => 7,
Pattern::String(_) => 8,
Pattern::Struct(_) => 9,
Pattern::Enum(_) => 10,
Pattern::Tuple(_) => 11,
Pattern::Or(_) => 12,
}
}
}
Expand All @@ -714,7 +699,6 @@ impl fmt::Display for Pattern {
Pattern::Numeric(range) => format!("{}", range),
Pattern::B256(n) => format!("{:#?}", n),
Pattern::Boolean(b) => format!("{}", b),
Pattern::Byte(range) => format!("{}", range),
Pattern::String(s) => s.clone(),
Pattern::Struct(struct_pattern) => format!("{}", struct_pattern),
Pattern::Enum(enum_pattern) => format!("{}", enum_pattern),
Expand Down Expand Up @@ -743,7 +727,6 @@ impl std::cmp::Ord for Pattern {
(Pattern::U64(x), Pattern::U64(y)) => x.cmp(y),
(Pattern::B256(x), Pattern::B256(y)) => x.cmp(y),
(Pattern::Boolean(x), Pattern::Boolean(y)) => x.cmp(y),
(Pattern::Byte(x), Pattern::Byte(y)) => x.cmp(y),
(Pattern::Numeric(x), Pattern::Numeric(y)) => x.cmp(y),
(Pattern::String(x), Pattern::String(y)) => x.cmp(y),
(Pattern::Struct(x), Pattern::Struct(y)) => x.cmp(y),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,6 @@ impl TyExpression {
Literal::U32(_) => TypeInfo::UnsignedInteger(IntegerBits::ThirtyTwo),
Literal::U64(_) => TypeInfo::UnsignedInteger(IntegerBits::SixtyFour),
Literal::Boolean(_) => TypeInfo::Boolean,
Literal::Byte(_) => TypeInfo::Byte,
Literal::B256(_) => TypeInfo::B256,
};
let id = crate::type_system::insert_type(return_type);
Expand Down
1 change: 0 additions & 1 deletion sway-core/src/semantic_analysis/node_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,6 @@ fn type_info_name(type_info: &TypeInfo) -> String {
TypeInfo::Tuple(fields) if fields.is_empty() => "unit",
TypeInfo::Tuple(..) => "tuple",
TypeInfo::SelfType => "self",
TypeInfo::Byte => "byte",
TypeInfo::B256 => "b256",
TypeInfo::Numeric => "numeric",
TypeInfo::Contract => "contract",
Expand Down
1 change: 0 additions & 1 deletion sway-core/src/type_system/resolved_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ pub enum ResolvedType {
UnsignedInteger(IntegerBits),
Boolean,
Unit,
Byte,
B256,
#[allow(dead_code)]
Struct {
Expand Down
1 change: 0 additions & 1 deletion sway-core/src/type_system/type_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ impl TypeEngine {
// If the types are exactly the same, we are done.
(Boolean, Boolean) => (vec![], vec![]),
(SelfType, SelfType) => (vec![], vec![]),
(Byte, Byte) => (vec![], vec![]),
(B256, B256) => (vec![], vec![]),
(Numeric, Numeric) => (vec![], vec![]),
(Contract, Contract) => (vec![], vec![]),
Expand Down
1 change: 0 additions & 1 deletion sway-core/src/type_system/type_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ impl ReplaceSelfType for TypeId {
| TypeInfo::UnsignedInteger(_)
| TypeInfo::Boolean
| TypeInfo::ContractCaller { .. }
| TypeInfo::Byte
| TypeInfo::B256
| TypeInfo::Numeric
| TypeInfo::Contract
Expand Down
Loading

0 comments on commit 2e32477

Please sign in to comment.