Skip to content

Commit 03da816

Browse files
committed
---
yaml --- r: 347031 b: refs/heads/master c: 0de5d40 h: refs/heads/master i: 347029: fd87717 347027: b5e6b47 347023: ae418d8
1 parent f80af06 commit 03da816

File tree

4 files changed

+70
-15
lines changed

4 files changed

+70
-15
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: fdafc1b7428f976cddeead975cd5f5b4d7ccbb0a
2+
refs/heads/master: 0de5d40f4fbfd7d95bedd3213d0bc7160c0dbb48
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/include/swift/Remote/MetadataReader.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,11 +410,15 @@ class MetadataReader {
410410
StoredPointer InstanceAddress =
411411
InstanceMetadataAddressAddress + 2 * sizeof(StoredPointer);
412412

413+
// When built with Objective-C interop, the runtime also stores a conformance
414+
// to Hashable and the base type introducing the Hashable conformance.
415+
if (isObjC)
416+
InstanceAddress += 2 * sizeof(StoredPointer);
417+
413418
// Round up to alignment, and we have the start address of the
414419
// instance payload.
415420
auto AlignmentMask = VWT->getAlignmentMask();
416-
auto Offset = (sizeof(HeapObject) + AlignmentMask) & ~AlignmentMask;
417-
InstanceAddress += Offset;
421+
InstanceAddress = (InstanceAddress + AlignmentMask) & ~AlignmentMask;
418422

419423
return RemoteExistential(
420424
RemoteAddress(*InstanceMetadataAddress),

trunk/lib/Sema/CSSimplify.cpp

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,10 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
12281228
llvm_unreachable("Not a relational constraint");
12291229
}
12301230

1231+
// Input types can be contravariant (or equal).
1232+
auto argumentLocator =
1233+
locator.withPathElement(ConstraintLocator::FunctionArgument);
1234+
12311235
TypeMatchOptions subflags = getDefaultDecompositionOptions(flags);
12321236

12331237
SmallVector<AnyFunctionType::Param, 8> func1Params;
@@ -1254,8 +1258,23 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
12541258
auto implodeParams = [&](SmallVectorImpl<AnyFunctionType::Param> &params) {
12551259
auto input = AnyFunctionType::composeInput(getASTContext(), params,
12561260
/*canonicalVararg=*/false);
1261+
12571262
params.clear();
1258-
params.emplace_back(input);
1263+
// If fixes are disabled let's do an easy thing and implode
1264+
// tuple directly into parameters list.
1265+
if (!shouldAttemptFixes()) {
1266+
params.emplace_back(input);
1267+
return;
1268+
}
1269+
1270+
// Synthesize new argument and bind it to tuple formed from existing
1271+
// arguments, this makes it easier to diagnose cases where we attempt
1272+
// a single tuple element formed when no arguments were present.
1273+
auto argLoc = argumentLocator.withPathElement(
1274+
LocatorPathElt::getSynthesizedArgument(0));
1275+
auto *typeVar = createTypeVariable(getConstraintLocator(argLoc));
1276+
params.emplace_back(typeVar);
1277+
assignFixedType(typeVar, input);
12591278
};
12601279

12611280
{
@@ -1323,10 +1342,6 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
13231342
}
13241343
}
13251344

1326-
// Input types can be contravariant (or equal).
1327-
auto argumentLocator = locator.withPathElement(
1328-
ConstraintLocator::FunctionArgument);
1329-
13301345
int diff = func1Params.size() - func2Params.size();
13311346
if (diff != 0) {
13321347
if (!shouldAttemptFixes())
@@ -1796,6 +1811,46 @@ repairFailures(ConstraintSystem &cs, Type lhs, Type rhs,
17961811

17971812
auto &elt = path.back();
17981813
switch (elt.getKind()) {
1814+
case ConstraintLocator::FunctionArgument: {
1815+
auto *argLoc = cs.getConstraintLocator(
1816+
locator.withPathElement(LocatorPathElt::getSynthesizedArgument(0)));
1817+
1818+
// Let's drop the last element which points to a single argument
1819+
// and see if this is a contextual mismatch.
1820+
path.pop_back();
1821+
if (path.empty() ||
1822+
!(path.back().getKind() == ConstraintLocator::ApplyArgToParam ||
1823+
path.back().getKind() == ConstraintLocator::ContextualType))
1824+
return;
1825+
1826+
auto arg = llvm::find_if(cs.getTypeVariables(),
1827+
[&argLoc](const TypeVariableType *typeVar) {
1828+
return typeVar->getImpl().getLocator() == argLoc;
1829+
});
1830+
1831+
// What we have here is a form or tuple splat with no arguments
1832+
// demonstrated by following example:
1833+
//
1834+
// func foo<T: P>(_: T, _: (T.Element) -> Int) {}
1835+
// foo { 42 }
1836+
//
1837+
// In cases like this `T.Element` might be resolved to `Void`
1838+
// which means that we have to try a single empty tuple argument
1839+
// as a narrow exception to SE-0110, see `matchFunctionTypes`.
1840+
//
1841+
// But if `T.Element` didn't get resolved to `Void` we'd like
1842+
// to diagnose this as a missing argument which can't be ignored.
1843+
if (arg != cs.getTypeVariables().end()) {
1844+
auto fnType = FunctionType::get({FunctionType::Param(lhs)},
1845+
cs.getASTContext().TheEmptyTupleType);
1846+
conversionsOrFixes.push_back(AddMissingArguments::create(
1847+
cs, fnType, {FunctionType::Param(*arg)},
1848+
cs.getConstraintLocator(anchor, path,
1849+
/*summaryFlags=*/0)));
1850+
}
1851+
break;
1852+
}
1853+
17991854
case ConstraintLocator::TypeParameterRequirement:
18001855
case ConstraintLocator::ConditionalRequirement: {
18011856
if (auto *fix = fixRequirementFailure(cs, lhs, rhs, anchor, path))
@@ -5707,7 +5762,8 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
57075762

57085763
case FixKind::SkipSameTypeRequirement:
57095764
case FixKind::SkipSuperclassRequirement:
5710-
case FixKind::ContextualMismatch: {
5765+
case FixKind::ContextualMismatch:
5766+
case FixKind::AddMissingArguments: {
57115767
return recordFix(fix) ? SolutionKind::Error : SolutionKind::Solved;
57125768
}
57135769

@@ -5723,7 +5779,6 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
57235779
case FixKind::AllowTypeOrInstanceMember:
57245780
case FixKind::AllowInvalidPartialApplication:
57255781
case FixKind::AllowInvalidInitRef:
5726-
case FixKind::AddMissingArguments:
57275782
llvm_unreachable("handled elsewhere");
57285783
}
57295784

trunk/test/Constraints/closures.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -894,12 +894,8 @@ do {
894894
}
895895

896896
func foo(_ arr: [Int]) {
897-
// FIXME: This behavior related to tuple splat being allowed
898-
// in conversion between a single dependent member
899-
// parameter and empty parameter functions e.g.
900-
// () -> Void `convertable to` (T.V) -> Void.
901897
_ = S(arr, id: \.self_) {
902-
// expected-error@-1 {{type '_' has no member 'self_'}}
898+
// expected-error@-1 {{contextual type for closure argument list expects 1 argument, which cannot be implicitly ignored}} {{30-30=_ in }}
903899
return 42
904900
}
905901
}

0 commit comments

Comments
 (0)