Skip to content

[pull] swiftwasm from main #4566

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 20 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
11266eb
[CodeCompletion] Look through @dynamicMemberLookup key path functions
ahoppen May 7, 2022
862f3fc
[Parse] Set missing contextual keyword token kind for `async`
bnbarham May 13, 2022
5806a7c
[Runtime] Define our own hidden global new/delete on Darwin.
mikeash May 13, 2022
d2051be
[cxx-interop] Pass clangSema.TUScope when calling LookupName for avai…
plotfi May 16, 2022
2f8c32c
[cxx-interop] Import complex inferred dependent return types
cabmeurer May 16, 2022
d738a64
[cxx-interop] Do not run `SIL/verify_all_overlays.py` on `std`
egorzhdan May 17, 2022
7483deb
Merge pull request #42411 from cabmeurer/cabmeurer/import-complex-inf…
zoecarver May 17, 2022
db3d021
Merge pull request #58944 from apple/egorzhdan/cxx-verify-all-overlays
aschwaighofer May 17, 2022
65ed38d
Merge pull request #58912 from bnbarham/highlight-async
bnbarham May 17, 2022
20db6c9
Merge pull request #58911 from apple/internal-new-delete
mikeash May 17, 2022
37f0426
[cxx-interop] Disable failing tests to unblock nightly toolchains
egorzhdan May 17, 2022
e977a21
Merge pull request #58937 from plotfi/availability-cxx-interop-renamed
plotfi May 17, 2022
8fb604c
Merge pull request #58947 from apple/egorzhdan/cxx-disable-tests
aschwaighofer May 17, 2022
9dd8d3a
Actually slice things in _StringGutsSlice
Catfish-Man May 17, 2022
7a65b6b
[Parser] Allow parsing 'any' in structural position within enum assoc…
hborla May 17, 2022
f720eea
Sema: Teach the compiler to refine `VarDecl` initializer expressions …
tshortli May 11, 2022
ebcf84b
Merge pull request #58948 from Catfish-Man/boundless-guts
swift-ci May 18, 2022
896dddc
Merge pull request #58950 from hborla/parse-any-associated-value
hborla May 18, 2022
bc43ced
Merge pull request #58870 from tshortli/pattern-binding-decl-type-ref…
tshortli May 18, 2022
42655e1
Merge pull request #58736 from ahoppen/pr/fix-dynamic-keypath-completion
ahoppen May 18, 2022
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
2 changes: 1 addition & 1 deletion lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8688,7 +8688,7 @@ getSwiftNameFromClangName(StringRef replacement) {
clang::LookupResult lookupResult(clangSema, identifier,
clang::SourceLocation(),
clang::Sema::LookupOrdinaryName);
if (!clangSema.LookupName(lookupResult, nullptr))
if (!clangSema.LookupName(lookupResult, clangSema.TUScope))
return "";

auto clangDecl = lookupResult.getAsSingle<clang::NamedDecl>();
Expand Down
2 changes: 1 addition & 1 deletion lib/ClangImporter/ImportType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ namespace {

// TODO: Add support for dependent types (SR-13809).
#define DEPENDENT_TYPE(Class, Base) \
ImportResult Visit##Class##Type(const clang::Class##Type *) { return Type(); }
ImportResult Visit##Class##Type(const clang::Class##Type *) { return Impl.SwiftContext.TheAnyType; }
#define TYPE(Class, Base)
#include "clang/AST/TypeNodes.inc"

Expand Down
141 changes: 99 additions & 42 deletions lib/IDE/ArgumentCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,98 @@ bool ArgumentTypeCheckCompletionCallback::addPossibleParams(
return ShowGlobalCompletions;
}

/// Information that \c getSelectedOverloadInfo gathered about a
/// \c SelectedOverload.
struct SelectedOverloadInfo {
/// The function that is being called.
ValueDecl *FuncD = nullptr;
/// The type of the called function itself (not its result type)
Type FuncTy;
/// The type on which the function is being called. \c null if the function is
/// a free function.
Type CallBaseTy;
};

/// Extract additional information about the overload that is being called by
/// \p CalleeLocator.
SelectedOverloadInfo getSelectedOverloadInfo(const Solution &S,
ConstraintLocator *CalleeLocator) {
auto &CS = S.getConstraintSystem();

SelectedOverloadInfo Result;

auto SelectedOverload = S.getOverloadChoiceIfAvailable(CalleeLocator);
if (!SelectedOverload) {
return Result;
}

switch (SelectedOverload->choice.getKind()) {
case OverloadChoiceKind::KeyPathApplication:
case OverloadChoiceKind::Decl:
case OverloadChoiceKind::DeclViaDynamic:
case OverloadChoiceKind::DeclViaBridge:
case OverloadChoiceKind::DeclViaUnwrappedOptional: {
Result.CallBaseTy = SelectedOverload->choice.getBaseType();
if (Result.CallBaseTy) {
Result.CallBaseTy = S.simplifyType(Result.CallBaseTy)->getRValueType();
}

Result.FuncD = SelectedOverload->choice.getDeclOrNull();
Result.FuncTy =
S.simplifyTypeForCodeCompletion(SelectedOverload->openedType);

// For completion as the arg in a call to the implicit [keypath: _]
// subscript the solver can't know what kind of keypath is expected without
// an actual argument (e.g. a KeyPath vs WritableKeyPath) so it ends up as a
// hole. Just assume KeyPath so we show the expected keypath's root type to
// users rather than '_'.
if (SelectedOverload->choice.getKind() ==
OverloadChoiceKind::KeyPathApplication) {
auto Params = Result.FuncTy->getAs<AnyFunctionType>()->getParams();
if (Params.size() == 1 &&
Params[0].getPlainType()->is<UnresolvedType>()) {
auto *KPDecl = CS.getASTContext().getKeyPathDecl();
Type KPTy =
KPDecl->mapTypeIntoContext(KPDecl->getDeclaredInterfaceType());
Type KPValueTy = KPTy->castTo<BoundGenericType>()->getGenericArgs()[1];
KPTy = BoundGenericType::get(KPDecl, Type(),
{Result.CallBaseTy, KPValueTy});
Result.FuncTy =
FunctionType::get({Params[0].withType(KPTy)}, KPValueTy);
}
}
break;
}
case OverloadChoiceKind::KeyPathDynamicMemberLookup: {
auto *fnType = SelectedOverload->openedType->castTo<FunctionType>();
assert(fnType->getParams().size() == 1 &&
"subscript always has one argument");
// Parameter type is KeyPath<T, U> where `T` is a root type
// and U is a leaf type (aka member type).
auto keyPathTy =
fnType->getParams()[0].getPlainType()->castTo<BoundGenericType>();

auto *keyPathDecl = keyPathTy->getAnyNominal();
assert(isKnownKeyPathType(keyPathTy) &&
"parameter is supposed to be a keypath");

auto KeyPathDynamicLocator = CS.getConstraintLocator(
CalleeLocator, LocatorPathElt::KeyPathDynamicMember(keyPathDecl));
Result = getSelectedOverloadInfo(S, KeyPathDynamicLocator);
break;
}
case OverloadChoiceKind::DynamicMemberLookup:
case OverloadChoiceKind::TupleIndex:
// If it's DynamicMemberLookup, we don't know which function is being
// called, so we can't extract any information from it.
// TupleIndex isn't a function call and is not relevant for argument
// completion because it doesn't take arguments.
break;
}

return Result;
}

void ArgumentTypeCheckCompletionCallback::sawSolutionImpl(const Solution &S) {
Type ExpectedTy = getTypeForCompletion(S, CompletionExpr);

Expand All @@ -104,41 +196,8 @@ void ArgumentTypeCheckCompletionCallback::sawSolutionImpl(const Solution &S) {

auto *CallLocator = CS.getConstraintLocator(ParentCall);
auto *CalleeLocator = S.getCalleeLocator(CallLocator);
ValueDecl *FuncD = nullptr;
Type FuncTy;
Type CallBaseTy;
// If we are calling a closure in-place there is no overload choice, but we
// still have all the other required information (like the argument's
// expected type) to provide useful code completion results.
if (auto SelectedOverload = S.getOverloadChoiceIfAvailable(CalleeLocator)) {

CallBaseTy = SelectedOverload->choice.getBaseType();
if (CallBaseTy) {
CallBaseTy = S.simplifyType(CallBaseTy)->getRValueType();
}

FuncD = SelectedOverload->choice.getDeclOrNull();
FuncTy = S.simplifyTypeForCodeCompletion(SelectedOverload->openedType);

// For completion as the arg in a call to the implicit [keypath: _]
// subscript the solver can't know what kind of keypath is expected without
// an actual argument (e.g. a KeyPath vs WritableKeyPath) so it ends up as a
// hole. Just assume KeyPath so we show the expected keypath's root type to
// users rather than '_'.
if (SelectedOverload->choice.getKind() ==
OverloadChoiceKind::KeyPathApplication) {
auto Params = FuncTy->getAs<AnyFunctionType>()->getParams();
if (Params.size() == 1 &&
Params[0].getPlainType()->is<UnresolvedType>()) {
auto *KPDecl = CS.getASTContext().getKeyPathDecl();
Type KPTy =
KPDecl->mapTypeIntoContext(KPDecl->getDeclaredInterfaceType());
Type KPValueTy = KPTy->castTo<BoundGenericType>()->getGenericArgs()[1];
KPTy = BoundGenericType::get(KPDecl, Type(), {CallBaseTy, KPValueTy});
FuncTy = FunctionType::get({Params[0].withType(KPTy)}, KPValueTy);
}
}
}
auto Info = getSelectedOverloadInfo(S, CalleeLocator);

// Find the parameter the completion was bound to (if any), as well as which
// parameters are already bound (so we don't suggest them even when the args
Expand Down Expand Up @@ -174,9 +233,6 @@ void ArgumentTypeCheckCompletionCallback::sawSolutionImpl(const Solution &S) {
ClaimedParams.insert(i);
}
}
} else {
// FIXME: We currently don't look through @dynamicMemberLookup applications
// for subscripts (rdar://90363138)
}

bool HasLabel = false;
Expand All @@ -190,8 +246,9 @@ void ArgumentTypeCheckCompletionCallback::sawSolutionImpl(const Solution &S) {

// If this is a duplicate of any other result, ignore this solution.
if (llvm::any_of(Results, [&](const Result &R) {
return R.FuncD == FuncD && nullableTypesEqual(R.FuncTy, FuncTy) &&
nullableTypesEqual(R.BaseType, CallBaseTy) &&
return R.FuncD == Info.FuncD &&
nullableTypesEqual(R.FuncTy, Info.FuncTy) &&
nullableTypesEqual(R.BaseType, Info.CallBaseTy) &&
R.ParamIdx == ParamIdx &&
R.IsNoninitialVariadic == IsNoninitialVariadic;
})) {
Expand All @@ -201,9 +258,9 @@ void ArgumentTypeCheckCompletionCallback::sawSolutionImpl(const Solution &S) {
llvm::SmallDenseMap<const VarDecl *, Type> SolutionSpecificVarTypes;
getSolutionSpecificVarTypes(S, SolutionSpecificVarTypes);

Results.push_back({ExpectedTy, isa<SubscriptExpr>(ParentCall), FuncD, FuncTy,
ArgIdx, ParamIdx, std::move(ClaimedParams),
IsNoninitialVariadic, CallBaseTy, HasLabel, IsAsync,
Results.push_back({ExpectedTy, isa<SubscriptExpr>(ParentCall), Info.FuncD,
Info.FuncTy, ArgIdx, ParamIdx, std::move(ClaimedParams),
IsNoninitialVariadic, Info.CallBaseTy, HasLabel, IsAsync,
SolutionSpecificVarTypes});
}

Expand Down
1 change: 1 addition & 0 deletions lib/Parse/ParsePattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,7 @@ ParserStatus Parser::parseEffectsSpecifiers(SourceLoc existingArrowLoc,
.fixItInsert(throwsLoc, isReasync ? "reasync " : "async ");
}
if (asyncLoc.isInvalid()) {
Tok.setKind(tok::contextual_keyword);
if (reasync)
*reasync = isReasync;
asyncLoc = Tok.getLoc();
Expand Down
3 changes: 1 addition & 2 deletions lib/Parse/ParseType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1643,8 +1643,7 @@ bool Parser::canParseTypeTupleBody() {

// If the tuple element starts with "ident :", then it is followed
// by a type annotation.
if (Tok.canBeArgumentLabel() &&
(peekToken().is(tok::colon) || peekToken().canBeArgumentLabel())) {
if (startsParameterName(/*isClosure=*/false)) {
consumeToken();
if (Tok.canBeArgumentLabel()) {
consumeToken();
Expand Down
Loading