Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5742b1d
Add leading space for left brace
evnik Jul 9, 2022
e72eb0d
[SILPrinter] print target branch debug names in SIL dumps
ktoso Jul 14, 2022
e9dedf3
[cxx-interop][SwiftCompilerSources] Use `swift::DiagnosticEngine` ins…
egorzhdan Jul 13, 2022
5c412b4
Sema: Don't allow opaque return types to reference DynamicSelfType
slavapestov Jul 13, 2022
421f39a
Sema: Fix some edge cases with opaque return types in structural posi…
slavapestov Jul 13, 2022
78e9af7
SILGen: Fix ownership violation in visitUnderlyingToOpaqueExpr()
slavapestov Jul 14, 2022
96f16e0
AccessStorageAnalysis: ignore `_swift_stdlib_malloc_size` and `_swift…
eeckstein Jul 14, 2022
692db6d
SideEffectAnalysis: ignore `_swift_stdlib_malloc_size` and `_swift_st…
eeckstein Jul 14, 2022
ff222ac
Setting hardcode `SWIFT_NOEXCEPT` and `noexcept` flags only to
Robertorosmaninho Jun 22, 2022
7a2e6d8
Merge pull request #60056 from eeckstein/ignore-malloc-size-in-analysis
eeckstein Jul 15, 2022
b63770b
also handle general successors
ktoso Jul 15, 2022
f91b892
Merge pull request #60053 from ktoso/wip-sil-branch-names
swift-ci Jul 15, 2022
11877d7
[Sema][Revert] Revert CTP to CTP_ReturnStmt for closure result in ret…
LucianoPAlmeida Jul 15, 2022
ceb093d
Merge pull request #59787 from Robertorosmaninho/cxx-interop/SwiftToC…
hyp Jul 15, 2022
fadee9c
Merge pull request #59980 from evnik/LeftBraceTrivia
ahoppen Jul 15, 2022
0ca2cc9
Merge pull request #60044 from slavapestov/fix-two-opaque-return-type…
slavapestov Jul 15, 2022
1be0086
[cxx-interop] Mark `operator!` as `prefix func`
egorzhdan Jul 15, 2022
5a33fc9
Merge pull request #60045 from apple/egorzhdan/scs-diagnostic-engine
egorzhdan Jul 15, 2022
2028931
Merge pull request #60068 from apple/egorzhdan/cxx-operator-exclaim-p…
egorzhdan Jul 15, 2022
44c35a2
[cxx-interop] Fix lookup of member operators
egorzhdan Jul 15, 2022
88c55c1
[interop][SwiftToCxx] add support for passing/returning value types f…
hyp Jul 15, 2022
42b2cd2
NFC, PrintAsClang: remove superfluous include
hyp Jul 15, 2022
584fb83
Merge pull request #60067 from LucianoPAlmeida/revert-closure-cpt
xedin Jul 15, 2022
9a38146
Merge pull request #60070 from apple/egorzhdan/cxx-operator-lookup-fix
egorzhdan Jul 15, 2022
4e1a1b8
Merge pull request #60071 from hyp/eng/value-type-xmod-refs
hyp Jul 15, 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
10 changes: 2 additions & 8 deletions SwiftCompilerSources/Sources/AST/DiagnosticEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,11 @@ public struct DiagnosticFixIt {
}

public struct DiagnosticEngine {
private let bridged: BridgedDiagnosticEngine
private let bridged: swift.DiagnosticEngine

public init(bridged: BridgedDiagnosticEngine) {
public init(bridged: swift.DiagnosticEngine) {
self.bridged = bridged
}
public init?(bridged: BridgedOptionalDiagnosticEngine) {
guard let object = bridged.object else {
return nil
}
self.bridged = BridgedDiagnosticEngine(object: object)
}

public func diagnose(_ position: SourceLoc?,
_ id: DiagID,
Expand Down
7 changes: 4 additions & 3 deletions SwiftCompilerSources/Sources/Parse/Regex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private func _RegexLiteralLexingFn(
_ curPtrPtr: UnsafeMutablePointer<UnsafePointer<CChar>>,
_ bufferEndPtr: UnsafePointer<CChar>,
_ mustBeRegex: CBool,
_ bridgedDiagnosticEngine: BridgedOptionalDiagnosticEngine
_ bridgedDiagnosticEngine: swift.DiagnosticEngine?
) -> /*CompletelyErroneous*/ CBool {
let inputPtr = curPtrPtr.pointee

Expand All @@ -62,7 +62,8 @@ private func _RegexLiteralLexingFn(

if let error = error {
// Emit diagnostic if diagnostics are enabled.
if let diagEngine = DiagnosticEngine(bridged: bridgedDiagnosticEngine) {
if let bridged = bridgedDiagnosticEngine {
let diagEngine = DiagnosticEngine(bridged: bridged)
let startLoc = SourceLoc(
locationInFile: error.location.assumingMemoryBound(to: UInt8.self))!
diagEngine.diagnose(startLoc, .regex_literal_parsing_error, error.message)
Expand Down Expand Up @@ -93,7 +94,7 @@ public func _RegexLiteralParsingFn(
_ captureStructureOut: UnsafeMutableRawPointer,
_ captureStructureSize: CUnsignedInt,
_ bridgedDiagnosticBaseLoc: swift.SourceLoc,
_ bridgedDiagnosticEngine: BridgedDiagnosticEngine
_ bridgedDiagnosticEngine: swift.DiagnosticEngine
) -> Bool {
let str = String(cString: inputPtr)
let captureBuffer = UnsafeMutableRawBufferPointer(
Expand Down
12 changes: 1 addition & 11 deletions include/swift/AST/ASTBridging.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,12 @@ typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedDiagID : uint32_t {
#include "swift/AST/DiagnosticsAll.def"
} BridgedDiagID;

typedef struct {
void * _Nonnull object;
} BridgedDiagnosticEngine;

typedef struct {
void *_Nullable object;
} BridgedOptionalDiagnosticEngine;

// FIXME: Can we bridge InFlightDiagnostic?
void DiagnosticEngine_diagnose(BridgedDiagnosticEngine, swift::SourceLoc loc,
void DiagnosticEngine_diagnose(swift::DiagnosticEngine &, swift::SourceLoc loc,
BridgedDiagID diagID, BridgedArrayRef arguments,
swift::CharSourceRange highlight,
BridgedArrayRef fixIts);

bool DiagnosticEngine_hadAnyError(BridgedDiagnosticEngine);

SWIFT_END_NULLABILITY_ANNOTATIONS

#endif // SWIFT_AST_ASTBRIDGING_H
32 changes: 0 additions & 32 deletions include/swift/AST/BridgingUtils.h

This file was deleted.

2 changes: 1 addition & 1 deletion include/swift/AST/DiagnosticEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ namespace swift {

/// Class responsible for formatting diagnostics and presenting them
/// to the user.
class DiagnosticEngine {
class SWIFT_IMPORT_REFERENCE DiagnosticEngine {
public:
/// The source manager used to interpret source locations and
/// display diagnostics.
Expand Down
3 changes: 3 additions & 0 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -4215,6 +4215,9 @@ NOTE(opaque_type_underlying_type_candidate_here,none,
ERROR(opaque_type_self_referential_underlying_type,none,
"function opaque return type was inferred as %0, which defines the "
"opaque type in terms of itself", (Type))
ERROR(opaque_type_cannot_contain_dynamic_self,none,
"function with opaque return type cannot return "
"the covariant 'Self' type of a class", ())
ERROR(opaque_type_var_no_init,none,
"property declares an opaque return type, but has no initializer "
"expression from which to infer an underlying type", ())
Expand Down
7 changes: 7 additions & 0 deletions include/swift/Basic/Compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,11 @@
#define SWIFT_VFORMAT(fmt)
#endif

// Tells Swift's ClangImporter to import a C++ type as a foreign reference type.
#if __has_attribute(swift_attr)
#define SWIFT_IMPORT_REFERENCE __attribute__((swift_attr("import_as_ref")))
#else
#define SWIFT_IMPORT_REFERENCE
#endif

#endif // SWIFT_BASIC_COMPILER_H
14 changes: 14 additions & 0 deletions include/swift/IRGen/IRABIDetailsProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ class IRABIDetailsProvider {
SizeType alignment;
};

/// Information about any ABI additional parameters.
struct ABIAdditionalParam {
enum class ABIParameterRole { Self, Error };

ABIParameterRole role;
TypeDecl *type;
};

SmallVector<ABIAdditionalParam, 1> ABIAdditionalParams;

/// Returns the size and alignment for the given type, or \c None if the type
/// is not a fixed layout type.
llvm::Optional<SizeAndAlignment>
Expand Down Expand Up @@ -99,6 +109,10 @@ class IRABIDetailsProvider {
/// their tag indices from the given EnumDecl
llvm::MapVector<EnumElementDecl *, unsigned> getEnumTagMapping(EnumDecl *ED);

/// Returns the additional params if they exist after lowering the function.
SmallVector<ABIAdditionalParam, 1>
getFunctionABIAdditionalParams(AbstractFunctionDecl *fd);

private:
std::unique_ptr<IRABIDetailsProviderImpl> impl;
};
Expand Down
12 changes: 6 additions & 6 deletions include/swift/Parse/RegexParserBridging.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@
/// past.
/// - MustBeRegex: whether an error during lexing should be considered a regex
/// literal, or some thing else.
/// - BridgedOptionalDiagnosticEngine: RegexLiteralLexingFn should diagnose the
/// token using this engine.
/// - OptionalDiagnosticEngine: RegexLiteralLexingFn should diagnose the
/// token using this engine.
///
/// Returns: A bool indicating whether lexing was completely erroneous, and
/// cannot be recovered from, or false if there either was no error,
/// or there was a recoverable error.
typedef bool (*RegexLiteralLexingFn)(
/*CurPtrPtr*/ const char *_Nonnull *_Nonnull,
/*BufferEnd*/ const char *_Nonnull,
/*MustBeRegex*/ bool, BridgedOptionalDiagnosticEngine);
/*MustBeRegex*/ bool, swift::DiagnosticEngine *_Nullable);
void Parser_registerRegexLiteralLexingFn(RegexLiteralLexingFn _Nullable fn);

/// Parse a regex literal string. Takes the following arguments:
Expand All @@ -48,16 +48,16 @@ void Parser_registerRegexLiteralLexingFn(RegexLiteralLexingFn _Nullable fn);
/// - CaptureStructureSize: The size of the capture structure buffer. Must be
/// greater than or equal to `strlen(InputPtr) + 3`.
/// - DiagnosticBaseLoc: Start location of the regex literal.
/// - BridgedDiagnosticEngine: RegexLiteralParsingFn should diagnose the
/// parsing errors using this engine.
/// - DiagnosticEngine: RegexLiteralParsingFn should diagnose the
/// parsing errors using this engine.
///
/// Returns: A bool value indicating if there was an error while parsing.
typedef bool (*RegexLiteralParsingFn)(/*InputPtr*/ const char *_Nonnull,
/*VersionOut*/ unsigned *_Nonnull,
/*CaptureStructureOut*/ void *_Nonnull,
/*CaptureStructureSize*/ unsigned,
/*DiagnosticBaseLoc*/ swift::SourceLoc,
BridgedDiagnosticEngine);
swift::DiagnosticEngine &);
void Parser_registerRegexLiteralParsingFn(RegexLiteralParsingFn _Nullable fn);

#endif // REGEX_PARSER_BRIDGING
3 changes: 3 additions & 0 deletions include/swift/SIL/SILFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,9 @@ class SILFunction
SILFunction *getDynamicallyReplacedFunction() const {
return ReplacedFunction;
}

static SILFunction *getFunction(SILDeclRef ref, SILModule &M);

void setDynamicallyReplacedFunction(SILFunction *f) {
assert(ReplacedFunction == nullptr && "already set");
assert(!hasObjCReplacement());
Expand Down
5 changes: 1 addition & 4 deletions include/swift/SILOptimizer/Analysis/AccessStorageAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,7 @@ class FunctionAccessStorage {
/// the callee.
///
/// TODO: Summarize ArraySemanticsCall accesses.
bool summarizeCall(FullApplySite fullApply) {
assert(accessResult.isEmpty() && "expected uninitialized results.");
return false;
}
bool summarizeCall(FullApplySite fullApply);

/// Merge effects directly from \p RHS.
bool mergeFrom(const FunctionAccessStorage &RHS) {
Expand Down
19 changes: 2 additions & 17 deletions lib/AST/ASTBridging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,18 @@

using namespace swift;

namespace {
/// BridgedDiagnosticEngine -> DiagnosticEngine *.
DiagnosticEngine *getDiagnosticEngine(const BridgedDiagnosticEngine &bridged) {
return static_cast<DiagnosticEngine *>(bridged.object);
}

} // namespace

void DiagnosticEngine_diagnose(
BridgedDiagnosticEngine bridgedEngine, SourceLoc loc,
BridgedDiagID bridgedDiagID,
DiagnosticEngine &engine, SourceLoc loc, BridgedDiagID bridgedDiagID,
BridgedArrayRef /*DiagnosticArgument*/ bridgedArguments,
CharSourceRange highlight,
BridgedArrayRef /*DiagnosticInfo::FixIt*/ bridgedFixIts) {
auto *D = getDiagnosticEngine(bridgedEngine);

auto diagID = static_cast<DiagID>(bridgedDiagID);
SmallVector<DiagnosticArgument, 2> arguments;
for (auto arg : getArrayRef<DiagnosticArgument>(bridgedArguments)) {
arguments.push_back(arg);
}
auto inflight = D->diagnose(loc, diagID, arguments);
auto inflight = engine.diagnose(loc, diagID, arguments);

// Add highlight.
if (highlight.isValid()) {
Expand All @@ -52,8 +42,3 @@ void DiagnosticEngine_diagnose(
inflight.fixItReplaceChars(range.getStart(), range.getEnd(), text);
}
}

bool DiagnosticEngine_hadAnyError(BridgedDiagnosticEngine bridgedEngine) {
auto *D = getDiagnosticEngine(bridgedEngine);
return D->hadAnyError();
}
3 changes: 3 additions & 0 deletions lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2234,6 +2234,9 @@ namespace {

// Make the actual member operator private.
MD->overwriteAccess(AccessLevel::Private);

// Make sure the synthesized decl can be found by lookupDirect.
result->addMemberToLookupTable(opFuncDecl);
}

if (cxxMethod->getDeclName().isIdentifier()) {
Expand Down
13 changes: 11 additions & 2 deletions lib/ClangImporter/SwiftDeclSynthesizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1881,9 +1881,13 @@ synthesizeOperatorMethodBody(AbstractFunctionDecl *afd, void *context) {
FuncDecl *
SwiftDeclSynthesizer::makeOperator(FuncDecl *operatorMethod,
clang::CXXMethodDecl *clangOperator) {
clang::OverloadedOperatorKind opKind = clangOperator->getOverloadedOperator();

assert(opKind != clang::OverloadedOperatorKind::OO_None &&
"expected a C++ operator");

auto &ctx = ImporterImpl.SwiftContext;
auto opName =
clang::getOperatorSpelling(clangOperator->getOverloadedOperator());
auto opName = clang::getOperatorSpelling(opKind);
auto paramList = operatorMethod->getParameters();
auto genericParamList = operatorMethod->getGenericParams();

Expand Down Expand Up @@ -1935,6 +1939,11 @@ SwiftDeclSynthesizer::makeOperator(FuncDecl *operatorMethod,
topLevelStaticFuncDecl->setBodySynthesizer(synthesizeOperatorMethodBody,
operatorMethod);

// If this is a unary prefix operator (e.g. `!`), add a `prefix` attribute.
if (clangOperator->param_empty()) {
topLevelStaticFuncDecl->getAttrs().add(new (ctx) PrefixAttr(SourceLoc()));
}

return topLevelStaticFuncDecl;
}

Expand Down
37 changes: 35 additions & 2 deletions lib/IRGen/IRABIDetailsProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//

#include "swift/IRGen/IRABIDetailsProvider.h"
#include "Callee.h"
#include "FixedTypeInfo.h"
#include "GenEnum.h"
#include "GenType.h"
Expand All @@ -21,7 +22,9 @@
#include "swift/AST/ASTContext.h"
#include "swift/AST/IRGenOptions.h"
#include "swift/AST/Types.h"
#include "swift/SIL/SILFunctionBuilder.h"
#include "swift/SIL/SILModule.h"
#include "swift/Subsystems.h"
#include "clang/CodeGen/ModuleBuilder.h"
#include "clang/CodeGen/SwiftCallingConv.h"
#include "llvm/IR/DerivedTypes.h"
Expand Down Expand Up @@ -125,8 +128,8 @@ class IRABIDetailsProviderImpl {

llvm::MapVector<EnumElementDecl *, unsigned> getEnumTagMapping(EnumDecl *ED) {
llvm::MapVector<EnumElementDecl *, unsigned> elements;
auto &enumImplStrat = getEnumImplStrategy(
IGM, ED->getDeclaredType()->getCanonicalType());
auto &enumImplStrat =
getEnumImplStrategy(IGM, ED->getDeclaredType()->getCanonicalType());

for (auto *element : ED->getAllElements()) {
auto tagIdx = enumImplStrat.getTagIndex(element);
Expand All @@ -136,6 +139,30 @@ class IRABIDetailsProviderImpl {
return elements;
}

llvm::SmallVector<IRABIDetailsProvider::ABIAdditionalParam, 1>
getFunctionABIAdditionalParams(AbstractFunctionDecl *afd) {
llvm::SmallVector<IRABIDetailsProvider::ABIAdditionalParam, 1> params;

auto function = SILFunction::getFunction(SILDeclRef(afd), *silMod);

auto silFuncType = function->getLoweredFunctionType();
auto funcPointerKind =
FunctionPointerKind(FunctionPointerKind::BasicKind::Function);
auto signature = Signature::getUncached(IGM, silFuncType, funcPointerKind);

for (auto attrSet : signature.getAttributes()) {
if (attrSet.hasAttribute(llvm::Attribute::AttrKind::SwiftSelf))
params.push_back(
{IRABIDetailsProvider::ABIAdditionalParam::ABIParameterRole::Self,
typeConverter.Context.getOpaquePointerDecl()});
if (attrSet.hasAttribute(llvm::Attribute::AttrKind::SwiftError))
params.push_back(
{IRABIDetailsProvider::ABIAdditionalParam::ABIParameterRole::Error,
typeConverter.Context.getOpaquePointerDecl()});
}
return params;
}

private:
Lowering::TypeConverter typeConverter;
// Default silOptions are sufficient, as we don't need to generated SIL.
Expand All @@ -158,6 +185,12 @@ IRABIDetailsProvider::getTypeSizeAlignment(const NominalTypeDecl *TD) {
return impl->getTypeSizeAlignment(TD);
}

llvm::SmallVector<IRABIDetailsProvider::ABIAdditionalParam, 1>
IRABIDetailsProvider::getFunctionABIAdditionalParams(
AbstractFunctionDecl *afd) {
return impl->getFunctionABIAdditionalParams(afd);
}

bool IRABIDetailsProvider::shouldPassIndirectly(Type t) {
return impl->shouldPassIndirectly(t);
}
Expand Down
3 changes: 1 addition & 2 deletions lib/Parse/Lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
//===----------------------------------------------------------------------===//

#include "swift/Parse/Lexer.h"
#include "swift/AST/BridgingUtils.h"
#include "swift/AST/DiagnosticsParse.h"
#include "swift/AST/Identifier.h"
#include "swift/Basic/LangOptions.h"
Expand Down Expand Up @@ -2091,7 +2090,7 @@ const char *Lexer::tryScanRegexLiteral(const char *TokStart, bool MustBeRegex,
// recovered from.
auto *Ptr = TokStart;
CompletelyErroneous = regexLiteralLexingFn(
&Ptr, BufferEnd, MustBeRegex, getBridgedOptionalDiagnosticEngine(Diags));
&Ptr, BufferEnd, MustBeRegex, Diags);

// If we didn't make any lexing progress, this isn't a regex literal and we
// should fallback to lexing as something else.
Expand Down
Loading