From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28992 invoked by alias); 15 May 2013 19:29:03 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 31410 Received: (qmail 18616 invoked from network); 15 May 2013 19:28:49 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at brasslantern.com does not designate permitted sender hosts) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type:x-gm-message-state; bh=G/ujIx18T68ny8APgYSRX4xNJTU9LPqJ+LqcL3KxdvA=; b=V4JToCbRUCO6nAyizjoUzlS+2elpQqkTo1bKOgEHfOe7ZO+TXaY5MWSzmeFp/KEK2I LLXOUIOLiENBjmxa5AnKdeY7FaghwB9Gp3Od+hSJzvHKmQsBE7LbwYVKhir6u3MzwaJ6 7r0Rhv+kQwQa1vmYbuTm5/D1c00UvlKQNCJCMKtitpV5PAWvRFdL4EzkGh5WRIoXs7DC jC77v/hHE4MnHp75Hss5BWnzglQSIiclzdqCwXc2VLAbAxSkmK5r1bQqQSOyfA8z1dbt 3nfaEdPapRHN4UPGs/7+N2ooNTYWiOfrQpTyHe4xGQZrrUCVEJLYrpDJStrdiJOZ8Jqv GHWA== MIME-Version: 1.0 X-Received: by 10.112.155.202 with SMTP id vy10mr18327136lbb.51.1368646121417; Wed, 15 May 2013 12:28:41 -0700 (PDT) In-Reply-To: References: Date: Wed, 15 May 2013 12:28:41 -0700 Message-ID: Subject: Re: zsh built-in commands are removed when passing through a built-in command that spawns commands From: Bart Schaefer To: Antoine Pietri Cc: Zsh hackers list Content-Type: text/plain; charset=ISO-8859-1 X-Gm-Message-State: ALoCoQkdXrC7NoiZC7yIOl5NI6oz+/FJ3weY5JtoWy51sRu5ylBSLk0AiGzPn8OzbBjH5hG+y9f0 On Wed, May 15, 2013 at 10:33 AM, Bart Schaefer wrote: > > Well, that indicates that the builtin time is still there. So > something else must be going on. Aha. I can in fact reproduce it, I was misled by $TIMEFMT. So ... what's happening is that the shell can't time itself timing time, if you see what I mean. The trivial case is % time time true The built-in time [which is actually a keyword rather than a command, which is why % time (sublist) works at all] is executed in the current shell and is able to record the elapsed time for a single "job". If that job is also executed in the current shell, the built-in handles that by reading the time stats for the shell itself. If that current-shell-job in turn is also the built-in time, there's no nested set of time stats available ... either the outer time has to be abandoned [or reported incorrectly] or the inner one has to be handled differently. Zsh chooses to solve this during parsing by simply not recognizing the time keyword inside another time keyword. You can see this by the strange parse error in this example: % time (true) ( true; ) 0.00s user 0.00s system 48% cpu 0.001 total % time time (true) zsh: missing end of name time (true) 0.00s user 0.00s system 49% cpu 0.001 total A possible alternative would be for a nested "time" keyword to force itself into a subshell. This wouldn't cost any more processes than the current approach of falling back to the external time command. Unfortunately this is not entirely trivial to implement, though someone who knows the internal wordcode representation better than I do could probably do it reasonably quickly. An intermediate approach is to recognize nested time keywords in explicit subshells, which turns out to be pretty straightforward. If that were implemented, % time ( time true ) would use the keyword in both positions, but % time time true % time { time true } would behave as they do now. We'd want to implement the subshell variant anyway in order to avoid an unnecessary fork for the time keyword inside the subshell, but by itself it'd introduce even more inconsistency.