Skip to content

Sema: Type resolution only needs a GenericSignature and not a GenericEnvironment #60435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions include/swift/AST/TypeRepr.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "swift/AST/Attr.h"
#include "swift/AST/DeclContext.h"
#include "swift/AST/GenericSignature.h"
#include "swift/AST/Identifier.h"
#include "swift/AST/Type.h"
#include "swift/AST/TypeAlignments.h"
Expand All @@ -34,7 +35,6 @@
namespace swift {
class ASTWalker;
class DeclContext;
class GenericEnvironment;
class IdentTypeRepr;
class TupleTypeRepr;
class TypeDecl;
Expand Down Expand Up @@ -492,14 +492,14 @@ inline IdentTypeRepr::ComponentRange IdentTypeRepr::getComponentRange() {
/// (x: Foo, y: Bar) -> Baz
/// \endcode
class FunctionTypeRepr : public TypeRepr {
// The generic params / environment / substitutions fields are only used
// The generic params / signature / substitutions fields are only used
// in SIL mode, which is the only time we can have polymorphic and
// substituted function values.
GenericParamList *GenericParams;
GenericEnvironment *GenericEnv;
GenericSignature GenericSig;
ArrayRef<TypeRepr *> InvocationSubs;
GenericParamList *PatternGenericParams;
GenericEnvironment *PatternGenericEnv;
GenericSignature PatternGenericSig;
ArrayRef<TypeRepr *> PatternSubs;

TupleTypeRepr *ArgsTy;
Expand All @@ -516,37 +516,37 @@ class FunctionTypeRepr : public TypeRepr {
ArrayRef<TypeRepr *> patternSubs = {},
ArrayRef<TypeRepr *> invocationSubs = {})
: TypeRepr(TypeReprKind::Function),
GenericParams(genericParams), GenericEnv(nullptr),
GenericParams(genericParams),
InvocationSubs(invocationSubs),
PatternGenericParams(patternGenericParams), PatternGenericEnv(nullptr),
PatternGenericParams(patternGenericParams),
PatternSubs(patternSubs),
ArgsTy(argsTy), RetTy(retTy),
AsyncLoc(asyncLoc), ThrowsLoc(throwsLoc), ArrowLoc(arrowLoc) {
}

GenericParamList *getGenericParams() const { return GenericParams; }
GenericEnvironment *getGenericEnvironment() const { return GenericEnv; }
GenericSignature getGenericSignature() const { return GenericSig; }

GenericParamList *getPatternGenericParams() const {
return PatternGenericParams;
}
GenericEnvironment *getPatternGenericEnvironment() const {
return PatternGenericEnv;
GenericSignature getPatternGenericSignature() const {
return PatternGenericSig;
}

ArrayRef<TypeRepr*> getPatternSubstitutions() const { return PatternSubs; }
ArrayRef<TypeRepr*> getInvocationSubstitutions() const {
return InvocationSubs;
}

void setPatternGenericEnvironment(GenericEnvironment *genericEnv) {
assert(PatternGenericEnv == nullptr);
PatternGenericEnv = genericEnv;
void setPatternGenericSignature(GenericSignature genericSig) {
assert(!PatternGenericSig);
PatternGenericSig = genericSig;
}

void setGenericEnvironment(GenericEnvironment *genericEnv) {
assert(GenericEnv == nullptr);
GenericEnv = genericEnv;
void setGenericSignature(GenericSignature genericSig) {
assert(!GenericSig);
GenericSig = genericSig;
}

TupleTypeRepr *getArgsTypeRepr() const { return ArgsTy; }
Expand Down Expand Up @@ -1239,7 +1239,7 @@ class SILBoxTypeRepr final : public TypeRepr,
SILBoxTypeReprField, TypeRepr *> {
friend TrailingObjects;
GenericParamList *GenericParams;
GenericEnvironment *GenericEnv = nullptr;
GenericSignature GenericSig;

SourceLoc LBraceLoc, RBraceLoc;
SourceLoc ArgLAngleLoc, ArgRAngleLoc;
Expand Down Expand Up @@ -1280,9 +1280,9 @@ class SILBoxTypeRepr final : public TypeRepr,
SourceLoc ArgLAngleLoc, ArrayRef<TypeRepr *> GenericArgs,
SourceLoc ArgRAngleLoc);

void setGenericEnvironment(GenericEnvironment *Env) {
assert(!GenericEnv);
GenericEnv = Env;
void setGenericSignature(GenericSignature Sig) {
assert(!GenericSig);
GenericSig = Sig;
}

ArrayRef<Field> getFields() const {
Expand All @@ -1297,8 +1297,8 @@ class SILBoxTypeRepr final : public TypeRepr,
GenericParamList *getGenericParams() const {
return GenericParams;
}
GenericEnvironment *getGenericEnvironment() const {
return GenericEnv;
GenericSignature getGenericSignature() const {
return GenericSig;
}

SourceLoc getLBraceLoc() const { return LBraceLoc; }
Expand Down
8 changes: 4 additions & 4 deletions include/swift/Subsystems.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ namespace swift {
class Evaluator;
class FileUnit;
class GeneratedModule;
class GenericEnvironment;
class GenericParamList;
class GenericSignature;
class IRGenOptions;
class LangOptions;
class SILOptions;
Expand Down Expand Up @@ -169,13 +169,13 @@ namespace swift {
/// \returns A well-formed type on success, or an \c ErrorType.
Type performTypeResolution(TypeRepr *TyR, ASTContext &Ctx, bool isSILMode,
bool isSILType,
GenericEnvironment *GenericEnv,
GenericSignature GenericSig,
GenericParamList *GenericParams,
DeclContext *DC, bool ProduceDiagnostics = true);

/// Expose TypeChecker's handling of GenericParamList to SIL parsing.
GenericEnvironment *handleSILGenericParams(GenericParamList *genericParams,
DeclContext *DC);
GenericSignature handleSILGenericParams(GenericParamList *genericParams,
DeclContext *DC);

/// Turn the given module into SIL IR.
///
Expand Down
2 changes: 1 addition & 1 deletion lib/IDE/CodeCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks {
ParsedTypeLoc.getTypeRepr(), P.Context,
/*isSILMode=*/false,
/*isSILType=*/false,
CurDeclContext->getGenericEnvironmentOfContext(),
CurDeclContext->getGenericSignatureOfContext(),
/*GenericParams=*/nullptr,
CurDeclContext,
/*ProduceDiagnostics=*/false);
Expand Down
2 changes: 1 addition & 1 deletion lib/IDE/ExprContextAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ void swift::ide::collectPossibleReturnTypesFromContext(
const auto type = swift::performTypeResolution(
CE->getExplicitResultTypeRepr(), DC->getASTContext(),
/*isSILMode=*/false, /*isSILType=*/false,
DC->getGenericEnvironmentOfContext(), /*GenericParams=*/nullptr,
DC->getGenericSignatureOfContext(), /*GenericParams=*/nullptr,
const_cast<DeclContext *>(DC), /*diagnostics=*/false);

if (!type->hasError()) {
Expand Down
Loading