Skip to content

Commit 1ef8fca

Browse files
committed
---
yaml --- r: 349381 b: refs/heads/master-next c: 8aa3c7a h: refs/heads/master i: 349379: 9827d7e
1 parent 8cd2352 commit 1ef8fca

File tree

6 files changed

+63
-93
lines changed

6 files changed

+63
-93
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 3574c513bbc5578dd9346b4ea9ab5995c5927bb5
3-
refs/heads/master-next: fb3d28c00d8716fd4588670decdc1afc36e62717
3+
refs/heads/master-next: 8aa3c7a5ad8f77761314184a1f6af0c5132777bf
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea
66
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-b: 66d897bfcf64a82cb9a87f5e663d889189d06d07

branches/master-next/lib/Sema/CodeSynthesis.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -648,20 +648,27 @@ createDesignatedInitOverride(ClassDecl *classDecl,
648648
// Determine the initializer parameters.
649649

650650
// Create the initializer parameter patterns.
651-
OptionSet<ParameterList::CloneFlags> options = ParameterList::Implicit;
652-
options |= ParameterList::Inherited;
653-
auto *bodyParams = superclassCtor->getParameters()->clone(ctx, options);
651+
OptionSet<ParameterList::CloneFlags> options
652+
= (ParameterList::Implicit |
653+
ParameterList::Inherited |
654+
ParameterList::WithoutTypes);
655+
auto *superclassParams = superclassCtor->getParameters();
656+
auto *bodyParams = superclassParams->clone(ctx, options);
654657

655658
// If the superclass is generic, we need to map the superclass constructor's
656659
// parameter types into the generic context of our class.
657660
//
658661
// We might have to apply substitutions, if for example we have a declaration
659662
// like 'class A : B<Int>'.
660-
for (auto *decl : *bodyParams) {
661-
auto paramTy = decl->getInterfaceType();
663+
for (unsigned idx : range(superclassParams->size())) {
664+
auto *superclassParam = superclassParams->get(idx);
665+
auto *bodyParam = bodyParams->get(idx);
666+
667+
auto paramTy = superclassParam->getInterfaceType();
662668
auto substTy = paramTy.subst(subMap, SubstFlags::UseErrorType);
663-
decl->setInterfaceType(substTy);
664-
decl->getTypeLoc() = TypeLoc::withoutLoc(substTy);
669+
670+
bodyParam->setInterfaceType(substTy);
671+
bodyParam->getTypeLoc() = TypeLoc::withoutLoc(substTy);
665672
}
666673

667674
// Create the initializer declaration, inheriting the name,

branches/master-next/lib/Sema/TypeCheckDecl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3916,6 +3916,7 @@ void TypeChecker::validateDecl(ValueDecl *D) {
39163916
auto newValueParam = valueParams->get(0);
39173917
newValueParam->setInterfaceType(valueIfaceTy);
39183918
newValueParam->getTypeLoc().setType(valueIfaceTy);
3919+
accessor->getBodyResultTypeLoc().setType(TupleType::getEmpty(Context));
39193920
break;
39203921
}
39213922

@@ -3932,6 +3933,7 @@ void TypeChecker::validateDecl(ValueDecl *D) {
39323933
// If we add yield types to the function type, we'll need to update this.
39333934
case AccessorKind::Read:
39343935
case AccessorKind::Modify:
3936+
accessor->getBodyResultTypeLoc().setType(TupleType::getEmpty(Context));
39353937
break;
39363938
}
39373939
}

branches/master-next/lib/Sema/TypeCheckGeneric.cpp

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -145,19 +145,6 @@ TypeChecker::gatherGenericParamBindingsText(
145145
return result.str().str();
146146
}
147147

148-
static void revertDependentTypeLoc(TypeLoc &tl) {
149-
// If there's no type representation, there's nothing to revert.
150-
if (!tl.getTypeRepr())
151-
return;
152-
153-
// Don't revert an error type; we've already complained.
154-
if (tl.wasValidated() && tl.isError())
155-
return;
156-
157-
// Make sure we validate the type again.
158-
tl.setType(Type());
159-
}
160-
161148
//
162149
// Generic functions
163150
//
@@ -592,42 +579,50 @@ void TypeChecker::validateGenericFuncOrSubscriptSignature(
592579
->getGenericSignatureOfContext(),
593580
resolution);
594581

595-
// Check parameter patterns.
596-
typeCheckParameterList(params, resolution, func
597-
? TypeResolverContext::AbstractFunctionDecl
598-
: TypeResolverContext::SubscriptDecl);
582+
// Infer requirements from the parameter list.
583+
auto *module = genCtx->getParentModule();
584+
TypeResolutionOptions options =
585+
(func
586+
? TypeResolverContext::AbstractFunctionDecl
587+
: TypeResolverContext::SubscriptDecl);
599588

600-
// Infer requirements from the pattern.
601-
builder.inferRequirements(*genCtx->getParentModule(), params);
589+
for (auto param : *params) {
590+
auto *typeRepr = param->getTypeLoc().getTypeRepr();
591+
if (typeRepr == nullptr)
592+
continue;
602593

603-
// Check the result type, but leave opaque return types alone
604-
// for structural checking.
605-
if (!resultTyLoc.isNull() &&
606-
!(resultTyLoc.getTypeRepr() &&
607-
isa<OpaqueReturnTypeRepr>(resultTyLoc.getTypeRepr())))
608-
validateType(resultTyLoc, resolution,
609-
TypeResolverContext::FunctionResult);
594+
auto paramOptions = options;
595+
paramOptions.setContext(param->isVariadic() ?
596+
TypeResolverContext::VariadicFunctionInput :
597+
TypeResolverContext::FunctionInput);
598+
paramOptions |= TypeResolutionFlags::Direct;
599+
600+
auto type = resolution.resolveType(typeRepr, paramOptions);
601+
602+
if (auto *specifier = dyn_cast_or_null<SpecifierTypeRepr>(typeRepr))
603+
typeRepr = specifier->getBase();
604+
605+
auto source = GenericSignatureBuilder::FloatingRequirementSource::
606+
forInferred(typeRepr);
607+
builder.inferRequirements(*module, type, typeRepr, source);
608+
}
609+
610+
// Infer requirements from the result type.
611+
auto *resultTypeRepr = resultTyLoc.getTypeRepr();
612+
if (resultTypeRepr && !isa<OpaqueReturnTypeRepr>(resultTypeRepr)) {
613+
TypeResolutionOptions resultOptions = TypeResolverContext::FunctionResult;
614+
615+
auto resultType = resolution.resolveType(resultTypeRepr, resultOptions);
610616

611-
// Infer requirements from it.
612-
if (resultTyLoc.getTypeRepr()) {
613617
auto source = GenericSignatureBuilder::FloatingRequirementSource::
614-
forInferred(resultTyLoc.getTypeRepr());
615-
builder.inferRequirements(*genCtx->getParentModule(),
616-
resultTyLoc.getType(),
617-
resultTyLoc.getTypeRepr(), source);
618+
forInferred(resultTypeRepr);
619+
builder.inferRequirements(*module, resultType, resultTypeRepr, source);
618620
}
619621

620622
// The signature is complete and well-formed. Determine
621623
// the type of the generic function or subscript.
622624
sig = std::move(builder).computeGenericSignature(decl->getLoc());
623625

624-
// The generic signature builder now has all of the requirements, although
625-
// there might still be errors that have not yet been diagnosed. Revert the
626-
// signature and type-check it again, completely.
627-
revertDependentTypeLoc(resultTyLoc);
628-
for (auto &param : *params)
629-
revertDependentTypeLoc(param->getTypeLoc());
630-
631626
// Debugging of the generic signature.
632627
if (Context.LangOpts.DebugGenericSignatures) {
633628
decl->dumpRef(llvm::errs());

branches/master-next/lib/Sema/TypeCheckStorage.cpp

Lines changed: 10 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -426,21 +426,6 @@ static VarDecl *getFirstParamDecl(FuncDecl *fn) {
426426
return getParamDeclAtIndex(fn, 0);
427427
};
428428

429-
430-
static ParamDecl *buildArgument(SourceLoc loc, DeclContext *DC,
431-
StringRef name,
432-
Type interfaceType,
433-
ParamDecl::Specifier specifier,
434-
ASTContext &context) {
435-
auto *param = new (context) ParamDecl(specifier, SourceLoc(), SourceLoc(),
436-
Identifier(), loc,
437-
context.getIdentifier(name),
438-
DC);
439-
param->setImplicit();
440-
param->setInterfaceType(interfaceType);
441-
return param;
442-
}
443-
444429
/// Build a parameter list which can forward the formal index parameters of a
445430
/// declaration.
446431
///
@@ -1648,8 +1633,6 @@ static AccessorDecl *createGetterPrototype(AbstractStorageDecl *storage,
16481633
ASTContext &ctx) {
16491634
SourceLoc loc = storage->getLoc();
16501635

1651-
GenericEnvironment *genericEnvironmentOfLazyAccessor = nullptr;
1652-
16531636
ParamDecl *selfDecl = nullptr;
16541637
if (storage->getDeclContext()->isTypeContext()) {
16551638
if (storage->getAttrs().hasAttribute<LazyAttr>()) {
@@ -1660,8 +1643,6 @@ static AccessorDecl *createGetterPrototype(AbstractStorageDecl *storage,
16601643
bindingDecl->getPatternEntryForVarDecl(varDecl).getInitContext());
16611644

16621645
selfDecl = bindingInit->getImplicitSelfDecl();
1663-
genericEnvironmentOfLazyAccessor =
1664-
bindingInit->getGenericEnvironmentOfContext();
16651646
}
16661647
}
16671648

@@ -1674,16 +1655,14 @@ static AccessorDecl *createGetterPrototype(AbstractStorageDecl *storage,
16741655
if (storage->isStatic())
16751656
staticLoc = storage->getLoc();
16761657

1677-
auto storageInterfaceType = storage->getValueInterfaceType();
1678-
16791658
auto getter = AccessorDecl::create(
16801659
ctx, loc, /*AccessorKeywordLoc*/ loc,
16811660
AccessorKind::Get, storage,
16821661
staticLoc, StaticSpellingKind::None,
16831662
/*Throws=*/false, /*ThrowsLoc=*/SourceLoc(),
16841663
genericParams,
16851664
getterParams,
1686-
TypeLoc::withoutLoc(storageInterfaceType),
1665+
TypeLoc(),
16871666
storage->getDeclContext());
16881667

16891668
// If we're stealing the 'self' from a lazy initializer, set it now.
@@ -1692,18 +1671,6 @@ static AccessorDecl *createGetterPrototype(AbstractStorageDecl *storage,
16921671
if (selfDecl)
16931672
*getter->getImplicitSelfDeclStorage() = selfDecl;
16941673

1695-
// We need to install the generic environment here because:
1696-
// 1) validating the getter will change the implicit self decl's DC to it,
1697-
// 2) it's likely that the initializer will be type-checked before the
1698-
// accessor (and therefore before the normal installation happens), and
1699-
// 3) type-checking a reference to the self decl will map its type into
1700-
// its context, which requires an environment to be installed on that
1701-
// context.
1702-
// We can safely use the enclosing environment because properties are never
1703-
// differently generic.
1704-
if (genericEnvironmentOfLazyAccessor)
1705-
getter->setGenericEnvironment(genericEnvironmentOfLazyAccessor);
1706-
17071674
if (storage->isGetterMutating())
17081675
getter->setSelfAccessKind(SelfAccessKind::Mutating);
17091676
else
@@ -1733,20 +1700,22 @@ static AccessorDecl *createSetterPrototype(AbstractStorageDecl *storage,
17331700
GenericParamList *genericParams = createAccessorGenericParams(storage);
17341701

17351702
// Add a "(value : T, indices...)" argument list.
1736-
auto storageInterfaceType = storage->getValueInterfaceType();
1737-
auto valueDecl = buildArgument(storage->getLoc(), storage->getDeclContext(),
1738-
"value", storageInterfaceType,
1739-
ParamDecl::Specifier::Default, ctx);
1740-
auto *params = buildIndexForwardingParamList(storage, valueDecl, ctx);
1703+
auto *param = new (ctx) ParamDecl(ParamDecl::Specifier::Default,
1704+
SourceLoc(), SourceLoc(),
1705+
Identifier(), loc,
1706+
ctx.getIdentifier("value"),
1707+
storage->getDeclContext());
1708+
param->setImplicit();
1709+
1710+
auto *params = buildIndexForwardingParamList(storage, param, ctx);
17411711

1742-
Type setterRetTy = TupleType::getEmpty(ctx);
17431712
auto setter = AccessorDecl::create(
17441713
ctx, loc, /*AccessorKeywordLoc*/ SourceLoc(),
17451714
AccessorKind::Set, storage,
17461715
/*StaticLoc=*/SourceLoc(), StaticSpellingKind::None,
17471716
/*Throws=*/false, /*ThrowsLoc=*/SourceLoc(),
17481717
genericParams, params,
1749-
TypeLoc::withoutLoc(setterRetTy),
1718+
TypeLoc(),
17501719
storage->getDeclContext());
17511720

17521721
if (isMutating)
@@ -1849,9 +1818,6 @@ SynthesizeAccessorRequest::evaluate(Evaluator &evaluator,
18491818
AccessorKind kind) const {
18501819
auto &ctx = storage->getASTContext();
18511820

1852-
if (!storage->hasInterfaceType())
1853-
ctx.getLazyResolver()->resolveDeclSignature(storage);
1854-
18551821
switch (kind) {
18561822
case AccessorKind::Get:
18571823
return createGetterPrototype(storage, ctx);

branches/master-next/lib/Sema/TypeChecker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ static void bindExtensionToNominal(ExtensionDecl *ext,
241241
nominal->addExtension(ext);
242242
}
243243

244-
static void bindExtensions(SourceFile &SF, TypeChecker &TC) {
244+
static void bindExtensions(SourceFile &SF) {
245245
// Utility function to try and resolve the extended type without diagnosing.
246246
// If we succeed, we go ahead and bind the extension. Otherwise, return false.
247247
auto tryBindExtension = [&](ExtensionDecl *ext) -> bool {
@@ -413,7 +413,7 @@ void swift::performTypeChecking(SourceFile &SF, TopLevelContext &TLC,
413413
// Resolve extensions. This has to occur first during type checking,
414414
// because the extensions need to be wired into the AST for name lookup
415415
// to work.
416-
bindExtensions(SF, TC);
416+
bindExtensions(SF);
417417

418418
// Look for bridging functions. This only matters when
419419
// -enable-source-import is provided.

0 commit comments

Comments
 (0)