authorgravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2021-08-28 23:18:47+02:00
committergravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2021-08-29 08:59:27+00:00
log7b863aa8ac6d48092c8d5b3c8713d9f8a9cfbdf3
tree31d86d703f717419c5224f129c4bfc2788ce96ec
parent4bb5d17edc85eac74626224810d6a44a3c73cca3

AstGen: short-circuit rvalue() if code is unreachable

This avoids generating instructions which will never be reached.

1 files changed, 2 insertions(+), 1 deletions(-)

src/AstGen.zig+2-1
...@@ -8389,7 +8389,7 @@ fn nodeImpliesRuntimeBits(tree: *const ast.Tree, start_node: ast.Node.Index) boo...@@ -8389,7 +8389,7 @@ fn nodeImpliesRuntimeBits(tree: *const ast.Tree, start_node: ast.Node.Index) boo
8389 }8389 }
8390}8390}
83918391
8392/// Applies `rl` semantics to `inst`. Expressions which do not do their own handling of8392/// Applies `rl` semantics to `result`. Expressions which do not do their own handling of
8393/// result locations must call this function on their result.8393/// result locations must call this function on their result.
8394/// As an example, if the `ResultLoc` is `ptr`, it will write the result to the pointer.8394/// As an example, if the `ResultLoc` is `ptr`, it will write the result to the pointer.
8395/// If the `ResultLoc` is `ty`, it will coerce the result to the type.8395/// If the `ResultLoc` is `ty`, it will coerce the result to the type.
...@@ -8399,6 +8399,7 @@ fn rvalue(...@@ -8399,6 +8399,7 @@ fn rvalue(
8399 result: Zir.Inst.Ref,8399 result: Zir.Inst.Ref,
8400 src_node: ast.Node.Index,8400 src_node: ast.Node.Index,
8401) InnerError!Zir.Inst.Ref {8401) InnerError!Zir.Inst.Ref {
8402 if (gz.endsWithNoReturn()) return result;
8402 switch (rl) {8403 switch (rl) {
8403 .none, .none_or_ref, .coerced_ty => return result,8404 .none, .none_or_ref, .coerced_ty => return result,
8404 .discard => {8405 .discard => {