@@ -16,11 +16,8 @@ import (
16
16
"cmd/compile/internal/ir"
17
17
"cmd/compile/internal/typecheck"
18
18
"cmd/compile/internal/types"
19
- "cmd/internal/src"
20
19
)
21
20
22
- // TODO: update tests to include full errors.
23
-
24
21
const go125ImprovedConcreteTypeAnalysis = true
25
22
26
23
// StaticCall devirtualizes the given call if possible when the concrete callee
@@ -154,7 +151,6 @@ func StaticCall(call *ir.CallExpr) {
154
151
if base .Flag .LowerM != 0 {
155
152
base .WarnfAt (call .Pos (), "partially devirtualizing %v to %v" , sel , typ )
156
153
}
157
- // TODO: with interleaved inlining and devirtualization we migth get here multiple times for the same call.
158
154
call .SetOp (ir .OCALLINTER )
159
155
call .Fun = x
160
156
default :
@@ -180,8 +176,6 @@ func StaticCall(call *ir.CallExpr) {
180
176
typecheck .FixMethodCall (call )
181
177
}
182
178
183
- const concreteTypeDebug = false
184
-
185
179
// concreteType determines the concrete type of n, following OCONVIFACEs and type asserts.
186
180
// Returns nil when the concrete type could not be determined, or when there are multiple
187
181
// (different) types assigned to an interface.
@@ -214,39 +208,19 @@ func concreteType(n ir.Node) (typ *types.Type) {
214
208
}
215
209
216
210
func concreteType1 (n ir.Node , analyzed map [* ir.Name ]* types.Type , getAssignements func (* ir.Name ) []valOrTyp ) (out * types.Type , isNil bool ) {
217
- nn := n
218
-
219
- if concreteTypeDebug {
220
- defer func () {
221
- base .WarnfAt (nn .Pos (), "concreteType1(%v) -> (typ: %v; isNil: %v)" , nn , out , isNil )
222
- }()
223
- }
224
-
225
211
for {
226
- if concreteTypeDebug {
227
- base .WarnfAt (n .Pos (), "concreteType1(%v) current iteration node: %v" , nn , n )
228
- }
229
-
230
212
if ! n .Type ().IsInterface () {
231
- if n , ok := n .(* ir.CallExpr ); ok {
232
- if n .Fun != nil {
233
- results := n .Fun .Type ().Results ()
234
- base .Assert (len (results ) == 1 )
235
- retTyp := results [0 ].Type
236
- if ! retTyp .IsInterface () {
237
- // TODO: isnt n.Type going to return that?
238
- return retTyp , false
239
- }
240
- }
241
- }
242
213
return n .Type (), false
243
214
}
244
215
245
216
switch n1 := n .(type ) {
246
217
case * ir.ConvExpr :
247
- // OCONVNOP might change the type, thus check whether they are identical.
248
- // TODO: can this happen for iface?
249
- if n1 .Op () == ir .OCONVNOP && types .Identical (n1 .Type (), n1 .X .Type ()) {
218
+ if n1 .Op () == ir .OCONVNOP {
219
+ if ! n1 .Type ().IsInterface () || ! types .Identical (n1 .Type (), n1 .X .Type ()) {
220
+ // As we check (directly before this switch) wheter n is an interface, thus we should only reach
221
+ // here for iface conversions where both operands are the same.
222
+ base .Fatalf ("not identical/interface types found n1.Type = %v; n1.X.Type = %v" , n1 .Type (), n1 .X .Type ())
223
+ }
250
224
n = n1 .X
251
225
continue
252
226
}
@@ -292,10 +266,6 @@ func concreteType1(n ir.Node, analyzed map[*ir.Name]*types.Type, getAssignements
292
266
return nil , false // conservatively assume it's reassigned with a different type indirectly
293
267
}
294
268
295
- if concreteTypeDebug {
296
- base .WarnfAt (src .NoXPos , "concreteType1(%v) name: %v, analyzing assignements" , nn , name )
297
- }
298
-
299
269
if typ , ok := analyzed [name ]; ok {
300
270
return typ , false
301
271
}
@@ -310,9 +280,6 @@ func concreteType1(n ir.Node, analyzed map[*ir.Name]*types.Type, getAssignements
310
280
if len (assignements ) == 0 {
311
281
// Variable either declared with zero value, or only assigned
312
282
// with nil (getAssignements does not return such assignements).
313
- if concreteTypeDebug {
314
- base .WarnfAt (src .NoXPos , "concreteType1(%v) name: %v assigned with only nil values" , nn , name )
315
- }
316
283
return nil , true
317
284
}
318
285
@@ -321,23 +288,14 @@ func concreteType1(n ir.Node, analyzed map[*ir.Name]*types.Type, getAssignements
321
288
t := v .typ
322
289
if v .node != nil {
323
290
var isNil bool
324
- if concreteTypeDebug {
325
- base .WarnfAt (src .NoXPos , "concreteType1(%v) name: %v assigned with node %v" , nn , name , v .node )
326
- }
327
291
t , isNil = concreteType1 (v .node , analyzed , getAssignements )
328
292
if isNil {
329
- if concreteTypeDebug {
330
- base .WarnfAt (src .NoXPos , "concreteType1(%v) name: %v assigned with nil" , nn , name )
331
- }
332
293
if t != nil {
333
294
base .Fatalf ("t = %v; want = <nil>" , t )
334
295
}
335
296
continue
336
297
}
337
298
}
338
- if concreteTypeDebug {
339
- base .WarnfAt (src .NoXPos , "concreteType1(%v) name: %v assigned with %v" , nn , name , t )
340
- }
341
299
if t == nil || (typ != nil && ! types .Identical (typ , t )) {
342
300
return nil , false
343
301
}
@@ -375,7 +333,6 @@ func ifaceAssignments(fun *ir.Func) map[*ir.Name][]valOrTyp {
375
333
return
376
334
}
377
335
378
- // TODO: is this needed?
379
336
n , ok := ir .OuterValue (name ).(* ir.Name )
380
337
if ! ok {
381
338
return
@@ -450,7 +407,7 @@ func ifaceAssignments(fun *ir.Func) map[*ir.Name][]valOrTyp {
450
407
} else if call , ok := rhs .(* ir.InlinedCallExpr ); ok {
451
408
assign (p , valOrTyp {node : call .Result (i )})
452
409
} else {
453
- // TODO: can we reach here? Fatal?
410
+ // TODO: can we reach here?
454
411
assign (p , valOrTyp {})
455
412
}
456
413
}
0 commit comments