Received: by 10.223.185.116 with SMTP id b49csp1434959wrg; Fri, 16 Feb 2018 20:32:13 -0800 (PST) X-Google-Smtp-Source: AH8x225HYOfpjPDgUKeC7x18t79NccWkRy4SbYYoGfGzm8IaIBI9Uk1rSVm/hfd2PNIWVy3EOQ7i X-Received: by 10.98.5.129 with SMTP id 123mr8099073pff.75.1518841933550; Fri, 16 Feb 2018 20:32:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518841933; cv=none; d=google.com; s=arc-20160816; b=Qv/brHV0whbv+yjAWgoJ5J0URz1Qv4z+gl2YLTEAhXuYeTnlAKoe72PMY5Zm7HvNZn YKhEi/H4chMP+jqZpY4P7CJknb5jCtRMe2I2B10fg9rDXS/UzANk6FUTZLazN9fG4Ikr VRGyTvIc0FfONtlJMahMt6+9gfZdvUlFdrNFbvWwT7M//M6lDfhb91rF5Hoed9Ab+nmR AWKdJEbx34gk+A2Vrt4c7Sa/8lUe2lmovveu+4spZx9KJv/57nQMmvqEK7FCWV+1BXbI /WIMVt6Hw11E0sT0mT7+nsZlNMGDejcJ6EQ8KS74/D81cGn62QEhT14xu6Ge/whtoC8A MbTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=1ouJhi6WZJtF1KvB05W47hEgonqMA48nJV7ODJVdsVY=; b=zAB3Xei5hs6kewDzEfSBCxzrUIBiOQDTSGvkUsuwGUy7VKMwxCG2Okn+Mjhf8+yeVz 94MFYymBkAPnsNCbIfNO1UYFmGh/D1uA/eY7cB8YCfZSd7Bx+Qo+Zb0hb5nG52MF+trY xlXDGD4+p9kYKWQSQMaWH3FvJKFV+c0895LTGhhZAvFEVMgfx9B/Srug63Fbdib6Jsu2 fKu27cGdIy9BgX7J33RmDJD9bMfSHdBSPhFd1aGDXAY4HspJD5dOzfclFPmoJjFvy5jG IHxvzZMNh5vhFRsbV0gWaUqauvGlBel+xPIjWh/roMvG8eFevZpkNWt9iPbl/vYTqvQr 01Cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=U0URvuDr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o15-v6si1001152pli.460.2018.02.16.20.31.21; Fri, 16 Feb 2018 20:32:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=U0URvuDr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751056AbeBQE3U (ORCPT + 99 others); Fri, 16 Feb 2018 23:29:20 -0500 Received: from mail-ua0-f195.google.com ([209.85.217.195]:44178 "EHLO mail-ua0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751011AbeBQE3R (ORCPT ); Fri, 16 Feb 2018 23:29:17 -0500 Received: by mail-ua0-f195.google.com with SMTP id x4so3161091uaj.11; Fri, 16 Feb 2018 20:29:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=1ouJhi6WZJtF1KvB05W47hEgonqMA48nJV7ODJVdsVY=; b=U0URvuDrMxKhmPQrnaa0g+3IqRpGu5KVKAt72gSii1plVR02F1WfHqVOl282mYOAmj mHxJHfbVZR3WVUThLgkrzoZg+khws0GVyBnwRaPM3cz7SdGuQAJEbgA0cJGUre1Xx1nu zJcJChZcCbnib9xBDIKzBm/E3sGXdHdCRyE8ugODUSTl+6XevVZNTVzBd/WGFpLeOlRt kT98Us9uEJto4HG/jrM5LFjqP4aEWbfzBu8YyyAW7ehn1BLp6opeXc/dvfHhcbJwE+XE hFX0u83efhacDjDaUwgPmlNJYtdwKtSiLdiIJIyroO7xjeP0zkj/gt4NorzKWZg6d363 C57Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=1ouJhi6WZJtF1KvB05W47hEgonqMA48nJV7ODJVdsVY=; b=CWDiqA587jU3QtKcVG6p+eKaJg/j5fgJIuleVCEQKIS8nf1r5a2b8m9oy3loes+0o0 A7b9U5Ks/rG16khK5kbHm8cZFdW8Cuv45SYHt1tIYuGNWbO3dQfPocwWvRU9DnanvG1Y WQXEAv/hF35pPZJ9N1Y4vDriDfqRTG9DjD/ONyXJ6oQIPYo43dSinqM/GOu+02saJ+IX blNwMw2uUEKu86RxdcdpRb54yBxUtYDjvplGI1B54+ho+HuocM7dkxsfk8xmBv11sKLU Nzk0kQpYgMBbicfh88S8ISV34RckIWoUal/hZVKZWxp+tEInaZrekN61UFQ6oVKCu9pt h0dQ== X-Gm-Message-State: APf1xPCo3Iv625CAxaHRbfwBOkB73Zgx6hclLZF+8ymB0baVLS++Ga8N 0kVXbm8P9hzqCJsmKXnu59sDN3VRHCHkyw6a7nY= X-Received: by 10.176.9.100 with SMTP id c36mr1176135uah.118.1518841756310; Fri, 16 Feb 2018 20:29:16 -0800 (PST) MIME-Version: 1.0 Received: by 10.103.70.21 with HTTP; Fri, 16 Feb 2018 20:29:15 -0800 (PST) In-Reply-To: References: <1518806331-7101-1-git-send-email-yamada.masahiro@socionext.com> <1518806331-7101-9-git-send-email-yamada.masahiro@socionext.com> <20180216235138.b4p6q62auvnzb2sy@huvuddator> From: Ulf Magnusson Date: Sat, 17 Feb 2018 05:29:15 +0100 Message-ID: Subject: Re: [PATCH 08/23] kconfig: add 'macro' keyword to support user-defined function To: Nicolas Pitre Cc: Masahiro Yamada , Linux Kbuild mailing list , Linus Torvalds , Greg Kroah-Hartman , Arnd Bergmann , Kees Cook , Randy Dunlap , Sam Ravnborg , Michal Marek , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Feb 17, 2018 at 3:30 AM, Nicolas Pitre wrote: > On Sat, 17 Feb 2018, Ulf Magnusson wrote: > >> On Fri, Feb 16, 2018 at 02:49:31PM -0500, Nicolas Pitre wrote: >> > On Sat, 17 Feb 2018, Masahiro Yamada wrote: >> > >> > > Now, we got a basic ability to test compiler capability in Kconfig. >> > > >> > > config CC_HAS_STACKPROTECTOR >> > > bool >> > > default $(shell $CC -Werror -fstack-protector -c -x c /dev/null -o /dev/null) >> > > >> > > This works, but it is ugly to repeat this long boilerplate. >> > > >> > > We want to describe like this: >> > > >> > > config CC_HAS_STACKPROTECTOR >> > > bool >> > > default $(cc-option -fstack-protector) >> > > >> > > It is straight-forward to implement a new function, but I do not like >> > > to hard-code specialized functions like this. Hence, here is another >> > > feature to add functions from Kconfig files. >> > > >> > > A user-defined function can be defined as a string type symbol with >> > > a special keyword 'macro'. It can be referenced in the same way as >> > > built-in functions. This feature was also inspired by Makefile where >> > > user-defined functions are referenced by $(call func-name, args...), >> > > but I omitted the 'call' to makes it shorter. >> > > >> > > The macro definition can contain $(1), $(2), ... which will be replaced >> > > with arguments from the caller. >> > > >> > > Example code: >> > > >> > > config cc-option >> > > string >> > > macro $(shell $CC -Werror $(1) -c -x c /dev/null -o /dev/null) >> > >> > I think this syntax for defining a macro shouldn't start with the >> > "config" keyword, unless you want it to be part of the config symbol >> > space and land it in .config. And typing it as a "string" while it >> > actually returns y/n (hence a bool) is also strange. >> > >> > What about this instead: >> > >> > macro cc-option >> > bool $(shell $CC -Werror $(1) -c -x c /dev/null -o /dev/null) >> > >> > This makes it easier to extend as well if need be. >> > >> > >> > Nicolas >> >> I haven't gone over the patchset in detail yet and might be missing >> something here, but if this is just meant to be a textual shorthand, >> then why give it a type at all? > > It is meant to be like a user-defined function. > >> Do you think a simpler syntax like this would make sense? >> >> macro cc-option "$(shell $CC -Werror $(1) -c -x c /dev/null -o /dev/null)" >> >> That's the most general version, where you could use it for other stuff >> besides $(shell ...) as well, just to keep parity. > > This is not extendable. Let's imagine that you might want to implement > some kind of conditionals some day e.g.: > > macro complex_test > bool $(shell foo) if LOCKDEP_SUPPORT > bool y if DEBUG_DRIVER > bool n I still don't quite get the semantics here. How would the behavior change if the type was changed to say string or int in some or all of the lines? Since the current model is to evaluate $() while the Kconfig files are being parsed, would this require evaluating Kconfig expressions during parsing? There is a relatively clean and (somewhat) easy to understand parsing/evaluation separation at the moment, which I like. Do you have anything in mind that would be cleaner and simpler to implement in this way compared to using plain symbols? > > There is no real advantage to simplify the macro definition to its > simplest expression, unlike its actual usage. Maybe I'm being grumpy, but this feels like it's adding complexity rather than reducing it. I like the rest of this patchset, because the behavior is easy to understand and fits well with Kconfig's evaluation model: $() is just a kind of preprocessor that runs during parsing and does value substitution based on shell commands, possibly along with some helper macros to avoid repetition. I think we should think hard about whether we actually need anything more than that before complicating Kconfig even further "just in case." If the goal is simplification, then it's bad if we eventually end up with a bigger mess than the Makefiles. > >> Are there any cases where something more advanced than that might be >> warranted (e.g., macros that expand to complete expressions)? > > Maybe not now, but there is no need to close the door on the possibility > either. > > > Nicolas Kconfig has no notion of types for expressions by the way. The simplest way to look at it is that all symbols have a tristate value (which is n for non-bool/tristate symbols) and a string value. Which one gets used depends on the context. In A && B, the tristate values are used, and in A = B the string values are compared. In something like 'default "foo bar"', "foo bar" is actually a constant symbol. If we were to drop the straightforward preprocessor model, then constant symbols would no longer necessarily be constant. I have a feeling that that might turn Kconfig's internals even messier. Constant (and undefined) symbols end up with their name as their string value by the way, which is why stuff like 'A = "foo"' works. IMO, let's just go with the simple preprocessor model and let macros be dumb text substitutions (if we don't want to hardcode functionality). It's simple and probably good enough, keeps parsing and evaluation nicely separated, and keeps Kconfig somewhat comprehensible. (Note that the preprocessor could still be extended, if we ever need anything besides $(shell ...). Macros could still just do text substitution.) Cheers, Ulf