Skip to content

Commit e8d4c7e

Browse files
griesemerjproberts
authored andcommitted
go/types, types2: remove special case for external types in validType
Because validType doesn't modify global state anymore, there's no need to ignore imported types. When we start tracking type parameters, we need to include imported types because they may contribute to cycles that invalidate a type. This CL effectively reverts CL 202483 (issue golang#35049, which doesn't apply anymore because we don't change the state of imported objects). Preparation for fixing issue golang#48962. For golang#35049. For golang#48962. Change-Id: I06f15575ad197375c74ffd09c222250610186b15 Reviewed-on: https://go-review.googlesource.com/c/go/+/378675 Trust: Robert Griesemer <[email protected]> Run-TryBot: Robert Griesemer <[email protected]> Reviewed-by: Robert Findley <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 6a4a407 commit e8d4c7e

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

src/cmd/compile/internal/types2/validtype.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,6 @@ func (check *Checker) validType0(typ Type, path []Object) typeInfo {
6060
// will terminate.
6161
t = t.orig
6262

63-
// don't touch the type if it is from a different package or the Universe scope
64-
// (doing so would lead to a race condition - was issue #35049)
65-
if t.obj.pkg != check.pkg {
66-
return valid
67-
}
68-
6963
// don't report a 2nd error if we already know the type is invalid
7064
// (e.g., if a cycle was detected earlier, via under).
7165
if t.underlying == Typ[Invalid] {
@@ -76,17 +70,25 @@ func (check *Checker) validType0(typ Type, path []Object) typeInfo {
7670
switch check.infoMap[t] {
7771
case unknown:
7872
check.infoMap[t] = marked
79-
check.infoMap[t] = check.validType0(t.fromRHS, append(path, t.obj)) // only types of current package added to path
73+
check.infoMap[t] = check.validType0(t.fromRHS, append(path, t.obj))
8074
case marked:
8175
// cycle detected
8276
for i, tn := range path {
77+
// Even though validType now can hande cycles through external
78+
// types, we can't have cycles through external types because
79+
// no such types are detected yet.
80+
// TODO(gri) Remove this check once we can detect such cycles,
81+
// and adjust cycleError accordingly.
8382
if t.obj.pkg != check.pkg {
8483
panic("type cycle via package-external type")
8584
}
8685
if tn == t.obj {
8786
check.cycleError(path[i:])
8887
check.infoMap[t] = invalid
89-
t.underlying = Typ[Invalid]
88+
// don't modify imported types (leads to race condition, see #35049)
89+
if t.obj.pkg == check.pkg {
90+
t.underlying = Typ[Invalid]
91+
}
9092
return invalid
9193
}
9294
}

src/go/types/validtype.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,6 @@ func (check *Checker) validType0(typ Type, path []Object) typeInfo {
6060
// will terminate.
6161
t = t.orig
6262

63-
// don't touch the type if it is from a different package or the Universe scope
64-
// (doing so would lead to a race condition - was issue #35049)
65-
if t.obj.pkg != check.pkg {
66-
return valid
67-
}
68-
6963
// don't report a 2nd error if we already know the type is invalid
7064
// (e.g., if a cycle was detected earlier, via under).
7165
if t.underlying == Typ[Invalid] {
@@ -76,17 +70,25 @@ func (check *Checker) validType0(typ Type, path []Object) typeInfo {
7670
switch check.infoMap[t] {
7771
case unknown:
7872
check.infoMap[t] = marked
79-
check.infoMap[t] = check.validType0(t.fromRHS, append(path, t.obj)) // only types of current package added to path
73+
check.infoMap[t] = check.validType0(t.fromRHS, append(path, t.obj))
8074
case marked:
8175
// cycle detected
8276
for i, tn := range path {
77+
// Even though validType now can hande cycles through external
78+
// types, we can't have cycles through external types because
79+
// no such types are detected yet.
80+
// TODO(gri) Remove this check once we can detect such cycles,
81+
// and adjust cycleError accordingly.
8382
if t.obj.pkg != check.pkg {
8483
panic("type cycle via package-external type")
8584
}
8685
if tn == t.obj {
8786
check.cycleError(path[i:])
8887
check.infoMap[t] = invalid
89-
t.underlying = Typ[Invalid]
88+
// don't modify imported types (leads to race condition, see #35049)
89+
if t.obj.pkg == check.pkg {
90+
t.underlying = Typ[Invalid]
91+
}
9092
return invalid
9193
}
9294
}

0 commit comments

Comments
 (0)