Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of the local builtin with support for dynamic local scopes #703

Open
wants to merge 55 commits into
base: dev
Choose a base branch
from

Commits on Apr 22, 2021

  1. Incomplete: Add local and declare builtins with a dynamic scope

    This implementation of local doesn't have proper scoping.
    The POSIX function scoping mechanism should be implemented
    in b_dot_cmd, although it should be done without breaking
    backward compatibility (i.e., typeset's behavior in POSIX
    functions shouldn't change as a result of implementing
    scoping).
    
    Discussion: ksh93#123
    
    src/cmd/ksh93/sh/name.c:
    - Set a dynamic scope in ksh functions for the local and
      declare builtins. This currently doesn't work in POSIX
      functions since b_dot_cmd doesn't apply any scoping
      right now.
    
    src/cmd/ksh93/bltins/typeset.c,
    src/cmd/ksh93/sh/xec.c:
    - Only allow the local builtin to run inside of functions. This
      is accomplished by using a new 'SH_INFUNCTION' state set when
      ksh is inside of a function.
    - Set shp->st.var_local to shp->var_tree for declare and local
      to get a dynamic scope in ksh functions. For typeset use
      shp->var_base to get a static scope in ksh functions.
      This will need bug-testing for when local is used in
      namespaces.
    - Add local and declare to top comment alongside other builtins.
    - Add a dictionary generator entry for declare(1).
    
    src/cmd/ksh93/data/builtins.c,
    src/cmd/ksh93/include/builtins.h:
    - Add local and declare to the builtin table as declaration
      builtins. Depending on how local is specified in the next
      POSIX standard, it may need to be changed to a special builtin.
      That does break backward compatibility with existing ksh
      scripts though (such as one regression test script), so for now
      it's just a regular builtin.
    - Update the man pages with references to local(1). Add
      information to the man page about the intended scoping
      of declare and local, although it's not completely
      implemented in POSIX functions.
    
    src/cmd/ksh93/tests/builtins.sh:
    - Run one of the regression tests for builtins inside of a
      function to fix a test failure with the local builtin.
    
    src/cmd/ksh93/tests/local.sh:
    - Add a number of regression tests mostly targeted at the
      local builtin. Most of the bugs tested for here are present
      in the ksh93v- and ksh2020 implementations of local and
      declare.
    JohnoKing committed Apr 22, 2021
    Configuration menu
    Copy the full SHA
    ccfe8a6 View commit details
    Browse the repository at this point in the history

Commits on Apr 26, 2021

  1. Configuration menu
    Copy the full SHA
    32672ad View commit details
    Browse the repository at this point in the history

Commits on May 3, 2021

  1. Configuration menu
    Copy the full SHA
    9ff934a View commit details
    Browse the repository at this point in the history

Commits on May 8, 2021

  1. Configuration menu
    Copy the full SHA
    3b55c89 View commit details
    Browse the repository at this point in the history

Commits on May 12, 2021

  1. Configuration menu
    Copy the full SHA
    03b849c View commit details
    Browse the repository at this point in the history

Commits on May 23, 2021

  1. Configuration menu
    Copy the full SHA
    99a7bcb View commit details
    Browse the repository at this point in the history

Commits on Dec 6, 2021

  1. Configuration menu
    Copy the full SHA
    d369dfd View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    94013f5 View commit details
    Browse the repository at this point in the history

Commits on Dec 17, 2021

  1. Configuration menu
    Copy the full SHA
    03b5fb8 View commit details
    Browse the repository at this point in the history

Commits on Jan 5, 2022

  1. Configuration menu
    Copy the full SHA
    cf953aa View commit details
    Browse the repository at this point in the history

Commits on Jan 27, 2022

  1. Merge upstream changes

    JohnoKing committed Jan 27, 2022
    Configuration menu
    Copy the full SHA
    ad96056 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    91d3079 View commit details
    Browse the repository at this point in the history

Commits on Jan 1, 2024

  1. Configuration menu
    Copy the full SHA
    7721eeb View commit details
    Browse the repository at this point in the history
  2. Fix builtins.sh failure by setting NV_GLOBAL in POSIX functions

    POSIX functions should default to placing variables on the global scope,
    so this should be perfectly fine.
    JohnoKing committed Jan 1, 2024
    Configuration menu
    Copy the full SHA
    666cd88 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    c9a2289 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    eba8be8 View commit details
    Browse the repository at this point in the history
  5. More tests

    JohnoKing committed Jan 1, 2024
    Configuration menu
    Copy the full SHA
    3493f2d View commit details
    Browse the repository at this point in the history
  6. Add another safety check

    JohnoKing committed Jan 1, 2024
    Configuration menu
    Copy the full SHA
    fa23bd4 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    10f9ad1 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    dc7841d View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    c91998b View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    bffb6b8 View commit details
    Browse the repository at this point in the history
  11. Add more (failing) tests

    I suspect that the only reason dynamic scoping even somewhat works is
    not because an actual scope was opened, but rather because the child
    functions use the parent function's scope outright. This is no good and
    will need a rewrite.
    JohnoKing committed Jan 1, 2024
    Configuration menu
    Copy the full SHA
    33a6f17 View commit details
    Browse the repository at this point in the history

Commits on Jan 15, 2024

  1. Abandon unsalvageable ksh93v- scoping code and rewrite scoping

    See the lengthy comment in xec.c for a detailed explanation.
    JohnoKing committed Jan 15, 2024
    Configuration menu
    Copy the full SHA
    88d77a5 View commit details
    Browse the repository at this point in the history

Commits on Jan 16, 2024

  1. Configuration menu
    Copy the full SHA
    babebd0 View commit details
    Browse the repository at this point in the history
  2. Sync with upstream commits

    JohnoKing committed Jan 16, 2024
    Configuration menu
    Copy the full SHA
    3f695ba View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    50bb787 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    a29d218 View commit details
    Browse the repository at this point in the history
  5. Fix modernish regression tests failing on init

    Bear in mind that there are still three test failures in the modernish
    test suite, which are probably cause by switching to sh_funscope() for
    POSIX function handling:
      001: push;set;check;send sig;unset;pop;check  - FAIL: check traps, test var=$(trap)
      007: trap stack in a subshell                 - FAIL: wrong output from 'trap' (3)
      008: 'trap' can ignore sig if no stack traps  - FAIL: not ignored while no stack traps
    These will need to be fixed at some point.
    JohnoKing committed Jan 16, 2024
    Configuration menu
    Copy the full SHA
    81499fc View commit details
    Browse the repository at this point in the history
  6. Attempt at freeze fix

    JohnoKing committed Jan 16, 2024
    Configuration menu
    Copy the full SHA
    6b5534e View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    9c751fe View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    3732068 View commit details
    Browse the repository at this point in the history
  9. Yet more cleanup

    JohnoKing committed Jan 16, 2024
    Configuration menu
    Copy the full SHA
    45d8749 View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    48a7d1d View commit details
    Browse the repository at this point in the history
  11. Configuration menu
    Copy the full SHA
    c07491a View commit details
    Browse the repository at this point in the history
  12. Undo unnecessary changes

    JohnoKing committed Jan 16, 2024
    Configuration menu
    Copy the full SHA
    c7ae6c8 View commit details
    Browse the repository at this point in the history
  13. Configuration menu
    Copy the full SHA
    bfd0052 View commit details
    Browse the repository at this point in the history
  14. Add static scoping flag and make other improvements

    List of changes:
    - A -c flag has been added to typeset that allows you to use statically
      scoped variables in POSIX functions.
    - A noteable caveat regarding typeset -p's interactions with the new
      scoping functionality has been documented.
    - The regression tests have been overhauled to account for the special
      handling of 'command typeset' in sh_exec(). More were also added for
      the new 'typeset -c' feature.
    - The two nv_scan calls have been rolled into one faster call, which
      should have equivalent functionality (cf. the code for the
      scanfilter() function).
    - Increment copyright dates using the update_copyright script from the
      wiki.
    JohnoKing committed Jan 16, 2024
    Configuration menu
    Copy the full SHA
    4434780 View commit details
    Browse the repository at this point in the history

Commits on Jan 17, 2024

  1. Configuration menu
    Copy the full SHA
    83d1324 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    189736a View commit details
    Browse the repository at this point in the history
  3. Fix compiler warning

    JohnoKing committed Jan 17, 2024
    Configuration menu
    Copy the full SHA
    c08f2bf View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    31d2d24 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    2a1ec61 View commit details
    Browse the repository at this point in the history
  6. Indent the large for loop

    JohnoKing committed Jan 17, 2024
    Configuration menu
    Copy the full SHA
    6d5b2fa View commit details
    Browse the repository at this point in the history
  7. Add preliminary support for -D to typeset -p

    TODO: Add regression tests for 'declare foo' and 'declare -l -i foo'.
    JohnoKing committed Jan 17, 2024
    Configuration menu
    Copy the full SHA
    010b0e3 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    fe00155 View commit details
    Browse the repository at this point in the history

Commits on Jan 18, 2024

  1. Configuration menu
    Copy the full SHA
    bae563d View commit details
    Browse the repository at this point in the history
  2. Add regression test for typeset -p output and update some documentation

    - local.sh: Added tests for the presence of the -D flag in output.
    - sh.1: Removed this comment as this behavior is subject to change.
    - xec.c: Update comment (the ksh93v- code is something I'm trying to
      salvage, but it certainly does seem unsalvageable.)
    JohnoKing committed Jan 18, 2024
    Configuration menu
    Copy the full SHA
    b601a87 View commit details
    Browse the repository at this point in the history

Commits on Jan 23, 2024

  1. Configuration menu
    Copy the full SHA
    532a6c4 View commit details
    Browse the repository at this point in the history

Commits on Feb 6, 2024

  1. Configuration menu
    Copy the full SHA
    c338eef View commit details
    Browse the repository at this point in the history
  2. Fix typo

    On a side note, I haven't had the chance develop local(1) further
    because of a lack of time. In any case the current scoping bug is
    evading a fix. The current approach needs significant changes,
    as it has no backward compatibility when POSIX functions
    are nested in ksh functions (the normal ksh93 behavior is to have
    POSIX functions inherit the ksh function's full scope and use it
    directly, which necessarily includes the ksh function's statically
    scoped local variables. The current approach doesn't allow for this
    as POSIX functions have their own scope for the local builtin. Backward
    compatibility is currently achieved by having typeset modify the global
    scope directly, but that's not really the correct thing to do. I have
    tried altering typeset to modify the parent ksh function's scope
    directly, but such changes cannot be seen in the POSIX function itself
    after the variable in the parent function was changed, as the change
    only happens in the parent scope and not the current local scope (which
    defeats the whole purpose). To attempt to fix that, I then tried linking
    the parent scope to the local scope, but so far that just breaks the
    local scope (the cdt API lends itself very poorly to dynamic scoping).
    JohnoKing committed Feb 6, 2024
    Configuration menu
    Copy the full SHA
    560d73d View commit details
    Browse the repository at this point in the history

Commits on Feb 14, 2024

  1. Configuration menu
    Copy the full SHA
    0d91670 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    24757cd View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    a473068 View commit details
    Browse the repository at this point in the history

Commits on Feb 15, 2024

  1. Configuration menu
    Copy the full SHA
    c04159d View commit details
    Browse the repository at this point in the history