Skip to content

[Type checker] Don't create new generic signature builders for known signatures #12091

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 3 commits into from
Sep 25, 2017
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
2 changes: 1 addition & 1 deletion include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -4591,7 +4591,7 @@ class ParamDecl : public VarDecl {
/// Clone constructor, allocates a new ParamDecl identical to the first.
/// Intentionally not defined as a typical copy constructor to avoid
/// accidental copies.
ParamDecl(ParamDecl *PD);
ParamDecl(ParamDecl *PD, bool withTypes);

/// Retrieve the argument (API) name for this function parameter.
Identifier getArgumentName() const { return ArgumentName; }
Expand Down
10 changes: 8 additions & 2 deletions include/swift/AST/ParameterList.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,15 @@ class alignas(ParamDecl *) ParameterList final :
Implicit = 0x01,
/// The cloned pattern is for an inherited constructor; mark default
/// arguments as inherited, and mark unnamed arguments as named.
Inherited = 0x02
Inherited = 0x02,
/// The cloned pattern will strip type information.
WithoutTypes = 0x04,
};


friend OptionSet<CloneFlags> operator|(CloneFlags flag1, CloneFlags flag2) {
return OptionSet<CloneFlags>(flag1) | flag2;
}

/// Make a duplicate copy of this parameter list. This allocates copies of
/// the ParamDecls, so they can be reparented into a new DeclContext.
ParameterList *clone(const ASTContext &C,
Expand Down
10 changes: 7 additions & 3 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4217,18 +4217,22 @@ ParamDecl::ParamDecl(Specifier specifier,

/// Clone constructor, allocates a new ParamDecl identical to the first.
/// Intentionally not defined as a copy constructor to avoid accidental copies.
ParamDecl::ParamDecl(ParamDecl *PD)
ParamDecl::ParamDecl(ParamDecl *PD, bool withTypes)
: VarDecl(DeclKind::Param, /*IsStatic*/false, PD->getSpecifier(),
/*IsCaptureList*/false, PD->getNameLoc(), PD->getName(),
PD->hasType() ? PD->getType() : Type(), PD->getDeclContext()),
PD->hasType() && withTypes? PD->getType() : Type(),
PD->getDeclContext()),
ArgumentName(PD->getArgumentName()),
ArgumentNameLoc(PD->getArgumentNameLoc()),
SpecifierLoc(PD->getSpecifierLoc()),
DefaultValueAndIsVariadic(nullptr, PD->DefaultValueAndIsVariadic.getInt()),
IsTypeLocImplicit(PD->IsTypeLocImplicit),
defaultArgumentKind(PD->defaultArgumentKind) {
typeLoc = PD->getTypeLoc().clone(PD->getASTContext());
if (PD->hasInterfaceType())
if (!withTypes && typeLoc.getTypeRepr())
typeLoc.setType(Type());

if (withTypes && PD->hasInterfaceType())
setInterfaceType(PD->getInterfaceType());
}

Expand Down
3 changes: 2 additions & 1 deletion lib/AST/Parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,12 @@ ParameterList *ParameterList::clone(const ASTContext &C,
SmallVector<ParamDecl*, 8> params(begin(), end());

// Remap the ParamDecls inside of the ParameterList.
bool withTypes = !options.contains(ParameterList::WithoutTypes);
for (auto &decl : params) {
bool hadDefaultArgument =
decl->getDefaultArgumentKind() == DefaultArgumentKind::Normal;

decl = new (C) ParamDecl(decl);
decl = new (C) ParamDecl(decl, withTypes);
if (options & Implicit)
decl->setImplicit();

Expand Down
3 changes: 2 additions & 1 deletion lib/Sema/CodeSynthesis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ buildIndexForwardingParamList(AbstractStorageDecl *storage,

// Clone the parameter list over for a new decl, so we get new ParamDecls.
auto indices = subscript->getIndices()->clone(context,
ParameterList::Implicit);
ParameterList::Implicit|
ParameterList::WithoutTypes);
if (prefix.empty())
return indices;

Expand Down
12 changes: 6 additions & 6 deletions lib/Sema/GenericTypeResolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ class ProtocolRequirementTypeResolver : public GenericTypeResolver {
/// to check the signature of a generic declaration and resolve (for example)
/// all dependent member refers to archetype members.
class CompleteGenericTypeResolver : public GenericTypeResolver {
TypeChecker &TC;
GenericSignatureBuilder &Builder;
ArrayRef<GenericTypeParamType *> GenericParams;
TypeChecker &tc;
GenericSignature *genericSig;
ModuleDecl &module;
GenericSignatureBuilder &builder;

public:
CompleteGenericTypeResolver(TypeChecker &tc, GenericSignatureBuilder &builder,
ArrayRef<GenericTypeParamType *> genericParams)
: TC(tc), Builder(builder), GenericParams(genericParams) { }
CompleteGenericTypeResolver(TypeChecker &tc, GenericSignature *genericSig,
ModuleDecl &module);

virtual Type mapTypeIntoContext(Type type);

Expand Down
21 changes: 15 additions & 6 deletions lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,8 @@ TypeChecker::handleSILGenericParams(GenericParamList *genericParams,
prepareGenericParamList(genericParams, DC);

parentEnv = checkGenericEnvironment(genericParams, DC, parentSig,
/*allowConcreteGenericParams=*/true);
/*allowConcreteGenericParams=*/true,
/*ext=*/nullptr);
parentSig = parentEnv->getGenericSignature();

// Compute the final set of archetypes.
Expand Down Expand Up @@ -5233,10 +5234,18 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
// Revert the types within the signature so it can be type-checked with
// archetypes below.
TC.revertGenericFuncSignature(FD);
} else if (FD->getDeclContext()->getGenericSignatureOfContext()) {
(void)TC.validateGenericFuncSignature(FD);
// Revert all of the types within the signature of the function.
TC.revertGenericFuncSignature(FD);
} else if (auto genericSig =
FD->getDeclContext()->getGenericSignatureOfContext()) {
if (!FD->getAccessorStorageDecl()) {
(void)TC.validateGenericFuncSignature(FD);

// Revert all of the types within the signature of the function.
TC.revertGenericFuncSignature(FD);
} else {
// We've inherited all of the type information already.
TC.configureInterfaceType(FD, genericSig);
}

FD->setGenericEnvironment(
FD->getDeclContext()->getGenericEnvironmentOfContext());
}
Expand Down Expand Up @@ -8039,7 +8048,7 @@ checkExtensionGenericParams(TypeChecker &tc, ExtensionDecl *ext, Type type,
auto *env = tc.checkGenericEnvironment(genericParams,
ext->getDeclContext(), nullptr,
/*allowConcreteGenericParams=*/true,
inferExtendedTypeReqs);
ext, inferExtendedTypeReqs);

// Validate the generic parameters for the last time, to splat down
// actual archetypes.
Expand Down
Loading