public inbox for libffi-discuss@sourceware.org
 help / color / mirror / Atom feed
From: "Kaz Kylheku (libffi)" <382-725-6798@kylheku.com>
To: Florian Weimer <fweimer@redhat.com>
Cc: Martin Uecker <ma.uecker@gmail.com>,
	Martin Uecker via Libffi-discuss <libffi-discuss@sourceware.org>
Subject: Re: wide function pointer type
Date: Wed, 20 Oct 2021 10:27:45 -0700	[thread overview]
Message-ID: <f32f2f810d519fd3d544c30ff10860d2@mail.kylheku.com> (raw)
In-Reply-To: <878ryoxdsn.fsf@oldenburg.str.redhat.com>

On 2021-10-20 02:10, Florian Weimer via Libffi-discuss wrote:
> Perhaps a set of standard attributes to describe the explicit closure
> argument would be useful, though.

For what purpose though? If there is some attribute mechanism in the 
syntax,
what translation decision does it drive? Or else, what diagnostic 
purpose?

Variable length arrays use matching names:

   void f(int x, double array[x])

the size attribute of the array is linked to the x parameter by name.

This is semantically important, because inside the function, the
run-time size of the array is computable with "sizeof array",
and that is derived from the value of x.

If the compiler knows that some closure argument c is linked with a
function f, what special treatment can it perform?

The function could be callable with fewer arguments, such that
c is implicitly inserted into the call.

Or, perhaps more usefully, we might be interested in diagnosing the
situation when the program neglects to pass the context parameter
to the function.

But if all we have is some parameter attributes, that is of limited
use; what if the function want to store those
two pieces into some structure, so that some other function
will later call f(c, ...).

The annotation mechanism would have to be propagated to all the
places in the program where the f value can reach; which means
additional declaration material in multiple places. If a structure
stores a function pointer and context value, we need to be able
to relate them in a structure, and so forth.

Imagine we had:

    struct callback {
      void *c __attribute__((context (f)));
      void (*f)(void *context);
    };

Let's use GCC-like attribute syntax with the understanding
that the actual syntax could be something else.

    void fun(void *context _attribute__ ((context (f))),
             void *other,
             void (*f)(void *))
    {
       struct callback cb;
       cb.f = f;
       cb.c = other; // ERROR
    }

This function could be diagnosable; however, depending on the exact
rules, it could requires data flow techniques, difficult to implement
without optimization.

The semantic constraint rules could be as simple as:

1. If either the members *f* or *c* are assigned, the other one
    must be assigned in the same expression, or adjacent statements
    of a compound statement, such that no other operation intervenes
    between the assignments.

2. Both members must be assigned from a linked pair. The assigned
    values are a linked function-context argument pair, or
    linked function-context members of the same structure.

3. In a struct definition with an initializer, if one linked member
    has an explicit initializer, the other must have one also, and
    the values must be a linked pair.

The only ingredient missing is the problem to go with this wonderful 
solution!



  parent reply	other threads:[~2021-10-20 17:27 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-10 11:32 Martin Uecker
2021-10-17 23:35 ` Anthony Green
2021-10-18  5:33   ` Martin Uecker
2021-10-18  5:58     ` Martin Uecker
2021-10-18  7:36       ` Florian Weimer
2021-10-18  7:56         ` Martin Uecker
2021-10-19  9:22           ` Florian Weimer
2021-10-19  9:43             ` Martin Uecker
2021-10-19 10:15               ` Florian Weimer
2021-10-19 12:13                 ` Martin Uecker
2021-10-20  8:24                   ` Kaz Kylheku (libffi)
2021-10-20 18:52                     ` Martin Uecker
2021-10-20  9:10                   ` Florian Weimer
2021-10-20  9:21                     ` Martin Uecker
2021-10-20  9:27                       ` Florian Weimer
2021-10-20 17:27                     ` Kaz Kylheku (libffi) [this message]
2021-10-21  9:48                       ` Florian Weimer
2021-10-10 17:01 Kaz Kylheku (libffi)
2021-10-10 17:44 ` Martin Uecker
2021-10-10 17:49   ` Daniel Colascione
2021-10-10 18:05     ` Martin Uecker
2021-10-10 18:17       ` Daniel Colascione
2021-10-10 18:47         ` Martin Uecker
2021-10-10 18:57           ` Daniel Colascione
2021-10-10 19:24             ` Martin Uecker
2021-10-16  8:08               ` Jarkko Hietaniemi
2021-10-16  9:35                 ` Jarkko Hietaniemi
2021-10-10 18:31   ` Kaz Kylheku (libffi)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f32f2f810d519fd3d544c30ff10860d2@mail.kylheku.com \
    --to=382-725-6798@kylheku.com \
    --cc=fweimer@redhat.com \
    --cc=libffi-discuss@sourceware.org \
    --cc=ma.uecker@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).