Skip to content

Commit b124154

Browse files
authored
Merge pull request #18336 from rudkx/function-types
Replace some uses of getInput().
2 parents 93e1afd + e8e292c commit b124154

File tree

4 files changed

+27
-23
lines changed

4 files changed

+27
-23
lines changed

include/swift/AST/Types.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -2861,6 +2861,9 @@ class AnyFunctionType : public TypeBase {
28612861
static bool equalParams(ArrayRef<AnyFunctionType::Param> a,
28622862
ArrayRef<AnyFunctionType::Param> b);
28632863

2864+
/// \brief Given two arrays of parameters determine if they are equal.
2865+
static bool equalParams(CanParamArrayRef a, CanParamArrayRef b);
2866+
28642867
Type getInput() const { return Input; }
28652868
Type getResult() const { return Output; }
28662869
ArrayRef<AnyFunctionType::Param> getParams() const;

lib/AST/ASTContext.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -3608,6 +3608,18 @@ bool AnyFunctionType::equalParams(ArrayRef<AnyFunctionType::Param> a,
36083608
return true;
36093609
}
36103610

3611+
bool AnyFunctionType::equalParams(CanParamArrayRef a, CanParamArrayRef b) {
3612+
if (a.size() != b.size())
3613+
return false;
3614+
3615+
for (unsigned i = 0, n = a.size(); i != n; ++i) {
3616+
if (a[i] != b[i])
3617+
return false;
3618+
}
3619+
3620+
return true;
3621+
}
3622+
36113623
FunctionType *FunctionType::get(ArrayRef<AnyFunctionType::Param> params,
36123624
Type result, const ExtInfo &info,
36133625
bool canonicalVararg) {

lib/AST/TypeJoinMeet.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -324,9 +324,8 @@ CanType TypeJoin::visitFunctionType(CanType second) {
324324
if (firstExtInfo.withNoEscape(false) != secondExtInfo.withNoEscape(false))
325325
return Unimplemented;
326326

327-
// FIXME: Properly compute parameter types from getParams().
328-
if (firstFnTy->getInput()->getCanonicalType() !=
329-
secondFnTy->getInput()->getCanonicalType())
327+
if (!AnyFunctionType::equalParams(firstFnTy->getParams(),
328+
secondFnTy->getParams()))
330329
return Unimplemented;
331330

332331
auto firstResult = firstFnTy->getResult()->getCanonicalType();
@@ -340,8 +339,8 @@ CanType TypeJoin::visitFunctionType(CanType second) {
340339
if (secondFnTy->getExtInfo().isNoEscape())
341340
extInfo = extInfo.withNoEscape(true);
342341

343-
return FunctionType::get(firstFnTy->getInput(), result,
344-
extInfo)->getCanonicalType();
342+
return FunctionType::get(firstFnTy->getParams(), result, extInfo)
343+
->getCanonicalType();
345344
}
346345

347346
CanType TypeJoin::visitGenericFunctionType(CanType second) {

lib/SIL/DynamicCasts.cpp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -485,22 +485,12 @@ swift::classifyDynamicCast(ModuleDecl *M,
485485
if (targetFunction->getRepresentation()
486486
!= sourceFunction->getRepresentation())
487487
return DynamicCastFeasibility::WillFail;
488-
489-
if (sourceFunction.getInput() == targetFunction.getInput()
490-
&& sourceFunction.getResult() == targetFunction.getResult())
488+
489+
if (AnyFunctionType::equalParams(sourceFunction.getParams(),
490+
targetFunction.getParams()) &&
491+
sourceFunction.getResult() == targetFunction.getResult())
491492
return DynamicCastFeasibility::WillSucceed;
492493

493-
auto isSubstitutable = [](CanType a, CanType b) -> bool {
494-
// FIXME: Unnecessarily conservative; should structurally check for
495-
// substitutability.
496-
return a == b || a->hasArchetype() || b->hasArchetype();
497-
};
498-
499-
if (isSubstitutable(sourceFunction.getInput(), targetFunction.getInput())
500-
&& isSubstitutable(targetFunction.getInput(),
501-
targetFunction.getResult()))
502-
return DynamicCastFeasibility::MaySucceed;
503-
504494
return DynamicCastFeasibility::WillFail;
505495
}
506496
}

0 commit comments

Comments
 (0)