<commit_before>// RUN: rm -rf %t && mkdir -p %t
// RUN: %target-build-swift -Xfrontend -enable-reflection-metadata -Xfrontend -enable-reflection-names -lswiftSwiftReflectionTest %s -o %T/example
// RUN: %target-swift-reflection-test %T/example 2>&1 | FileCheck %s
// REQUIRES: objc_interop

import SwiftReflectionTest

class Container {
  var x: Int
  var y: Int
  var z: Container?
  init(x: Int, y: Int, z: Container? = nil) {
    self.x = x
    self.y = y
    self.z = z
  }
}

class MyClass<T, U> {
  let f: () -> ()
  var x: T
  var y: U
  init(x: T, y: U, f: () -> ()) {
    self.x = x
    self.y = y
    self.f = f
  }
  func doFoo() {
    f()
  }
}

var lhs = Container(x: 111, y: 222, z: nil)
var rhs = Container(x: 111, y: 222, z: nil)

func doFoo() {
  lhs.x *= 10
  rhs.x *= 10
  print(lhs)
  print(rhs)
}

var mc = MyClass(x: lhs, y: rhs, f: doFoo)

reflect(object: mc)

// CHECK: Reflecting an object.
// CHECK: Instance pointer in child address space: 0x{{[0-9a-fA-F]+}}

// CHECK: Type reference:
// CHECK: (bound_generic_class example.MyClass
// CHECK:   (class example.Container)
// CHECK:   (class example.Container))

// CHECK: Type info:
// CHECK: (class_instance size=48 alignment=16 stride=48 num_extra_inhabitants=0
// CHECK:   (field name=f offset=16
// CHECK:     (thick_function size=16 alignment=8 stride=16 num_extra_inhabitants=0
// CHECK:       (field name=function offset=0
// CHECK:         (builtin size=8 alignment=8 stride=8 num_extra_inhabitants=1))
// CHECK:       (field name=context offset=8
// CHECK:         (reference kind=strong refcounting=native))))
// CHECK:   (field name=x offset=32
// CHECK:     (reference kind=strong refcounting=native))
// CHECK:   (field name=y offset=40
// CHECK:     (reference kind=strong refcounting=native)))

reflect(any: mc)

// CHECK: Reflecting an existential.
// CHECK: Instance pointer in child address space: 0x{{[0-9a-fA-F]+}}
// CHECK: Type reference:
// CHECK: (bound_generic_class example.MyClass
// CHECK:   (class example.Container)
// CHECK:   (class example.Container))

// CHECK: Type info:
// CHECK: (reference kind=strong refcounting=native)<commit_msg>Use target-run to run swift-reflection-test-based tests<commit_after>// RUN: rm -rf %t && mkdir -p %t
// RUN: %target-build-swift -Xfrontend -enable-reflection-metadata -Xfrontend -enable-reflection-names -lswiftSwiftReflectionTest %s -o %T/example
// RUN: %target-run %target-swift-reflection-test %T/example 2>&1 | FileCheck %s --check-prefix=CHECK-%target-ptrsize
// REQUIRES: objc_interop

import SwiftReflectionTest

class Container {
  var x: Int
  var y: Int
  var z: Container?
  init(x: Int, y: Int, z: Container? = nil) {
    self.x = x
    self.y = y
    self.z = z
  }
}

class MyClass<T, U> {
  let f: () -> ()
  var x: T
  var y: U
  init(x: T, y: U, f: () -> ()) {
    self.x = x
    self.y = y
    self.f = f
  }
  func doFoo() {
    f()
  }
}

var lhs = Container(x: 111, y: 222, z: nil)
var rhs = Container(x: 111, y: 222, z: nil)

func doFoo() {
  lhs.x *= 10
  rhs.x *= 10
  print(lhs)
  print(rhs)
}

var mc = MyClass(x: lhs, y: rhs, f: doFoo)

reflect(object: mc)

// CHECK-64: Reflecting an object.
// CHECK-64: Instance pointer in child address space: 0x{{[0-9a-fA-F]+}}

// CHECK-64: Type reference:
// CHECK-64: (bound_generic_class example.MyClass
// CHECK-64:   (class example.Container)
// CHECK-64:   (class example.Container))

// CHECK-64: Type info:
// CHECK-64: (class_instance size=48 alignment=16 stride=48 num_extra_inhabitants=0
// CHECK-64:   (field name=f offset=16
// CHECK-64:     (thick_function size=16 alignment=8 stride=16 num_extra_inhabitants=0
// CHECK-64:       (field name=function offset=0
// CHECK-64:         (builtin size=8 alignment=8 stride=8 num_extra_inhabitants=1))
// CHECK-64:       (field name=context offset=8
// CHECK-64:         (reference kind=strong refcounting=native))))
// CHECK-64:   (field name=x offset=32
// CHECK-64:     (reference kind=strong refcounting=native))
// CHECK-64:   (field name=y offset=40
// CHECK-64:     (reference kind=strong refcounting=native)))


// CHECK-32: Reflecting an object.
// CHECK-32: Instance pointer in child address space: 0x{{[0-9a-fA-F]+}}

// CHECK-32: Type reference:
// CHECK-32: (bound_generic_class example.MyClass
// CHECK-32:   (class example.Container)
// CHECK-32:   (class example.Container))

// CHECK-32: Type info:
// CHECK-32: (class_instance size=28 alignment=16 stride=32 num_extra_inhabitants=0
// CHECK-32:   (field name=f offset=12
// CHECK-32:     (thick_function size=8 alignment=4 stride=8 num_extra_inhabitants=0
// CHECK-32:       (field name=function offset=0
// CHECK-32:         (builtin size=4 alignment=4 stride=4 num_extra_inhabitants=1))
// CHECK-32:       (field name=context offset=4
// CHECK-32:         (reference kind=strong refcounting=native))))
// CHECK-32:   (field name=x offset=20
// CHECK-32:     (reference kind=strong refcounting=native))
// CHECK-32:   (field name=y offset=24
// CHECK-32:     (reference kind=strong refcounting=native)))

reflect(any: mc)

// CHECK-64: Reflecting an existential.
// CHECK-64: Instance pointer in child address space: 0x{{[0-9a-fA-F]+}}
// CHECK-64: Type reference:
// CHECK-64: (bound_generic_class example.MyClass
// CHECK-64:   (class example.Container)
// CHECK-64:   (class example.Container))

// CHECK-64: Type info:
// CHECK-64: (reference kind=strong refcounting=native)


// CHECK-32: Reflecting an existential.
// CHECK-32: Instance pointer in child address space: 0x{{[0-9a-fA-F]+}}
// CHECK-32: Type reference:
// CHECK-32: (bound_generic_class example.MyClass
// CHECK-32:   (class example.Container)
// CHECK-32:   (class example.Container))

// CHECK-32: Type info:
// CHECK-32: (reference kind=strong refcounting=native)
{'fraction_non_alphanumeric': 0.15737534626038782, 'fraction_numerical': 0.03999307479224377, 'mean_word_length': 3.269770879526977, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4879448', 'n_tokens_mistral': 2215, 'n_tokens_neox': 2083, 'n_words': 556}