]> git.ipfire.org Git - thirdparty/gcc.git/commit
compiler: move lowering pass after check types pass
authorIan Lance Taylor <iant@golang.org>
Fri, 20 Oct 2023 02:34:31 +0000 (19:34 -0700)
committerIan Lance Taylor <iant@golang.org>
Tue, 19 Dec 2023 01:30:56 +0000 (17:30 -0800)
commitc20328e7cad2989bcdc9ff5003d6a16405c31ab5
tree837db6d6d15e763947916017b122788e30ea1e59
parent15cb5204e4c5f79d1b7179ae2590bb65e24b745f
compiler: move lowering pass after check types pass

This change 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.

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/536643
13 files changed:
gcc/go/gofrontend/MERGE
gcc/go/gofrontend/expressions.cc
gcc/go/gofrontend/expressions.h
gcc/go/gofrontend/go.cc
gcc/go/gofrontend/gogo.cc
gcc/go/gofrontend/gogo.h
gcc/go/gofrontend/parse.cc
gcc/go/gofrontend/runtime.cc
gcc/go/gofrontend/statements.cc
gcc/go/gofrontend/statements.h
gcc/go/gofrontend/types.cc
gcc/go/gofrontend/types.h
gcc/go/gofrontend/wb.cc