Skip to content

Replace some uses of getInput(). #18336

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
Jul 29, 2018
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
5 changes: 4 additions & 1 deletion include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -2861,6 +2861,9 @@ class AnyFunctionType : public TypeBase {
static bool equalParams(ArrayRef<AnyFunctionType::Param> a,
ArrayRef<AnyFunctionType::Param> b);

/// \brief Given two arrays of parameters determine if they are equal.
static bool equalParams(CanParamArrayRef a, CanParamArrayRef b);

Type getInput() const { return Input; }
Type getResult() const { return Output; }
ArrayRef<AnyFunctionType::Param> getParams() const;
Expand Down
14 changes: 13 additions & 1 deletion lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -3608,6 +3608,18 @@ bool AnyFunctionType::equalParams(ArrayRef<AnyFunctionType::Param> a,
return true;
}

bool AnyFunctionType::equalParams(CanParamArrayRef a, CanParamArrayRef b) {
if (a.size() != b.size())
return false;

for (unsigned i = 0, n = a.size(); i != n; ++i) {
if (a[i] != b[i])
return false;
}

return true;
}

FunctionType *FunctionType::get(ArrayRef<AnyFunctionType::Param> params,
Type result, const ExtInfo &info,
bool canonicalVararg) {
Expand Down
11 changes: 5 additions & 6 deletions lib/AST/TypeJoinMeet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -324,9 +324,8 @@ CanType TypeJoin::visitFunctionType(CanType second) {
if (firstExtInfo.withNoEscape(false) != secondExtInfo.withNoEscape(false))
return Unimplemented;

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

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

return FunctionType::get(firstFnTy->getInput(), result,
extInfo)->getCanonicalType();
return FunctionType::get(firstFnTy->getParams(), result, extInfo)
->getCanonicalType();
}

CanType TypeJoin::visitGenericFunctionType(CanType second) {
Expand Down
20 changes: 5 additions & 15 deletions lib/SIL/DynamicCasts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -485,22 +485,12 @@ swift::classifyDynamicCast(ModuleDecl *M,
if (targetFunction->getRepresentation()
!= sourceFunction->getRepresentation())
return DynamicCastFeasibility::WillFail;

if (sourceFunction.getInput() == targetFunction.getInput()
&& sourceFunction.getResult() == targetFunction.getResult())

if (AnyFunctionType::equalParams(sourceFunction.getParams(),
targetFunction.getParams()) &&
sourceFunction.getResult() == targetFunction.getResult())
return DynamicCastFeasibility::WillSucceed;

auto isSubstitutable = [](CanType a, CanType b) -> bool {
// FIXME: Unnecessarily conservative; should structurally check for
// substitutability.
return a == b || a->hasArchetype() || b->hasArchetype();
};

if (isSubstitutable(sourceFunction.getInput(), targetFunction.getInput())
&& isSubstitutable(targetFunction.getInput(),
targetFunction.getResult()))
return DynamicCastFeasibility::MaySucceed;

return DynamicCastFeasibility::WillFail;
}
}
Expand Down