Skip to content

Commit

Permalink
cleaning up PR
Browse files Browse the repository at this point in the history
  • Loading branch information
xunilrj committed Jan 9, 2024
1 parent 3cffbe2 commit 6676f97
Show file tree
Hide file tree
Showing 82 changed files with 79 additions and 189 deletions.
2 changes: 0 additions & 2 deletions examples/identity/src/errors.sw
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
library;

use core::codec::*;

pub enum MyError {
UnauthorizedUser: Identity,
}
1 change: 0 additions & 1 deletion examples/identity/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ mod errors;

use abi::IdentityExample;
use errors::MyError;
use core::codec::*;

use std::{
constants::{
Expand Down
1 change: 0 additions & 1 deletion examples/option/src/main.sw
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
script;
use core::codec::*;

fn divide(numerator: u64, denominator: u64) -> Option<u64> {
if denominator == 0 {
Expand Down
1 change: 0 additions & 1 deletion examples/signatures/src/main.sw
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
script;

use core::codec::*;
use std::{b512::B512, ecr::{ec_recover, ec_recover_address, EcRecoverError}};

const MSG_HASH = 0xee45573606c96c98ba970ff7cf9511f1b8b25e6bcd52ced30b89df1e4a9c4323;
Expand Down
2 changes: 0 additions & 2 deletions examples/storage_vec/src/main.sw
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
contract;

use core::codec::*;

// ANCHOR: storage_vec_import
use std::storage::storage_vec::*;
// ANCHOR_END: storage_vec_import
Expand Down
1 change: 0 additions & 1 deletion examples/subcurrency/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
contract;

use std::hash::*;
use core::codec::*;

////////////////////////////////////////
// Event declarations
Expand Down
2 changes: 0 additions & 2 deletions examples/vec/src/main.sw
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
script;

use core::codec::*;

fn main() {
// ANCHOR: vec_new
let v: Vec<u64> = Vec::new();
Expand Down
55 changes: 26 additions & 29 deletions forc-plugins/forc-doc/src/tests/expects/impl_trait/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,49 +36,46 @@ fn test_impl_traits_default() {
);
assert_search_js(
&doc_path,
&expect![[r#"
var SEARCH_INDEX={"core":[{"html_filename":"trait.AsRawSlice.html","module_info":["core","raw_slice"],"name":"AsRawSlice","preview":"Trait to return a type as a <code>raw_slice</code>.\n","type_name":"trait"},{"html_filename":"fn.from_str_array.html","module_info":["core","str"],"name":"from_str_array","preview":"","type_name":"function"},{"html_filename":"trait.Add.html","module_info":["core","ops"],"name":"Add","preview":"Trait for the addition of two values.\n","type_name":"trait"},{"html_filename":"trait.Subtract.html","module_info":["core","ops"],"name":"Subtract","preview":"Trait for the subtraction of two values.\n","type_name":"trait"},{"html_filename":"trait.Multiply.html","module_info":["core","ops"],"name":"Multiply","preview":"Trait for the multiplication of two values.\n","type_name":"trait"},{"html_filename":"trait.Divide.html","module_info":["core","ops"],"name":"Divide","preview":"Trait for the division of two values.\n","type_name":"trait"},{"html_filename":"trait.Mod.html","module_info":["core","ops"],"name":"Mod","preview":"Trait for the modulo of two values.\n","type_name":"trait"},{"html_filename":"trait.Not.html","module_info":["core","ops"],"name":"Not","preview":"Trait to invert a type.\n","type_name":"trait"},{"html_filename":"trait.Eq.html","module_info":["core","ops"],"name":"Eq","preview":"Trait to evaluate if two types are equal.\n","type_name":"trait"},{"html_filename":"trait.Ord.html","module_info":["core","ops"],"name":"Ord","preview":"Trait to evaluate if one value is greater or less than another of the same type.\n","type_name":"trait"},{"html_filename":"trait.BitwiseAnd.html","module_info":["core","ops"],"name":"BitwiseAnd","preview":"Trait to bitwise AND two values of the same type.\n","type_name":"trait"},{"html_filename":"trait.BitwiseOr.html","module_info":["core","ops"],"name":"BitwiseOr","preview":"Trait to bitwise OR two values of the same type.\n","type_name":"trait"},{"html_filename":"trait.BitwiseXor.html","module_info":["core","ops"],"name":"BitwiseXor","preview":"Trait to bitwise XOR two values of the same type.\n","type_name":"trait"},{"html_filename":"trait.Shift.html","module_info":["core","ops"],"name":"Shift","preview":"Trait to bit shift a value.\n","type_name":"trait"},{"html_filename":"enum.Never.html","module_info":["core","never"],"name":"Never","preview":"<code>Never</code> represents the type of computations which never resolve to any value at all.","type_name":"enum"},{"html_filename":"struct.StorageKey.html","module_info":["core","storage"],"name":"StorageKey","preview":"Describes a location in storage.\n","type_name":"struct"},{"html_filename":"struct.Buffer.html","module_info":["core","codec"],"name":"Buffer","preview":"","type_name":"struct"},{"html_filename":"trait.AbiEncode.html","module_info":["core","codec"],"name":"AbiEncode","preview":"","type_name":"trait"},{"html_filename":"fn.encode.html","module_info":["core","codec"],"name":"encode","preview":"","type_name":"function"}],"impl_traits":[{"html_filename":"trait.Foo.html","module_info":["impl_traits","foo"],"name":"Foo","preview":"","type_name":"trait"},{"html_filename":"trait.Baz.html","module_info":["impl_traits","foo"],"name":"Baz","preview":"","type_name":"trait"},{"html_filename":"struct.Bar.html","module_info":["impl_traits","bar"],"name":"Bar","preview":"","type_name":"struct"}]};
"object"==typeof exports&&"undefined"!=typeof module&&(module.exports=SEARCH_INDEX);"#]],
&expect![[
r#"var SEARCH_INDEX={"core":[{"html_filename":"trait.AsRawSlice.html","module_info":["core","raw_slice"],"name":"AsRawSlice","preview":"Trait to return a type as a <code>raw_slice</code>.\n","type_name":"trait"},{"html_filename":"fn.from_str_array.html","module_info":["core","str"],"name":"from_str_array","preview":"","type_name":"function"},{"html_filename":"trait.Add.html","module_info":["core","ops"],"name":"Add","preview":"Trait for the addition of two values.\n","type_name":"trait"},{"html_filename":"trait.Subtract.html","module_info":["core","ops"],"name":"Subtract","preview":"Trait for the subtraction of two values.\n","type_name":"trait"},{"html_filename":"trait.Multiply.html","module_info":["core","ops"],"name":"Multiply","preview":"Trait for the multiplication of two values.\n","type_name":"trait"},{"html_filename":"trait.Divide.html","module_info":["core","ops"],"name":"Divide","preview":"Trait for the division of two values.\n","type_name":"trait"},{"html_filename":"trait.Mod.html","module_info":["core","ops"],"name":"Mod","preview":"Trait for the modulo of two values.\n","type_name":"trait"},{"html_filename":"trait.Not.html","module_info":["core","ops"],"name":"Not","preview":"Trait to invert a type.\n","type_name":"trait"},{"html_filename":"trait.Eq.html","module_info":["core","ops"],"name":"Eq","preview":"Trait to evaluate if two types are equal.\n","type_name":"trait"},{"html_filename":"trait.Ord.html","module_info":["core","ops"],"name":"Ord","preview":"Trait to evaluate if one value is greater or less than another of the same type.\n","type_name":"trait"},{"html_filename":"trait.BitwiseAnd.html","module_info":["core","ops"],"name":"BitwiseAnd","preview":"Trait to bitwise AND two values of the same type.\n","type_name":"trait"},{"html_filename":"trait.BitwiseOr.html","module_info":["core","ops"],"name":"BitwiseOr","preview":"Trait to bitwise OR two values of the same type.\n","type_name":"trait"},{"html_filename":"trait.BitwiseXor.html","module_info":["core","ops"],"name":"BitwiseXor","preview":"Trait to bitwise XOR two values of the same type.\n","type_name":"trait"},{"html_filename":"trait.Shift.html","module_info":["core","ops"],"name":"Shift","preview":"Trait to bit shift a value.\n","type_name":"trait"},{"html_filename":"enum.Never.html","module_info":["core","never"],"name":"Never","preview":"<code>Never</code> represents the type of computations which never resolve to any value at all.","type_name":"enum"},{"html_filename":"struct.StorageKey.html","module_info":["core","storage"],"name":"StorageKey","preview":"Describes a location in storage.\n","type_name":"struct"}],"impl_traits":[{"html_filename":"trait.Foo.html","module_info":["impl_traits","foo"],"name":"Foo","preview":"","type_name":"trait"},{"html_filename":"trait.Baz.html","module_info":["impl_traits","foo"],"name":"Baz","preview":"","type_name":"trait"},{"html_filename":"struct.Bar.html","module_info":["impl_traits","bar"],"name":"Bar","preview":"","type_name":"struct"}]};
"object"==typeof exports&&"undefined"!=typeof module&&(module.exports=SEARCH_INDEX);"#
]],
);
assert_file_tree(
doc_dir_name,
project_name,
vec![
"core/str/fn.from_str_array.html",
"core/storage/index.html",
"core/ops/trait.Add.html",
"core/ops/index.html",
"core/never/index.html",
"core/index.html",
"core/ops/trait.Subtract.html",
"core/ops/trait.Ord.html",
"core/ops/trait.BitwiseOr.html",
"core/str/fn.from_str_array.html",
"search.js",
"core/storage/struct.StorageKey.html",
"core/ops/trait.Mod.html",
"core/ops/trait.Shift.html",
"core/ops/trait.Not.html",
"impl_traits/foo/trait.Baz.html",
"core/never/index.html",
"core/all.html",
"core/raw_slice/trait.AsRawSlice.html",
"core/ops/trait.BitwiseAnd.html",
"core/ops/trait.Eq.html",
"core/ops/trait.BitwiseOr.html",
"core/str/index.html",
"core/raw_slice/index.html",
"impl_traits/all.html",
"impl_traits/foo/trait.Foo.html",
"core/codec/fn.encode.html",
"core/ops/trait.BitwiseXor.html",
"core/storage/index.html",
"core/codec/index.html",
"impl_traits/index.html",
"core/ops/trait.BitwiseXor.html",
"core/ops/trait.Ord.html",
"core/ops/trait.Divide.html",
"core/ops/trait.Eq.html",
"core/codec/trait.AbiEncode.html",
"impl_traits/foo/trait.Foo.html",
"impl_traits/bar/struct.Bar.html",
"impl_traits/foo/index.html",
"core/ops/trait.BitwiseAnd.html",
"core/str/index.html",
"core/ops/trait.Not.html",
"core/ops/trait.Mod.html",
"core/raw_slice/trait.AsRawSlice.html",
"impl_traits/bar/index.html",
"core/ops/trait.Shift.html",
"core/ops/trait.Multiply.html",
"search.js",
"core/all.html",
"impl_traits/bar/index.html",
"core/never/enum.Never.html",
"core/index.html",
"core/raw_slice/index.html",
"core/codec/struct.Buffer.html",
"core/ops/trait.Add.html",
"impl_traits/bar/struct.Bar.html",
"impl_traits/foo/trait.Baz.html",
],
);
}
Expand Down
3 changes: 3 additions & 0 deletions sway-core/src/language/ty/expression/intrinsic_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ pub struct TyIntrinsicFunctionKind {
}

impl TyIntrinsicFunctionKind {
/// Returns the actual type being logged. When the "new_encoding" is off,
/// this is just the `__log` argument; but when it is on, it is actually the
/// type of the argument to fn `encode`.
pub fn get_logged_type(&self, new_encoding: bool) -> Option<TypeId> {
if new_encoding {
if matches!(self.kind, Intrinsic::Log) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ use crate::{
type_system::*,
};

/// Contains all information needed to implement AbiEncode
struct AutoImplAbiEncodeContext {
buffer_type_id: TypeId,
}

/// Verify with a enum has all variants that can be auto implemented.
fn can_enum_auto_impl_abi_encode(
ctx: &mut TypeCheckContext,
decl: ty::TyDecl,
Expand Down Expand Up @@ -95,6 +97,7 @@ fn can_enum_auto_impl_abi_encode(
all_variants_are_abi_encode.then_some(AutoImplAbiEncodeContext { buffer_type_id })
}

/// Auto implements AbiEncode for structs
fn enum_auto_impl_abi_encode(
handler: &Handler,
ctx: &mut TypeCheckContext,
Expand All @@ -110,6 +113,8 @@ fn enum_auto_impl_abi_encode(

let enum_decl = ctx.engines().de().get(implementing_for_decl_ref.id());

// Check if the compilation context has acces to the
// core library.
let import_handler = Handler::default();
let _ = ctx.star_import(
&import_handler,
Expand Down Expand Up @@ -478,11 +483,14 @@ fn enum_auto_impl_abi_encode(
let _ = TyDecl::type_check(handler, ctx.by_ref(), impl_trait);
}

// Check if a struct can implement AbiEncode
fn can_struct_auto_impl_abi_encode(
ctx: &mut TypeCheckContext,
decl: ty::TyDecl,
) -> Option<AutoImplAbiEncodeContext> {
// skip module "core"
// Because of ordering, we cannot guarantee auto impl
// for structs inside "core"
if matches!(ctx.namespace.root().name.as_ref(), Some(x) if x.as_str() == "core") {
return None;
}
Expand Down Expand Up @@ -565,6 +573,7 @@ fn can_struct_auto_impl_abi_encode(
all_fields_are_abi_encode.then_some(AutoImplAbiEncodeContext { buffer_type_id })
}

// Auto implements AbiEncode for structs
fn struct_auto_impl_abi_encode(
_handler: &Handler,
ctx: &mut TypeCheckContext,
Expand Down Expand Up @@ -948,6 +957,7 @@ impl TyDecl {
let decl: ty::TyDecl = decl_engine.insert(enum_decl).into();
ctx.insert_symbol(handler, call_path.suffix, decl.clone())?;

// auto implement AbiEncode
if let Some(AutoImplAbiEncodeContext { buffer_type_id }) =
can_enum_auto_impl_abi_encode(&mut ctx, decl.clone())
{
Expand Down Expand Up @@ -1106,6 +1116,7 @@ impl TyDecl {
// insert the struct decl into namespace
ctx.insert_symbol(handler, call_path.suffix, decl.clone())?;

// auto implement AbiEncode
if let Some(AutoImplAbiEncodeContext { buffer_type_id }) =
can_struct_auto_impl_abi_encode(&mut ctx, decl.clone())
{
Expand Down
1 change: 0 additions & 1 deletion sway-core/src/semantic_analysis/ast_node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ impl ty::TyAstNode {
let star_import_handler = Handler::default();
let import =
ctx.star_import(&star_import_handler, &path, a.is_absolute);

if import.is_ok() {
handler.append(star_import_handler);
import
Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/semantic_analysis/namespace/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ impl Root {
return Err(handler.emit_err(CompileError::SymbolNotFound {
name: symbol.clone(),
span: symbol.span(),
}));
}))
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/type_system/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ impl TypeId {
extend(
&mut found,
ty.type_id
.extract_any_including_self(engines, filter_fn, vec![]),
.extract_any_including_self(engines, filter_fn, vec![], depth + 1),
);
}
}
Expand Down
8 changes: 3 additions & 5 deletions sway-core/src/type_system/unify/unify_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,15 +344,13 @@ impl<'a> UnifyCheck<'a> {
(
UnknownGeneric {
name: ln,
//trait_constraints: ltc,
..
trait_constraints: ltc,
},
UnknownGeneric {
name: rn,
//trait_constraints: rtc,
..
trait_constraints: rtc,
},
) => ln == rn, /*&& rtc.eq(ltc, self.engines)*/
) => ln == rn && rtc.eq(ltc, self.engines),
// any type can be coerced into a generic,
// except if the type already contains the generic
(_e, _g @ UnknownGeneric { .. }) => {
Expand Down
1 change: 0 additions & 1 deletion sway-lib-std/src/address.sw
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use ::error_signals::FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
use ::hash::sha256;
use ::revert::revert;
use ::outputs::{Output, output_amount, output_count, output_type};
use core::codec::*;

/// The `Address` type, a struct wrapper around the inner `b256` value.
pub struct Address {
Expand Down
1 change: 0 additions & 1 deletion sway-lib-std/src/b512.sw
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//! which are needed when working with public keys and signatures.
library;

use core::codec::*;
use ::constants::ZERO_B256;
use ::convert::From;

Expand Down
1 change: 0 additions & 1 deletion sway-lib-std/src/bytes.sw
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! The `Bytes` type is used when a collection of tightly-packed arbitrary bytes is needed.
library;

use core::codec::*;
use ::{alloc::{alloc_bytes, realloc_bytes}, vec::Vec};
use ::assert::assert;
use ::intrinsics::size_of_val;
Expand Down
1 change: 0 additions & 1 deletion sway-lib-std/src/contract_id.sw
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ library;
use ::alias::SubId;
use ::convert::From;
use ::hash::*;
use core::codec::*;

/// The `ContractId` type, a struct wrapper around the inner `b256` value.
pub struct ContractId {
Expand Down
1 change: 0 additions & 1 deletion sway-lib-std/src/identity.sw
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use ::constants::{BASE_ASSET_ID, ZERO_B256};
use ::contract_id::{AssetId, ContractId};
use ::hash::*;
use ::option::Option::{self, *};
use core::codec::*;

/// The `Identity` type: either an `Address` or a `ContractId`.
// ANCHOR: docs_identity
Expand Down
2 changes: 0 additions & 2 deletions sway-lib-std/src/logging.sw
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//! Allows logging of arbitrary stack types, emitted as either `Log` or `Logd` receipts.
library;

use core::codec::*;

/// Log any stack type.
///
/// # Additional Information
Expand Down
1 change: 0 additions & 1 deletion sway-lib-std/src/low_level_call.sw
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use ::contract_id::{AssetId, ContractId};
use ::option::Option;
use ::revert::require;
use ::vec::Vec;
use core::codec::*;

/// A struct representing the call parameters of a function call.
pub struct CallParams {
Expand Down
1 change: 0 additions & 1 deletion sway-lib-std/src/math.sw
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ fn exponentiation_test_math_sw() {
use ::assert::*;

// u256

let five = 0x0000000000000000000000000000000000000000000000000000000000000005u256;

// 5^2 = 25 = 0x19
Expand Down
1 change: 0 additions & 1 deletion sway-lib-std/src/revert.sw
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ library;

use ::logging::log;
use ::error_signals::FAILED_REQUIRE_SIGNAL;
use core::codec::*;

/// Will either panic or revert with a given number depending on the context.
///
Expand Down
8 changes: 0 additions & 8 deletions sway-lib-std/src/u256.sw
Original file line number Diff line number Diff line change
Expand Up @@ -719,8 +719,6 @@ impl Power for U256 {
#[test]
#[allow(deprecated)]
fn test_five_pow_two_u256() {
use core::codec::*;

let five = U256::from((0, 0, 0, 5));

let five_pow_two = five.pow(2);
Expand All @@ -733,8 +731,6 @@ fn test_five_pow_two_u256() {
#[test]
#[allow(deprecated)]
fn test_five_pow_three_u256() {
use core::codec::*;

let five = U256::from((0, 0, 0, 5));

let five_pow_three = five.pow(3);
Expand All @@ -747,8 +743,6 @@ fn test_five_pow_three_u256() {
#[test]
#[allow(deprecated)]
fn test_five_pow_28_u256() {
use core::codec::*;

let five = U256::from((0, 0, 0, 5));

let five_pow_28 = five.pow(28);
Expand All @@ -761,8 +755,6 @@ fn test_five_pow_28_u256() {
#[test]
#[allow(deprecated)]
fn test_is_zero() {
use core::codec::*;

let zero_u256 = U256::new();
assert(zero_u256.is_zero());
}
2 changes: 0 additions & 2 deletions sway-lib-std/src/vec.sw
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,6 @@ impl<T> From<raw_slice> for Vec<T> {
}
}

use core::codec::*;

impl<T> AbiEncode for Vec<T>
where
T: AbiEncode
Expand Down
Loading

0 comments on commit 6676f97

Please sign in to comment.