Skip to content

Commit 8cb583a

Browse files
committed
Revert "try method #1"
2f0382b
1 parent 2f0382b commit 8cb583a

File tree

2 files changed

+1
-51
lines changed

2 files changed

+1
-51
lines changed

sway-core/src/asm_generation/checks.rs

-42
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ use crate::asm_lang::allocated_ops::{AllocatedOp, AllocatedOpcode};
66
use crate::asm_lang::*;
77
use crate::error::*;
88

9-
use sway_ir::*;
10-
119
/// Checks for disallowed opcodes in non-contract code.
1210
/// i.e., if this is a script or predicate, we can't use certain contract opcodes.
1311
/// See https://github.com/FuelLabs/sway/issues/350 for details.
@@ -74,43 +72,3 @@ fn check_for_contract_opcodes(ops: &[AllocatedOp]) -> CompileResult<()> {
7472
err(vec![], errors)
7573
}
7674
}
77-
78-
pub fn check_invalid_return(ir: &Context, module: &Module) -> CompileResult<()> {
79-
let default_span =
80-
sway_types::span::Span::new("no span found for opcode".into(), 0, 1, None).unwrap();
81-
match module.get_kind(ir) {
82-
Kind::Contract | Kind::Library => ok((), vec![], vec![]),
83-
Kind::Predicate | Kind::Script => {
84-
let entry_point_function = module
85-
.function_iter(&ir)
86-
.find(|func| func.get_name(&ir) == crate::constants::DEFAULT_ENTRY_POINT_FN_NAME)
87-
.unwrap();
88-
89-
let ret_ty = entry_point_function.get_return_type(ir);
90-
91-
if type_has_ptr(&ir, &ret_ty) {
92-
err(
93-
vec![],
94-
vec![CompileError::PointerReturnNotAllowedInMain {
95-
span: default_span.clone(),
96-
}],
97-
)
98-
} else {
99-
ok((), vec![], vec![])
100-
}
101-
}
102-
}
103-
}
104-
105-
fn type_has_ptr(ir: &Context, ty: &Type) -> bool {
106-
match ty {
107-
Type::Pointer(_) => true,
108-
Type::Array(aggregate) | Type::Union(aggregate) | Type::Struct(aggregate) => {
109-
match aggregate.get_content(ir) {
110-
AggregateContent::ArrayType(ty, _) => type_has_ptr(ir, ty),
111-
AggregateContent::FieldTypes(tys) => tys.iter().any(|ty| type_has_ptr(ir, ty)),
112-
}
113-
}
114-
_ => false,
115-
}
116-
}

sway-core/src/asm_generation/from_ir.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::{
22
asm_builder::AsmBuilder,
3-
checks::{check_invalid_opcodes, check_invalid_return},
3+
checks::check_invalid_opcodes,
44
finalized_asm::FinalizedAsm,
55
programs::{AbstractProgram, ProgramKind},
66
register_sequencer::RegisterSequencer,
@@ -25,14 +25,6 @@ pub fn compile_ir_to_asm(
2525
let mut errors: Vec<CompileError> = Vec::new();
2626

2727
let module = ir.module_iter().next().unwrap();
28-
29-
check!(
30-
check_invalid_return(&ir, &module),
31-
return err(warnings, errors),
32-
warnings,
33-
errors
34-
);
35-
3628
let abstract_program = check!(
3729
compile_module_to_asm(RegisterSequencer::new(), ir, module),
3830
return err(warnings, errors),

0 commit comments

Comments
 (0)