Skip to content

Commit 1a563d4

Browse files
committed
Make the creation of generic environments for opaque archetype eager.
We don't need lazy creation of generic environments for opaque archetypes, because they don't do much work up front. Make it eager, so we can move away from delayed generic environment creation entirely.
1 parent 183cf58 commit 1a563d4

File tree

3 files changed

+5
-18
lines changed

3 files changed

+5
-18
lines changed

include/swift/AST/Types.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5647,14 +5647,9 @@ class OpenedArchetypeType final : public ArchetypeType,
56475647
friend TrailingObjects;
56485648
friend ArchetypeType;
56495649

5650-
mutable GenericEnvironment *Environment = nullptr;
56515650
TypeBase *Opened;
56525651
UUID ID;
56535652

5654-
/// Create a generic environment with this opened type bound to its generic
5655-
/// parameter.
5656-
GenericEnvironment *createGenericEnvironment() const;
5657-
56585653
public:
56595654
/// Create a new archetype that represents the opened type
56605655
/// of an existential value.

lib/AST/ASTContext.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4319,16 +4319,13 @@ CanOpenedArchetypeType OpenedArchetypeType::get(Type existential,
43194319
GenericTypeParamType::get(/*type sequence*/ false,
43204320
/*depth*/ 0, /*index*/ 0, ctx);
43214321

4322+
auto signature = ctx.getOpenedArchetypeSignature(existential);
4323+
result->Environment = GenericEnvironment::forOpenedExistential(
4324+
signature, result);
4325+
43224326
openedExistentialArchetypes[*knownID] = result;
4323-
return CanOpenedArchetypeType(result);
4324-
}
43254327

4326-
GenericEnvironment *OpenedArchetypeType::createGenericEnvironment() const {
4327-
auto thisType = const_cast<OpenedArchetypeType*>(this);
4328-
auto &ctx = thisType->getASTContext();
4329-
// Create a generic environment to represent the opened type.
4330-
auto signature = ctx.getOpenedArchetypeSignature(Opened);
4331-
return GenericEnvironment::forOpenedExistential(signature, thisType);
4328+
return CanOpenedArchetypeType(result);
43324329
}
43334330

43344331
CanType OpenedArchetypeType::getAny(Type existential) {

lib/AST/Type.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3215,11 +3215,6 @@ GenericEnvironment *ArchetypeType::getGenericEnvironment() const {
32153215
return Environment;
32163216
}
32173217

3218-
// Opened archetypes lazily create their generic environment.
3219-
if (auto opened = dyn_cast<OpenedArchetypeType>(this)) {
3220-
return Environment = opened->createGenericEnvironment();
3221-
}
3222-
32233218
// Nested archetypes get their environment from their root.
32243219
if (auto nested = dyn_cast<NestedArchetypeType>(this)) {
32253220
return Environment = nested->getRoot()->getGenericEnvironment();

0 commit comments

Comments
 (0)