Skip to content

Commit 603b63e

Browse files
committed
chore: fix explanation, fix used variables
1 parent a9e9738 commit 603b63e

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

internal/refactor/inline/inline.go

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,25 +1438,28 @@ next:
14381438
// a binding decl or when using the literalization
14391439
// strategy.
14401440

1441-
// Check if the types are identical to eliminate redundant type conversion.
1441+
// If the types are identical, we can eliminate
1442+
// redundant type conversions such as this:
14421443
//
1443-
// As trivialConversion is unable to distinguish between typed and untyped constants,
1444-
// it leads to redundant conversions:
1445-
// A callee:
1446-
// func f1(i int32) { print(i) }
1447-
// Called from:
1448-
// func f() { f1(int32(1)) }
1449-
// Will be inlined as:
1450-
// func f() { print(int32(int32(1)))
1444+
// Callee:
1445+
// func f(i int32) { print(i) }
1446+
// Caller:
1447+
// func g() { f(int32(1)) }
1448+
// Inlined as:
1449+
// func g() { print(int32(int32(1)))
14511450
//
1452-
// However, at this point arg.typ includes information regarding constants being typed or untyped.
1453-
// This happens due to state.arguments() performing re-typechecking.
1454-
// Hence, the redundant conversion can be eliminated by making a check if types are identical at this stage.
1455-
typesIdentical := types.Identical(arg.typ, param.obj.Type())
1456-
if len(param.info.Refs) > 0 && !typesIdentical && !trivialConversion(args[i].constant, args[i].typ, params[i].obj.Type()) {
1457-
arg.expr = convert(params[i].fieldType, arg.expr)
1451+
// Recall that non-trivial does not imply non-identical
1452+
// for constant conversions; however, at this point state.arguments
1453+
// has already re-typechecked the constant and set arg.type to
1454+
// its (possibly "untyped") inherent type, so
1455+
// the conversion from untyped 1 to int32 is non-trivial even
1456+
// though both arg and param have identical types (int32).
1457+
if len(param.info.Refs) > 0 &&
1458+
!types.Identical(arg.typ, param.obj.Type()) &&
1459+
!trivialConversion(arg.constant, arg.typ, param.obj.Type()) {
1460+
arg.expr = convert(param.fieldType, arg.expr)
14581461
logf("param %q: adding explicit %s -> %s conversion around argument",
1459-
param.info.Name, args[i].typ, params[i].obj.Type())
1462+
param.info.Name, arg.typ, param.obj.Type())
14601463
}
14611464

14621465
// It is safe to substitute param and replace it with arg.

0 commit comments

Comments
 (0)