aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/syntax
Commit message (Collapse)AuthorAge
* Don't convert InterruptException to EvalException in struct field call ↵Gravatar Benjamin Peterson2018-08-08
| | | | | | | | | | | expressions. This is probably only a theoretical problem, since a blocking struct field is probably a very bad idea. Closes #5132. Change-Id: Ie84a78ab4d9ce215f2806ac49bf8911de6959930 PiperOrigin-RevId: 207902766
* [Skylark] Make range function lazy.Gravatar Taras Tsugrii2018-07-17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | range used to use MutableList which would eagerly allocate an array list with all range elements, which is not efficient for very large ranges or when only a small number of its elements are used. This implementation uses a constant amount of RAM and computes a value for each requested index. For the following Skylark snippet: ``` def check_content(t): if t == []: return t return False def modulo(n): return n % 797 N = 10000000 [check_content(i) for i in range(N)] [check_content(i) for i in range(N)] [modulo(i) for i in range(N)] [modulo(i) for i in range(N)] ``` the total runtime goes from ``` $ time bazel-bin/src/main/java/com/google/devtools/skylark/Skylark test.bzl bazel-bin/src/main/java/com/google/devtools/skylark/Skylark test.bzl 93.09s user 1.67s system 316% cpu 29.930 total ``` to ``` $ time bazel-bin/src/main/java/com/google/devtools/skylark/Skylark test.bzl bazel-bin/src/main/java/com/google/devtools/skylark/Skylark test.bzl 31.45s user 0.86s system 179% cpu 17.974 total ``` which reflects the reduced system time (fewer allocations) and performance. Closes #5240. PiperOrigin-RevId: 204918577
* Remove SkylarkCallable.mandatoryPositionalsGravatar cparsons2018-07-13
| | | | | RELNOTES: None. PiperOrigin-RevId: 204505003
* [Skylark] Allow tuples as first argument of str.{starts,ends}withGravatar Yannic Bonenberger2018-06-28
| | | | | | | | Closes #5307 Closes #5455. PiperOrigin-RevId: 202567483
* Require @SkylarkCallable parameters to be explicitly specified.Gravatar cparsons2018-06-28
| | | | | | | | | | This will be enforced by annotation processor. This will be followed up, along with turndown of mandatoryPositionals, by removing the intepreter code which infers the correct number and type of parameters. RELNOTES: None. PiperOrigin-RevId: 202499089
* Automated refactor of Label.parseAbsolute() to always pass a repository mappingGravatar dannark2018-06-27
| | | | | RELNOTES: None PiperOrigin-RevId: 202360925
* Make @SkylarkCallable.name mandatory.Gravatar cparsons2018-06-22
| | | | | RELNOTES: None. PiperOrigin-RevId: 201748802
* Allow structField callables to specify useSkylarkSemantics, useLocation, and ↵Gravatar cparsons2018-06-20
| | | | | | | | | | useEnvironment Unfortunately this doesn't work for all callers, namely NativeInfo objects, as they may have structField callables invoked from contexts that have no environment available. RELNOTES[INC]: Skylark structs (using struct()) may no longer have to_json and to_proto overridden. PiperOrigin-RevId: 201376969
* Move remaining BazelLibrary skylark functions to MethodLibraryGravatar cparsons2018-06-15
| | | | | | | | | Ultimately, we'll need to make the call on whether these functions belong as part of the build API or as part of skylark builtins. For now, we keep them as skylark builtins. (In either case, we'll want to migrate to @SkylarkCallable, but that's for a later change) RELNOTES: None. PiperOrigin-RevId: 200723605
* Skylark Pretty Printer: shorten empty listGravatar Klaus Aehlig2018-06-14
| | | | | | | | | | | | | | When pretty printing a Skylark value, lists are presented as the opening bracket on a line by itself, each entry on its own line, and the closing bracket again on its own line. While this generally improves readability, for the empty list this is not the case, as the expression [] can easily be understood at a glance. In fact, the additional line even makes the outer structure harder to see, as it is spread over even more lines. Therefore, shorten the printing of the empty list to be on a single line. Change-Id: I032d1550b1f99bce47dbec7e77a4d5c6656d78a1 PiperOrigin-RevId: 200558784
* Remap repository names inside load statements in BUILD files if the ↵Gravatar dannark2018-06-12
| | | | | | | | | | | | | | | | | | | repository name is remapped. For example if main/WORKSPACE contains: local_repository( name = "a", path = "../a", repo_mapping = {"@x" : "@y"}, ) a/BUILD load("@x//:sample.bzl", "sample") Then the load in a/BUILD will be resolved as "@y//:sample.bzl" RELNOTES: None PiperOrigin-RevId: 200227431
* Use Identifiers instead of StringsGravatar Taras Tsugrii2018-06-08
| | | | | | | | | | | | The high level summary of the changes: - use `Identifier` instead of `name` in `Keyword` and `Parameter`. - construct `Identifier` through a factory method in case future interning is desired. These changes are in preparation for using `Identifier` instead of `name` for environment lookups. Closes #5304. PiperOrigin-RevId: 199869171
* Stop allocating new tokens in the lexerGravatar laurentlb2018-06-05
| | | | | | | | | | There's only one Token and it gets reused. This reduces the memory usage of the lexer. Parsing time seems to be 5%-10% faster with this change on a large file. This makes little difference on the overall performance of Bazel though. RELNOTES: None. PiperOrigin-RevId: 199310860
* Get rid of the tokens queue in the lexerGravatar laurentlb2018-06-04
| | | | | | | Next step will be to skip token allocation. RELNOTES: None. PiperOrigin-RevId: 199121625
* Add a pretty-printer class to SkylarkGravatar Klaus Aehlig2018-05-29
| | | | | | | | | | | With the recording of the results of repository rules (that eventually will lead to an implementation of the WORKSPACE.resolved proposal) bazel started writing out lengthy Skylark values. To make this file more readable for humans, add a Skylkark printer that does at least some basic line breaking and indenting. Change-Id: I469d029421df9212b43747509dd17bd6c64da4a8 PiperOrigin-RevId: 198389112
* Extend tests of range()'s list-like behaviorGravatar brandjon2018-05-25
| | | | | | | | | | | | | | This expands on https://github.com/bazelbuild/bazel/commit/33f08e75fa4e7480f8d46b8305ce03a171adefa0 to ensure list-like behavior of range for the following operations - str/repr/type - equality and ordering - append / augmented assignment - concatenation - all of the above with slices This is a prerequisite to both optimizing range() while preserving its current API, as well as changing its API via an incompatible change flag. RELNOTES: None PiperOrigin-RevId: 198046941
* Make @SkylarkModule detection (through superclasses/superinterfaces) ↵Gravatar cparsons2018-05-24
| | | | | | | | | well-defined. Moving forward, if a class not already annotated with @SkylarkModule has SkylarkModule supertypes A and B, then it must be the case that A is a type of B, or B is a type of A. The skylark type of a given class is dictated by the *most specific* superclass annotated with @SkylarkModule. RELNOTES: None. PiperOrigin-RevId: 197946898
* Add test that range() returns a listGravatar brandjon2018-05-24
| | | | | | | This is useful before we optimize range() to return a lazy object that appears like a list to the user. RELNOTES: None PiperOrigin-RevId: 197944773
* Fix SkylarkCallable-annotation detection to appropriately handle methods ↵Gravatar cparsons2018-05-24
| | | | | | | with generic parameters RELNOTES: None. PiperOrigin-RevId: 197932265
* Migrate struct() to skylarkbuildapiGravatar cparsons2018-05-24
| | | | | RELNOTES: None. PiperOrigin-RevId: 197915097
* Reject files when the first line is indented.Gravatar laurentlb2018-05-24
| | | | | | | | | | | | A bug in the lexer ignored indentation on the first line of a file. This now causes an error. Also, remove the COMMENT token from the lexer. Comments are now accessed separately. This will allow further optimizations in the lexer. It also aligns the code a bit more with the Go implementation. RELNOTES[INC]: Indentation on the first line of a file was previously ignored. This is now fixed. PiperOrigin-RevId: 197889775
* Delete GlobListGravatar laurentlb2018-05-24
| | | | | RELNOTES: None. PiperOrigin-RevId: 197881012
* Initial implementation of a Skylark debug server API.Gravatar Googler2018-05-23
| | | | | | | | | | | | | | | | | | I've pulled out the API for separate review. It includes all hooks from blaze/skylark used by the debugger. Debuggable thread contexts are currently declared in 3 places: - BuildFileAST (top-level evaluation of BUILD files) - SkylarkRuleConfiguredTargetUtil (rules) - SkylarkAspectFactory (aspects) The purpose of declaring these contexts is so that the debugger can track currently-active threads (and stop tracking them when the task is completed). Details of the actual debugging server are in unknown commit. PiperOrigin-RevId: 197770547
* Add typo detection when lookups on SkylarkModules fail.Gravatar Googler2018-05-22
| | | | | | Also consolidate code with getattr so getattr now also gets typo detection. PiperOrigin-RevId: 197612666
* Make the parser look at only one Token at a time.Gravatar laurentlb2018-05-22
| | | | | | | | | Remove all references to `Token` (except one) in the parser. In particular, remove the mechanism to push tokens back. This change will make possible for the lexer to reuse tokens instead of allocating new objects each time. RELNOTES: None. PiperOrigin-RevId: 197585185
* Skylark: do not eagerly scan the whole fileGravatar laurentlb2018-05-22
| | | | | | | | With this change, the parser explicitly asks the lexer to give the next token. To avoid changing the lexer too much, the tokenize() method populates a queue (it may add multiple tokens at the same time). While this reduces the peak memory usage, further work is needed to actually improve the performance. RELNOTES: None. PiperOrigin-RevId: 197576326
* Clean up code that directly imports nested classes like Builder, Entry, etc.Gravatar jcater2018-05-01
| | | | PiperOrigin-RevId: 195040539
* Move BazelLibrary from syntax/ to packages/Gravatar brandjon2018-05-01
| | | | | | | | | This helps the Skylark interpreter to not depend on Bazel concepts, though it adds a temporary dependency of Skylint on packages/. The fix for that will be to create a Build API interface for BazelLibrary (e.g., "BazelLibraryAPI"). Refactored some GlobalFrame construction logic to be more uniform. Instead of constructing a whole Environment just to get a frame, we build the frame directly, using ImmutableMap.Builder to accumulate bindings. This convention may further change once we convert MethodLibrary and the like to @SkylarkGlobalLibrary, but for now it's more readable. RELNOTES: None PiperOrigin-RevId: 194960824
* Use a new pattern for builtin Provider objects with @SkylarkCallable.Gravatar cparsons2018-05-01
| | | | | | | | This deprecates the old NativeProvider pattern. The new pattern is demonstrated using AppleStaticLibraryInfo. RELNOTES: None. PiperOrigin-RevId: 194956883
* Introduce @SkylarkCallable.selfCall, to signify the containing class should ↵Gravatar cparsons2018-04-24
| | | | | | | | | | | | be treated as a callable skylark object. This will allow Skylark Provider objects to be better specified. For example, "JavaInfo" can have a fully-documented, fully-specified @SkylarkCallable method with selfCall=true to represent the method JavaInfo(), instead of being a subclass of BaseFunction and requiring a @SkylarkSignature annotation. There are no usages of this pattern introduced in this CL, and also no updates to docgen to support the new pattern. These will be introduced in another CL. RELNOTES: None. PiperOrigin-RevId: 194088227
* Refactor SyntaxTests to not rely on actions/analysis packages arbitrarilyGravatar brandjon2018-04-17
| | | | | | | | | | | | | | | In the process, clean up SkylarkType-related tests. - Factor test of EvalUtils.getSkylarkType logic from SkylarkEvaluationTest and ValidationTest to EvalUtilsTest. - Move test of EvalUtils.getSkylarkType's behavior on lists to SkylarkListTest. - Move other SkylarkType tests from ValidationTest to new SkylarkTypeTest and split them up a little. - Throughout, don't use Bazel types like Artifact as test subjects. RELNOTES: None PiperOrigin-RevId: 193303463
* Remove flag `incompatible_disallow_toplevel_if_statement`.Gravatar laurentlb2018-04-12
| | | | | | RELNOTES: Removed flag `--incompatible_disallow_toplevel_if_statement`. PiperOrigin-RevId: 192621765
* Migrate StringModule methods to SkylarkCallable from SkylarkSignature.Gravatar cparsons2018-04-11
| | | | | | | StringModule is a special case in a number of places because it represents effectively methods which should be annotated on String.class. However, String may not be subclassed in Java. StringModule thus serves as a proxy module for String. RELNOTES: None. PiperOrigin-RevId: 192508607
* Introduce Param.legacyNamed() to handle migration from @SkylarkSignature to ↵Gravatar cparsons2018-04-11
| | | | | | | | | | @SkylarkCallable. @SkylarkSignature.parameters() treat named()=true for parameters regardless of whether named() was actually set to true, and thus for ease of migration we mark migrated parameters as legacyNamed() = true, which is currently semantically equivalent to named() = true. We make a distinction so that it's easier to bulk fix these later. RELNOTES: None. PiperOrigin-RevId: 192477405
* Introduce `--incompatible_disallow_slash_operator` to disable `/` operator.Gravatar laurentlb2018-04-11
| | | | | | | | RELNOTES: The `/` operator is deprecated in favor of `//` (floor integer division). Try the `--incompatible_disallow_slash_operator` flag to ensure your code is forward-compatible. PiperOrigin-RevId: 192430310
* Migrate Info's skylark methods to @SkylarkCallableGravatar cparsons2018-04-10
| | | | | RELNOTES: None PiperOrigin-RevId: 192337555
* Introduce extraPositonals and extraArguments to SkylarkCallable, to have ↵Gravatar cparsons2018-04-09
| | | | | | | | | parity with @SkylarkSignature. This is necessary for several builtin functions that still use @SkylarkSignature, such as string format. These will be migrated in a future CL. RELNOTES: None. PiperOrigin-RevId: 192200282
* Cleanup @SkylarkCallable parameters and their error handling.Gravatar cparsons2018-04-06
| | | | | | | This involves enforcing additional compiletime restrictions on Param ordering and semantics. RELNOTES: None. PiperOrigin-RevId: 191927206
* Fix the definition of Argument in the Skylark specificationGravatar vladmos2018-04-05
| | | | PiperOrigin-RevId: 191717115
* Migrate SkylarkNativeModule methods to use @SkylarkCallable instead of ↵Gravatar cparsons2018-04-04
| | | | | | | | | @SkylarkSignature Most notably, this involves introduction of a new function abstraction, BuiltinMethod, which can wrap a {objc, SkylarkCallable} pair into a BaseFunction for later calling. (This is required due to the current layer of indirection on the end "native" module) RELNOTES: None. PiperOrigin-RevId: 191642467
* Migrate depset.union() and depset.to_list() to SkylarkCallableGravatar cparsons2018-04-04
| | | | | RELNOTES: None. PiperOrigin-RevId: 191641410
* Add option to restrict format strings to %sGravatar brandjon2018-04-04
| | | | | | | This is useful for contexts like ctx.actions.args()'s methods, where %d and %r aren't appropriate placeholders. RELNOTES: None PiperOrigin-RevId: 191629195
* Migrate SkylarkDict and MutableList methods to use @SkylarkCallable instead ↵Gravatar cparsons2018-03-30
| | | | | | | of @SkylarkSignature. RELNOTES: None. PiperOrigin-RevId: 191112273
* Enforce @SkylarkCallable must have a non-empty doc string or explicitly be ↵Gravatar cparsons2018-03-30
| | | | | | | documented=false. RELNOTES: None. PiperOrigin-RevId: 191112140
* Move more tests to test suite (int function, list index, list mutation)Gravatar laurentlb2018-03-28
| | | | | RELNOTES: None. PiperOrigin-RevId: 190823566
* Migrate string tests to Skylark test suite.Gravatar laurentlb2018-03-28
| | | | | RELNOTES: None. PiperOrigin-RevId: 190785580
* Fix incorrect int() exampleGravatar brandjon2018-03-26
| | | | | | | Also add tests for leading "+" in int(<string>) form. RELNOTES: None PiperOrigin-RevId: 190507678
* Automated rollback of commit 316cd7da6f6b003b853ccf7d144f395a9a557400.Gravatar janakr2018-03-26
| | | | | | | | *** Reason for rollback *** Roll-forward with fix (equality and hashcode for relevant classes). Also add a bit more debugging info in case of failure. PiperOrigin-RevId: 190492934
* Bugfixes for int()Gravatar brandjon2018-03-23
| | | | | | | | | | - fix negatives + prefixes - fix boundary cases (min int value) The only remaining relevant differences from Python are that we disallow int() with zero args, we don't allow whitespace in strings, and we take Python 3's view on prohibiting leading 0s when base is 0. RELNOTES: None PiperOrigin-RevId: 190216646
* Victory lap: Remove all code that used to support the three-argument form of ↵Gravatar lberki2018-03-23
| | | | | | | vardef(). RELNOTES: None. PiperOrigin-RevId: 190196933