diff --git a/cmd/starlark/starlark.go b/cmd/starlark/starlark.go index 6d667557..141f9d64 100644 --- a/cmd/starlark/starlark.go +++ b/cmd/starlark/starlark.go @@ -32,7 +32,6 @@ func init() { flag.BoolVar(&resolve.AllowSet, "set", resolve.AllowSet, "allow set data type") flag.BoolVar(&resolve.AllowLambda, "lambda", resolve.AllowLambda, "allow lambda expressions") flag.BoolVar(&resolve.AllowNestedDef, "nesteddef", resolve.AllowNestedDef, "allow nested def statements") - flag.BoolVar(&resolve.AllowBitwise, "bitwise", resolve.AllowBitwise, "allow bitwise operations (&, |, ^, ~, <<, and >>)") flag.BoolVar(&resolve.AllowRecursion, "recursion", resolve.AllowRecursion, "allow while statements and recursive functions") flag.BoolVar(&resolve.AllowGlobalReassign, "globalreassign", resolve.AllowGlobalReassign, "allow reassignment of globals, and if/for/while statements at top level") } diff --git a/doc/spec.md b/doc/spec.md index c9cb1d49..29fd1437 100644 --- a/doc/spec.md +++ b/doc/spec.md @@ -443,9 +443,6 @@ arithmetic is exact, motivated by the need for lossless manipulation of protocol messages which may contain signed and unsigned 64-bit integers. The Java implementation currently supports only signed 32-bit integers. - -The Go implementation of Starlark requires the `-bitwise` flag to -enable support for `&`, `|`, `^`, `~`, `<<`, and `>>` operations. The Java implementation does not support `^`, `~`, `<<`, and `>>` operations. @@ -837,8 +834,7 @@ A set used in a Boolean context is considered true if it is non-empty. Implementation note: The Go implementation of Starlark requires the `-set` flag to -enable support for sets and the `-bitwise` flag to enable support for -the `&`, `|`, and `^` operators. +enable support for sets. The Java implementation does not support sets. @@ -4021,7 +4017,6 @@ See [Starlark spec issue 20](https://github.com/bazelbuild/starlark/issues/20). * Integers are represented with infinite precision. * Integer arithmetic is exact. -* Integers support bitwise operators `&`, `|`, `<<`, `>>`, `^`, `~`, and their assignment forms. * Floating-point literals are supported (option: `-float`). * The `float` built-in function is provided (option: `-float`). * Real division using `float / float` is supported (option: `-float`). diff --git a/resolve/resolve.go b/resolve/resolve.go index 9c5a0b80..b1a6657a 100644 --- a/resolve/resolve.go +++ b/resolve/resolve.go @@ -94,8 +94,9 @@ var ( AllowFloat = false // allow floating point literals, the 'float' built-in, and x / y AllowSet = false // allow the 'set' built-in AllowGlobalReassign = false // allow reassignment to globals declared in same file (deprecated) - AllowBitwise = false // allow bitwise operations (&, |, ^, ~, <<, and >>) AllowRecursion = false // allow while statements and recursive functions + + AllowBitwise = true // obsolete; bitwise operations (&, |, ^, ~, <<, and >>) are always enabled ) // File resolves the specified file. @@ -439,12 +440,6 @@ func (r *resolver) stmt(stmt syntax.Stmt) { r.stmts(stmt.False) case *syntax.AssignStmt: - if !AllowBitwise { - switch stmt.Op { - case syntax.AMP_EQ, syntax.PIPE_EQ, syntax.CIRCUMFLEX_EQ, syntax.LTLT_EQ, syntax.GTGT_EQ: - r.errorf(stmt.OpPos, doesnt+"support bitwise operations") - } - } r.expr(stmt.RHS) // x += y may be a re-binding of a global variable, // but we cannot tell without knowing the type of x. @@ -644,21 +639,12 @@ func (r *resolver) expr(e syntax.Expr) { } case *syntax.UnaryExpr: - if !AllowBitwise && e.Op == syntax.TILDE { - r.errorf(e.OpPos, doesnt+"support bitwise operations") - } r.expr(e.X) case *syntax.BinaryExpr: if !AllowFloat && e.Op == syntax.SLASH { r.errorf(e.OpPos, doesnt+"support floating point (use //)") } - if !AllowBitwise { - switch e.Op { - case syntax.AMP, syntax.PIPE, syntax.CIRCUMFLEX, syntax.LTLT, syntax.GTGT: - r.errorf(e.OpPos, doesnt+"support bitwise operations") - } - } r.expr(e.X) r.expr(e.Y) diff --git a/resolve/resolve_test.go b/resolve/resolve_test.go index 2885a5bf..b913670c 100644 --- a/resolve/resolve_test.go +++ b/resolve/resolve_test.go @@ -15,7 +15,6 @@ import ( ) func setOptions(src string) { - resolve.AllowBitwise = option(src, "bitwise") resolve.AllowFloat = option(src, "float") resolve.AllowGlobalReassign = option(src, "globalreassign") resolve.AllowLambda = option(src, "lambda") diff --git a/starlark/eval_test.go b/starlark/eval_test.go index 51119e68..fb3da9f9 100644 --- a/starlark/eval_test.go +++ b/starlark/eval_test.go @@ -21,7 +21,6 @@ import ( // A test may enable non-standard options by containing (e.g.) "option:recursion". func setOptions(src string) { - resolve.AllowBitwise = option(src, "bitwise") resolve.AllowFloat = option(src, "float") resolve.AllowGlobalReassign = option(src, "globalreassign") resolve.AllowLambda = option(src, "lambda") diff --git a/starlark/testdata/int.star b/starlark/testdata/int.star index 85fe004f..1a09cb9b 100644 --- a/starlark/testdata/int.star +++ b/starlark/testdata/int.star @@ -1,5 +1,5 @@ # Tests of Starlark 'int' -# option:bitwise option:float +# option:float load("assert.star", "assert") diff --git a/starlark/testdata/set.star b/starlark/testdata/set.star index 61a47167..9e5250b6 100644 --- a/starlark/testdata/set.star +++ b/starlark/testdata/set.star @@ -1,5 +1,5 @@ # Tests of Starlark 'set' -# option:set option:bitwise +# option:set # Sets are not a standard part of Starlark, so the features # tested in this file must be enabled in the application by setting diff --git a/starlark/testdata/string.star b/starlark/testdata/string.star index 34c54dd2..bb07e5c4 100644 --- a/starlark/testdata/string.star +++ b/starlark/testdata/string.star @@ -1,5 +1,5 @@ # Tests of Starlark 'string' -# option:float option:bitwise option:set +# option:float option:set load("assert.star", "assert")