{"action":"created","issue":{"url":"https://api.github.com/repos/WebAssembly/design/issues/685","repository_url":"https://api.github.com/repos/WebAssembly/design","labels_url":"https://api.github.com/repos/WebAssembly/design/issues/685/labels{/name}","comments_url":"https://api.github.com/repos/WebAssembly/design/issues/685/comments","events_url":"https://api.github.com/repos/WebAssembly/design/issues/685/events","html_url":"https://github.com/WebAssembly/design/issues/685","id":154386545,"number":685,"title":"Add a get_value operator to duplicate a value from the expression stack.","user":{"login":"JSStats","id":11826073,"avatar_url":"https://avatars.githubusercontent.com/u/11826073?v=3","gravatar_id":"","url":"https://api.github.com/users/JSStats","html_url":"https://github.com/JSStats","followers_url":"https://api.github.com/users/JSStats/followers","following_url":"https://api.github.com/users/JSStats/following{/other_user}","gists_url":"https://api.github.com/users/JSStats/gists{/gist_id}","starred_url":"https://api.github.com/users/JSStats/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JSStats/subscriptions","organizations_url":"https://api.github.com/users/JSStats/orgs","repos_url":"https://api.github.com/users/JSStats/repos","events_url":"https://api.github.com/users/JSStats/events{/privacy}","received_events_url":"https://api.github.com/users/JSStats/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-05-12T02:58:40Z","updated_at":"2016-05-23T07:34:06Z","closed_at":null,"body":"Would there be any immediate interest in adding an operator, say `get_value`, to duplicate a value from the expression stack?\r\n\r\nWith the post-order encoding there is already the issue that expression results accumulate in blocks to be discarded at the block exits. It seems consistent with the SSA decoder to allow re-use of these, so why not take advantage of them. Each of these could be viewed as binding a block local variable that could be accessed. So rather than `block` we could effective have `let`:\r\n\r\n```\r\n(let (($v1 (f64.load ...))\r\n      ($v2 (i32.load ...))\r\n      (_ (f64.store :offset 8 (get_value $v2) (get_value $v1)))\r\n      (_ (f64.store :offset 16 (get_value $v2) (get_value $v1))))\r\n  ;; The fall through result.\r\n  (get_value $v1))\r\n```\r\n\r\nAdding this now might allow some experimentation with the tooling, to take advantage of this.\r\n\r\nIt's not necessary to land this change, and it can be explored in local work, and local tools can rewrite the wast into this encoding, but might there happen to be any interesting in such an incremental change?"},"comment":{"url":"https://api.github.com/repos/WebAssembly/design/issues/comments/220907131","html_url":"https://github.com/WebAssembly/design/issues/685#issuecomment-220907131","issue_url":"https://api.github.com/repos/WebAssembly/design/issues/685","id":220907131,"user":{"login":"JSStats","id":11826073,"avatar_url":"https://avatars.githubusercontent.com/u/11826073?v=3","gravatar_id":"","url":"https://api.github.com/users/JSStats","html_url":"https://github.com/JSStats","followers_url":"https://api.github.com/users/JSStats/followers","following_url":"https://api.github.com/users/JSStats/following{/other_user}","gists_url":"https://api.github.com/users/JSStats/gists{/gist_id}","starred_url":"https://api.github.com/users/JSStats/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JSStats/subscriptions","organizations_url":"https://api.github.com/users/JSStats/orgs","repos_url":"https://api.github.com/users/JSStats/repos","events_url":"https://api.github.com/users/JSStats/events{/privacy}","received_events_url":"https://api.github.com/users/JSStats/received_events","type":"User","site_admin":false},"created_at":"2016-05-23T07:34:06Z","updated_at":"2016-05-23T07:34:06Z","body":"@qwertie The definitions are already on the values stack in a post-order decoder. All the block top level expression definitions are on the values stack at the end of the block. This proposal is to allow re-use of them, the `get_value` operator. These values might even be used by `get_value` and also later consumed by an implicit pop, so not only block top level expressions.\r\n\r\nThe `const $c1` syntax is how it could look in an alternative text format such as https://github.com/sunfishcode/design/blob/text-syntax-strawman-proposal/TextFormat.md So these do not need a new type of local variable. It matches a functional style of programming, and looks subjectively more readable to me. A value that is not a block top-level expression might not look so pretty, but would read well in another block-like pattern, for example:\r\n\r\n```\r\n$l1 + {const $c1 = ...; call $fn($c1, $c1); $c1};\r\n```\r\n\r\nThere may also be some utility in being able to explicitly declare the last use of these definitions. This happens implicitly when they are used as an expression argument and are popped from the top of the values stack. This could help a single pass compiler such as https://bugzilla.mozilla.org/show_bug.cgi?id=1232205 with register allocation, so it knows when a value in a register is no longer needed and can free up the register without flushing it to a memory stack."}}
{"actor":{"display_login":"JSStats"}}