Skip to content

Commit

Permalink
Merge pull request #823 from swiftwasm/master
Browse files Browse the repository at this point in the history
[pull] swiftwasm from master
  • Loading branch information
pull[bot] authored Apr 28, 2020
2 parents efed91a + 3b746be commit 6f8db38
Show file tree
Hide file tree
Showing 63 changed files with 1,008 additions and 248 deletions.
4 changes: 2 additions & 2 deletions docs/CppInteroperabilityManifesto.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ that pick different sides, forcing the user to choose.

Swift/C++ interoperability builds on top of the Swift/C interoperability, so it
helps to be familiar with [Swift's strategy for importing C
modules](HowSwiftImportsCModules.md).
modules](HowSwiftImportsCAPIs.md).

# Importing C++ APIs into Swift

Expand Down Expand Up @@ -2406,7 +2406,7 @@ unambiguously to C++.
// C++ support module in the Swift standard library.

typealias CxxPointer<T> = UnsafeMutablePointer<T> // T*
typealias CxxConstPointer<T> = UnsafeMutablePointer<T> // const T*
typealias CxxConstPointer<T> = UnsafePointer<T> // const T*

typealias CxxRef<T> = UnsafeMutablePointer<T> // T&
typealias CxxConstRef<T> = UnsafePointer<T> // const T&
Expand Down
2 changes: 2 additions & 0 deletions include/swift/IDE/RefactoringKinds.def
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ CURSOR_REFACTORING(TrailingClosure, "Convert To Trailing Closure", trailingclosu

CURSOR_REFACTORING(MemberwiseInitLocalRefactoring, "Generate Memberwise Initializer", memberwise.init.local.refactoring)

CURSOR_REFACTORING(AddEquatableConformance, "Add Equatable Conformance", add.equatable.conformance)

RANGE_REFACTORING(ExtractExpr, "Extract Expression", extract.expr)

RANGE_REFACTORING(ExtractFunction, "Extract Method", extract.function)
Expand Down
6 changes: 3 additions & 3 deletions include/swift/SILOptimizer/Utils/InstOptUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@ FullApplySite findApplyFromDevirtualizedResult(SILValue value);
/// - a type of the return value is a subclass of the expected return type.
/// - actual return type and expected return type differ in optionality.
/// - both types are tuple-types and some of the elements need to be casted.
SILValue castValueToABICompatibleType(SILBuilder *builder, SILLocation Loc,
SILValue value, SILType srcTy,
SILType destTy);
std::pair<SILValue, bool /* changedCFG */>
castValueToABICompatibleType(SILBuilder *builder, SILLocation Loc,
SILValue value, SILType srcTy, SILType destTy);
/// Peek through trivial Enum initialization, typically for pointless
/// Optionals.
///
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/ASTScopeCreation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ class ScopeCreator final {
}
}
}
for (const auto dcAndScope : bogusDCs) {
for (const auto &dcAndScope : bogusDCs) {
llvm::errs() << "ASTScope tree confabulated: " << dcAndScope.getFirst()
<< ":\n";
dcAndScope.getFirst()->printContext(llvm::errs());
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/ASTScopeLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ bool isLocWithinAnInactiveClause(const SourceLoc loc, SourceFile *SF) {
for (const auto &clause : ifc->getClauses()) {
if (clause.isActive)
continue;
for (const auto n : clause.Elements) {
for (const auto &n : clause.Elements) {
SourceRange sr = n.getSourceRange();
if (sr.isValid() && SM.rangeContainsTokenLoc(sr, loc)) {
wasFoundWithinInactiveClause = true;
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1828,7 +1828,7 @@ static bool isDefaultInitializable(const TypeRepr *typeRepr, ASTContext &ctx) {
if (tuple->hasEllipsis())
return false;

for (const auto elt : tuple->getElements()) {
for (const auto &elt : tuple->getElements()) {
if (!isDefaultInitializable(elt.Type, ctx))
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions lib/AST/Expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1897,6 +1897,8 @@ Expr *AutoClosureExpr::getUnwrappedCurryThunkExpr() const {

if (auto *openExistential = dyn_cast<OpenExistentialExpr>(innerBody)) {
innerBody = openExistential->getSubExpr();
if (auto *ICE = dyn_cast<ImplicitConversionExpr>(innerBody))
innerBody = ICE->getSyntacticSubExpr();
}

if (auto *outerCall = dyn_cast<ApplyExpr>(innerBody)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/FrontendSourceFileDepGraphFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ void FrontendSourceFileDepGraphFactory::addAllDefinedDecls() {
template <NodeKind kind, typename ContentsT>
void FrontendSourceFileDepGraphFactory::addAllDefinedDeclsOfAGivenType(
std::vector<ContentsT> &contentsVec) {
for (const auto declOrPair : contentsVec) {
for (const auto &declOrPair : contentsVec) {
Optional<std::string> fp = getFingerprintIfAny(declOrPair);
addADefinedDecl(
DependencyKey::createForProvidedEntityInterface<kind>(declOrPair),
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/GenericSignatureBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5508,7 +5508,7 @@ GenericSignatureBuilder::finalize(SourceLoc loc,
for (const auto gp : getGenericParams())
depth = std::max(depth, gp->getDepth());

for (const auto pa : Impl->PotentialArchetypes) {
for (const auto &pa : Impl->PotentialArchetypes) {
auto rep = pa->getRepresentative();

if (pa->getRootGenericParamKey().Depth < depth)
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/IncrementalRanges.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ std::vector<CharSourceRange> SwiftRangesEmitter::coalesceSortedRanges(
std::vector<SerializableSourceRange>
SwiftRangesEmitter::serializeRanges(std::vector<CharSourceRange> ranges) const {
std::vector<SerializableSourceRange> result;
for (const auto r : ranges)
for (const auto &r : ranges)
result.push_back(SerializableSourceRange(r, sourceMgr));
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/NameLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2160,7 +2160,7 @@ InheritedProtocolsRequest::evaluate(Evaluator &evaluator,
SmallPtrSet<const ProtocolDecl *, 2> known;
known.insert(PD);
bool anyObject = false;
for (const auto found : getDirectlyInheritedNominalTypeDecls(PD, anyObject)) {
for (const auto &found : getDirectlyInheritedNominalTypeDecls(PD, anyObject)) {
if (auto proto = dyn_cast<ProtocolDecl>(found.Item)) {
if (known.insert(proto).second)
result.push_back(proto);
Expand Down
2 changes: 1 addition & 1 deletion lib/Basic/OutputFileMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ static void writeQuotedEscaped(llvm::raw_ostream &os,

void OutputFileMap::write(llvm::raw_ostream &os,
ArrayRef<StringRef> inputs) const {
for (const auto input : inputs) {
for (const auto &input : inputs) {
writeQuotedEscaped(os, input);
os << ":";

Expand Down
2 changes: 1 addition & 1 deletion lib/Driver/Job.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ CommandOutput::dump() const {

void CommandOutput::writeOutputFileMap(llvm::raw_ostream &out) const {
SmallVector<StringRef, 4> inputs;
for (const CommandInputPair IP : Inputs) {
for (const CommandInputPair &IP : Inputs) {
assert(IP.Base == IP.Primary && !IP.Base.empty() &&
"output file maps won't work if these differ");
inputs.push_back(IP.Primary);
Expand Down
40 changes: 33 additions & 7 deletions lib/IDE/CodeCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1872,6 +1872,10 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
expectedTypeContext.possibleTypes.push_back(T);
}

void setIdealExpectedType(Type Ty) {
expectedTypeContext.idealType = Ty;
}

CodeCompletionContext::TypeContextKind typeContextKind() const {
if (expectedTypeContext.empty()) {
return CodeCompletionContext::TypeContextKind::None;
Expand Down Expand Up @@ -2011,12 +2015,6 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
if (ForcedSemanticContext)
return *ForcedSemanticContext;

if (IsUnresolvedMember) {
if (isa<EnumElementDecl>(D)) {
return SemanticContextKind::ExpressionSpecific;
}
}

switch (Reason) {
case DeclVisibilityKind::LocalVariable:
case DeclVisibilityKind::FunctionParameter:
Expand Down Expand Up @@ -2080,6 +2078,23 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
llvm_unreachable("unhandled kind");
}

bool isUnresolvedMemberIdealType(Type Ty) {
assert(Ty);
if (!IsUnresolvedMember)
return false;
Type idealTy = expectedTypeContext.idealType;
if (!idealTy)
return false;
/// Consider optional object type is the ideal.
/// For exmaple:
/// enum MyEnum { case foo, bar }
/// func foo(_: MyEnum?)
/// fooo(.<HERE>)
/// Prefer '.foo' and '.bar' over '.some' and '.none'.
idealTy = idealTy->lookThroughAllOptionalTypes();
return idealTy->isEqual(Ty);
}

void addValueBaseName(CodeCompletionResultBuilder &Builder,
DeclBaseName Name) {
auto NameStr = Name.userFacingName();
Expand Down Expand Up @@ -2406,6 +2421,9 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
DynamicOrOptional);
else
addTypeAnnotation(Builder, VarType);

if (isUnresolvedMemberIdealType(VarType))
Builder.setSemanticContext(SemanticContextKind::ExpressionSpecific);
}

static bool hasInterestingDefaultValues(const AbstractFunctionDecl *func) {
Expand Down Expand Up @@ -2862,6 +2880,9 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
}
}
Builder.addTypeAnnotation(TypeStr);

if (isUnresolvedMemberIdealType(ResultType))
Builder.setSemanticContext(SemanticContextKind::ExpressionSpecific);
};

if (!AFT || IsImplicitlyCurriedInstanceMethod) {
Expand Down Expand Up @@ -3148,6 +3169,9 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
}

addTypeAnnotation(Builder, EnumType);

if (isUnresolvedMemberIdealType(EnumType))
Builder.setSemanticContext(SemanticContextKind::ExpressionSpecific);
}

void addKeyword(StringRef Name, Type TypeAnnotation = Type(),
Expand Down Expand Up @@ -4117,7 +4141,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
auto &SM = CurrDeclContext->getASTContext().SourceMgr;
if (DotLoc.isValid())
bytesToErase = SM.getByteDistance(DotLoc, SM.getCodeCompletionLoc());
addKeyword("nil", T, SemanticContextKind::ExpressionSpecific,
addKeyword("nil", T, SemanticContextKind::None,
CodeCompletionKeywordKind::kw_nil, bytesToErase);
}
getUnresolvedMemberCompletions(T);
Expand Down Expand Up @@ -5755,6 +5779,7 @@ void CodeCompletionCallbacksImpl::doneParsing() {
ExprContextInfo ContextInfo(CurDeclContext, CodeCompleteTokenExpr);
Lookup.setExpectedTypes(ContextInfo.getPossibleTypes(),
ContextInfo.isSingleExpressionBody());
Lookup.setIdealExpectedType(CodeCompleteTokenExpr->getType());
Lookup.getUnresolvedMemberCompletions(ContextInfo.getPossibleTypes());
DoPostfixExprBeginning();
break;
Expand Down Expand Up @@ -5810,6 +5835,7 @@ void CodeCompletionCallbacksImpl::doneParsing() {
ExprContextInfo ContextInfo(CurDeclContext, CodeCompleteTokenExpr);
Lookup.setExpectedTypes(ContextInfo.getPossibleTypes(),
ContextInfo.isSingleExpressionBody());
Lookup.setIdealExpectedType(CodeCompleteTokenExpr->getType());
Lookup.getUnresolvedMemberCompletions(ContextInfo.getPossibleTypes());
break;
}
Expand Down
7 changes: 7 additions & 0 deletions lib/IDE/CodeCompletionResultBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ struct ExpectedTypeContext {
/// Possible types of the code completion expression.
llvm::SmallVector<Type, 4> possibleTypes;

/// Pre typechecked type of the expression at the completion position.
Type idealType;

/// Whether the `ExpectedTypes` comes from a single-expression body, e.g.
/// `foo({ here })`.
///
Expand Down Expand Up @@ -136,6 +139,10 @@ class CodeCompletionResultBuilder {
NotRecReason = Reason;
}

void setSemanticContext(SemanticContextKind Kind) {
SemanticContext = Kind;
}

void
setExpectedTypeRelation(CodeCompletionResult::ExpectedTypeRelation relation) {
ExpectedTypeRelation = relation;
Expand Down
4 changes: 2 additions & 2 deletions lib/IDE/CommentConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ struct CommentToXMLConverter {

void printTagFields(ArrayRef<StringRef> Tags) {
OS << "<Tags>";
for (const auto Tag : Tags) {
for (const auto &Tag : Tags) {
if (Tag.empty()) {
continue;
}
Expand Down Expand Up @@ -821,7 +821,7 @@ void ide::getDocumentationCommentAsDoxygen(const DocComment *DC,
Converter.visit(N);
}

for (const auto PF : DC->getParamFields()) {
for (const auto &PF : DC->getParamFields()) {
Converter.visit(PF);
}

Expand Down
Loading

0 comments on commit 6f8db38

Please sign in to comment.