public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Alexandre Oliva <oliva@adacore.com>
To: Nathan Sidwell <nathan@acm.org>
Cc: ebotcazou@adacore.com, gcc-patches@gcc.gnu.org, joseph@codesourcery.com
Subject: Re: [PATCH] introduce attribute exalias
Date: Tue, 25 Aug 2020 04:50:41 -0300	[thread overview]
Message-ID: <ormu2j6u5q.fsf@livre.home> (raw)
In-Reply-To: <4647d37b-13af-e485-c782-c222360b12b9@acm.org> (Nathan Sidwell's message of "Sat, 15 Aug 2020 17:11:03 -0400")

On Aug 15, 2020, Nathan Sidwell <nathan@acm.org> wrote:

> 'alias' is also now a confusing term, because of the concept of object-aliasing.

True, but it's also an established attribute name.  It seems thus
desirable to bring the conceptual framework of the alias attribute to
mind through the name of the attribute used in this new feature, but
with a twist that distinguishes it from the original attribute in a
meaningful way.


> The existing alias attribute is defined as:

>> The @code{alias} attribute causes the declaration to be emitted as an alias
>> for another symbol, which must have been previously declared with the same
>> type, and for variables, also the same size and alignment.  Declaring an alias
>> with a different type than the target is undefined and may be diagnosed.  As
>> an example, the following declarations:

> I.e. it is creating a declaration that is aliased to some other symbol
> (which has to also be emitted by the same TU due to the usual elf-like
> object file semantics).  Notice it says nothing about emitting a
> *symbol*.

It's an implied expectation that declarations of language entities get
symbols associated with them, and that attribute alias causes the symbol
name associated with one declaration to refer to the same entity denoted
by the named symbol, instead of introducing a separate entity.

> The new attribute is emitting a symbol that equates the declaration it
> is attached to (i.e. the other way round).

I.e., now we have a single declaration of a language entity, and we wish
additional symbol names to be associated with it.

> Its intent is to allow code written in another language to refer to
> this definition.  I imagine you'd commonly use the foreign language's
> mangling for the string provided.

What I have in mind are mnemonic, user-chosen names, rather than
machine-mangled ones.


> If we spell it 'X', consider:

> [[gnu::X ("other")]] int i;

> Most commonly, the assembly emitted would contain:
> 	.globl other
> 	.equiv other, i

> so, perhaps we should spell it 'equiv'?  That's using an existing term.

Uhh, my turn to find the term meaningless.  Not just because on my
machines, aliases use .set rather than .equiv.  It's missing about as
much context as 'aka' and 'nickname' in the relationship to alias.

The problem we face is that alias is a symmetric relationship, in that
if X aliases Y, then Y aliases X, but attribute alias is not symmetric:
its attribute must be placed in an undefined declaration, naming the
already-defined entity.

It would have made just as much sense to make it work backwards, namely,
attaching the attribute to the defined entity, naming any other
undefined declarations that ought to refer to the same entity.  That's
pretty much the attribute I propose.

Thus clearly, though "alias" is symmetric, our use thereof isn't.  Our
implementation uses the phrase "alias target" to refer to the
already-defined entity that a declaration holding an alias attribute
should alias; the declaration holding the alias attribute is referred to
as an alias.

Since attribute alias is already taken, it would thus make sense to look
for opposites of alias target to denote the new attribute.  Alias source
and alias origin are probably the most natural opposites of alias
target, but they don't suggest to me what we're looking for.  Alias lead
might work.  Alias bead might, too.

OTOH, since the alias attribute is associated with the alias
declaration, and it names an alias target; the opposite of that, with an
attribute in the alias target declaration, would best have the attribute
named alias_target (that's an attribute of the declaration, after all),
and then the named symbol would be the alias.  This would be
surprisingly consistent with the current use of attribute alias:

int attribute((alias_target("Y"))) X; // X is the alias target for Y
int attribute((alias("Y"))) Z; // Z is an alias for Y


Now, if we were to use "equiv", it would make sense to think of the
current alias attribute as "equiv_to" / "alias_target".


Another possibility that occurs to me is to reuse the existing attribute
alias, but naming the equivalent symbol as a second parameter to
attribute alias, suggesting a relation alias(X,Y), building on the
existing alias(X) in which the Y is implied, and introducing a variant
in which it is the X that is implied.  Alas, an explicit placeholder is
needed in this case.

Hmm, maybe such a two-argument variant of alias could be made more
readable by requiring the *second* argument to be number 2:

int attribute((alias("Y", 2))) X;

reading as imperative "alias Y to X", whereas existing uses:

int attribute((alias("Y"))) Z;

read as imperative "alias Y Z", nonsense, but taken as "alias Z to Y",
perhaps by analogy with how "give Y Z" is taken as "give Z to Y".


/me jokingly suggests inhalias and exhalias ;-)


This is enough bikeshedding for me ;-)

-- 
Alexandre Oliva, happy hacker
https://FSFLA.org/blogs/lxo/
Free Software Activist
GNU Toolchain Engineer

  reply	other threads:[~2020-08-25  7:50 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-29 20:56 [RFC, WIP] " Alexandre Oliva
2020-08-07 17:38 ` [PATCH] " Alexandre Oliva
2020-08-14 15:39   ` Alexandre Oliva
2020-08-14 16:24     ` Nathan Sidwell
2020-08-14 19:24       ` Alexandre Oliva
2020-08-14 22:12         ` Nathan Sidwell
2020-08-15  2:43           ` Alexandre Oliva
2020-08-15  9:22             ` Iain Sandoe
2020-08-15 16:39               ` Alexandre Oliva
2020-08-15 18:17                 ` Iain Sandoe
2020-08-25  8:34                   ` Alexandre Oliva
2020-08-25 11:23                     ` Iain Sandoe
2020-08-15 17:26               ` Alexandre Oliva
2020-08-15 21:11             ` Nathan Sidwell
2020-08-25  7:50               ` Alexandre Oliva [this message]
2023-07-15  1:08   ` [PATCH v3] Introduce attribute reverse_alias Alexandre Oliva
2023-07-15 21:55     ` Nathan Sidwell
2023-07-18  4:29       ` Alexandre Oliva
2023-07-18 11:37         ` Richard Biener
2023-07-19 23:11           ` [PATCH v4] Introduce attribute sym Alexandre Oliva
2023-07-20 13:09             ` Richard Biener
2023-07-21  9:23               ` Alexandre Oliva
2023-07-22  3:12             ` Fangrui Song
2023-08-16  4:27               ` Alexandre Oliva
     [not found]             ` <orpm2tgrsd.fsf_-_@lxoliva.fsfla.org>
     [not found]               ` <CAH6eHdQ3vT3MjohuE-izto+K=BMRykY3T-UyWa5-=OTDPM-JsQ@mail.gmail.com>
     [not found]                 ` <ory1h9t6nr.fsf@lxoliva.fsfla.org>
2023-09-20  5:59                   ` [PATCH v5] Introduce attribute sym_alias (was: Last call for bikeshedding on attribute sym/exalias/reverse_alias) Alexandre Oliva
2023-11-20 12:54                     ` [PATCH v5] Introduce attribute sym_alias Alexandre Oliva
2023-11-22 12:14                       ` Richard Biener
2023-11-22 19:16                         ` Joseph Myers
2023-11-22 13:13                     ` [PATCH v5] Introduce attribute sym_alias (was: Last call for bikeshedding on attribute sym/exalias/reverse_alias) Jan Hubicka
2023-11-30 12:53                       ` [PATCH v6] Introduce attribute sym_alias Alexandre Oliva
2023-11-30 15:24                         ` Jan Hubicka
2023-12-01 11:25                           ` [PATCH v7] " Alexandre Oliva
2023-12-06  2:10                             ` [PATCH v8] " Alexandre Oliva
2023-12-06 10:06                             ` [PATCH v7] " Jan Hubicka
2023-12-07 20:52                               ` Alexandre Oliva

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=ormu2j6u5q.fsf@livre.home \
    --to=oliva@adacore.com \
    --cc=ebotcazou@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=joseph@codesourcery.com \
    --cc=nathan@acm.org \
    /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).