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 istrue
then temporary lifetime is extended through this Expression/Statement or no otherwise. -
Full list
isTmpConsumer == false
ItemStatement
LetStatement
MacroStatement
-
ExprStatement
if 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 istrue
andisTmpConsumer == true
then 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
isYoung
intofalse
(isYoung = false
) from another expression (most of them could produce newisYoung==true
temporary variables):
-
IfCondExpr
from itsef -
WhileCondExpr
from itsef -
Operator1Expr
fromOperatorArgSingle
-
Operator2Expr
(exceptAssignOperatorExpr
) fromOperatorArgLeft
andOperatorArgRight
-
ArrayExpr
from allArrayElementExpr
-
ArrayIndexExpr
fromArrayIndexCallierExpr
andArrayIndexIndexingExpr
-
TupleExpr
from allTupleElementExpr
-
TupleIndexExpr
from allTupleIndexCallierExpr
-
StructExpr
from allStructFieldExpr
andStructBaseExpr
-
CallExpr
from allCallArgExpr
andCallCallierExpr
-
MethodCallExpr
from allMethodCallArgExpr
andMethodCallCallierExpr
-
FieldExpr
fromFieldCallierExpr
-
RangeExpr
fromRangeFromExpr
andRangeToExpr
Is it sound reasonable? Do I forget something?