From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: How does one find out what file a library has been loaded from? Date: Sun, 24 Jul 2022 11:32:29 -0400 Message-ID: References: <83sfmxm79z.fsf@gnu.org> <83fsiwncem.fsf@gnu.org> <83mtd3ngcw.fsf@gnu.org> <838rommjxj.fsf@gnu.org> <83k084i1ed.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37771"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: Eli Zaretskii , emacs-devel@gnu.org To: Alan Mackenzie Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Jul 24 17:33:56 2022 Return-path: 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 ) id 1oFdcA-0009eM-Vh for ged-emacs-devel@m.gmane-mx.org; Sun, 24 Jul 2022 17:33:54 +0200 Original-Received: from localhost ([::1]:35284 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oFdc9-0005fb-F2 for ged-emacs-devel@m.gmane-mx.org; Sun, 24 Jul 2022 11:33:53 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49366) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oFdb0-0004z4-4n for emacs-devel@gnu.org; Sun, 24 Jul 2022 11:32:42 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:53404) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oFdas-0001Hr-E9; Sun, 24 Jul 2022 11:32:40 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 730CA1002F9; Sun, 24 Jul 2022 11:32:32 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id D5461100169; Sun, 24 Jul 2022 11:32:30 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1658676750; bh=ycI/blCa2EerMki8AOsxgCXmGzI5dddmWn0/HN86jQs=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=bvpQGzc5ntVntYtDLhezW+tynBAc3r5kuhc626S5+PZDXrSEjHcKP2Ffqb5FFYgFg 3JOZ65fHjUhT6G7ylzASGuGGyleO7pFjoyfHZz9izw+h3Ml8WG0hTgIA0QbKmmhWd1 L8vQrt9AIBHBbgQ+jch3+/thtmGr9oE6wfyAuz5C93NwhinieiyYslXUUdF7vifUh6 VfMK7xTmT6rxVFG/mAhFPSatputU6kuNjAz506baZbO1shjezuWFiD+yEYUV7p438P 4je9JXX/HdA4rCoD2DocIUfBEWEEfvviUyDcOSY0+795FS9IEIEzBhB+CJiTLFNXPq aUazdRGAfDfkw== Original-Received: from pastel (unknown [45.72.195.111]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 9258712046C; Sun, 24 Jul 2022 11:32:30 -0400 (EDT) In-Reply-To: (Alan Mackenzie's message of "Sun, 24 Jul 2022 11:27:56 +0000") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:292594 Archived-At: > 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 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