Merge remote-tracking branch 'origin/topic/vern/when-lambda'

* origin/topic/vern/when-lambda:
  explicitly provide the frame for evaluating a "when" timeout expression
  attempt to make "when" btest deterministic
  tests for new "when" semantics/errors
  update existing test suite usage of "when" statements to include captures
  update uses of "when" in base scripts to include captures
  captures for "when" statements update Triggers to IntrusivePtr's and simpler AST traversal introduce IDSet type, migrate associated "ID*" types to "const ID*"
  logic (other than in profiling) for assignments that yield separate values
  option for internal use to mark a function type as allowing non-expression returns
  removed some now-obsolete profiling functionality
  minor commenting clarifications
This commit is contained in:
Tim Wojtulewicz 2022-01-14 14:41:15 -07:00
commit 3d9d6e953b
56 changed files with 931 additions and 255 deletions

View file

@ -137,6 +137,7 @@ using EventExprPtr = IntrusivePtr<EventExpr>;
using ExprPtr = IntrusivePtr<Expr>;
using NameExprPtr = IntrusivePtr<NameExpr>;
using RefExprPtr = IntrusivePtr<RefExpr>;
using LambdaExprPtr = IntrusivePtr<LambdaExpr>;
class Stmt;
using StmtPtr = IntrusivePtr<Stmt>;
@ -959,6 +960,15 @@ public:
bool IsTemp() const { return is_temp; }
void SetIsTemp() { is_temp = true; }
// The following is a hack that's used in "when" expressions to support
// assignments to new locals, like "when ( (local l = foo()) && ...".
// These methods return the value to use when evaluating such
// assignments. That would normally be the RHS of the assignment,
// but to get when's to work in a convenient fashion, for them it's
// instead boolean T.
ValPtr AssignVal() { return val; }
const ValPtr& AssignVal() const { return val; }
protected:
bool TypeCheck(const AttributesPtr& attrs = nullptr);
bool TypeCheckArithmetics(TypeTag bt1, TypeTag bt2);
@ -1419,7 +1429,8 @@ protected:
class LambdaExpr final : public Expr
{
public:
LambdaExpr(std::unique_ptr<function_ingredients> ingredients, IDPList outer_ids);
LambdaExpr(std::unique_ptr<function_ingredients> ingredients, IDPList outer_ids,
StmtPtr when_parent = nullptr);
const std::string& Name() const { return my_name; }
const IDPList& OuterIDs() const { return outer_ids; }
@ -1440,7 +1451,7 @@ protected:
void ExprDescribe(ODesc* d) const override;
private:
void CheckCaptures();
void CheckCaptures(StmtPtr when_parent);
std::unique_ptr<function_ingredients> ingredients;