From mboxrd@z Thu Jan  1 00:00:00 1970
Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail
From: "T.V Raman" <raman@google.com>
Newsgroups: gmane.emacs.devel
Subject: Re: How does one find out what file a library has been loaded from?
Date: Sun, 24 Jul 2022 08:49:51 -0700
Message-ID: <p91y1wifr34.fsf@google.com>
References: <83sfmxm79z.fsf@gnu.org> <YtbkvUeMhKGyOIb4@ACM>
 <83fsiwncem.fsf@gnu.org> <YtfrP84c5Q2hl2og@ACM> <YthmvWi7lIFfGAGR@ACM>
 <83mtd3ngcw.fsf@gnu.org> <YtmOz+0n1Ah9kTse@ACM>
 <838rommjxj.fsf@gnu.org> <Ytm5lAEpnTaX5sNh@ACM>
 <83k084i1ed.fsf@gnu.org> <Yt0svLd/mP66lOO7@ACM>
 <jwvr12azgyz.fsf-monnier+emacs@gnu.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=gb18030
Content-Transfer-Encoding: quoted-printable
Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214";
	logging-data="7254"; mail-complaints-to="usenet@ciao.gmane.io"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)
Cc: Alan Mackenzie <acm@muc.de>,  Eli Zaretskii <eliz@gnu.org>,
 emacs-devel@gnu.org
To: Stefan Monnier <monnier@iro.umontreal.ca>
Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Jul 24 17:52:31 2022
Return-path: <emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org>
Envelope-to: ged-emacs-devel@m.gmane-mx.org
Original-Received: from lists.gnu.org ([209.51.188.17])
	by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
	(Exim 4.92)
	(envelope-from <emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org>)
	id 1oFduB-0001fF-Ez
	for ged-emacs-devel@m.gmane-mx.org; Sun, 24 Jul 2022 17:52:31 +0200
Original-Received: from localhost ([::1]:49516 helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org>)
	id 1oFduA-0007qQ-BC
	for ged-emacs-devel@m.gmane-mx.org; Sun, 24 Jul 2022 11:52:30 -0400
Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52280)
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <raman@google.com>) id 1oFdrh-0005pJ-Sz
 for emacs-devel@gnu.org; Sun, 24 Jul 2022 11:49:57 -0400
Original-Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]:42631)
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <raman@google.com>) id 1oFdrg-0003eg-4n
 for emacs-devel@gnu.org; Sun, 24 Jul 2022 11:49:57 -0400
Original-Received: by mail-pg1-x536.google.com with SMTP id q22so3132374pgt.9
 for <emacs-devel@gnu.org>; Sun, 24 Jul 2022 08:49:55 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112;
 h=from:to:cc:subject:in-reply-to:references:date:message-id
 :user-agent:mime-version:content-transfer-encoding;
 bh=dWZm0wCmQ2Q3Aws81R4P+Eiv2CfO50KE6Gdq0TYgwdg=;
 b=inqoi57vthwQXUe74vdSsd1xO09JLVmDPvLPV9Z5Nqz8YTRN6SZQ/mNAsQR0c28V0v
 hFmrx+UXEcD8HklBL2NnB4ThNkY3bd0szaWXshpXpNCH3MtziDwwbbUb8hLCEOrz3iQP
 wiLz9KZ5VTGM48+RT1sKDx+M5Y1m/+SuKS9V8QyHkVq9H9bDA0K+9HY7UG6cZDnkTJyn
 ZADoM+YRjvTO7NpQ0/jdeT6jiZSI2RbeL05lxfIWkQu/Pp4lxU9ubYXiuJpLwd8LDsOr
 AvixUEboXlmFgQ/PJNjzPL676GHWkJlWV8ItkM9RNPwx9+Awjbs+koz6pRKCRW5vx7Yk
 MYnA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20210112;
 h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date
 :message-id:user-agent:mime-version:content-transfer-encoding;
 bh=dWZm0wCmQ2Q3Aws81R4P+Eiv2CfO50KE6Gdq0TYgwdg=;
 b=cVSx/vJw+9JlT//l6lqQkUs6fUGDQZBZR4MVELlw+kFIgDXPmJdLH1kY7hMI9yqToe
 znF0/aiChdEUdnGolHyWzTukC3QfGjXn4TUaJI9BqAlUpESvdCwsaUgkG8yHC1uVLvkg
 XLQqZ4mk9XtVJWsqDwWYr2c01QMi5lDt197SbCijDvF/GYOFnzYKLaVSIgHPgy7GAspI
 nr1doN8PQnGDYu6C8zLbTTB4eswuaNcQ/pHdoRy9qfdTtzkaZPy2EY1m4hIUIZBZVOvJ
 WfxVDFiMGmQEbPS9BG7WzLK8KFmClV1hqV2Y6kmvacte9SnJUn2FaO7s+lFqlaLdUBc2
 UwWA==
X-Gm-Message-State: AJIora8PgmxxKPFgN/cXDtOdnz8z6U27AkqGkNYwvYTsOfzp60rlbi65
 SdicKFaZeqneEXUve+dNYaNmVCg2JfpNBPAa
X-Google-Smtp-Source: AGRyM1tVzUMQbBg6jRubSAySAGA6yZCxIMiNSnwTEIrs1AxcKjWcwcWI8Yqd3PDewh6fX7Gos+WGnA==
X-Received: by 2002:a05:6a00:1745:b0:52a:f0d3:ae7 with SMTP id
 j5-20020a056a00174500b0052af0d30ae7mr9300357pfc.72.1658677794287; 
 Sun, 24 Jul 2022 08:49:54 -0700 (PDT)
Original-Received: from raman9 (c-24-4-174-65.hsd1.ca.comcast.net. [24.4.174.65])
 by smtp.gmail.com with ESMTPSA id
 x2-20020a63f702000000b0040ca587fe0fsm6571068pgh.63.2022.07.24.08.49.53
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Sun, 24 Jul 2022 08:49:53 -0700 (PDT)
In-Reply-To: <jwvr12azgyz.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message
 of "Sun, 24 Jul 2022 11:32:29 -0400")
Received-SPF: pass client-ip=2607:f8b0:4864:20::536;
 envelope-from=raman@google.com; helo=mail-pg1-x536.google.com
X-Spam_score_int: -175
X-Spam_score: -17.6
X-Spam_bar: -----------------
X-Spam_report: (-17.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001,
 DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
 ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,
 SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, USER_IN_DEF_DKIM_WL=-7.5,
 USER_IN_DEF_SPF_WL=-7.5 autolearn=unavailable autolearn_force=no
X-Spam_action: no action
X-BeenThere: emacs-devel@gnu.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Emacs development discussions." <emacs-devel.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/emacs-devel>,
 <mailto:emacs-devel-request@gnu.org?subject=unsubscribe>
List-Archive: <https://lists.gnu.org/archive/html/emacs-devel>
List-Post: <mailto:emacs-devel@gnu.org>
List-Help: <mailto:emacs-devel-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/emacs-devel>,
 <mailto:emacs-devel-request@gnu.org?subject=subscribe>
Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org
Original-Sender: "Emacs-devel"
 <emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org>
Xref: news.gmane.io gmane.emacs.devel:292597
Archived-At: <http://permalink.gmane.org/gmane.emacs.devel/292597>

Stefan Monnier <monnier@iro.umontreal.ca> writes:

In that context, how does find-function work?

>> I just don't understand you saying that the information is still correct.
>> In about "half" the cases, when a .eln file has been loaded, the current
>> text in the Elisp manual and load-history doc string is no longer
>> correct.  The file given in load-history is not the file that was loaded
>> into Emacs.
>
> Because of the design decision to make native code compilation
> transparent, `load-history` does not mean "this is exactly the file that
> was loaded directly" but rather something like: "this is the file from
> which we loaded the definitions, tho the path to loading them may
> include turning the code into some other representation such a native
> code, while being (hopefully) faithful to the file's semantics".
>
> So if you actually need to know more precisely where the code comes
> from, you need to look at supplemental information (such as the one
> Andrea gave you).
>
>>> > > Did you try comp-el-to-eln-filename?
>>> > No.  How could I have known that such a function exists?
>>> I just told you about it.  I told you about it not as an accusation,
>>> but as a way to help you find the best way of solving your problem.
>> OK, thanks.  But I still don't think I could have found out the existence
>> of this function without asing "are there any relevant
>> functions/variables to what I'm trying to do?".
>
> Which is why your effort to try and document this is worthwhile, indeed.
> [ It may also inform improvements to the API to make it easier to find,
>   but documenting the status quo is an indispensable first step.  ]
>
>>> Then I think you should describe the purpose better and in more detail.
>> I simply wish to know the file from which a function has been loaded, or
>> the loaded file corresponding to some source file.
>
> "I" as in "I the human being", and "simply" as in "out of pure curiosity"?
> What are you going to do with that knowledge?  Would you be satisfied
> with knowing only if it's native code rather than byte code (rather
> than see the gory file name with all its hashes and stuff)?
>
>> I would like to know whether this file is a source file, a .elc, or
>> a .eln.
>
> `C-h o <function> RET` should tell you that without needing any knowledge
> of ELisp.  Admittedly, it doesn't quite satisfy your requirements since
> the input is now a function name rather than a file name.
>
>>> What exactly are you trying to accomplish and why?
>> There are lots of reasons I might want to know the loaded file, some of
>> which have already come up in the thread.  I might want to be sure I've
>> built Emacs with native compilation.
>
> I think the canonical way to test this is
>
>     (featurep 'native-compile)
>
>> I might be interested in benchmarking or RAM occupancy.
>
> I don't see the connection, but `subrp` or `byte-code-function-p` or
> just printing the output of `symbol-function` on a relevant function
> should tell you how your code was compiled.  No need for any file name.
>
>>> What is the data from which you start and what is the data you want to
>>> obtain as result?
>> The name of a source file or function, and the name of the matching file
>> which was loaded.
>
> Wanting a "matching file" is IMO the result of your mental model not
> firmed up enough yet, then :-)
>
> After all, even if the answer is a nasty `.../blabla.eln` you still
> won't know whether your function is implemented as native code since
> that `.eln` can contain (and generate) byte code.  And that's not
> just theory, it does happen in practice.
>
>
>         Stefan
>
>

--=20

Thanks,

--Raman(I Search, I Find, I Misplace, I Research)
=817=A94 Id: kg:/m/0285kf1  =950=DC8