Skip to content

Commit

Permalink
Merge branch 'master' into add-as-u256-for-u128
Browse files Browse the repository at this point in the history
  • Loading branch information
bitzoic authored Feb 25, 2025
2 parents a9185d4 + a879ffb commit 5f42aff
Show file tree
Hide file tree
Showing 22 changed files with 316 additions and 53 deletions.
4 changes: 4 additions & 0 deletions sway-core/src/asm_lang/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,10 @@ impl Op {
let (r1, r2, r3, i0) = three_regs_imm_06(handler, args, immediate, whole_op_span)?;
VirtualOp::LDC(r1, r2, r3, i0)
}
"bldd" => {
let (r1, r2, r3, r4) = four_regs(handler, args, immediate, whole_op_span)?;
VirtualOp::BLDD(r1, r2, r3, r4)
}
"log" => {
let (r1, r2, r3, r4) = four_regs(handler, args, immediate, whole_op_span)?;
VirtualOp::LOG(r1, r2, r3, r4)
Expand Down
15 changes: 14 additions & 1 deletion sway-core/src/language/ty/code_block.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
decl_engine::*, engine_threading::*, language::ty::*, semantic_analysis::TypeCheckContext,
type_system::*,
transform::AllowDeprecatedState, type_system::*,
};
use serde::{Deserialize, Serialize};
use std::hash::Hasher;
Expand All @@ -13,6 +13,19 @@ pub struct TyCodeBlock {
pub(crate) whole_block_span: Span,
}

impl TyCodeBlock {
pub(crate) fn check_deprecated(
&self,
engines: &Engines,
handler: &Handler,
allow_deprecated: &mut AllowDeprecatedState,
) {
for n in self.contents.iter() {
n.check_deprecated(engines, handler, allow_deprecated);
}
}
}

impl Default for TyCodeBlock {
fn default() -> Self {
Self {
Expand Down
215 changes: 198 additions & 17 deletions sway-core/src/language/ty/expression/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,81 @@ impl TyExpression {
}

match &self.expression {
TyExpressionVariant::Literal(..) => {}
TyExpressionVariant::FunctionApplication {
call_path,
fn_ref,
arguments,
..
} => {
for (_, expr) in arguments.iter() {
expr.check_deprecated(engines, handler, allow_deprecated);
}

let fn_ty = engines.de().get(fn_ref);
if let Some(TyDecl::ImplSelfOrTrait(t)) = &fn_ty.implementing_type {
let t = &engines.de().get(&t.decl_id).implementing_for;
if let TypeInfo::Struct(struct_id) = &*engines.te().get(t.type_id) {
let s = engines.de().get(struct_id);
emit_warning_if_deprecated(
&s.attributes,
&call_path.span(),
handler,
"deprecated struct",
allow_deprecated,
);
}
}

emit_warning_if_deprecated(
&fn_ty.attributes,
&call_path.span(),
handler,
"deprecated function",
allow_deprecated,
);
}
TyExpressionVariant::LazyOperator { lhs, rhs, .. } => {
lhs.check_deprecated(engines, handler, allow_deprecated);
rhs.check_deprecated(engines, handler, allow_deprecated);
}
TyExpressionVariant::ConstantExpression { span, decl, .. } => {
emit_warning_if_deprecated(
&decl.attributes,
span,
handler,
"deprecated constant",
allow_deprecated,
);
}
TyExpressionVariant::ConfigurableExpression { span, decl, .. } => {
emit_warning_if_deprecated(
&decl.attributes,
span,
handler,
"deprecated configurable",
allow_deprecated,
);
}
TyExpressionVariant::VariableExpression { .. } => {}
TyExpressionVariant::Tuple { fields } => {
for e in fields.iter() {
e.check_deprecated(engines, handler, allow_deprecated);
}
}
TyExpressionVariant::ArrayExplicit { contents, .. } => {
for e in contents.iter() {
e.check_deprecated(engines, handler, allow_deprecated);
}
}
TyExpressionVariant::ArrayRepeat { value, length, .. } => {
value.check_deprecated(engines, handler, allow_deprecated);
length.check_deprecated(engines, handler, allow_deprecated);
}
TyExpressionVariant::ArrayIndex { prefix, index } => {
prefix.check_deprecated(engines, handler, allow_deprecated);
index.check_deprecated(engines, handler, allow_deprecated);
}
TyExpressionVariant::StructExpression {
struct_id,
instantiation_span,
Expand All @@ -451,26 +526,132 @@ impl TyExpression {
allow_deprecated,
);
}
TyExpressionVariant::FunctionApplication {
call_path, fn_ref, ..
TyExpressionVariant::CodeBlock(block) => {
block.check_deprecated(engines, handler, allow_deprecated);
}
TyExpressionVariant::FunctionParameter => {}
TyExpressionVariant::MatchExp {
desugared,
//scrutinees,
..
} => {
if let Some(TyDecl::ImplSelfOrTrait(t)) =
&engines.de().get(fn_ref).implementing_type
{
let t = &engines.de().get(&t.decl_id).implementing_for;
if let TypeInfo::Struct(struct_id) = &*engines.te().get(t.type_id) {
let s = engines.de().get(struct_id);
emit_warning_if_deprecated(
&s.attributes,
&call_path.span(),
handler,
"deprecated struct",
allow_deprecated,
);
}
desugared.check_deprecated(engines, handler, allow_deprecated);
// TODO: check scrutinees if necessary
}
TyExpressionVariant::IfExp {
condition,
then,
r#else,
} => {
condition.check_deprecated(engines, handler, allow_deprecated);
then.check_deprecated(engines, handler, allow_deprecated);
if let Some(e) = r#else {
e.check_deprecated(engines, handler, allow_deprecated);
}
}
_ => {}
TyExpressionVariant::AsmExpression { .. } => {}
TyExpressionVariant::StructFieldAccess {
prefix,
field_to_access,
field_instantiation_span,
..
} => {
prefix.check_deprecated(engines, handler, allow_deprecated);
emit_warning_if_deprecated(
&field_to_access.attributes,
field_instantiation_span,
handler,
"deprecated struct field",
allow_deprecated,
);
}
TyExpressionVariant::TupleElemAccess { prefix, .. } => {
prefix.check_deprecated(engines, handler, allow_deprecated);
}
TyExpressionVariant::EnumInstantiation {
enum_ref,
tag,
contents,
variant_instantiation_span,
..
} => {
let enum_ty = engines.de().get(enum_ref);
emit_warning_if_deprecated(
&enum_ty.attributes,
variant_instantiation_span,
handler,
"deprecated enum",
allow_deprecated,
);
if let Some(variant_decl) = enum_ty.variants.get(*tag) {
emit_warning_if_deprecated(
&variant_decl.attributes,
variant_instantiation_span,
handler,
"deprecated enum variant",
allow_deprecated,
);
}
if let Some(expr) = contents {
expr.check_deprecated(engines, handler, allow_deprecated);
}
}
TyExpressionVariant::AbiCast { address, .. } => {
// TODO: check abi name?
address.check_deprecated(engines, handler, allow_deprecated);
}
TyExpressionVariant::StorageAccess(access) => {
// TODO: check storage access?
if let Some(expr) = &access.key_expression {
expr.check_deprecated(engines, handler, allow_deprecated);
}
}
TyExpressionVariant::IntrinsicFunction(kind) => {
for arg in kind.arguments.iter() {
arg.check_deprecated(engines, handler, allow_deprecated);
}
}
TyExpressionVariant::AbiName(..) => {}
TyExpressionVariant::EnumTag { exp } => {
exp.check_deprecated(engines, handler, allow_deprecated);
}
TyExpressionVariant::UnsafeDowncast {
exp,
//variant,
..
} => {
exp.check_deprecated(engines, handler, allow_deprecated);
// TODO: maybe check variant?
}
TyExpressionVariant::WhileLoop { condition, body } => {
condition.check_deprecated(engines, handler, allow_deprecated);
body.check_deprecated(engines, handler, allow_deprecated);
}
TyExpressionVariant::ForLoop { desugared } => {
desugared.check_deprecated(engines, handler, allow_deprecated);
}
TyExpressionVariant::Break => {}
TyExpressionVariant::Continue => {}
TyExpressionVariant::Reassignment(reass) => {
if let TyReassignmentTarget::Deref(expr) = &reass.lhs {
expr.check_deprecated(engines, handler, allow_deprecated);
}
reass
.rhs
.check_deprecated(engines, handler, allow_deprecated);
}
TyExpressionVariant::ImplicitReturn(expr) => {
expr.check_deprecated(engines, handler, allow_deprecated);
}
TyExpressionVariant::Return(expr) => {
expr.check_deprecated(engines, handler, allow_deprecated);
}
TyExpressionVariant::Ref(expr) => {
expr.check_deprecated(engines, handler, allow_deprecated);
}
TyExpressionVariant::Deref(expr) => {
expr.check_deprecated(engines, handler, allow_deprecated);
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions sway-lib-std/src/ecr.sw
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ pub fn ed_verify(public_key: b256, signature: B512, msg: Bytes) -> Result<bool,
/// }
/// ```
#[deprecated(note = "std::ecr has been replaced by std::crypto, and is no longer maintained")]
#[allow(deprecated)]
pub fn ec_recover_address(signature: B512, msg_hash: b256) -> Result<Address, EcRecoverError> {
let pub_key_result = ec_recover(signature, msg_hash);

Expand Down Expand Up @@ -263,6 +264,7 @@ pub fn ec_recover_address(signature: B512, msg_hash: b256) -> Result<Address, Ec
/// }
/// ```
#[deprecated(note = "std::ecr has been replaced by std::crypto, and is no longer maintained")]
#[allow(deprecated)]
pub fn ec_recover_address_r1(signature: B512, msg_hash: b256) -> Result<Address, EcRecoverError> {
let pub_key_result = ec_recover_r1(signature, msg_hash);

Expand Down
1 change: 1 addition & 0 deletions sway-lib-std/src/vm/evm/ecr.sw
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use ::vm::evm::evm_address::EvmAddress;
/// }
/// ```
#[deprecated(note = "std:vm::evm:ecr has been replaced by std::crypto, and is no longer maintained")]
#[allow(deprecated)]
pub fn ec_recover_evm_address(
signature: B512,
msg_hash: b256,
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[[package]]
name = "bldd"
source = "member"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[project]
authors = ["Fuel Labs <contact@fuel.sh>"]
license = "Apache-2.0"
name = "bldd"
entry = "main.sw"
implicit-std = false
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
library;

// Intentionally not using `b256::zero()` to avoid dependency to `core`.
const B256_ZERO: b256 = 0x0000000000000000000000000000000000000000000000000000000000000000;

pub fn main() {
asm(r1: B256_ZERO, r2: B256_ZERO, r3: 42u64, r4: 21u64) {
bldd r1 r2 r3 r4;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
category = "compile"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[[package]]
name = "ecall"
source = "member"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[project]
authors = ["Fuel Labs <contact@fuel.sh>"]
license = "Apache-2.0"
name = "ecall"
entry = "main.sw"
implicit-std = false
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
script;
library;

fn main() {
pub fn main() {
asm(r1: 1u64, r2: 2u32, r3: 3u32, r4: 4u32) {
ecal r1 r2 r3 r4;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
category = "compile"
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[[package]]
name = "asm_wqxx_instructions"
source = "member"
dependencies = ["std"]

[[package]]
name = "core"
source = "path+from-root-DEA77F133437397D"
source = "path+from-root-6CA79EAC12B0D10A"

[[package]]
name = "std"
source = "path+from-root-DEA77F133437397D"
source = "path+from-root-6CA79EAC12B0D10A"
dependencies = ["core"]

[[package]]
name = "wqxx"
source = "member"
dependencies = ["std"]
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
[project]
name = "ecall_basic"
authors = ["Fuel Labs <contact@fuel.sh>"]
entry = "main.sw"
implicit-std = false
license = "Apache-2.0"
name = "wqxx"

[dependencies]
core = { path = "../../../../../../../sway-lib-core" }
std = { path = "../../../../../../reduced_std_libs/sway-lib-std-assert" }

This file was deleted.

Loading

0 comments on commit 5f42aff

Please sign in to comment.