Commit Graph

10171 Commits

Author SHA1 Message Date
ridiculousfish
0ca3ae7c7e Rejigger var_stack_t's ctors
Prepare var_stack_t to support snapshotting.
2019-04-14 15:50:24 -07:00
ridiculousfish
69655ef5c1 Reorganize env.cpp
Group functions together more logically
2019-04-14 15:50:19 -07:00
ridiculousfish
1d464da698 Introduce env_scoped_t
env_scoped_t lives between environment_t and env_stack_t.
It represents the read-only logic of env_stack_t and will be used to back
the new environment snapshot implementation.
2019-04-14 15:50:12 -07:00
ridiculousfish
46fd47a0da Organize some code slightly better in env.h 2019-04-14 15:50:06 -07:00
Mahmoud Al-Qudsi
a9e0990773 Add changelog note about parser error propagation fix
..as this affects backwards compatibility (as witnessed by the tests
that failed after making this fix).
2019-04-13 17:28:16 -05:00
Mahmoud Al-Qudsi
2dfc85245f Add regression tests for eval 2019-04-13 17:28:16 -05:00
Mahmoud Al-Qudsi
05f52924c1 Fix bad tests
These tests used raw, unescaped parentheses to perform `test` logical
grouping, but the test failures weren't caught because the parser
evaluation errors were not being propagated (fixed in bdbd173e).
2019-04-13 17:28:16 -05:00
Mahmoud Al-Qudsi
b2a1da602f Fix error propagation in parser_t::eval
It was unconditionally returning `parse_execution_success`. This was
causing certain parser errors to incorrectly return after evaluation
with `$status` equal to `0`, as reported after `eval`, `source`, or
sub-`fish` execution.
2019-04-13 17:28:16 -05:00
Mahmoud Al-Qudsi
8e4010b263 Make eval override previous status
Closes #5692 (again).
2019-04-13 17:28:10 -05:00
Mahmoud Al-Qudsi
47a61a3202 Test: validate $status is preserved on calling into a function 2019-04-13 17:21:13 -05:00
Mahmoud Al-Qudsi
ab37dfaf78 Add tests for evaluaton of empty blocks and functions 2019-04-13 17:21:13 -05:00
Mahmoud Al-Qudsi
87f6856954 Fix tests expecting non-zero status after empty function call 2019-04-13 17:21:13 -05:00
Mahmoud Al-Qudsi
4530a41004 Fix return code after execution of empty function 2019-04-13 17:21:13 -05:00
ridiculousfish
cc9386fca9 Clean up some headers in env and env_dispatch.cpp 2019-04-13 14:39:20 -07:00
ridiculousfish
2537fe0f9e Put back a missing lock in env_stack_t::set_internal
Setting a variable could race with getting it.

The lockin^g here needs a serious overhaul.
2019-04-13 12:40:58 -07:00
ridiculousfish
2f1e572756 Minor cleanup of env_node_t
Mark some fields const that don't need to change. Trying to get ready to
improve locking here.
2019-04-13 12:40:58 -07:00
ridiculousfish
372291ad02 Collapse a weirdly structured clause in env.cpp 2019-04-13 12:40:57 -07:00
ridiculousfish
a597b0e6e1 Remove get_proc_had_barrier
Prior to this change, fish used a global flag to decide if we should check
for changes to universal variables. This flag was then checked at arbitrary
locations, potentially triggering variable updates and event handlers for
those updates; this was very hard to reason about.

Switch to triggering a universal variable update at a fixed location,
after running an external command.  The common case is that the variable
file has not changed, which we can identify with just a stat() call, so
this is pretty cheap.
2019-04-13 12:40:57 -07:00
ridiculousfish
341799194e Factor out fetching electric variables into a separate function
This factors env_stack_t::get() a little better
2019-04-13 12:40:57 -07:00
ridiculousfish
f35f2fe110 Mark the benchmark as using the terminal
Prevents buffering all output from the command.
2019-04-13 12:40:12 -07:00
ridiculousfish
e634abc1c8 Add a benchmark for external commands
This just runs '/usr/bin/true' a lot.
2019-04-13 12:40:09 -07:00
ridiculousfish
2c7dc98337 Revert "fcntl a little less"
This reverts commits:
e5362a4ae5.
dd9a26715d.

These commits were incorrect because they stomped other flags, such as
O_NONBLOCK.
2019-04-13 12:27:05 -07:00
ridiculousfish
13c5f93d63 Revert "Optimize function calls by reducing inherit vars heap allocations and copies"
This reverts commit cdce8511a1.

This change was unsafe. The prior version (now restored) took the lock and
then copied the data. By returning a reference, the caller holds a
reference to data outside of the lock.

This function isn't worth optimizing. Hardly any functions use this
facility, and for those that do, they typically just capture one or two
variables.
2019-04-13 12:03:02 -07:00
Mahmoud Al-Qudsi
cdce8511a1 Optimize function calls by reducing inherit vars heap allocations and copies
* Convert `function_get_inherit_vars()` to return a reference to the
  (possibly) existing map, rather than a copy;
* Preallocate and reuse a static (read-only) map for the (very) common
  case of no inherited vars;
* Pass references to the inherit vars map around thereafter, never
  triggering the map copy (or even move) constructor.

NB: If it turns out the reference is unsafe, we can switch the inherit vars
to be a shared_ptr and return that instead.
2019-04-13 11:26:10 -05:00
David Adam
56125f73e4 env: trigger locale updates if LOCPATH changes
Closes #5815.
2019-04-13 21:58:54 +08:00
ridiculousfish
47b9907113 Remove an unused variable 2019-04-12 23:03:28 -07:00
ridiculousfish
4e1fdaf5a7 Use move semantics in builtin_eval
Saves some allocations
2019-04-12 23:02:45 -07:00
ridiculousfish
c95e1b83c7 Minor cleanup of eval builtin
Fix some copy and paste errors, remove some dead variables and code,
make the return a bit more structured.
2019-04-12 22:42:27 -07:00
Mahmoud Al-Qudsi
5989a92dae Add completions for rg (ripgrep)
[ci skip]
2019-04-12 15:20:45 -05:00
David Adam
2ca1bc433f fish_indent_lexer: explicitly encode/decode bytes over pipe
Universal newlines behaves differently between Python 2.7 and 3.x,
leading to problems when running Sphinx with Python 2.7.

fish_indent always uses \n, so there's no need to use universal newline
detection.

This also allows full UTF-8 in documentation sources.

Closes #5808.
2019-04-12 23:10:53 +08:00
Fabian Homborg
a8030c020b src/fish_indent.cpp: Fix return-value warning 2019-04-12 15:38:38 +02:00
Mahmoud Al-Qudsi
e0e0fe9dd3 Re-implement eval as a regular builtin
I did not realize builtins could safely call into the parser and inject
jobs during execution. This is much cleaner than hacking around the
required shape of a plain_statement.
2019-04-12 07:04:15 -05:00
Geographer
9cf1b18b26 Honor dirprev scope (#5796)
* Honour `dirprev` scope

Honour the scope of the `dirprev` variable if it is universal
and avoid to shadow it with a global. This enables to share
the `cd` history between sessions.

* Honor dirnext and __fish_cd_direction scope

If these variables exist in the universal scope, do not shadow them
2019-04-12 09:43:34 +02:00
Fabian Homborg
898ed12a6c
Merge pull request #5795 from cstyles/git-completions
Add git completions
2019-04-12 09:42:52 +02:00
Fabian Homborg
e672b03993 functions/fish_hg_prompt: Remove --color and --pager
These weren't added long enough ago, and I only added them
speculatively.

So it should make it work with old hg versions.

CC @zanchey.

[ci skip]
2019-04-12 09:01:34 +02:00
Fabian Homborg
b0388ed488 docs: Workaround bug with python2-sphinx
It can't handle a `→` literal inside code blocks. Since we only have
two of those, let's just replace them with `=>`.

Fixes #5808.
2019-04-12 08:46:41 +02:00
Aaron Gyes
014ab7935e Test expansion syntax errors.
If there is a better way to do stuff that will stop execution than
fish -c for our tests, please let me know.
2019-04-11 21:59:23 -07:00
Aaron Gyes
1834e962d2 Correct carat position for unexpected } in brace expansion
before:

$ echo {}}-
fish: Unexpected '}' for unopened brace expansion

$ ./fish -c 'echo {}}}}'
fish: Unexpected '}' for unopened brace expansion
echo {}}}}
^

now:
$ echo {}}}}}}1-
fish: Unexpected '}' for unopened brace expansion
echo {}}}}}}
       ^
2019-04-11 17:18:53 -07:00
Aaron Gyes
75db3b4ff4 fix incorrectly aligned carat in command expansion errors and more
- fix the carat position expanding e.g. `command $,`
- improve the error reporting for not-allowed command subtitutions
  by figuring out where the expansion failed instead of using
  SOURCE_LOCATION_UNKNOWN
- allow nullptr for parse_util_licate_brackets_range() out_string
  argument if we don't need it to do any work.

Fixes #5812
2019-04-11 14:44:46 -07:00
Mahmoud Al-Qudsi
4539a9db15 Drop unused include in src/exec.cpp
It was added in 2544c622841fd8b7317109f12fe4eb55c5ea1d0a,
and caught by @faho.
2019-04-11 13:01:29 -05:00
Mahmoud Al-Qudsi
0cf0829c5f Add comment clarifying presence of empty eval function 2019-04-11 12:59:04 -05:00
Mahmoud Al-Qudsi
b82fa187ea Changelog: mention changes to eval scoping 2019-04-11 11:55:12 -05:00
David Adam
87518a524f docs: update the VCS prompt function documentation
Edited for clarity and formatting.

[ci skip]
2019-04-11 23:51:47 +08:00
David Adam
c50eb7c85f docs: import SphinxWarning in configuration
Fixes a NameError when reporting problems.

[ci skip]
2019-04-11 23:51:38 +08:00
Mahmoud Al-Qudsi
4d54147e7e Merge branch 'eval_parser'
Implements `eval` in cpp rather than as a fish function.
2019-04-11 10:41:33 -05:00
Mahmoud Al-Qudsi
da20d197b4 Add regression test for eval scope (#4443) 2019-04-11 10:40:22 -05:00
Mahmoud Al-Qudsi
2fe2169065 Make eval a decorator
`eval` has always been implemented as a function, which was always a bit
of a hack that caused some issues such as triggering the creation of a
new scope. This turns `eval` into a decorator.

The scoping issues with eval prevented it from being usable to actually
implement other shell components in fish script, such as the problems
described in #4442, which should now no longer be the case.

Closes #4443.
2019-04-11 10:36:49 -05:00
Aaron Gyes
90547a861a __fish_macos_set_env: don't create empty PATH components
It was creating empty entries for blank lines, which will actually
create '.' for colon-separated vars

Fixes #5809
2019-04-11 02:52:18 -07:00
ridiculousfish
f7817a2586 Remove env_node_t::contains_any_of
Dead code...
2019-04-10 23:18:30 -07:00
Mahmoud Al-Qudsi
0bda853dc7 Add detection of eval to the parser
While `eval` is still a function, this paves the way for changing that
in the future, and lets the proc/exec functions detect when an eval is
used to allow/disallow certain behaviors and optimizations.
2019-04-10 21:19:57 -05:00