瀏覽代碼

Rename more unchecked to overflowing (#1269)

Recently unchecked was renamed overflowing in CFG. A few renames were
missed.

Signed-off-by: Sean Young <sean@mess.org>
Sean Young 2 年之前
父節點
當前提交
bceff5928a

+ 10 - 10
src/codegen/expression.rs

@@ -1128,7 +1128,7 @@ fn post_incdec(
     ns: &Namespace,
     loc: &pt::Loc,
     expr: &ast::Expression,
-    unchecked: bool,
+    overflowing: bool,
     opt: &Options,
 ) -> Expression {
     let res = vartab.temp_anonymous(ty);
@@ -1159,7 +1159,7 @@ fn post_incdec(
         ast::Expression::PostDecrement { .. } => Expression::Subtract {
             loc: *loc,
             ty: ty.clone(),
-            overflowing: unchecked,
+            overflowing,
             left: Box::new(Expression::Variable {
                 loc: *loc,
                 ty: ty.clone(),
@@ -1170,7 +1170,7 @@ fn post_incdec(
         ast::Expression::PostIncrement { .. } => Expression::Add {
             loc: *loc,
             ty: ty.clone(),
-            overflowing: unchecked,
+            overflowing,
             left: Box::new(Expression::Variable {
                 loc: *loc,
                 ty: ty.clone(),
@@ -1252,7 +1252,7 @@ fn pre_incdec(
     ns: &Namespace,
     loc: &pt::Loc,
     expr: &ast::Expression,
-    unchecked: bool,
+    overflowing: bool,
     opt: &Options,
 ) -> Expression {
     let res = vartab.temp_anonymous(ty);
@@ -1275,14 +1275,14 @@ fn pre_incdec(
         ast::Expression::PreDecrement { .. } => Expression::Subtract {
             loc: *loc,
             ty: ty.clone(),
-            overflowing: unchecked,
+            overflowing,
             left: Box::new(v),
             right: one,
         },
         ast::Expression::PreIncrement { .. } => Expression::Add {
             loc: *loc,
             ty: ty.clone(),
-            overflowing: unchecked,
+            overflowing,
             left: Box::new(v),
             right: one,
         },
@@ -2288,7 +2288,7 @@ fn alloc_dynamic_array(
 fn add(
     loc: &pt::Loc,
     ty: &Type,
-    unchecked: bool,
+    overflowing: bool,
     left: &ast::Expression,
     cfg: &mut ControlFlowGraph,
     contract_no: usize,
@@ -2301,7 +2301,7 @@ fn add(
     Expression::Add {
         loc: *loc,
         ty: ty.clone(),
-        overflowing: unchecked,
+        overflowing,
         left: Box::new(expression(left, cfg, contract_no, func, ns, vartab, opt)),
         right: Box::new(expression(right, cfg, contract_no, func, ns, vartab, opt)),
     }
@@ -2310,7 +2310,7 @@ fn add(
 fn subtract(
     loc: &pt::Loc,
     ty: &Type,
-    unchecked: bool,
+    overflowing: bool,
     left: &ast::Expression,
     cfg: &mut ControlFlowGraph,
     contract_no: usize,
@@ -2323,7 +2323,7 @@ fn subtract(
     Expression::Subtract {
         loc: *loc,
         ty: ty.clone(),
-        overflowing: unchecked,
+        overflowing,
         left: Box::new(expression(left, cfg, contract_no, func, ns, vartab, opt)),
         right: Box::new(expression(right, cfg, contract_no, func, ns, vartab, opt)),
     }

+ 3 - 3
src/codegen/strength_reduce/mod.rs

@@ -219,7 +219,7 @@ fn expression_reduce(expr: &Expression, vars: &Variables, ns: &mut Namespace) ->
             Expression::Multiply {
                 loc,
                 ty,
-                overflowing: unchecked,
+                overflowing,
                 left,
                 right,
             } => {
@@ -282,7 +282,7 @@ fn expression_reduce(expr: &Expression, vars: &Variables, ns: &mut Namespace) ->
                                     expr: Box::new(Expression::Multiply {
                                         loc: *loc,
                                         ty: Type::Int(64),
-                                        overflowing: *unchecked,
+                                        overflowing: *overflowing,
                                         left: Box::new(
                                             left.as_ref().clone().cast(&Type::Int(64), ns),
                                         ),
@@ -313,7 +313,7 @@ fn expression_reduce(expr: &Expression, vars: &Variables, ns: &mut Namespace) ->
                                 expr: Box::new(Expression::Multiply {
                                     loc: *loc,
                                     ty: Type::Uint(64),
-                                    overflowing: *unchecked,
+                                    overflowing: *overflowing,
                                     left: Box::new(left.as_ref().clone().cast(&Type::Uint(64), ns)),
                                     right: Box::new(
                                         right.as_ref().clone().cast(&Type::Uint(64), ns),

+ 16 - 28
src/codegen/subexpression_elimination/operator.rs

@@ -7,18 +7,18 @@ use crate::sema::ast::Type;
 #[derive(PartialEq, Eq, Hash, Clone, Debug)]
 pub enum Operator {
     Add,
-    UncheckedAdd,
+    OverflowingAdd,
     Subtract,
-    UncheckedSubtract,
+    OverflowingSubtract,
     Multiply,
-    UncheckedMultiply,
+    OverflowingMultiply,
     SignedDivide,
     UnsignedDivide,
     Modulo,
     SignedModulo,
     UnsignedModulo,
     Power,
-    UncheckedPower,
+    OverflowingPower,
     BitwiseOr,
     BitwiseAnd,
     BitwiseXor,
@@ -53,32 +53,23 @@ impl Expression {
     /// Get the respective Operator from an Expression
     pub fn get_ave_operator(&self) -> Operator {
         match self {
-            Expression::Add {
-                overflowing: unchecked,
-                ..
-            } => {
-                if *unchecked {
-                    Operator::UncheckedAdd
+            Expression::Add { overflowing, .. } => {
+                if *overflowing {
+                    Operator::OverflowingAdd
                 } else {
                     Operator::Add
                 }
             }
-            Expression::Subtract {
-                overflowing: unchecked,
-                ..
-            } => {
-                if *unchecked {
-                    Operator::UncheckedSubtract
+            Expression::Subtract { overflowing, .. } => {
+                if *overflowing {
+                    Operator::OverflowingSubtract
                 } else {
                     Operator::Subtract
                 }
             }
-            Expression::Multiply {
-                overflowing: unchecked,
-                ..
-            } => {
-                if *unchecked {
-                    Operator::UncheckedMultiply
+            Expression::Multiply { overflowing, .. } => {
+                if *overflowing {
+                    Operator::OverflowingMultiply
                 } else {
                     Operator::Multiply
                 }
@@ -87,12 +78,9 @@ impl Expression {
             Expression::UnsignedDivide { .. } => Operator::UnsignedDivide,
             Expression::SignedModulo { .. } => Operator::SignedModulo,
             Expression::UnsignedModulo { .. } => Operator::UnsignedModulo,
-            Expression::Power {
-                overflowing: unchecked,
-                ..
-            } => {
-                if *unchecked {
-                    Operator::UncheckedPower
+            Expression::Power { overflowing, .. } => {
+                if *overflowing {
+                    Operator::OverflowingPower
                 } else {
                     Operator::Power
                 }

+ 9 - 9
src/emit/expression.rs

@@ -130,7 +130,7 @@ pub(super) fn expression<'a, T: TargetRuntime<'a> + ?Sized>(
         Expression::Add {
             loc,
             ty,
-            overflowing: unchecked,
+            overflowing,
             left,
             right,
             ..
@@ -138,7 +138,7 @@ pub(super) fn expression<'a, T: TargetRuntime<'a> + ?Sized>(
             let left = expression(target, bin, left, vartab, function, ns).into_int_value();
             let right = expression(target, bin, right, vartab, function, ns).into_int_value();
 
-            if !unchecked {
+            if !overflowing {
                 let signed = ty.is_signed_int(ns);
                 build_binary_op_with_overflow_check(
                     target,
@@ -159,14 +159,14 @@ pub(super) fn expression<'a, T: TargetRuntime<'a> + ?Sized>(
         Expression::Subtract {
             loc,
             ty,
-            overflowing: unchecked,
+            overflowing,
             left,
             right,
         } => {
             let left = expression(target, bin, left, vartab, function, ns).into_int_value();
             let right = expression(target, bin, right, vartab, function, ns).into_int_value();
 
-            if !unchecked {
+            if !overflowing {
                 let signed = ty.is_signed_int(ns);
                 build_binary_op_with_overflow_check(
                     target,
@@ -187,7 +187,7 @@ pub(super) fn expression<'a, T: TargetRuntime<'a> + ?Sized>(
         Expression::Multiply {
             loc,
             ty: res_ty,
-            overflowing: unchecked,
+            overflowing,
             left,
             right,
         } => {
@@ -198,7 +198,7 @@ pub(super) fn expression<'a, T: TargetRuntime<'a> + ?Sized>(
                 target,
                 bin,
                 function,
-                *unchecked,
+                *overflowing,
                 left,
                 right,
                 res_ty.is_signed_int(ns),
@@ -682,7 +682,7 @@ pub(super) fn expression<'a, T: TargetRuntime<'a> + ?Sized>(
         Expression::Power {
             loc,
             ty: res_ty,
-            overflowing: unchecked,
+            overflowing,
             base: l,
             exp: r,
         } => {
@@ -694,7 +694,7 @@ pub(super) fn expression<'a, T: TargetRuntime<'a> + ?Sized>(
             let f = power(
                 target,
                 bin,
-                *unchecked,
+                *overflowing,
                 bits,
                 res_ty.is_signed_int(ns),
                 o,
@@ -713,7 +713,7 @@ pub(super) fn expression<'a, T: TargetRuntime<'a> + ?Sized>(
             // Load the result pointer
             let res = bin.builder.build_load(left.get_type(), o, "");
 
-            if *unchecked || ns.target.is_substrate() {
+            if *overflowing || ns.target.is_substrate() {
                 // In Substrate, overflow case will hit an unreachable expression, so no additional checks are needed.
                 res
             } else {