Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,6 @@ fn type_check_gtf(

/// Signature: `__addr_of<T>(val: T) -> raw_ptr`
/// Description: Returns the address in memory where `val` is stored.
/// Constraints: `T` is a reference type.
fn type_check_addr_of(
handler: &Handler,
ctx: TypeCheckContext,
Expand All @@ -1042,18 +1041,6 @@ fn type_check_addr_of(
.with_help_text("")
.with_type_annotation(type_engine.new_unknown());
let exp = ty::TyExpression::type_check(handler, ctx, &arguments[0])?;
let copy_type_info = type_engine
.to_typeinfo(exp.return_type, &span)
.map_err(|e| handler.emit_err(e.into()))
.unwrap_or_else(TypeInfo::ErrorRecovery);
if copy_type_info.is_copy_type() {
return Err(handler.emit_err(CompileError::IntrinsicUnsupportedArgType {
name: kind.to_string(),
span,
hint: "Only a reference type can be used as argument here".to_string(),
}));
}

let intrinsic_function = ty::TyIntrinsicFunctionKind {
kind,
arguments: vec![exp],
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
[[package]]
name = 'addrof_intrinsic'
source = 'member'
dependencies = ['std']
name = "addrof_intrinsic"
source = "member"
dependencies = ["std"]

[[package]]
name = 'core'
source = 'path+from-root-B3EAB3022B5FAD04'

[[package]]
name = 'std'
source = 'path+from-root-B3EAB3022B5FAD04'
dependencies = ['core']
name = "std"
source = "path+from-root-B3EAB3022B5FAD04"
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"concreteTypes": [
{
"concreteTypeId": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d",
"type": "()"
}
],
"configurables": [],
"encodingVersion": "1",
"errorCodes": {},
"functions": [
{
"attributes": null,
"inputs": [],
"name": "main",
"output": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d"
}
],
"loggedTypes": [],
"messagesTypes": [],
"metadataTypes": [],
"programType": "script",
"specVersion": "1.1"
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
script;

const B1 = Address {
value: 0x0100000000000000000000000000000000000000000000000000000000000010
};

pub fn addr_of<T>(val: T) -> raw_ptr {
if !__is_reference_type::<T>() {
revert(0);
}
pub fn as_raw_ptr<T>(val: T) -> raw_ptr {
asm(ptr: val) {
ptr: raw_ptr
}
Expand All @@ -18,21 +11,63 @@ enum X {
B: u64,
}

fn main() {
let sender = Identity::Address(B1);
assert (__addr_of(sender) == addr_of(sender));
struct Y {
a: u32,
b: u64,
}

fn main() {
let x = X::A(2);
let y = X::B(22);
assert(__addr_of(x) == addr_of(x));
assert(__addr_of(x) != addr_of(y));
assert(__addr_of(x) == as_raw_ptr(&x));
assert(__addr_of(x) != as_raw_ptr(&y));

let y = Y { a: 2, b: 22 };
let z = Y { a: 3, b: 23 };
assert(__addr_of(y) == as_raw_ptr(&y));
assert(__addr_of(y) != as_raw_ptr(&z));

let addr_y_a = __addr_of(y.a);
let addr_y_b = __addr_of(y.b);
assert(addr_y_a == as_raw_ptr(&y.a));
assert(addr_y_b == as_raw_ptr(&y.b));
assert(addr_y_a != addr_y_b);

let a = [1,2,3];
assert(__addr_of(a) == addr_of(a));
assert(__addr_of(a) == as_raw_ptr(&a));

let b = "hello";
assert(__addr_of(b) == addr_of(b));
assert(__addr_of(b) == as_raw_ptr(&b));

let c = (1, 2);
assert(__addr_of(c) == addr_of(c));
assert(__addr_of(c) == as_raw_ptr(&c));

let i1 = 42u64;
let i2 = 43u64;
assert(__addr_of(i1) == as_raw_ptr(&i1));
assert(__addr_of(i1) != as_raw_ptr(&i2));

let b1 = true;
let b2 = false;
assert(__addr_of(b1) == as_raw_ptr(&b1));
assert(__addr_of(b1) != as_raw_ptr(&b2));

let u8_1 = 8u8;
let u8_2 = 9u8;
assert(__addr_of(u8_1) == as_raw_ptr(&u8_1));
assert(__addr_of(u8_1) != as_raw_ptr(&u8_2));

let u256_1: u256 = 0x0000000000000000000000000000000000000000000000000000000000000001u256;
let u256_2: u256 = 0x0000000000000000000000000000000000000000000000000000000000000002u256;
assert(__addr_of(u256_1) == as_raw_ptr(&u256_1));
assert(__addr_of(u256_1) != as_raw_ptr(&u256_2));

let addr_addr_of = __addr_of(__addr_of(x));
assert (addr_addr_of != as_raw_ptr(0));

let some_temp = __addr_of(1 + 4);
assert(some_temp != as_raw_ptr(0));

let raw_ptr = __addr_of(x);
assert(raw_ptr != as_raw_ptr(0));
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
# redundant temporary value erasure is performed.
#
# Once we have temporaries removal implemented this test can be re-enabled.
category = "disabled"
expected_result = { action = "return", value = 0 }
expected_result_new_encoding = { action = "return_data", value = "0000000000000000" }
category = "run"
expected_result_new_encoding = { action = "return_data", value = "" }
validate_abi = true
expected_warnings = 1
expected_warnings = 0