Skip to content

Commit

Permalink
Merge branch 'master' into de-monomorph-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
emilyaherbert authored Aug 29, 2022
2 parents 562fcb9 + 38166d5 commit 1c4f378
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 23 deletions.
3 changes: 2 additions & 1 deletion sway-core/src/asm_generation/from_ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ impl<'ir> AsmBuilder<'ir> {
let index_reg = self.value_to_register(index);
self.bytecode.push(Op {
opcode: either::Either::Left(VirtualOp::GTF(
instr_reg,
instr_reg.clone(),
index_reg,
VirtualImmediate12 {
value: tx_field_id as u16,
Expand All @@ -1171,6 +1171,7 @@ impl<'ir> AsmBuilder<'ir> {
comment: "get transaction field".into(),
owning_span: self.md_mgr.val_to_span(self.context, *instr_val),
});
self.reg_map.insert(*instr_val, instr_reg);
}

fn compile_insert_element(
Expand Down
25 changes: 15 additions & 10 deletions sway-core/src/semantic_analysis/ast_node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,19 +474,24 @@ impl TypedAstNode {
};

if let TypedAstNode {
content: TypedAstNodeContent::Expression(TypedExpression { .. }),
content: TypedAstNodeContent::Expression(TypedExpression { ref expression, .. }),
..
} = node
{
let warning = Warning::UnusedReturnValue {
r#type: Box::new(node.type_info()),
};
assert_or_warn!(
node.type_info().is_unit() || node.type_info() == TypeInfo::ErrorRecovery,
warnings,
node.span.clone(),
warning
);
if !matches!(
expression,
TypedExpressionVariant::Break | TypedExpressionVariant::Continue,
) {
let warning = Warning::UnusedReturnValue {
r#type: Box::new(node.type_info()),
};
assert_or_warn!(
node.type_info().is_unit() || node.type_info() == TypeInfo::ErrorRecovery,
warnings,
node.span.clone(),
warning
);
}
}

ok(node, warnings, errors)
Expand Down
11 changes: 11 additions & 0 deletions sway-core/tests/ir_to_asm/gtf.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.program:
ji i4
noop
DATA_SECTION_OFFSET[0..32]
DATA_SECTION_OFFSET[32..64]
lw $ds $is 1
add $$ds $$ds $is
gtf $r0 $zero i1 ; get transaction field
ret $r0
noop ; word-alignment of data section
.data:
8 changes: 8 additions & 0 deletions sway-core/tests/ir_to_asm/gtf.ir
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
script {
fn main() -> u64 {
entry:
v0 = const u64 0
v1 = gtf v0, 1
ret u64 v1
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
category = "fail"

# check: $()fn main() {
# nextln: $()break;
# nextln: $()not assigned to anything

# check: $()This code is unreachable

# check: $()fn main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
category = "fail"

# check: $()fn main() {
# nextln: $()continue;
# nextln: $()not assigned to anything

# check: $()This code is unreachable

# check: $()fn main() {
# nextln: $()continue;
# nextln: $()"continue" used outside of a loop
# nextln: $()"continue" used outside of a loop
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
{
"components": null,
"name": "",
"type": "bool"
"type": "bool",
"typeArguments": null
}
],
"type": "function"
}
]
]
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
category = "disabled"
category = "run"
expected_result = { action = "return", value = 1 }
validate_abi = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[[package]]
name = 'break_and_continue_block_ret'
source = 'root'
dependencies = []
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[project]
authors = ["Fuel Labs <[email protected]>"]
entry = "main.sw"
license = "Apache-2.0"
name = "break_and_continue_block_ret"
implicit-std = false
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
script;

fn main() {
while true {
if true {
break;
}
}

while true {
if true {
continue;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
category = "compile"

# not: $()This returns a value of type unknown, which is not assigned to anything and is ignored.

0 comments on commit 1c4f378

Please sign in to comment.