Go patch committed: Move lowering pass after check types pass

1 view
Skip to first unread message

Ian Lance Taylor

unread,
Dec 18, 2023, 8:32:29 PM12/18/23
to gofrontend-dev, gcc-patches
This Go frontend patch moves the lowering pass after the type
determination and the type checking passes. This lets us simplify
some of the code that determines the type of an expression, which
previously had to work correctly both before and after type
determination.

I'm doing this to help with future generic support. For example, with
generics, we can see code like

func ident[T any](v T) T { return v }

func F() int32 {
s := int32(1)
return ident(s)
}

Before this change, we would type check return statements in the
lowering pass (see Return_statement::do_lower). With a generic
example like the above, that means we have to determine the type of s,
and use that to infer the type arguments passed to ident, and use that
to determine the result type of ident. That is too much to do at
lowering time. Of course we can change the way that return statements
work, but similar issues arise with index expressions, the types of
closures for function literals, and probably other cases as well.

Rather than try to deal with all those cases, we move the lowering
pass after type checking. This requires a bunch of changes, notably
for determining constant types. We have to add type checking for
various constructs that formerly disappeared in the lowering pass. So
it's a lot of shuffling. Sorry for the size of the patch.

Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu. Committed
to mainline.

Ian
patch.txt.bz2

Ian Lance Taylor

unread,
Jan 18, 2024, 11:49:28 PMJan 18
to gofrontend-dev, gcc-patches
Sorry, I forgot to commit the changes to some of the test files. I've
committed this patch to fix them. This fixes PR 113447.

Ian
patch.txt
Reply all
Reply to author
Forward
0 new messages