Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rqFFh-00BMXb-2o for pgsql-hackers@arkaria.postgresql.org; Fri, 29 Mar 2024 16:38:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rqFFf-00302U-GL for pgsql-hackers@arkaria.postgresql.org; Fri, 29 Mar 2024 16:38:47 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rqFFf-00302M-2p for pgsql-hackers@lists.postgresql.org; Fri, 29 Mar 2024 16:38:47 +0000 Received: from mail-yw1-x1135.google.com ([2607:f8b0:4864:20::1135]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rqFFZ-007Jsa-S5 for pgsql-hackers@lists.postgresql.org; Fri, 29 Mar 2024 16:38:46 +0000 Received: by mail-yw1-x1135.google.com with SMTP id 00721157ae682-60a068e26d8so22480427b3.3 for ; Fri, 29 Mar 2024 09:38:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dunslane-net.20230601.gappssmtp.com; s=20230601; t=1711730319; x=1712335119; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:subject:from:references:cc:to :content-language:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=TDy2k/0htNkzG5OqUKrUDj+x7ORQkvsQ9uH8KMphjDs=; b=qu5MUhadyQf368iZ/HDX7ZUyScej3OyvH2ieoOHmybAzTuETvR+1qQ6dL8wzmE+8pu OvufKeByVXnswXEUvoavY4fZWumb5KjzMm00JUqkBmRxp47hBMxDHroJSyuyH1iny2hm fiZX3mK7OxEsaDa95QLnYJxlcosLMO1W9tvxERFRFdddSJr6k00ErJssWsdVEhMpuhg9 M0YSyW7bBHo/SxBd+WpN/HjJZPIZnuv1ujNJffmjoBTnSDiFjQYC635kSffl+kYy9pK9 KGbUrPOHlPZxW24r64vEDs9IL+/AI+0v1h0fDEozz8sIK+li+cjp8SgaBkjlWhqa416Y aANA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711730319; x=1712335119; h=content-transfer-encoding:in-reply-to:subject:from:references:cc:to :content-language:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=TDy2k/0htNkzG5OqUKrUDj+x7ORQkvsQ9uH8KMphjDs=; b=bPholoagLFa5Ai5htu2dCvZ1snAXNxse/TM+MWRQ3f82rmCcKKQNDMjl95eiuOdoNH upoJa1I4L2bRidfRC4Np8FzOVx7gg3VAjl8Y+38gXKYV7A35E8XsCT/4/xxcLzz9d1er KhlJABUJ1DMlNDdEvll+jkqRie5Huw+Bt9UqpNixPCKAI6ZJOoNTyvMdHx9ZJCrv0W2M GR8fZqYR9cWWXC8bKCLRHtUibBMh2KNxONIv9vLxdG1qza+YnWB5z3kls8BFZ5Fav2q4 ytxPqhhylhRveonyYvin/riaI/W6UfcTJTl7Fk23OkZ0VjyEet0zLgxSsnJo7aBB+tu8 X9gQ== X-Forwarded-Encrypted: i=1; AJvYcCU8znYhER4LKHH3L9kfWM9uzxvc7NSjGWD+gjHcSXlQM8iCWYA/m5i7jfqPWzhvx0cqcUKuo+mkqmyrESS+SpJa0p+6iNSiL/hvdzxsNg7A0w+i X-Gm-Message-State: AOJu0Yz+R16ZY277D2kLfJ3MRtMyLZCU53lUQHclsYxllkts2rINtxlA VPaEA+Yt3KvtXhOAu6BBxqKZ1IBLnzzCzqchbq0WuKRDbOsrj95AC23RD1aCpcY= X-Google-Smtp-Source: AGHT+IHcHCKha6xrM17edYu3rUNytjrLygXQpP/lfXXJ37s16Trc9f/31fZ1U8AReB2mr9nDgjDY8Q== X-Received: by 2002:a81:7707:0:b0:611:2960:e52b with SMTP id s7-20020a817707000000b006112960e52bmr3140020ywc.47.1711730319605; Fri, 29 Mar 2024 09:38:39 -0700 (PDT) Received: from ?IPV6:2605:a601:9180:9800::2bb? ([2605:a601:9180:9800::2bb]) by smtp.googlemail.com with ESMTPSA id b27-20020a05620a119b00b0078bcffed4acsm189837qkk.19.2024.03.29.09.38.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 29 Mar 2024 09:38:39 -0700 (PDT) Message-ID: <1b3abed6-9014-d3ed-408f-acdf8e1e3c9a@dunslane.net> Date: Fri, 29 Mar 2024 12:38:38 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Content-Language: en-US To: Jacob Champion Cc: Robert Haas , Peter Smith , PostgreSQL Hackers References: <7b0a51d6-0d9d-7366-3a1a-f74397a02f55@dunslane.net> <682c8fff-355c-a04f-57ac-81055c4ccda8@dunslane.net> <70705cf3-c875-d489-c6a9-7dd61f1dc1af@dunslane.net> <694fd815-0414-0f09-98b3-db28d77fa37f@dunslane.net> From: Andrew Dunstan Subject: Re: WIP Incremental JSON Parser In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2024-03-26 Tu 17:52, Jacob Champion wrote: > On Mon, Mar 25, 2024 at 3:14 PM Jacob Champion > wrote: >> - add Assert calls in impossible error cases [2] > To expand on this one, I think these parts of the code (marked with > `<- here`) are impossible to reach: > >> switch (top) >> { >> case JSON_TOKEN_STRING: >> if (next_prediction(pstack) == JSON_TOKEN_COLON) >> ctx = JSON_PARSE_STRING; >> else >> ctx = JSON_PARSE_VALUE; <- here >> break; >> case JSON_TOKEN_NUMBER: <- here >> case JSON_TOKEN_TRUE: <- here >> case JSON_TOKEN_FALSE: <- here >> case JSON_TOKEN_NULL: <- here >> case JSON_TOKEN_ARRAY_START: <- here >> case JSON_TOKEN_OBJECT_START: <- here >> ctx = JSON_PARSE_VALUE; >> break; >> case JSON_TOKEN_ARRAY_END: <- here >> ctx = JSON_PARSE_ARRAY_NEXT; >> break; >> case JSON_TOKEN_OBJECT_END: <- here >> ctx = JSON_PARSE_OBJECT_NEXT; >> break; >> case JSON_TOKEN_COMMA: <- here >> if (next_prediction(pstack) == JSON_TOKEN_STRING) >> ctx = JSON_PARSE_OBJECT_NEXT; >> else >> ctx = JSON_PARSE_ARRAY_NEXT; >> break; > Since none of these cases are non-terminals, the only way to get to > this part of the code is if (top != tok). But inspecting the > productions and transitions that can put these tokens on the stack, it > looks like the only way for them to be at the top of the stack to > begin with is if (tok == top). (Otherwise, we would have chosen a > different production, or else errored out on a non-terminal.) > > This case is possible... > >> case JSON_TOKEN_STRING: >> if (next_prediction(pstack) == JSON_TOKEN_COLON) >> ctx = JSON_PARSE_STRING; > ...if we're in the middle of JSON_PROD_[MORE_]KEY_PAIRS. But the > corresponding else case is not, because if we're in the middle of a > _KEY_PAIRS production, the next_prediction() _must_ be > JSON_TOKEN_COLON. > > Do you agree, or am I missing a way to get there? > One good way of testing would be to add the Asserts, build with -DFORCE_JSON_PSTACK, and run the standard regression suite, which has a fairly comprehensive set of JSON errors. I'll play with that. cheers andrew -- Andrew Dunstan EDB: https://www.enterprisedb.com