]> git.lizzy.rs Git - rust.git/commit
auto merge of #15921 : dotdash/rust/match_lifetimes, r=pcwalton
authorbors <bors@rust-lang.org>
Thu, 24 Jul 2014 09:51:16 +0000 (09:51 +0000)
committerbors <bors@rust-lang.org>
Thu, 24 Jul 2014 09:51:16 +0000 (09:51 +0000)
commite70ee120bf70d5b6195c2b355b9820a8609564cf
tree8fd7e31dd7d687834797f564818bffb431a0bb9f
parent02464196eaf56838c16d747e77536cefd14c5238
parent0d6f2576573534215fc3a6cb96a3fd5d5e813cf7
auto merge of #15921 : dotdash/rust/match_lifetimes, r=pcwalton

The allocas used in match expression currently don't get good lifetime
markers, in fact they only get lifetime start markers, because their
lifetimes don't match to cleanup scopes.

While the bindings themselves are bog standard and just need a matching
pair of start and end markers, they might need them twice, once for a
guard clause and once for the match body.

The __llmatch alloca OTOH needs a single lifetime start marker, but
when there's a guard clause, it needs two end markers, because its
lifetime ends either when the guard doesn't match or after the match
body.

With these intrinsics in place, LLVM can now, for example, optimize
code like this:

````rust
enum E {
  A1(int),
  A2(int),
  A3(int),
  A4(int),
}

pub fn variants(x: E) {
  match x {
    A1(m) => bar(&m),
    A2(m) => bar(&m),
    A3(m) => bar(&m),
    A4(m) => bar(&m),
  }
}
````

To a single call to bar, using only a single stack slot. It still fails
to eliminate some of checks.

````gas
.Ltmp5:
.cfi_def_cfa_offset 16
movb (%rdi), %al
testb %al, %al
je .LBB3_5
movzbl %al, %eax
cmpl $1, %eax
je .LBB3_5
cmpl $2, %eax
.LBB3_5:
movq 8(%rdi), %rax
movq %rax, (%rsp)
leaq (%rsp), %rdi
callq _ZN3bar20hcb7a0d8be8e17e37daaE@PLT
popq %rax
retq
````

Refs #15665