Skip to content

Commit

Permalink
topdown+builtins: Block all ND builtins from partial eval.
Browse files Browse the repository at this point in the history
This commit removes the `IgnoreDuringPartialEval` list in
`ast/builtins`, and instead changes the partial evaluator to simply
ignore all non-deterministic builtins. This keeps true to the intent of
the original list, and reduces the potential for human error in
maintenance in the future.

Fixes: #5171

Signed-off-by: Philip Conrad <philipaconrad@gmail.com>
  • Loading branch information
philipaconrad committed Sep 23, 2022
1 parent b116844 commit a0be1dd
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 17 deletions.
11 changes: 0 additions & 11 deletions ast/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,17 +284,6 @@ var DefaultBuiltins = [...]*Builtin{
// built-in definitions.
var BuiltinMap map[string]*Builtin

// IgnoreDuringPartialEval is a set of built-in functions that should not be
// evaluated during partial evaluation. These functions are not partially
// evaluated because they are not pure.
var IgnoreDuringPartialEval = []*Builtin{
NowNanos,
HTTPSend,
UUIDRFC4122,
RandIntn,
NetLookupIPAddr,
}

/**
* Unification
*/
Expand Down
8 changes: 2 additions & 6 deletions topdown/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,12 +375,8 @@ func ignoreExprDuringPartial(expr *ast.Expr) bool {
}

func ignoreDuringPartial(bi *ast.Builtin) bool {
for _, ignore := range ast.IgnoreDuringPartialEval {
if bi == ignore {
return true
}
}
return false
// Note(philipc): For now, we throw out all non-deterministic builtins.
return bi.Nondeterministic
}

type inliningControl struct {
Expand Down

0 comments on commit a0be1dd

Please sign in to comment.