aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/types2/typexpr.go
AgeCommit message (Collapse)Author
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-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: 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-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-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-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-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-16[dev.typeparams] cmd/compile/internal/types2: more consistent handling of ↵Robert Griesemer
predeclared "any" Rather than removing "any" from the universe scope, keep it predeclared but provide a better error message. While at it, remove some unnecessary type assertions. Change-Id: I10603274282ea6afc107f703ab194f32bd334dd1 Reviewed-on: https://go-review.googlesource.com/c/go/+/334911 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-07-13[dev.typeparams] cmd/compile/internal/types2: use InstantiateLazy to create ↵Robert Griesemer
instance types (cleanup) This change concentrates the creation is lazily instantiated types in one place (InstantiateLazy). This should also make it easier to replace the implementation of lazily instantiated types (e.g. getting rid of instance types). Change-Id: I452c463219b466ce79f227c44fb67b79d428842a Reviewed-on: https://go-review.googlesource.com/c/go/+/333669 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-07-13[dev.typeparams] cmd/compile/internal/types2: replace types2.Instantiate ↵Robert Griesemer
with Checker.Instantiate Allow Checker.Instantiate to work with a nil *Checker receiver (for now). This opens the door to passing in a *Checker at all times. Also, added a verify flag to Instantiate, InstantiateLazy, and instance, to be able to control if constraint satisfaction should be checked or not. Removed types2.Instantiate. For #47103. Change-Id: Ie00ce41b3e50a0fc4341e013922e5f874276d282 Reviewed-on: https://go-review.googlesource.com/c/go/+/333569 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-07-01[dev.typeparams] cmd/compile/internal/types2: rename newTypeSet -> ↵Robert Griesemer
computeTypeSet Follow-up on comment in https://golang.org/cl/329309. Change-Id: I31f746180237b916c1825fa1688641849478ba41 Reviewed-on: https://go-review.googlesource.com/c/go/+/332089 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-07-01[dev.typeparams] cmd/compile/internal/types2: "comparable" must not be ↵Robert Griesemer
visible before Go 1.18 While at it, clean up the setup of comparable in universe.go. Fixes #46090 Change-Id: I9655b3e137a03763d677d9a2a730c5570ccff6dc Reviewed-on: https://go-review.googlesource.com/c/go/+/331517 Trust: 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-04[dev.typeparams] cmd/compile: lazy import resolution for types2Matthew Dempsky
This CL adds three new functions to the types2 API to support lazy import resolution: 1. A new Scope.InsertLazy method to allow recording that Objects exist in a particular Scope (in particular, package scopes) without having to yet fully construct those objects. Instead, types2 will call the provided `resolve` function if/when the object is actually needed. 2. Similarly, a new NewTypeNameLazy function to create TypeName objects without yet instantiating their underlying Named instance. 3. Finally, an InstantiateLazy method, that allows creating type instances without requiring any of the types to be expanded right away. Importantly, this requires providing a types2.Checker argument to handle recursive types correctly. The APIs as-is are a bit clumsy (esp. NewTypeNameLazy), but seem to work well for cmd/compile's needs. In particular, they simplify some of the complexities of handling recursive type definitions within the importer. Also, the current prototype is a bit fragile. It uses sync.Once to manage concurrent lazy resolution, which is frustrating to debug in the presence of reentrancy issues. It also means the importer needs to deal with concurrency as well. These aren't issues for types2 though as cmd/compile only walks the type-checked AST sequentially. Finally, it looks like some of the details of lazy type names are similar to the lazy "instance" stuff used for generics, so maybe there's opportunity for unifying them under a more general (but still internal) lazy type mechanism. I had originally intended for this CL to also update the types2 importer, but (1) it doesn't have access to the types2.Checker instance needed to call InstantiateLazy, and (2) it creates a new TypeName/TypeParam at each use rather than reusing them, which evidently works with types2.Instantiate but not types2.(*Checker).instantiate (i.e., InstantiateLazy). I spent a while trying to fix these issues, but kept running into more subtle issues. Instead, I've included my WIP "unified IR" CL as a followup CL that demonstrates these Lazy methods (see noder/reader2.go). Updates #46449. Change-Id: I4d1e8e649f6325a11790d25fd90c39fa07c8d41d Reviewed-on: https://go-review.googlesource.com/c/go/+/323569 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Trust: Matthew Dempsky <mdempsky@google.com> Trust: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2021-05-21[dev.typeparams] cmd/compile/internal/types2: move signature checking into ↵Robert Griesemer
separate file This only moves functionality from one file into another. Except for import adjustments there are no changes to the code. Change-Id: Id0d20a7537f20abe3a257ad3f550b0cb4499598c Reviewed-on: https://go-review.googlesource.com/c/go/+/321590 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-05-21[dev.typeparams] cmd/compile/internal/types2: move struct checking into ↵Robert Griesemer
separate file This only moves functionality from one file into another. Except for import adjustments there are no changes to the code. Change-Id: I8dff41fe82693c96b09a152975c3fd1e3b439e8d Reviewed-on: https://go-review.googlesource.com/c/go/+/321589 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-05-21[dev.typeparams] cmd/compile/internal/types2: move interface checking into ↵Robert Griesemer
separate file This only moves functionality from one file into another. Except for import adjustments there are no changes to the code. Change-Id: Ia7d611d3a01c1ed3331dcc7cfe94a96f87b338e7 Reviewed-on: https://go-review.googlesource.com/c/go/+/321549 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-05-19[dev.typeparams] cmd/compile/internal/types2: implement package heightMatthew Dempsky
This CL extends types2 with package height information, styled after the way it works already in cmd/compile: - A new NewPackageHeight entry point for constructing packages with explicit height information, and a corresponding Height accessor method. - The types2 importer is updated to provide package height for imported packages. - The types2 type checker sets height based on imported packages. - Adds an assertion to irgen to verify that types1 and types2 calculated the same height for the source package. - Func.less's ordering incorporates package height to match types.Sym.less and is generalized to object.less. - sortTypes (used for sorting embedded types) now sorts defined types using object.less as well. Change-Id: Id4dbbb627aef405cc7438d611cbdd5a5bd97fc96 Reviewed-on: https://go-review.googlesource.com/c/go/+/321231 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Trust: Matthew Dempsky <mdempsky@google.com> Trust: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2021-05-19[dev.typeparams] cmd/compile/internal/types2: tweak anonymous parameter positionMatthew Dempsky
When declaring anonymous parameters, use the syntax.Field's Pos directly rather than its Type field's Pos. When the type expression is a qualified identifier (i.e., SelectorExpr), its Pos returns the position of the dot, whereas we typically declare the anonymous parameter at the starting position of the type. (We could equivalently use syntax.StartPos(field.Type), but we already have this as field.Pos().) Change-Id: If6ac9635b6e9c2b75a1989d5893a78e0b21cba88 Reviewed-on: https://go-review.googlesource.com/c/go/+/320611 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2021-04-22cmd/compile/internal/types2: avoid follow-on errors for invalid [...] arrayRobert Griesemer
Fixes #42987. Change-Id: Iaaa46e1f79525cd1e418c1a81a6414d11f8120b5 Reviewed-on: https://go-review.googlesource.com/c/go/+/311889 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-04-14cmd/compile/internal/types2: add Named.SetTParams and Named.Orig methodsRobert Griesemer
Named.SetTParams sets the type parameters for a named type. Named.Orig returns the original generic type an instantiated type is derived from. Added a new field orig for that purpose and renamed the already existing orig field to fromRHS. Finally, updated various comments. Change-Id: Ic9d173e42740422d195713d8bdc62a54dc8c5f54 Reviewed-on: https://go-review.googlesource.com/c/go/+/309832 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-04-07cmd/compile/internal/types2: remove Config.AcceptMethodTypeParams flagRobert Griesemer
Type parameters for methods are not part of the accepted language, but maintaining the code for type-checking them ensures regularity of the type checker implementation. For now, keep the flag internally, disabled by default. The flag is set when running tests. Change-Id: Ic99934bd00bd2608dc1178e4131f46dd1507f0f5 Reviewed-on: https://go-review.googlesource.com/c/go/+/307214 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-04-06cmd/compile/internal/types2: simplify Checker.funcInstRobert Griesemer
Now that we use square brackets for instantiations, we can tell type arguments from ordinary arguments without "guessing" which permits a simpler implementation. While at it, also fix a minor position error for type instantiations (now matching the code for function instantiations). Change-Id: I20eca51c5b06259703767b5906e89197d6cd595a Reviewed-on: https://go-review.googlesource.com/c/go/+/306169 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-04-06cmd/compile/internal/types2: review of pos.go and move into syntax packageRobert Griesemer
This moves the two helper functions startPos and endPos into the syntax package where they belong. Export the functions and adjust dependent code. Change-Id: I8170faeadd7cfa8f53009f81fcffd50ec0fc6a98 Reviewed-on: https://go-review.googlesource.com/c/go/+/305578 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-03-13cmd/compile/internal/types2: simplify error reporting API (cleanup)Robert Griesemer
- Remove specialized errorf functions for invalid AST/argument/operation. Instead use prefix constants with the error message. - Replace several calls to Checker.errorf with calls to Checker.error if there are no arguments to format. - Replace a handful of %s format verbs with %v to satisfy vet check. - Add a basic test that checks that we're not using Checker.errorf when we should be using Checker.error. Change-Id: I7bc7c14f3cf774689ec8cd5782ea31b6e30dbcd6 Reviewed-on: https://go-review.googlesource.com/c/go/+/300995 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-03-10cmd/compile/internal/types2: remove concept of finalsRobert Griesemer
This is a 1:1 port of the respective change in go/types in https://golang.org/cl/299590. Change-Id: I65ad723f2e21e3d95fc0b94665e0121e31871a48 Reviewed-on: https://go-review.googlesource.com/c/go/+/300250 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-03-10cmd/compile/internal/types2: better error reporting framework (starting point)Robert Griesemer
Until now, errors which came with additional details (e.g., a declaration cycle error followed by the list of objects involved in the cycle, one per line) were reported as an ordinary error followed by "secondary" errors, with the secondary errors marked as such by having a tab-indented error message. This approach often required clients to filter these secondary errors (as they are not new errors, they are just clarifying a previously reported error). This CL introduces a new internal error_ type which permits accumulating various error information that may then be reported as a single error. Change-Id: I25b2f094facd37e12737e517f7ef8853d465ff77 Reviewed-on: https://go-review.googlesource.com/c/go/+/296689 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-03-02all: fix spellingJohn Bampton
Change-Id: Iad14571c3e19b01740cd744f0b3025b3e2f1cb72 GitHub-Last-Rev: e8064019299f4e593116060ce2bbd14d62830af7 GitHub-Pull-Request: golang/go#44685 Reviewed-on: https://go-review.googlesource.com/c/go/+/297409 Trust: Alberto Donizetti <alb.donizetti@gmail.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-02-18[dev.typeparams] cmd/compile/internal/types2: minor adjustments to match ↵Robert Griesemer
go/types more closely Change-Id: Ib0144e0dd33e9202037e461a85f72f5db08ebd3a Reviewed-on: https://go-review.googlesource.com/c/go/+/293631 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-18[dev.typeparams] cmd/compile/internal/types2: replace Named, TypeParam ↵Robert Griesemer
methods with functions This removes two more converter methods in favor of functions. This further reduces the API surface of types2.Type and matches the approach taken in go/types. Change-Id: I3cdd54c5e0d1e7664a69f3697fc081a66315b969 Reviewed-on: https://go-review.googlesource.com/c/go/+/293292 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-02-18[dev.typeparams] cmd/compile/internal/types2: use converter functions rather ↵Robert Griesemer
than methods This change replaces methods with functions to reduce the API surface of types2.Type and to match the approach taken in go/types. The converter methods for Named and TypeParam will be addressed in a follow-up CL. Also: Fixed behavior of optype to return the underlying type for arguments that are not type parameters. Change-Id: Ia369c796754bc33bbaf0c9c8478badecb729279b Reviewed-on: https://go-review.googlesource.com/c/go/+/293291 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-02-10[dev.typeparams] cmd/compile/internal/types2: overlapping embedded ↵Robert Griesemer
interfaces requires go1.14 Add respective check to type checker. Enables another excluded test in test/run.go. This CL completes the currently required checks for language compatibility in types2. Updates #31793. Change-Id: Icececff9e6023d38f600c93bcb54cdcafcf501b9 Reviewed-on: https://go-review.googlesource.com/c/go/+/290911 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-01-27[dev.typeparams] cmd/compile/internal/types2: report unused packages in ↵Robert Griesemer
source order 1) Rather than map-iterate through all file scopes and collect unused packages, collect all imports in the Checker.imports list so that errors are reported in source order. 2) From cmd/compile, borrow the idea of a "dotImportRefs" map to map dot-imported objects to the package they were dot-imported through (we call the map "dotImportMap"). 3) From cmd/compile, borrow the "pkgnotused" function (called Checker.errorUnusedPkg in this code) and clean up unused package error reporting. 4) Adjust unused package error message to match compiler message exactly. 5) Enable one more excluded test case in test/run.go. Change-Id: I4e4e55512a6043a7fd54f576c7441e3dd4077d6f Reviewed-on: https://go-review.googlesource.com/c/go/+/287072 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-01-23[dev.typeparams] cmd/compile/internal/types2: use same sort criteria for ↵Robert Griesemer
methods as compiler Note: This invalidates the implementation of MethodSet further (it also has not been updated to accomodate for type parameters). But types2 doesn't make use of it. We should remove it. Change-Id: Ia2601bdd59b3f3ee0b72bc2512153c42bf5053b5 Reviewed-on: https://go-review.googlesource.com/c/go/+/285994 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-01-23[dev.typeparams] cmd/compile/internal/types2: factor out sorting of methodsRobert Griesemer
Cleanup and first step towards uniformly changing the sort criteria. Change-Id: I0a7b6a10b5b646fc83f4897e4915ef4dae24aa66 Reviewed-on: https://go-review.googlesource.com/c/go/+/285993 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-01-20[dev.typeparams] cmd/compile/internal/types2: report type of nil based on ↵Robert Griesemer
context With this CL, the type reported for uses of the predeclared identifier nil changes from untyped nil to the type of the context within which nil is used, matching the behaviour of types2 for other untyped types. If an untyped nil value is assigned or converted to an interface, the nil expression is given the interface type. The predicate TypeAndValue.IsNil doesn't change in behavior, it still reports whether the relevant expression is a (typed or untyped) nil value. Change-Id: Id766468f3f3f2a53e4c55e1e6cd521e459c4a94f Reviewed-on: https://go-review.googlesource.com/c/go/+/284218 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-01-14[dev.typeparams] cmd/compile/internal/types2: better error message for ↵Robert Griesemer
invalid ... use This partially addresses the issue below: In many (all) cases we want to handle invalid ... use in the parser as a syntax error; but this ensures that we get a decent error if we get here anyway. Updates #43680. Change-Id: I93af43a5f5741d8bc76e7a13c0db75e6edf43111 Reviewed-on: https://go-review.googlesource.com/c/go/+/283475 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-01-11[dev.typeparams] cmd/compile/internal/types2: fixes for all.bashMatthew Dempsky
This CL implements a number of minor fixes that were discovered in getting -G=3 working for running all.bash. 1. Field tags were handled incorrectly. If a struct type had some fields with tags, but later fields without tags, the trailing tag-less fields would all copy the tag of the last tagged field. Fixed by simply reinitializing `tag` to "" for each field visited. 2. Change the ending of switch case clause scopes from the end of the last statement to the next "case" token or the switch-ending "}" token. I don't think this is strictly necessary, but it matches my intuition about where case-clause scopes end and cmd/compile's current scoping logic (admittedly influenced by the former). 3. Change select statements to correctly use the scope of each individual communication clause, instead of the scope of the entire select statement. This issue appears to be due to the original go/types code being written to rebind "s" from the *SelectStmt to the Stmt in the range loop, and then being further asserted to "clause" of type *CommClause. In most places within the loop body, "clause" was used, but the rebound "s" identifier was used for the scope boundaries. However, in the syntax AST, SelectStmt directly contains a []*CommClause (rather than a *BlockStmt, with []Stmt), so no assertion is necessary and instead of rebinding "s", the range loop was updated to directly declare "clause". 4. The end position for increment/decrement statements (x++/x--) was incorrectly calculated. Within the syntax AST, these are represented as "x += ImplicitOne", and for AssignStmts types2 calculated the end position as the end position of the RHS operand. But ImplicitOne doesn't have any position information. To workaround this, this CL detects ImplicitOne and then computes the end position of the LHS operand instead, and then adds 2. In practice this should be correct, though it could be wrong for ill-formatted statements like "x ++". Change-Id: I13d4830af39cb3f3b9f0d996672869d3db047ed2 Reviewed-on: https://go-review.googlesource.com/c/go/+/282914 Trust: Matthew Dempsky <mdempsky@google.com> Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2021-01-06[dev.typeparams] cmd/compile/internal/types2: remove disabled code related ↵Robert Griesemer
to type lists Earlier (contract-based) versions of the generics design restricted the kind of types that could be used in a type list - the current design does not have these restrictions anymore. Remove the respective checking code. Change-Id: Ia333f7aa8a9c31a92c08acbd5cadba3532a455b6 Reviewed-on: https://go-review.googlesource.com/c/go/+/281546 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-01-06[dev.typeparams] cmd/compile/internal/types2: review of typexpr.goRobert Griesemer
This code matches go/types/typexpr but for the necessary adjustments because of the use of package syntax rather than go/ast, and for the code being part of cmd/compile/internal/types2 rather than go/types. Primary differences to go.types/typexpr.go: - syntax.FuncType doesn't carry type parameters - type instantiations are represented using syntax.IndexExpr nodes - there's an explicit syntax.SliceType - *x is expressed as a unary operation, not a StarExpr - grouped fields are identified by identical pointer types To see the changes copied from recent go/types changes, compare Patchsets 1 and 2. Change-Id: I8aa9452882d1f5e9529c52a30c7c8e65f3fcbb43 Reviewed-on: https://go-review.googlesource.com/c/go/+/281545 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>
2020-12-14[dev.typeparams] cmd/compile/internal/types2: report error for invalid type ↵Robert Griesemer
expression This bug was introduced by the change from go/ast to syntax which represents pointer types as (unary) operations rather than dedicated StarExpr nodes. Accordingly, this bug does not exist for go/types. It's still ok to backport the test. Fixes #43125. Change-Id: Ic55d913f8afc92862856e1eb7c2861d07fc56cfb Reviewed-on: https://go-review.googlesource.com/c/go/+/278013 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org>
2020-12-14[dev.typeparams] cmd/compile/internal/types2: don't report two errors for ↵Robert Griesemer
bad strings If the parser reported an error for (string) literals, don't report a second error during type checking. This should have a couple of tests but they are tricky to arrange with the current testing framework as the ERROR comment cannot be on the line where the string. But the change is straightforward and we have test/fixedbugs/issue32133.go that is passing now. Change-Id: I0cd7f002b04e4092b8eb66009c7413288c8bfb23 Reviewed-on: https://go-review.googlesource.com/c/go/+/277993 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org>
2020-12-03[dev.typeparams] cmd/compile/internal/types: adjust some error messages to ↵Robert Griesemer
match the compiler Change-Id: I04bd7b294de4ed0fb01bc0609e09debea2d797bd Reviewed-on: https://go-review.googlesource.com/c/go/+/274974 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>
2020-12-02[dev.typeparams] cmd/compile/internal/types2: set compiler error message for ↵Robert Griesemer
undeclared variable Change-Id: Ie2950cdc5406915935f114bfd97ef03d965f9069 Reviewed-on: https://go-review.googlesource.com/c/go/+/274616 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org>
2020-12-01[dev.typeparams] cmd/compile/internal/types2: adjustments toward matching ↵Robert Griesemer
compiler error messages In order to get types2 usable by the compiler, we need to pass all the compiler tests with respect to error messages. Sometimes the compiler error messages are better, sometimes the types2 error messages are better. Where we can, we decide on a case-by-case basis; but sometimes, for expediency's sake, we just choose the compiler error message as it may reduce the amount of tests that we need to update. This CL introduces a new Config flag: CompilerErrorMessages. If set, the typechecker emits an error message that matches the expected errors in the tests most easily. Eventually, we need to get rid of this flag by either adjusting the typechecker errors or the test cases; t.b.d. on a case-by-case basis. This CL also adjust a few error typechecker error messages already. Change-Id: I9d4e491efadf87e999fc0d5b5151ec02a059f891 Reviewed-on: https://go-review.googlesource.com/c/go/+/274312 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2020-12-01[dev.typeparams] cmd/compile/internal/types2: remove support for type ↵Robert Griesemer
parameter pointer designation An earlier version of the draft design supported pointer designation for type parameters. Remove related code since we don't need it anymore. Change-Id: I0d9e8c5f02a9a6745ff7ee15b8267a99ab1529e1 Reviewed-on: https://go-review.googlesource.com/c/go/+/273327 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>
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>