summaryrefslogtreecommitdiff
path: root/test/lit/passes/local-subtyping-nn.wast
blob: 3754230d82f54d025dfafe0a476e49ca005b4b9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
;; RUN: wasm-opt %s --local-subtyping -all -S -o - | filecheck %s

(module
  (type $struct (struct))

  ;; CHECK:      (import "out" "i32" (func $i32 (type $0) (result i32)))
  (import "out" "i32" (func $i32 (result i32)))

  ;; CHECK:      (func $non-nullable (type $1)
  ;; CHECK-NEXT:  (local $x (ref none))
  ;; CHECK-NEXT:  (local $y (ref $0))
  ;; CHECK-NEXT:  (local.set $x
  ;; CHECK-NEXT:   (ref.as_non_null
  ;; CHECK-NEXT:    (ref.null none)
  ;; CHECK-NEXT:   )
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT:  (local.set $y
  ;; CHECK-NEXT:   (ref.func $i32)
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT:  (drop
  ;; CHECK-NEXT:   (local.get $x)
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT: )
  (func $non-nullable
    (local $x (ref null $struct))
    (local $y funcref)
    ;; x is assigned a value that is non-nullable.
    (local.set $x
      (ref.as_non_null (ref.null $struct))
    )
    ;; y is assigned a value that is non-nullable, and also allows a more
    ;; specific heap type.
    (local.set $y
      (ref.func $i32)
    )
    ;; Verify that the presence of a get does not alter things.
    (drop
      (local.get $x)
    )
  )

  ;; CHECK:      (func $uses-default (type $2) (param $i i32)
  ;; CHECK-NEXT:  (local $x nullref)
  ;; CHECK-NEXT:  (if
  ;; CHECK-NEXT:   (local.get $i)
  ;; CHECK-NEXT:   (then
  ;; CHECK-NEXT:    (local.set $x
  ;; CHECK-NEXT:     (ref.as_non_null
  ;; CHECK-NEXT:      (ref.null none)
  ;; CHECK-NEXT:     )
  ;; CHECK-NEXT:    )
  ;; CHECK-NEXT:   )
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT:  (drop
  ;; CHECK-NEXT:   (local.get $x)
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT: )
  (func $uses-default (param $i i32)
    (local $x (ref null any))
    (if
      (local.get $i)
      ;; The only set to this local uses a non-nullable type.
      (then
        (local.set $x
          (ref.as_non_null (ref.null $struct))
        )
      )
    )
    (drop
      ;; This get may use the null value, so we can refine the heap type but not
      ;; alter nullability.
      (local.get $x)
    )
  )
)