Skip to content

Commit f292c1b

Browse files
committed
AST: Remove GenericContext::setGenericEnvironment()
This was a transitional step before converting all callers to store a generic signature instead of an environment.
1 parent 0405ab5 commit f292c1b

16 files changed

+59
-94
lines changed

include/swift/AST/Decl.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,9 +1535,6 @@ class GenericContext : private _GenericContext, public DeclContext {
15351535
/// Retrieve the generic requirements.
15361536
ArrayRef<Requirement> getGenericRequirements() const;
15371537

1538-
/// Set the generic context of this context.
1539-
void setGenericEnvironment(GenericEnvironment *genericEnv);
1540-
15411538
/// Set the generic signature of this context.
15421539
void setGenericSignature(GenericSignature *genericSig);
15431540

lib/AST/Builtins.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ getBuiltinGenericFunction(Identifier Id,
192192
ArrayRef<AnyFunctionType::Param> ArgParamTypes,
193193
Type ResType,
194194
GenericParamList *GenericParams,
195-
GenericEnvironment *Env) {
195+
GenericSignature *Sig) {
196196
assert(GenericParams && "Missing generic parameters");
197197
auto &Context = ResType->getASTContext();
198198

@@ -227,7 +227,7 @@ getBuiltinGenericFunction(Identifier Id,
227227
paramList,
228228
TypeLoc::withoutLoc(ResType), DC);
229229

230-
func->setGenericEnvironment(Env);
230+
func->setGenericSignature(Sig);
231231
func->computeType();
232232
func->setValidationToChecked();
233233
func->setImplicit();
@@ -458,7 +458,7 @@ namespace {
458458
private:
459459
GenericParamList *TheGenericParamList;
460460
SmallVector<GenericTypeParamDecl*, 2> GenericTypeParams;
461-
GenericEnvironment *GenericEnv = nullptr;
461+
GenericSignature *GenericSig = nullptr;
462462
SmallVector<AnyFunctionType::Param, 4> InterfaceParams;
463463
Type InterfaceResult;
464464

@@ -474,12 +474,11 @@ namespace {
474474
gp->getDeclaredInterfaceType()->castTo<GenericTypeParamType>());
475475
}
476476

477-
auto GenericSig = evaluateOrDefault(
477+
GenericSig = evaluateOrDefault(
478478
ctx.evaluator,
479479
AbstractGenericSignatureRequest{
480480
nullptr, std::move(genericParamTypes), { }},
481481
nullptr);
482-
GenericEnv = GenericSig->getGenericEnvironment();
483482
}
484483

485484
template <class G>
@@ -499,7 +498,7 @@ namespace {
499498
return getBuiltinGenericFunction(name, InterfaceParams,
500499
InterfaceResult,
501500
TheGenericParamList,
502-
GenericEnv);
501+
GenericSig);
503502
}
504503

505504
// Don't use these generator classes directly; call the make{...}

lib/AST/Decl.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -850,10 +850,6 @@ GenericEnvironment *GenericContext::getGenericEnvironment() const {
850850
return nullptr;
851851
}
852852

853-
void GenericContext::setGenericEnvironment(GenericEnvironment *genericEnv) {
854-
setGenericSignature(genericEnv ? genericEnv->getGenericSignature() : nullptr);
855-
}
856-
857853
void GenericContext::setGenericSignature(GenericSignature *genericSig) {
858854
assert(GenericSig == nullptr && "Generic signature cannot be changed");
859855
this->GenericSig = genericSig;
@@ -3826,7 +3822,7 @@ GetDestructorRequest::evaluate(Evaluator &evaluator, ClassDecl *CD) const {
38263822
DD->copyFormalAccessFrom(CD, /*sourceIsParentContext*/true);
38273823

38283824
// Wire up generic environment of DD.
3829-
DD->setGenericEnvironment(CD->getGenericEnvironmentOfContext());
3825+
DD->setGenericSignature(CD->getGenericSignatureOfContext());
38303826

38313827
// Mark DD as ObjC, as all dtors are.
38323828
DD->setIsObjC(ctx.LangOpts.EnableObjCInterop);

lib/ClangImporter/ImportDecl.cpp

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,7 +1727,7 @@ buildSubscriptGetterDecl(ClangImporter::Implementation &Impl,
17271727
TypeLoc::withoutLoc(elementTy), dc,
17281728
getter->getClangNode());
17291729

1730-
thunk->setGenericEnvironment(dc->getGenericEnvironmentOfContext());
1730+
thunk->setGenericSignature(dc->getGenericSignatureOfContext());
17311731
thunk->computeType();
17321732
thunk->setValidationToChecked();
17331733

@@ -1782,7 +1782,7 @@ buildSubscriptSetterDecl(ClangImporter::Implementation &Impl,
17821782
valueIndicesPL,
17831783
TypeLoc::withoutLoc(TupleType::getEmpty(C)), dc,
17841784
setter->getClangNode());
1785-
thunk->setGenericEnvironment(dc->getGenericEnvironmentOfContext());
1785+
thunk->setGenericSignature(dc->getGenericSignatureOfContext());
17861786
thunk->computeType();
17871787
thunk->setValidationToChecked();
17881788

@@ -3751,7 +3751,7 @@ namespace {
37513751
nameLoc, bodyParams, resultTy,
37523752
/*throws*/ false, dc, decl);
37533753

3754-
result->setGenericEnvironment(dc->getGenericEnvironmentOfContext());
3754+
result->setGenericSignature(dc->getGenericSignatureOfContext());
37553755

37563756
if (!dc->isModuleScopeContext()) {
37573757
if (selfIsInOut)
@@ -4339,7 +4339,7 @@ namespace {
43394339
// Record the return type.
43404340
result->getBodyResultTypeLoc().setType(resultTy);
43414341

4342-
result->setGenericEnvironment(dc->getGenericEnvironmentOfContext());
4342+
result->setGenericSignature(dc->getGenericSignatureOfContext());
43434343

43444344
// Optional methods in protocols.
43454345
if (decl->getImplementationControl() == clang::ObjCMethodDecl::Optional &&
@@ -4555,9 +4555,7 @@ namespace {
45554555
// Determine the type and generic args of the extension.
45564556
if (objcClass->getGenericParams()) {
45574557
result->createGenericParamsIfMissing(objcClass);
4558-
4559-
auto *env = objcClass->getGenericEnvironment();
4560-
result->setGenericEnvironment(env);
4558+
result->setGenericSignature(objcClass->getGenericSignature());
45614559
}
45624560

45634561
// Create the extension declaration and record it.
@@ -4831,8 +4829,8 @@ namespace {
48314829
if (genericParams) {
48324830
result->setGenericParams(genericParams);
48334831

4834-
auto *env = Impl.buildGenericEnvironment(genericParams, dc);
4835-
result->setGenericEnvironment(env);
4832+
auto *sig = Impl.buildGenericSignature(genericParams, dc);
4833+
result->setGenericSignature(sig);
48364834
}
48374835
} else {
48384836
return nullptr;
@@ -5156,7 +5154,7 @@ namespace {
51565154
/*genericparams=*/nullptr, dc);
51575155

51585156
if (auto *GTD = dyn_cast<GenericTypeDecl>(typeDecl)) {
5159-
typealias->setGenericEnvironment(GTD->getGenericEnvironment());
5157+
typealias->setGenericSignature(GTD->getGenericSignature());
51605158
if (GTD->isGeneric())
51615159
typealias->setGenericParams(GTD->getGenericParams()->clone(typealias));
51625160
}
@@ -5388,7 +5386,7 @@ Decl *SwiftDeclConverter::importCompatibilityTypeAlias(
53885386

53895387
auto *GTD = dyn_cast<GenericTypeDecl>(typeDecl);
53905388
if (GTD && !isa<ProtocolDecl>(GTD)) {
5391-
alias->setGenericEnvironment(GTD->getGenericEnvironment());
5389+
alias->setGenericSignature(GTD->getGenericSignature());
53925390
if (GTD->isGeneric())
53935391
alias->setGenericParams(GTD->getGenericParams()->clone(alias));
53945392
}
@@ -6345,7 +6343,7 @@ ConstructorDecl *SwiftDeclConverter::importConstructor(
63456343
addObjCAttribute(result, selector);
63466344

63476345
// Calculate the function type of the result.
6348-
result->setGenericEnvironment(dc->getGenericEnvironmentOfContext());
6346+
result->setGenericSignature(dc->getGenericSignatureOfContext());
63496347
result->computeType();
63506348

63516349
Impl.recordImplicitUnwrapForDecl(result,
@@ -6776,7 +6774,7 @@ SwiftDeclConverter::importSubscript(Decl *decl,
67766774
if (setterObjCMethod)
67776775
Impl.importAttributes(setterObjCMethod, setterThunk);
67786776

6779-
subscript->setGenericEnvironment(dc->getGenericEnvironmentOfContext());
6777+
subscript->setGenericSignature(dc->getGenericSignatureOfContext());
67806778

67816779
subscript->setIsSetterMutating(false);
67826780
makeComputed(subscript, getterThunk, setterThunk);
@@ -8041,12 +8039,6 @@ GenericSignature *ClangImporter::Implementation::buildGenericSignature(
80418039
nullptr);
80428040
}
80438041

8044-
// Calculate the generic environment from an imported generic param list.
8045-
GenericEnvironment *ClangImporter::Implementation::buildGenericEnvironment(
8046-
GenericParamList *genericParams, DeclContext *dc) {
8047-
return buildGenericSignature(genericParams, dc)->getGenericEnvironment();
8048-
}
8049-
80508042
DeclContext *
80518043
ClangImporter::Implementation::importDeclContextOf(
80528044
const clang::Decl *decl,
@@ -8135,7 +8127,7 @@ ClangImporter::Implementation::importDeclContextOf(
81358127

81368128
if (auto protoDecl = ext->getExtendedProtocolDecl()) {
81378129
ext->createGenericParamsIfMissing(protoDecl);
8138-
ext->setGenericEnvironment(protoDecl->getGenericEnvironment());
8130+
ext->setGenericSignature(protoDecl->getGenericSignature());
81398131
}
81408132

81418133
// Add the extension to the nominal type.

lib/ClangImporter/ImporterImpl.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -802,10 +802,6 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
802802
GenericSignature *buildGenericSignature(GenericParamList *genericParams,
803803
DeclContext *dc);
804804

805-
/// Utility function for building simple generic environments.
806-
GenericEnvironment *buildGenericEnvironment(GenericParamList *genericParams,
807-
DeclContext *dc);
808-
809805
/// Import the given Clang declaration context into Swift.
810806
///
811807
/// Usually one will use \c importDeclContextOf instead.

lib/Sema/CodeSynthesis.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ synthesizeStubBody(AbstractFunctionDecl *fn, void *) {
356356
/*isTypeChecked=*/true };
357357
}
358358

359-
static std::tuple<GenericEnvironment *, GenericParamList *, SubstitutionMap>
359+
static std::tuple<GenericSignature *, GenericParamList *, SubstitutionMap>
360360
configureGenericDesignatedInitOverride(ASTContext &ctx,
361361
ClassDecl *classDecl,
362362
Type superclassTy,
@@ -367,7 +367,7 @@ configureGenericDesignatedInitOverride(ASTContext &ctx,
367367
auto subMap = superclassTy->getContextSubstitutionMap(
368368
moduleDecl, superclassDecl);
369369

370-
GenericEnvironment *genericEnv;
370+
GenericSignature *genericSig;
371371

372372
// Inheriting initializers that have their own generic parameters
373373
auto *genericParams = superclassCtor->getGenericParams();
@@ -445,20 +445,19 @@ configureGenericDesignatedInitOverride(ASTContext &ctx,
445445
subMap = SubstitutionMap::get(superclassSig,
446446
substFn, lookupConformanceFn);
447447

448-
auto *genericSig = evaluateOrDefault(
448+
genericSig = evaluateOrDefault(
449449
ctx.evaluator,
450450
AbstractGenericSignatureRequest{
451451
classDecl->getGenericSignature(),
452452
std::move(newParamTypes),
453453
std::move(requirements)
454454
},
455455
nullptr);
456-
genericEnv = genericSig->getGenericEnvironment();
457456
} else {
458-
genericEnv = classDecl->getGenericEnvironment();
457+
genericSig = classDecl->getGenericSignature();
459458
}
460459

461-
return std::make_tuple(genericEnv, genericParams, subMap);
460+
return std::make_tuple(genericSig, genericParams, subMap);
462461
}
463462

464463
static void
@@ -640,11 +639,11 @@ createDesignatedInitOverride(ClassDecl *classDecl,
640639
return nullptr;
641640
}
642641

643-
GenericEnvironment *genericEnv;
642+
GenericSignature *genericSig;
644643
GenericParamList *genericParams;
645644
SubstitutionMap subMap;
646645

647-
std::tie(genericEnv, genericParams, subMap) =
646+
std::tie(genericSig, genericParams, subMap) =
648647
configureGenericDesignatedInitOverride(ctx,
649648
classDecl,
650649
superclassTy,
@@ -690,7 +689,7 @@ createDesignatedInitOverride(ClassDecl *classDecl,
690689
ctor->setImplicit();
691690

692691
// Set the interface type of the initializer.
693-
ctor->setGenericEnvironment(genericEnv);
692+
ctor->setGenericSignature(genericSig);
694693
ctor->computeType();
695694

696695
ctor->setImplicitlyUnwrappedOptional(

lib/Sema/DerivedConformanceCodable.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -761,8 +761,7 @@ static FuncDecl *deriveEncodable_encode(DerivedConformance &derived) {
761761
encodeDecl->getAttrs().add(attr);
762762
}
763763

764-
if (auto env = conformanceDC->getGenericEnvironmentOfContext())
765-
encodeDecl->setGenericEnvironment(env);
764+
encodeDecl->setGenericSignature(conformanceDC->getGenericSignatureOfContext());
766765
encodeDecl->computeType(FunctionType::ExtInfo().withThrows());
767766

768767
encodeDecl->setValidationToChecked();
@@ -1043,8 +1042,7 @@ static ValueDecl *deriveDecodable_init(DerivedConformance &derived) {
10431042
initDecl->getAttrs().add(reqAttr);
10441043
}
10451044

1046-
if (auto env = conformanceDC->getGenericEnvironmentOfContext())
1047-
initDecl->setGenericEnvironment(env);
1045+
initDecl->setGenericSignature(conformanceDC->getGenericSignatureOfContext());
10481046
initDecl->computeType(AnyFunctionType::ExtInfo().withThrows());
10491047

10501048
initDecl->setValidationToChecked();

lib/Sema/DerivedConformanceCodingKey.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ static ValueDecl *deriveInitDecl(DerivedConformance &derived, Type paramType,
142142
synthesizer(initDecl);
143143

144144
// Compute the interface type of the initializer.
145-
if (auto env = parentDC->getGenericEnvironmentOfContext())
146-
initDecl->setGenericEnvironment(env);
145+
initDecl->setGenericSignature(parentDC->getGenericSignatureOfContext());
147146
initDecl->computeType();
148147

149148
initDecl->setAccess(derived.Nominal->getFormalAccess());

lib/Sema/DerivedConformanceEquatableHashable.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -772,8 +772,7 @@ deriveEquatable_eq(
772772
eqDecl->setBodySynthesizer(bodySynthesizer);
773773

774774
// Compute the interface type.
775-
if (auto genericEnv = parentDC->getGenericEnvironmentOfContext())
776-
eqDecl->setGenericEnvironment(genericEnv);
775+
eqDecl->setGenericSignature(parentDC->getGenericSignatureOfContext());
777776
eqDecl->computeType();
778777

779778
eqDecl->copyFormalAccessFrom(derived.Nominal, /*sourceIsParentContext*/ true);
@@ -899,8 +898,7 @@ deriveHashable_hashInto(
899898
hashDecl->setImplicit();
900899
hashDecl->setBodySynthesizer(bodySynthesizer);
901900

902-
if (auto env = parentDC->getGenericEnvironmentOfContext())
903-
hashDecl->setGenericEnvironment(env);
901+
hashDecl->setGenericSignature(parentDC->getGenericSignatureOfContext());
904902
hashDecl->computeType();
905903
hashDecl->copyFormalAccessFrom(derived.Nominal);
906904
hashDecl->setValidationToChecked();
@@ -1254,8 +1252,7 @@ static ValueDecl *deriveHashable_hashValue(DerivedConformance &derived) {
12541252
getterDecl->setIsTransparent(false);
12551253

12561254
// Compute the interface type of hashValue().
1257-
if (auto env = parentDC->getGenericEnvironmentOfContext())
1258-
getterDecl->setGenericEnvironment(env);
1255+
getterDecl->setGenericSignature(parentDC->getGenericSignatureOfContext());
12591256
getterDecl->computeType();
12601257

12611258
getterDecl->setValidationToChecked();

lib/Sema/DerivedConformanceRawRepresentable.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,7 @@ deriveRawRepresentable_init(DerivedConformance &derived) {
445445
initDecl->setBodySynthesizer(&deriveBodyRawRepresentable_init);
446446

447447
// Compute the interface type of the initializer.
448-
if (auto env = parentDC->getGenericEnvironmentOfContext())
449-
initDecl->setGenericEnvironment(env);
448+
initDecl->setGenericSignature(parentDC->getGenericSignatureOfContext());
450449
initDecl->computeType();
451450

452451
initDecl->copyFormalAccessFrom(enumDecl, /*sourceIsParentContext*/true);

0 commit comments

Comments
 (0)