aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/types2
AgeCommit message (Collapse)Author
2021-08-26cmd/compile/internal/types2: remove need for instance (struct)Robert Griesemer
instance was only used to hold the instantiation position for lazy instantiation (and encode the fact that we have a lazy instantiation). Just use a (pointer to a) syntax.Pos instead. We could use a syntax.Pos (no pointer) and rely on the fact that we have a known position (or fake position, if need be) to indicate lazy instantiation. But using a pointer leads to a smaller Named struct. Change-Id: I441a839a125f453ad6c501de1ce499b72a2f67a4 Reviewed-on: https://go-review.googlesource.com/c/go/+/345177 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-08-26cmd/compile/internal/types2: address some TODOs (cleanup)Robert Griesemer
- Address some easy TODOs. - Remove some TODOs that are not correct anymore or are unimportent. - Simplify some code on the way. Change-Id: I4d20de3725b3a735022afe022cbc002b2798936d Reviewed-on: https://go-review.googlesource.com/c/go/+/345176 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-08-25cmd/compile/internal/types2: fix type set printing and add testRobert Griesemer
Change-Id: I44ca1f889b041467d5febacaf6037cfd75859175 Reviewed-on: https://go-review.googlesource.com/c/go/+/344873 Trust: Robert Griesemer <gri@golang.org> Trust: Dan Scales <danscales@google.com> Reviewed-by: Dan Scales <danscales@google.com>
2021-08-25cmd/compile/internal/types2: rename IsMethodSet to IsConstraint (cleanup)Robert Griesemer
Invert the boolean result to match the new name. Change-Id: Ide6c649ed8ac3a5d263640309960e61a005c886e Reviewed-on: https://go-review.googlesource.com/c/go/+/344872 Trust: Robert Griesemer <gri@golang.org> Trust: Dan Scales <danscales@google.com> Reviewed-by: Dan Scales <danscales@google.com>
2021-08-25cmd/compile: always accept 1.18 syntax but complain if not 1.18Robert Griesemer
This CL configures the parser to always accept 1.18 syntax (type parameters, type instantiations, interface elements), even when -lang is set to an earlier release. Instead, the type checker looks for 1.18 operations and complains if the language version is set to an earlier release. Doing these checks during type checking is necessary because it it is possible to write "generic" code using pre-1.18 syntax; for instance, an imported generic function may be implicitly instantiated (as in imported.Max(2, 3)), or an imported constraint interface may be embedded in an "ordinary" interface. Fixes #47818. Change-Id: I83ec302b3f4ba7196c0a4743c03670cfb901310d Reviewed-on: https://go-review.googlesource.com/c/go/+/344871 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-08-25go/types, types2: don't re-evaluate context string for each function ↵Robert Griesemer
argument (optimization) Change-Id: Ie1b4d5b64350ea42484adea14df84cacd1d2653b Reviewed-on: https://go-review.googlesource.com/c/go/+/344576 Trust: Robert Griesemer <gri@golang.org> Trust: Dan Scales <danscales@google.com> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Dan Scales <danscales@google.com>
2021-08-24cmd/compile/internal/types2: use TypeList in the Inferred structRobert Griesemer
This is a port of CL 343934 from go/types with the necessary adjustments to the compiler. Change-Id: I810144e6e2eb2bc8fa0d34dc206403c993cbbe7a Reviewed-on: https://go-review.googlesource.com/c/go/+/344616 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 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-24cmd/compile/internal/types2: use an opaque environment for InstantiateRobert Griesemer
This is a port of CL 343930 from go/types, adjusted to work for the compiler: here Environment carries a *Checker, if available. Change-Id: I44544fad7da870fa0c02832baa6abd2909d50304 Reviewed-on: https://go-review.googlesource.com/c/go/+/344612 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>
2021-08-24cmd/compile/internal/types2: don't export TypeSetRobert Griesemer
For now don't export TypeSet in the interest of keeping the types2 API surface small(er). This is a clean port of CL 341289 from go/types. Change-Id: I50c747629f25472f2ec5ba59d7f543ee3c1c423b Reviewed-on: https://go-review.googlesource.com/c/go/+/344610 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-23go/types: return an error from InstantiateRobert Findley
This is a port of CL 342152 to go/types. Additionally, a panic was removed from interface substitution, which is a fix from CL 333155 that was previously missed. A check for a nil Checker was also removed from types2.instantiate, since check must not be nil in that method. Change-Id: I4ea6bdccbd50ea2008ee6d870f702bee5cdd5a8e Reviewed-on: https://go-review.googlesource.com/c/go/+/342671 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-22cmd/compile/internal/types2: enable TestSelection API testRobert Griesemer
This test was never fully ported from go/types. Implement a conversion function from syntax.Pos to string index so that the test can be enabled again. Also renamed the local variable syntax to segment to avoid confusion with the syntax package. Change-Id: I1b34e50ec138403798efb14c828545780f565507 Reviewed-on: https://go-review.googlesource.com/c/go/+/344253 Trust: Robert Griesemer <gri@golang.org> Trust: Dan Scales <danscales@google.com> Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Dan Scales <danscales@google.com>
2021-08-22cmd/compile/internal/types2: report argument type for unsafe.OffsetOfRobert Griesemer
Before parameterized types, unsafe.OffsetOf was always evaluating to a constant. With parameterized types, the result may be a run-time value, and unsafe.OffsetOf(x.f) is a call that is recorded. Also record the argument x.f. Fixes #47895. Change-Id: Ia3da25028d4865d7295ce7990c7216bffe9e7c72 Reviewed-on: https://go-review.googlesource.com/c/go/+/344252 Trust: Robert Griesemer <gri@golang.org> Trust: Dan Scales <danscales@google.com> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Dan Scales <danscales@google.com>
2021-08-19cmd/compile/internal/types2: return an error from InstantiateRobert Findley
Change Instantiate to be a function (not a method) and return an error. Introduce an ArgumentError type to report information about which type argument led to an error during verification. This resolves a few concerns with the current API: - The Checker method set was previously just Files. It is somewhat odd to add an additional method for instantiation. Passing the checker as an argument seems cleaner. - pos, posList, and verify were bound together. In cases where no verification is required, the call site was somewhat cluttered. - Callers will likely want to access structured information about why type information is invalid, and also may not have access to position information. Returning an argument index solves both these problems; if callers want to associate errors with an argument position, they can do this via the resulting index. We may want to make the first argument an opaque environment rather than a Checker. Change-Id: I3bc56d205c13d832b538401a4c91d3917c041225 Reviewed-on: https://go-review.googlesource.com/c/go/+/342152 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-18cmd/compile/internal/types2: change Checker.verify to return an errorRobert Findley
In preparation for upcoming API changes, change the internal API for verification of type arguments to return an error and argument index, and use this to lift up error reporting into Instantiate. Change-Id: I88b1e64dd9055c4c20c0db49c96c79c5da894450 Reviewed-on: https://go-review.googlesource.com/c/go/+/342151 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-18cmd/compile/internal/types2: no need to validate substituted instancesRobert Findley
When substituting a type instance, we rely on the instance being expanded and do not call validType, so there is need to depend on subster.pos for error reporting or to use subst.check for creating the new Named type. Errors will be reported for the unsubstituted instance. This is a superficial change, but justifies some later simplification where we don't have access to pos or check. Change-Id: I1f3f12aa245d821512c6242ad829c940f20afae4 Reviewed-on: https://go-review.googlesource.com/c/go/+/342150 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
2021-08-18cmd/compile/internal/types2: consolidate verification logicRobert Findley
Change an internal call of instantiateLazy to call Instantiate, so that we can consolidate the logic for invoking verification. This made verification of signatures lazy, which is not necessary but should be harmless. Change-Id: I2e59b04ac859e08c2e2910ded3c183093d1e34a7 Reviewed-on: https://go-review.googlesource.com/c/go/+/342149 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-18cmd/compile/internal/types2: clean up panics in instantiationRobert Findley
Clean up a few issues related to panicking during invalid instantiation. - Panic early in instantiateLazy when check == nil and verify == true. Otherwise, we would panic at check.later. - Always panic when check == nil and verify == true, even if targs is of incorrect length. This is more consistent behavior. - Lift the check for len(posList) <= len(targs) out of Checker.instantiate. This is the only reason why posList is passed to that function, and doing this allows us to eliminate posList from instance. At this point instance is close to being unnecessary, so update a TODO to this effect. Change-Id: Id5f44cbb1a5897aef10ce2a573aa78acd7ae4026 Reviewed-on: https://go-review.googlesource.com/c/go/+/341862 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-17cmd/compile/internal/types2: fix method lookup for type-parameter based typesRobert Griesemer
Pointers to type parameters don't have methods, but pointers to defined types whose underlying types are type parameters may have methods. Fix the respective test. For #47747. Change-Id: I1de47be094ed9297f0e7782538011657c37c5adc Reviewed-on: https://go-review.googlesource.com/c/go/+/342990 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-17cmd/compile/internal/types2: allow composite literals of type parameter typeRobert Griesemer
Change-Id: Iaaa2a3b462da6b121f13a10595950a8502b5f271 Reviewed-on: https://go-review.googlesource.com/c/go/+/342690 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-08-16go/types,types2: superficial changes to align types and types2Robert Findley
This CL contains an assortment of superficial fixes noticed while self-reviewing the most recent stack of ports. It also makes a couple adjustments to termlist_test.go, in both go/types and cmd/compile/internal/types2. Change-Id: I64c8cda5e1704e86ac11c6ffc86d55248f44ef79 Reviewed-on: https://go-review.googlesource.com/c/go/+/342490 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-16cmd/compile/internal/types2: use the underlying TypeParam inRobert Findley
assignableTo In CL 338310, assignableTo was altered to walk the constituent types of TypeParams rather than Unions, but was not also adjusted to use under rather than optype. This manifested in the port to go/types. Change-Id: Ie057b96ce93cef204af88b536ea49344c9bc8f12 Reviewed-on: https://go-review.googlesource.com/c/go/+/342409 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-14cmd/compile/internal/types2: rename TypeParams to TParamListRobert Findley
The 'TypeParams' name is too easily confused with the singular 'TypeParam', and does not say anything about what type of collection it is. We decided that TTuple was not great. TParamList seems OK for now, though perhaps a better name will emerge. Change-Id: I5eabdc91b1f666bb4c7ea8acdbebf7c372d19227 Reviewed-on: https://go-review.googlesource.com/c/go/+/341861 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-14cmd/compile/internal/types2: remove targs from substMapRobert Findley
Now that we always capture targs when constructing an instance, we no longer need to pass them via the substMap. This simplifies the code and resolves a TODO. Change-Id: I592dccaeb89c7cc31ac037d919137bb762820365 Reviewed-on: https://go-review.googlesource.com/c/go/+/341859 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-14cmd/compile/internal/types2: use the orig object for Named.ObjRob Findley
Exposing a synthetic type name for instantiated types is problematic: there is no way to ensure that type instances are first created in the same type checking pass, and therefore no guarantee that their instantiation positions are the same. Even type checking a given package with different file ordering could result in different positions being associated with type instances. This is therefore an implementation detail that we should not expose. Keep the synthetic type name for accurate error reporting, but hide it in the API. Change-Id: I61f0e3ed322e97b157eb1ca316480f5719dcc174 Reviewed-on: https://go-review.googlesource.com/c/go/+/341858 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-14cmd/compile/internal/types2: simplify Named.underRob Findley
Remove some unnecessary logic from Named.under: - no need to have special handling for Typ[Invalid]: this is the same as other cases where the underlying type is resolved. - use Underlying() to get the loaded and expanded underlying - no need for special handling of the first iteration Change-Id: I2029711f51fa9eaaee11debadd55974a1376a980 Reviewed-on: https://go-review.googlesource.com/c/go/+/341857 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-14cmd/compile/internal/types2: define Identical for instancesRob Findley
Instantiation of parameterized types may occur in other packages, so we need an intrinsic notion of type identity for instances. Add the natural definition: two instances are identical if their bases and type arguments are identical. Type unification was already considering type arguments, but has some inaccurate logic with respect to objects. This will be addressed in a follow-up CL. Change-Id: Ib2ce67c05de65eb302ee588cc40c89c60018da50 Reviewed-on: https://go-review.googlesource.com/c/go/+/341856 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-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-11[dev.typeparams] cmd/compile/internal/types2: remove unused TypeParam.Bound ↵Robert Griesemer
method Use TypeParam.Constraint instead. Change-Id: Iebd77d304f2b7238baa231fb9869c964f66ea355 Reviewed-on: https://go-review.googlesource.com/c/go/+/340990 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-08-10[dev.typeparams] cmd/compile/internal/types2: remove Named.SetTArgsRob Findley
Calling SetTArgs without substituting can leave the type in incoherent state, so we should avoid exposing this API unless necessary. Since it is currently not used by the importer(s), it is probably not necessary to expose for 1.18, so remove it. Change-Id: I06bd7b5bbfacd3c65e2e66a9d5980f20cd1c10c1 Reviewed-on: https://go-review.googlesource.com/c/go/+/341290 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-10[dev.typeparams] cmd/compile/internal/types2: parameterized functions must ↵Robert Griesemer
have a body Add the respective check and add missing bodies to tests. Use {} as body for functions that don't return a result. Use { panic(0) } as body for functions that return a result. For #47069. Change-Id: Ia5d7525c9c036baf8a955d13bff448401e08235e Reviewed-on: https://go-review.googlesource.com/c/go/+/340911 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-08-10[dev.typeparams] cmd/compile/internal/types2: expand is only required for ↵Robert Griesemer
*Named types Now that the pointer identity for a *Named type doesn't change anymore when going from lazy instantiated to actually instantiated (= expanded) state, expand() only needs to be called when we deal with *Named types and only if we care about a *Named type's internals. Remove the expand function and respective calls for all types and replace with specific t.expand() method calls where t is a *Named. Change-Id: If82299360d60108b00adc4013b29399aec90b940 Reviewed-on: https://go-review.googlesource.com/c/go/+/340749 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-08-06[dev.typeparams] cmd/compile/internal/types2: remove Interface.Complete ↵Robert Griesemer
(cleanup) Interface.Complete is not needed anymore. We can remove it in types2 (and eventually make it an empty function in go/types, where we must maintain the existing API). Change-Id: I689f0d6f3a83997d8ca5bae773b9af0083d0bf4f Reviewed-on: https://go-review.googlesource.com/c/go/+/340255 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-06[dev.typeparams] cmd/compile/internal/types2: limit termlist lengthsRobert Griesemer
At the moment, operations on termlists are O(n^2). This is fine for normal-sized unions, but overlong termlist lenghts will lead to excessive type checking times. Limit the length of termlists to avoid "compilations that don't finish". Change-Id: I39a7fc61b01c9db06faeb49a0e014b1ede532710 Reviewed-on: https://go-review.googlesource.com/c/go/+/340254 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-06[dev.typeparams] cmd/compile: change types2.Union API to accept a list of TermsRobert Griesemer
Instead of providing a list of tildes and types, use a list of Terms to create a Union, with suitable accessors. Define the (exported) notion of a Term representing a union term. This simplified various uses and also will be easier to extend should we want to add more information to a Term in the future. Change-Id: I52fd73938bfa11bac60adbf10580b6d0680df4f1 Reviewed-on: https://go-review.googlesource.com/c/go/+/340250 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-06[dev.typeparams] cmd/compile/internal/types2: add defined type to ↵Robert Griesemer
term/termlist tests Follow-up on https://golang.org/cl/339596 . Change-Id: Ifa249379df083f80176b9f99900be0bf12483f41 Reviewed-on: https://go-review.googlesource.com/c/go/+/339905 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-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-06[dev.typeparams] cmd/compile/internal/types2: fix make with type parameter ↵Robert Griesemer
argument For make with a type parameter argument, the structural type of the type parameter's constraint determines what make is making. Change-Id: I3b48f8ce3236b7624e0638b5f5be208c5915c987 Reviewed-on: https://go-review.googlesource.com/c/go/+/339899 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-06[dev.typeparams] cmd/compile/internal/types2: fix range over exprs of type ↵Robert Griesemer
parameter type For range expressions of type parameter type, the structural type of the type parameter's constraint determines the range operation. While at it, rename implicitArrayDeref to arrayPtrDeref. Change-Id: Ib631a8a14e717498e5264944f659309df1f68cc2 Reviewed-on: https://go-review.googlesource.com/c/go/+/339897 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-06[dev.typeparams] cmd/compile/internal/types2: better names for things (cleanup)Robert Griesemer
- use the symbol 𝓤 (as in 𝓤niverse) instead of ⊤ to denote the set of all types (for better readabilty, ⊤ is hard to distinguish from T in some fonts) - use isAll instead of isTop to test for the set of all types - use allTermlist instead of topTermlist to denote the termlist representing all types Change-Id: Idcb0b3398782b38653338e65173c0dbb935e430a Reviewed-on: https://go-review.googlesource.com/c/go/+/339891 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: cleanup panic callsRobert Griesemer
End-users are not expected to deal with the details of panics, so providing extra information such as an "internal error" prefix or the name of the function invoking the panic are not helpful. Remove unnecessary panic verbiage if it is readily available from a stack trace (such as the function where it happens, and the fact that is is an "internal error"). Change-Id: I5f86bae6d2cca7c04ce692d17257da7ddee206d7 Reviewed-on: https://go-review.googlesource.com/c/go/+/339969 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-08-05[dev.typeparams] cmd/compile/internal/types2: remove ↵Robert Griesemer
TestIncompleteInterfaces (cleanup) TestIncompleteInterfaces is not useful anymore because interface printing always shows the syntactic type structure of an interface. Also remove the respective support code in interface printing and simplify that code. Move the newDefined and nopos support declarations unchanged into api_test.go where they are used. Updates #46167. Change-Id: I23e303bc4ae4271912ba75f201bd2b7cd4a17b3e Reviewed-on: https://go-review.googlesource.com/c/go/+/339832 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-08-05[dev.typeparams] cmd/compile/internal/types2: remove unused ↵Robert Griesemer
gcCompatibilityMode flag (cleanup) This flag is not needed by types2 (and possibly can also be removed from go/types). Removed some unnecessary comments along the way. Updates #46174. Change-Id: I1a7a99f724205a084d1c9850bce6f6f5d33f83ca Reviewed-on: https://go-review.googlesource.com/c/go/+/339831 Trust: Robert Griesemer <gri@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-08-04[dev.typeparams] cmd/compile/internal/types2: implement term listsRobert Griesemer
Prerequisite for clean implementation of type sets on top of term lists. Change-Id: Ice87f2f47327aa6b1f3eaad7f9af20ad7c548155 Reviewed-on: https://go-review.googlesource.com/c/go/+/339596 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-04[dev.typeparams] cmd/compile/internal/types2: fix a panic in missingMethodRob Findley
When static == false, missingMethod incorrectly continues with a nil Func. Also remove some unnecessary type names from typeterm_test.go, which was done in the go/types port. Change-Id: I21fa637ac82b115563d3601314a470a5a43f9ae0 Reviewed-on: https://go-review.googlesource.com/c/go/+/339672 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-08-02[dev.typeparams] cmd/compile/internal/types2: move instance.go contents into ↵Robert Griesemer
named.go (cleanup) This just moves the code around the instance type into named.go where it belongs. While at it, also removed some left-over references to instance types (which are gone). Removed instance.go. Change-Id: I302a86ca50675b0be54f6138fa47f48f00f9c98f Reviewed-on: https://go-review.googlesource.com/c/go/+/338469 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-08-02[dev.typeparams] cmd/compile/internal/types2: print constraint info for type ↵Robert Griesemer
param operands Change-Id: Ic7a249fc150b526835db744431bef500c20fbd26 Reviewed-on: https://go-review.googlesource.com/c/go/+/338309 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-07-29[dev.typeparams] go/types,cmd/compile/internal/types2: fix TypeParams.At docsMatthew Dempsky
Presumably the "It is safe to call on a nil receiver" comment was mistakenly copied from TypeParams.Len, which is actually safe to call on a nil receiver. Change-Id: Iec5ae32c98dc91ce84a6207b47f2b1e530bdbfe2 Reviewed-on: https://go-review.googlesource.com/c/go/+/338430 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Robert Griesemer <gri@golang.org>