aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/types2/infer.go
AgeCommit message (Collapse)Author
2021-08-24cmd/compile/internal/types2: use a TypeList type to hold type argumentsRobert Griesemer
This is a port of CL 343933 from go/types with the necessary adjustments in the compiler. With this CL type parameters and type lists are now held in TParamList and TypeList data types which don't expose the internal representation. Change-Id: I6d60881b5db995dbc04ed3f4a96e8b5d41f83969 Reviewed-on: https://go-review.googlesource.com/c/go/+/344615 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Dan Scales <danscales@google.com>
2021-08-24cmd/compile/internal/types2: use []*TypeParam rather than []*TypeName for ↵Robert Griesemer
type param lists This is a port of CL 343932 from go/types, with the necessary adjustments to the compiler. This change improves type safety slightly, avoids many internal type assertions, and simplifies some code paths. Change-Id: Ie9c4734814f49cd248927152d7b3264d3578428c Reviewed-on: https://go-review.googlesource.com/c/go/+/344614 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Dan Scales <danscales@google.com>
2021-08-14cmd/compile/internal/types2: merge Instantiate and InstantiateLazyRob Findley
Instantiate and InstantiateLazy have the same signature; on first principles, if Instantiate should work for importers it should be possible to consolidate these APIs. This CL does this. In order to make it work, a typMap needs to be threaded through type expansion to prevent infinite recursion in the case that the Checker is nil. Notably, Named types now must be expanded before returning from Underlying(). This makes Underlying generally unsafe to call while type checking a package, so a helper function safeUnderlying is added to provide the previous behavior. This is probably overly conservative at most call sites, but cleanup is deferred to a later CL. Change-Id: I03cfb75bea0750862cd6eea4e3cdc875a7daa989 Reviewed-on: https://go-review.googlesource.com/c/go/+/341855 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2021-08-06[dev.typeparams] cmd/compile/internal/types2: minor cleanup of writeTParamListRobert Griesemer
Change-Id: Iaa58b17ad65e93548bb3da8231e0cb6da0c48105 Reviewed-on: https://go-review.googlesource.com/c/go/+/339903 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-08-05[dev.typeparams] cmd/compile/internal/types2: implement type sets with term ↵Robert Griesemer
lists This CL resolves several known issues and TODOs. - Represent type sets with term lists and using term list abstractions. - Represent Unions internally as a list of (syntactical) terms. Use term operations to print terms and detect overlapping union entries. - Compute type sets corresponding to unions lazily, on demand. - Adjust code throughout. - Adjusted error check in test/typeparam/mincheck.dir/main.go to make test pass. Change-Id: Ib36fb7e1d343c2b6aec51d304f0f7d1ad415f999 Reviewed-on: https://go-review.googlesource.com/c/go/+/338310 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-07-29[dev.typeparams] cmd/compile/internal/types2: use type terms to represent unionsRobert Griesemer
This is just an internal representation change for now. Change-Id: I7e0126e9b17850ec020c2a60db13582761557bea Reviewed-on: https://go-review.googlesource.com/c/go/+/338092 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-07-28[dev.typeparams] cmd/compile/internal/types2: merge instance and Named to ↵Rob Findley
eliminate sanitization This is a port of CL 335929 to types2. It differs significantly from that CL to handle lazy loading, which wasn't tested in go/types. Additionally, the *Checker field was moved out of instance and back onto Named. This way we can tell whether a Named type is uninstantiated simply by checking whether Named.instance is non-nil, which simplified the code considerably. Fixes #46151 Change-Id: I617263bcfaa768ac5442213cecad8d567c2749fc Reviewed-on: https://go-review.googlesource.com/c/go/+/336252 Trust: Robert Findley <rfindley@google.com> Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2021-07-22[dev.typeparams] cmd/compile/internal/types2: adjust ↵Robert Griesemer
unsafe.Alignof/Offsetof/Sizeof Changed the implementation such that the result is a variable rather than a constant if the argument type (or the struct in case of unsafe.Offsetof) has a size that depends on type parameters. Minor unrelated adjustments. For #40301. Change-Id: I1e988f1479b95648ad95a455c764ead829d75749 Reviewed-on: https://go-review.googlesource.com/c/go/+/335413 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-06-30[dev.typeparams] cmd/compile/internal/types2: remove unused *Checker ↵Robert Griesemer
arguments (cleanup) Simplified names and unnecessary function indirections where possible. Change-Id: I1c7a386393d086fd7ad29f892e03f048781f3547 Reviewed-on: https://go-review.googlesource.com/c/go/+/331512 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-06-30[dev.typeparams] cmd/compile/internal/types2: introduce type set abstraction ↵Robert Griesemer
for interfaces With this change, interfaces are "completed" on-demand, when needed, and the respective information (set of all methods, type constraints) is recorded in a new typeSet data structure. As a consequence, interfaces don't need to be explicitly completed anymore and (internal) uses of interfaces have become much simpler. This change also introduces a new field Interface.complete to indicate that all methods and embedded elements have been set up. This prevent the computation and recording (!) of a partial type set for erroneous programs (if we compute the partial type set and store it, subsequent type set accesses use the wrong type set which may lead to follow-on errors). Change-Id: I1ffc907f7d0fb93b3e987fe5ff9c6fa5cae00d7f Reviewed-on: https://go-review.googlesource.com/c/go/+/329309 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-06-02[dev.typeparams] cmd/compile/internal/types2: eliminate need for unpack and ↵Robert Griesemer
asUnion functions Change-Id: Iaa75b091d52f44939330e5945305aea323ba58f4 Reviewed-on: https://go-review.googlesource.com/c/go/+/323355 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-06-02[dev.typeparams] cmd/compile/internal/types2: replace Sum type with Union typeRobert Griesemer
- We still mostly ignore the tilde information. - More consistent naming: A Union term is the pair (type, tilde). Rename Union.terms to Union.types; the Union.types and Union.tilde slices make up the Union terms. - Replace Sum.is with Union.underIs: underIs iterates through all union terms and calls its argument function with the underlying type of the term (and thus can ignore the tilde information). This also eliminates the need to call under in the argument function. - Added Union.is for situations where we need to consider the tilde information for each Union term. Change-Id: I70fcf1813e072651dc0f61d52d5555642ee762fd Reviewed-on: https://go-review.googlesource.com/c/go/+/323274 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-05-24[dev.typeparams] cmd/compile/internal/types2: accept embedded interface elementsRobert Griesemer
Accept embedded interface elements of the form ~T or A|B and treat them like type lists: for now the elements of a union cannot be interfaces. Also, translate existing style "type"- lists in interfaces into interface elements: "type a, b, c" becomes a union element "~a|~b|~c" which in turn is handled internally like a type list. For now, "~" is still ignored and type lists are mapped to Sum types as before, thus ensuring that all existing tests work as before (with some minor adjustments). Introduced a new Union type to represent union elements. For now they don't make it past interface completion where they are represented as a Sum type. Thus, except for printing (and the respective tests) and substitution for interfaces, the various type switches ignore Union types. In a next step, we'll replace Sum types with union types and then consider the ~ functionality as well. Because union elements are no different from embedded interfaces we don't need a separate Interface.types field anymore. Removed. For #45346. Change-Id: I98ac3286aea9d706e98aee80241d4712ed99af08 Reviewed-on: https://go-review.googlesource.com/c/go/+/321689 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-05-07cmd/compile/internal/types2: add test case for issue 45985Robert Griesemer
This is a port of https://golang.org/cl/317471. Updates #45985. Change-Id: I539d0fa6f9a77eb2fc169a21c5db9921f8eceb03 Reviewed-on: https://go-review.googlesource.com/c/go/+/317732 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-04-21cmd/compile/internal/types2: fix type inferenceRobert Griesemer
Don't let type parameters that are not filled in with concrete type arguments escape from constraint type inference - such inferred types are not "real". While at it, implement a tparamsList.String method for debugging. Fixes #45548. Change-Id: I40f13ff7af08d0357a5c66234bfcdd0b7ed5fdd6 Reviewed-on: https://go-review.googlesource.com/c/go/+/311651 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-04-07cmd/compile/internal/types2: combine two loops (cleanup of TODO)Robert Griesemer
Follow-up on https://golang.org/cl/306170. Change-Id: I71b451382b6780101a0c94174ebe579e8a0684c2 Reviewed-on: https://go-review.googlesource.com/c/go/+/307949 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-04-07cmd/compile/internal/types2: remove Config.InferFromConstraints flagRobert Griesemer
Constraint type inference is part of the proposed language. Use an internal flag to control the feayure for debugging. Change-Id: I7a9eaee92b5ffc23c25d9e68a729acc0d705e879 Reviewed-on: https://go-review.googlesource.com/c/go/+/306770 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-04-07cmd/compile/internal/types2: combine all type inference in a single functionRobert Griesemer
Rather than splitting up type inference into function argument and constraint type inference, provide a single Checker.infer that accepts type parameters, type arguments, value parameters, and value arguments, if any. Checker.infer returns the completed list of type arguments, or nil. Updated (and simplified) call sites. Change-Id: I9200a44b9c4ab7f2d21eed824abfffaab68ff766 Reviewed-on: https://go-review.googlesource.com/c/go/+/306170 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-02-18[dev.typeparams] cmd/compile/internal/types2: remove Type.Under method in ↵Robert Griesemer
favor of function This removes the need for the aType embedded type and brings the types2.Type API in sync with the go/types.Type API. For reasons not fully understood yet, introducing the new under function causes a very long initialization cycle error, which doesn't exist in go/types. For now, circumvent the problem through a helper function variable. This CL also eliminates superflous (former) Under() method calls inside optype calls (optype takes care of this). Plus some minor misc. cleanups and comment adjustments. Change-Id: I86e13ccf6f0b34d7496240ace61a1c84856b6033 Reviewed-on: https://go-review.googlesource.com/c/go/+/293470 Reviewed-by: Robert Findley <rfindley@google.com> Trust: Robert Griesemer <gri@golang.org>
2021-02-12[dev.typeparams] cmd/compile/internal/types: review of infer.goRobert Griesemer
The changes between (equivalent, and reviewed) go/types/infer.go and infer.go can be seen by comparing patchset 1 and 2. The actual change is just removing the "// UNREVIEWED" marker and fixing a few comments. Change-Id: Ieb0c07c325a2e446550f85b159f99d4dfe5f1d5a Reviewed-on: https://go-review.googlesource.com/c/go/+/291171 Reviewed-by: Robert Findley <rfindley@google.com> Trust: Robert Griesemer <gri@golang.org>
2020-10-27[dev.typeparams] cmd/compile: enable type-checking of generic codeRobert Griesemer
This change makes a first connection between the compiler and types2. When the -G flag is provided, the compiler accepts code using type parameters; with this change generic code is also type-checked (but then compilation ends). Change-Id: I0fa6f6213267a458a6b33afe8ff26869fd838a63 Reviewed-on: https://go-review.googlesource.com/c/go/+/264303 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-10-21[dev.typeparams] cmd/compile/internal/importer, types2: initial check-in of ↵Robert Griesemer
types2 and importer This is a copy of the importer and types2 (unreviewed) prototype version excluding the testdata directory containing tests (see below). Each file is marked with the comment // UNREVIEWED on the first line. The plan is to check in this code wholesale (it runs and passes all tests) and then review the code file-by-file via subsequent CLs and remove the "// UNREVIEWED" comments as we review the files. Since most tests are unchanged from the original go/types, the next CL will commit those tests as they don't need to be reviewed again. (Eventually we may want to factor them out and share them from a single place, e.g. the test directory.) The existing file fmtmap_test.go was updated. Change-Id: I9bd0ad1a7e7188b501423483a44d18e623c0fe71 Reviewed-on: https://go-review.googlesource.com/c/go/+/263624 Trust: Robert Griesemer <gri@golang.org> Trust: Keith Randall <khr@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>