From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) by sourceware.org (Postfix) with ESMTPS id 5F4DD3858D39 for ; Fri, 26 Jan 2024 09:25:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5F4DD3858D39 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5F4DD3858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::22f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706261107; cv=none; b=AMNk/tMIp6NJwGF6pLXo3Z3SJd0Wj4duD+O2JVqemXiUOHzRjLDh0XAhySlj9Cv+Ktr94z1cDeDyoLbc9TirLN3GiHjKft4xREUhPu59tGBc5e7gi4jD4GFYwqhXqtLFFcV0upmSdYeFJD41AC4TWABMeRYs2VEw+bD0jbITuLs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706261107; c=relaxed/simple; bh=9rYd45AyzfsYvmIqJG2hFgzryGqu+po/IyTzG4nEDaY=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=o4nkexAzW6FVJMMgLuxyPkdpsMMpeUu4NWZypaM50uLG8ZPGi+uTYhslZUyRoa7RSgRLHsYV1hWkJepMSzXBDeOEpHIrOchO42GaxR5iaWwdIA9uKPq18UsCMtshBGdKE/XBmeltrov2WQfVCbnHO10VVbree+mj6hIlxpxPy3s= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-2cf1524cb17so1781401fa.2 for ; Fri, 26 Jan 2024 01:25:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706261103; x=1706865903; darn=gcc.gnu.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=YQ6+O1yiZNquoODu2SmPNuzFhousQDegemu4vgKaRto=; b=R/2mqHqJ94y/rsWmKmbxH7HtxDf7GNqhNCzloxOfSdzXObbtbI1nBTH+rUdEbvjxP7 oKytZhpGkw8AZtdwYbDYQd3PQErC9q2xiNhi3ImJ1IaGKzP7v08/82EWxoH+obC/4a3l wg9CXdbPueRc6s70Cy0Y28LV4bogRCvb+1vaFPGI9LYD3KvRhrxQyfYw045UVA66cRqD ZEmZGchfKAOxKsBaQGjUOWWmoQK/gMQ3EqN5xRraFB5t4DsydPg1waftqZoYsYqncLGe +2HidHclzpeTFMb1HPQi3YiTU8BE4UPnerLfzddrHD/uKaHmqGEKMhFOJfmV7URFe4yd QNrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706261103; x=1706865903; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=YQ6+O1yiZNquoODu2SmPNuzFhousQDegemu4vgKaRto=; b=aNHGIjQ6KLK+P1wx+7/+Zuql6wFHfhO+GYIDQ82WHSZzKe78hHuDJoFfntVzvKIBw1 +oW8ratM0XY9nS6tC4HnGABie3aQwUchc3IBp/5NKTO/8as6E106uhwImsCuWfNeT5qn rX8xOfC8mhir1a7rly9X3fmFGJjMW3W60Rvtj/vXJ89KJ0OQdQZBWjNRoxRkw395yYKh ZMYZSJfwz0aAaYaAniDb+funrxzuzdG1ntjpYTJtXFIf/kTgKaNnBAT4+xcHyYJLiLwF cZkLlZUMAklxJfcJjHdmRX0qoNRK6pK8Fp7I4GiJPYX29xSdJB5fG7q2iyapKmwU7KZH Gu6g== X-Gm-Message-State: AOJu0YzhV+n5A5iLYsBMHowTdncbVvhU3cdsN0Hm4wUlvMFdTeuUramf Z3mnMaHkScd5xf2+XmIVHmQm/j8tNho739ag8r6RMh3Ft0JSEwD3bjvoKFHcUqHAjtdukgzpWpQ = X-Google-Smtp-Source: AGHT+IFXQbeOTmIHfzbN65yB3sK2Ycex6eprfTnS6aLq8BVrskpHDvNCtbHsayJa/p3ShqCLYALwUA== X-Received: by 2002:a2e:8194:0:b0:2cd:449:149 with SMTP id e20-20020a2e8194000000b002cd04490149mr576538ljg.80.1706261102469; Fri, 26 Jan 2024 01:25:02 -0800 (PST) Received: from ?IPV6:2a04:cec0:1900:b4ea:a904:7352:e226:659a? ([2a04:cec0:1900:b4ea:a904:7352:e226:659a]) by smtp.gmail.com with ESMTPSA id u17-20020a2e8551000000b002cd91d0ceefsm105985ljj.33.2024.01.26.01.25.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 26 Jan 2024 01:25:02 -0800 (PST) Message-ID: Date: Fri, 26 Jan 2024 10:24:57 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [Request for Comments] Using Rust libraries in the Rust frontend To: Richard Biener Cc: GCC Mailing List References: <818C5FC1-9658-4A3A-AAF3-FE3D0E165E86@gmail.com> Content-Language: en-US From: Arthur Cohen In-Reply-To: <818C5FC1-9658-4A3A-AAF3-FE3D0E165E86@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 1/25/24 19:19, Richard Biener wrote: > > >> Am 25.01.2024 um 16:03 schrieb Arthur Cohen : >> >> Hi Richard, >> >>> On 1/23/24 08:23, Richard Biener wrote: >>>> On Mon, Jan 22, 2024 at 7:51 PM Arthur Cohen wrote: >>>> >>>> Hi everyone, >>>> >>>> In order to increase the development speed of Rust features, we are >>>> seeking feedback on reusing some Rust components directly within our >>>> front-end. As mentioned in other conferences, the most important >>>> component we would like to integrate into the front-end is the polonius >>>> borrow-checker. Another component we've become interested in is the >>>> `rustc_format_parser` library, responsible for handling parsing and >>>> handling of format arguments as described in the documentation for >>>> `std::fmt` [1]. >>>> >>>> However, since these libraries are written in Rust, GCC in itself is not >>>> yet able to compile them. They all depend on the Rust standard library, >>>> which we cannot yet compile and link properly. This obviously raises a >>>> question - how to actually compile, integrate and distribute these >>>> components? >>>> >>>> We do have the option to rewrite them from scratch, but we feel that >>>> spending time on these existing, correct, battle-tested and easily >>>> integrable components instead of focusing on other aspects of the >>>> language would be a mistake. Spending this time instead on Rust features >>>> that we are missing for compiling these components would, in our >>>> opinion, yield more results, as it would also help in compiling other >>>> Rust programs. >>>> >>>> We could either distribute these components as compiled libraries, or >>>> look at integrating the official Rust compiler to our build system as a >>>> temporary measure. I am aware that this would mean restricting the Rust >>>> GCC front-end to platforms where the official Rust compiler is also >>>> available, which is less than ideal. >>> But that's only for the host part - you can still cross compile to another >>> target and possibly, once the GCC frontend can compile these libraries >>> itself, also use them to bootstrap a hosted version on that target - >>> speaking of .. >>>> However, this would only be >>>> temporary - as soon as the Rust front-end is able to compile these >>>> components, we would simply reuse them and compile them with gccrs as >>>> part of our bootstrapping process. >>> .. gccrs would then need to be able to build itself without those modules, >>> at least during stage1 so that the stage1 compiler can then be used to >>> build them. Or you go like m2 and build a "mini-rust" that's just capable >>> of building the modules. >> >> Right, that makes a lot of sense. We should definitely be able to build the format string parser without a format string parser, as it does not use format strings for error handling or anything. And even if it did, it would be pretty easy to remove that and do the formatting by hand. >> >> Similarly, the borrow checker is not "needed" for compilation and we do plan on building stage1 without it, while making it mandatory for stage2/3 builds. >> >>> I think re-using parts already available is very sensible at this point. Note >>> that while we might temporarily require a host rust compiler to boostrap >>> gccrs I'd rather not have the build system download something from the >>> internet - so at least the sources of those dependences need to be in the >>> GCC repository, possibly in a new toplevel directory. >> >> Okay, that makes a lot of sense. I was thinking of adding a basic check for the Rust compiler to be present when compiling these components - and error out if that isn't the case. Are you suggesting we embed a full copy of rustc in GCC and build it from source when compiling the Rust frontend? Or am I misunderstanding? > > No, you’d have the format parser and all it’s dependencies in the source tree but rely on an installed rustc to build that. Maybe that doesn’t make sense - I’m not too familiar with the rust compilation model. Ah, no worries that makes total sense! This is what I was planning on doing anyways. If compiling directly with rustc, you can specify paths where the compiler should look for already compiled crates. If you instead use cargo, the Rust build system, you can specify a path for specific dependencies. Thanks, Arthur > > Richard > >>>> The documentation for `std::fmt` [1] describes all of the features >>>> available in Rust format strings. It also contains a grammar for the >>>> format-string parser, which we would need to re-implement on top of >>>> supporting all the formatting features. As a prototype, I wrote an FFI >>>> interface to the `rustc_format_parser` library and integrated it to our >>>> macro expansion system, which took me less than a couple hours. In less >>>> than an afternoon, we had bindings for all of the exported types and >>>> functions in the library and had access to a compliant and performant >>>> Rust format string parser. But re-implementing a correct >>>> `format_args!()` parser - with the same performance as the Rust one, and >>>> the same amount of features - would probably take days, if not weeks. >>>> And we are talking about one of the simplest components we aim to reuse. >>>> Something like a fully-compliant trait solver for the Rust programming >>>> language would take months if not years to implement properly from scratch. >>>> >>>> I would like to stress once again that relying on distributing compiled >>>> libraries or using `rustc` in our build system would be temporary, and >>>> that these measures would be removed as soon as gccrs is able to compile >>>> these components from source. >>>> >>>> I am looking for comments on this decision as well as the best practices >>>> we could adopt. Have there been any similar decisions for other >>>> self-hosted front-ends? Any previous email threads/commits that you >>>> could point me to would be greatly appreciated. >>> Not in this very same way but the D frontend is a shim around the official >>> DMD frontend and the Go frontend imports the golang standard library >>> (but the frontend itself is written in C++ and doesn't use any part of it). >>> The C++ frontend uses part of the C++ standard library (but it can of >>> course build that itself - but it requires a host C++ compiler with library). >> >> Thanks for the pointers. I was wondering if this is something that the Ada frontend had faced at the beginning, but I've been told it does not have a lot of dependencies anyway so this might not be helpful. >> >>> Richard. >>>> Thanks, >>>> >>>> Arthur >>>> >>>> [1]: https://doc.rust-lang.org/std/fmt/ >> >> Thanks a lot for taking the time, I really appreciate it. >> >> Best, >> >> Arthur