Skip to content

Commit defc293

Browse files
committed
[SIL] Replace a use of getInput() in classifyDynamicCast.
Use getParams() instead.
1 parent 4ffffb1 commit defc293

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
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/SIL/DynamicCasts.cpp

Lines changed: 5 additions & 4 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,9 +485,10 @@ 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

493494
return DynamicCastFeasibility::WillFail;

0 commit comments

Comments
 (0)