Source file src/cmd/compile/internal/inline/inlheur/testdata/props/returns2.go

     1  // Copyright 2023 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // DO NOT EDIT (use 'go test -v -update-expected' instead.)
     6  // See cmd/compile/internal/inline/inlheur/testdata/props/README.txt
     7  // for more information on the format of this file.
     8  // <endfilepreamble>
     9  
    10  package returns2
    11  
    12  // returns2.go T_return_feeds_iface_call 18 0 1
    13  // <endpropsdump>
    14  // {"Flags":0,"ParamFlags":null,"ResultFlags":null}
    15  // callsite: returns2.go:19:13|0 flagstr "" flagval 0 score 1 mask 16384 maskstr "returnFeedsConcreteToInterfaceCallAdj"
    16  // <endcallsites>
    17  // <endfuncpreamble>
    18  func T_return_feeds_iface_call() {
    19  	b := newBar(10)
    20  	b.Plark()
    21  }
    22  
    23  // returns2.go T_multi_return_feeds_iface_call 29 0 1
    24  // <endpropsdump>
    25  // {"Flags":0,"ParamFlags":null,"ResultFlags":null}
    26  // callsite: returns2.go:30:20|0 flagstr "" flagval 0 score 3 mask 16384 maskstr "returnFeedsConcreteToInterfaceCallAdj"
    27  // <endcallsites>
    28  // <endfuncpreamble>
    29  func T_multi_return_feeds_iface_call() {
    30  	_, b, _ := newBar2(10)
    31  	b.Plark()
    32  }
    33  
    34  // returns2.go T_returned_inlinable_func_feeds_indirect_call 41 0 1
    35  // <endpropsdump>
    36  // {"Flags":0,"ParamFlags":[0],"ResultFlags":null}
    37  // callsite: returns2.go:42:18|0 flagstr "" flagval 0 score -51 mask 8200 maskstr "passConstToIfAdj|returnFeedsInlinableFuncToIndCallAdj"
    38  // callsite: returns2.go:44:20|1 flagstr "" flagval 0 score -23 mask 8192 maskstr "returnFeedsInlinableFuncToIndCallAdj"
    39  // <endcallsites>
    40  // <endfuncpreamble>
    41  func T_returned_inlinable_func_feeds_indirect_call(q int) {
    42  	f := returnsFunc(10)
    43  	f(q)
    44  	f2 := returnsFunc2()
    45  	f2(q)
    46  }
    47  
    48  // returns2.go T_returned_noninlineable_func_feeds_indirect_call 54 0 1
    49  // <endpropsdump>
    50  // {"Flags":0,"ParamFlags":[0],"ResultFlags":null}
    51  // callsite: returns2.go:55:30|0 flagstr "" flagval 0 score -23 mask 4096 maskstr "returnFeedsFuncToIndCallAdj"
    52  // <endcallsites>
    53  // <endfuncpreamble>
    54  func T_returned_noninlineable_func_feeds_indirect_call(q int) {
    55  	f := returnsNonInlinableFunc()
    56  	f(q)
    57  }
    58  
    59  // returns2.go T_multi_return_feeds_indirect_call 65 0 1
    60  // <endpropsdump>
    61  // {"Flags":0,"ParamFlags":[0],"ResultFlags":null}
    62  // callsite: returns2.go:66:29|0 flagstr "" flagval 0 score -21 mask 8192 maskstr "returnFeedsInlinableFuncToIndCallAdj"
    63  // <endcallsites>
    64  // <endfuncpreamble>
    65  func T_multi_return_feeds_indirect_call(q int) {
    66  	_, f, _ := multiReturnsFunc()
    67  	f(q)
    68  }
    69  
    70  // returns2.go T_return_feeds_ifswitch 76 0 1
    71  // <endpropsdump>
    72  // {"Flags":0,"ParamFlags":[0],"ResultFlags":[0]}
    73  // callsite: returns2.go:77:14|0 flagstr "" flagval 0 score 10 mask 2048 maskstr "returnFeedsConstToIfAdj"
    74  // <endcallsites>
    75  // <endfuncpreamble>
    76  func T_return_feeds_ifswitch(q int) int {
    77  	x := meaning(q)
    78  	if x < 42 {
    79  		switch x {
    80  		case 42:
    81  			return 1
    82  		}
    83  	}
    84  	return 0
    85  }
    86  
    87  // returns2.go T_multi_return_feeds_ifswitch 93 0 1
    88  // <endpropsdump>
    89  // {"Flags":0,"ParamFlags":[0],"ResultFlags":[0]}
    90  // callsite: returns2.go:94:21|0 flagstr "" flagval 0 score 9 mask 2048 maskstr "returnFeedsConstToIfAdj"
    91  // <endcallsites>
    92  // <endfuncpreamble>
    93  func T_multi_return_feeds_ifswitch(q int) int {
    94  	x, y, z := meanings(q)
    95  	if x < y {
    96  		switch x {
    97  		case 42:
    98  			return z
    99  		}
   100  	}
   101  	return 0
   102  }
   103  
   104  // returns2.go T_two_calls_feed_ifswitch 111 0 1
   105  // <endpropsdump>
   106  // {"Flags":0,"ParamFlags":[0],"ResultFlags":[0]}
   107  // callsite: returns2.go:115:14|0 flagstr "" flagval 0 score 25 mask 0 maskstr ""
   108  // callsite: returns2.go:116:14|1 flagstr "" flagval 0 score 25 mask 0 maskstr ""
   109  // <endcallsites>
   110  // <endfuncpreamble>
   111  func T_two_calls_feed_ifswitch(q int) int {
   112  	// This case we don't handle; for the heuristic to kick in,
   113  	// all names in a given if/switch cond have to come from the
   114  	// same callsite
   115  	x := meaning(q)
   116  	y := meaning(-q)
   117  	if x < y {
   118  		switch x + y {
   119  		case 42:
   120  			return 1
   121  		}
   122  	}
   123  	return 0
   124  }
   125  
   126  // returns2.go T_chained_indirect_call 132 0 1
   127  // <endpropsdump>
   128  // {"Flags":0,"ParamFlags":[0,0],"ResultFlags":null}
   129  // callsite: returns2.go:135:18|0 flagstr "" flagval 0 score -31 mask 8192 maskstr "returnFeedsInlinableFuncToIndCallAdj"
   130  // <endcallsites>
   131  // <endfuncpreamble>
   132  func T_chained_indirect_call(x, y int) {
   133  	// Here 'returnsFunc' returns an inlinable func that feeds
   134  	// directly into a call (no named intermediate).
   135  	G += returnsFunc(x - y)(x + y)
   136  }
   137  
   138  // returns2.go T_chained_conc_iface_call 144 0 1
   139  // <endpropsdump>
   140  // {"Flags":0,"ParamFlags":[0,0],"ResultFlags":null}
   141  // callsite: returns2.go:148:8|0 flagstr "" flagval 0 score 1 mask 16384 maskstr "returnFeedsConcreteToInterfaceCallAdj"
   142  // <endcallsites>
   143  // <endfuncpreamble>
   144  func T_chained_conc_iface_call(x, y int) {
   145  	// Similar to the case above, return from call returning concrete type
   146  	// feeds directly into interface call. Note that only the first
   147  	// iface call is interesting here.
   148  	newBar(10).Plark().Plark()
   149  }
   150  
   151  func returnsFunc(x int) func(int) int {
   152  	if x < 0 {
   153  		G++
   154  	}
   155  	return adder
   156  }
   157  
   158  func returnsFunc2() func(int) int {
   159  	return func(x int) int {
   160  		return adder(x)
   161  	}
   162  }
   163  
   164  func returnsNonInlinableFunc() func(int) int {
   165  	return adderNoInline
   166  }
   167  
   168  func multiReturnsFunc() (int, func(int) int, int) {
   169  	return 42, func(x int) int { G++; return 1 }, -42
   170  }
   171  
   172  func adder(x int) int {
   173  	G += 1
   174  	return G
   175  }
   176  
   177  func adderNoInline(x int) int {
   178  	defer func() { G += x }()
   179  	G += 1
   180  	return G
   181  }
   182  
   183  func meaning(q int) int {
   184  	r := 0
   185  	for i := 0; i < 42; i++ {
   186  		r += q
   187  	}
   188  	G += r
   189  	return 42
   190  }
   191  
   192  func meanings(q int) (int, int, int) {
   193  	r := 0
   194  	for i := 0; i < 42; i++ {
   195  		r += q
   196  	}
   197  	return 42, 43, r
   198  }
   199  
   200  type Bar struct {
   201  	x int
   202  	y string
   203  }
   204  
   205  func (b *Bar) Plark() Itf {
   206  	return b
   207  }
   208  
   209  type Itf interface {
   210  	Plark() Itf
   211  }
   212  
   213  func newBar(x int) Itf {
   214  	s := 0
   215  	for i := 0; i < x; i++ {
   216  		s += i
   217  	}
   218  	return &Bar{
   219  		x: s,
   220  	}
   221  }
   222  
   223  func newBar2(x int) (int, Itf, bool) {
   224  	s := 0
   225  	for i := 0; i < x; i++ {
   226  		s += i
   227  	}
   228  	return 0, &Bar{x: s}, false
   229  }
   230  
   231  var G int
   232  

View as plain text