[M3commit] [modula3/cm3] aa3dff: Fix failure p035. Rework closure calls.

GitHub noreply at github.com
Tue Aug 15 19:07:45 CEST 2017

  Branch: refs/heads/master
  Home:   https://github.com/modula3/cm3
  Commit: aa3dffed934c3c94aca6fb369d2836b0d894d2ef
  Author: Rodney Bates <rodney.m.bates at acm.org>
  Date:   2017-08-15 (Tue, 15 Aug 2017)

  Changed paths:
    M m3-sys/llvm3.6.1/src/M3CG_LLVM.m3

  Log Message:
  Fix failure p035. Rework closure calls.

Rework to fix failure on p035 for a variable call.  Simplifies
handling of closure calls.  Also handles variable calls that are
statically known to always call a global procedure (the procedure
value is a variable) and those statically known to always call a
nested procedure (internally generated procedure for a FINALLY block).

There is a big semantic mismatch between CG IR and llvm IR.  The
former can have a call with dynamically differing parameter list
(here, with/without a static link), which will work as long as it
matches what the (also dynamically differing) procedure's code
expects.  In llvm, a call instruction has to have a static function
type, including its parameter list.  So we need two call instructions,
in different basic blocks.

We have to use some inside knowledge of the code sequences CG is
producing.  Specifically, the sequence for a closure-call, (after
pop_static_link,) ends with load (of code address), a store (which we
don't use) and a branch (which we need to replace with a branch to an
inserted basic block for the static-link-passing version.

The CG IR code contains two nil-checks.  The first is part of deciding
whether this is a closure, and if nil, just branches to the code that
is common to closure and non-closure cases. Its only purpose is to
prevent a segfault looking for the closure tag.

The second, at the branched-to common point, gives a runtime error if
nil.  In the non-closure case, it's a redundant check, except for the
resulting action.  In the closure case, it checks the code address in
the closure, rather than the address in the original procedure
variable.  This is not algorithmically redundant, but I believe it
can't happen.  The llvm translated code does not perform this check.

The CG-produced code could really be reviewed here.

  Commit: 266eb83bf1514cddc97887d71c622aeed0c2ba0f
  Author: Rodney Bates <rodney.m.bates at acm.org>
  Date:   2017-08-15 (Tue, 15 Aug 2017)

  Changed paths:
    M scripts/python/pylib.py

  Log Message:
  Merge branch 'master' of https://github.com/modula3/cm3

Compare: https://github.com/modula3/cm3/compare/b60508958726...266eb83bf151

More information about the M3commit mailing list