I'm thinking about new rules for lifetimes of Temporary variables.
Last discussion by lang-team: Temporary lifetimes
I found that next new rules could be handy:
-
First Rule - "extend" lifetime (to exclude "too short" temporary lifetimes). All Expressions and Statements must have boolean "property"
isTmpConsumer, if it istruethen temporary lifetime is extended through this Expression/Statement or no otherwise. -
Full list
isTmpConsumer == false
ItemStatementLetStatementMacroStatement-
ExprStatementif it is before another Statement
-
The rest majority of Expressions are on the list where
isTmpConsumer == true -
Second Rule - "cut" lifetime (to exclude "too long" temporary lifetimes). Each temporary variable must have boolean "property"
isYoung, if it istrueandisTmpConsumer == truethen lifetime is extended through this Expression or it ends with this Expression ifisYoung == false(orisTmpConsumer == false) -
Full list of Expressions, that convert temp variable property
isYoungintofalse(isYoung = false) from another expression (most of them could produce newisYoung==truetemporary variables):
-
IfCondExprfrom itsef -
WhileCondExprfrom itsef -
Operator1ExprfromOperatorArgSingle -
Operator2Expr(exceptAssignOperatorExpr) fromOperatorArgLeftandOperatorArgRight -
ArrayExprfrom allArrayElementExpr -
ArrayIndexExprfromArrayIndexCallierExprandArrayIndexIndexingExpr -
TupleExprfrom allTupleElementExpr -
TupleIndexExprfrom allTupleIndexCallierExpr -
StructExprfrom allStructFieldExprandStructBaseExpr -
CallExprfrom allCallArgExprandCallCallierExpr -
MethodCallExprfrom allMethodCallArgExprandMethodCallCallierExpr -
FieldExprfromFieldCallierExpr -
RangeExprfromRangeFromExprandRangeToExpr
Is it sound reasonable? Do I forget something?