Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7a0754b
[Immediate] Switch immediate mode from MCJIT to LLJIT.
lhames Feb 15, 2020
557e566
[SE-0263] Add test for public API
benrimmington Mar 3, 2020
cf89884
[SE-0263] Rename internal API
benrimmington Mar 3, 2020
b11856a
[SE-0263] Update documentation
benrimmington Mar 3, 2020
1767167
[Immediate] Switch the JIT codegen opt-level to Default.
lhames Mar 5, 2020
f34fa7f
Match prototype’s #file string format to upcoming SE-0274 revision
beccadax Jan 21, 2020
fe11864
IRGen: Generate runtime type manglings using ObjC runtime names.
jckarter Mar 5, 2020
8e5ca8a
[NFC] Generate `#file` -> `#filePath` table ahead of time
beccadax Jan 24, 2020
54f5967
Include `#file` -> `#filePath` table in printed SIL
beccadax Jan 24, 2020
0aec5a7
[ownership] Implement InteriorPointer abstraction/validate current re…
gottesmm Mar 5, 2020
1a981f9
[Constraint system] Clean up constraints associated with patterns.
DougGregor Mar 6, 2020
d590823
Warn about conflicts between #file strings
beccadax Jan 24, 2020
85599f7
Keep gyb from messing up line endings on Windows
beccadax Mar 6, 2020
62ab3df
Temporarily disable new #file test on Windows
beccadax Mar 6, 2020
c4ed7bd
Merge pull request #30249 from gottesmm/pr-1c59567660f53bc35248d864c5…
gottesmm Mar 6, 2020
2cc9446
Merge pull request #29412 from brentdax/two-revisions-for-slashing
beccadax Mar 6, 2020
633d46f
[test] Disable introspective test in back deployment
milseman Mar 6, 2020
58950a5
Merge pull request #30250 from jckarter/mangle-objc-runtime-names
jckarter Mar 6, 2020
fd468d0
[stdlib] Disable assertion tripping up ASAN
milseman Mar 6, 2020
8d5d381
Merge pull request #30180 from benrimmington/se-0263-test
milseman Mar 6, 2020
b2facd0
Merge pull request #30258 from DougGregor/constraint-pattern-locators
DougGregor Mar 6, 2020
1d5c008
Merge pull request #29863 from lhames/switch-imm-to-lljit
lhames Mar 6, 2020
c4f1b83
Merge pull request #30259 from milseman/backspective
milseman Mar 6, 2020
3f69d6b
Merge pull request #30260 from milseman/assert_san
rintaro Mar 6, 2020
069e7e8
Merge branch 'master' into master-next
beccadax Mar 6, 2020
8c2aeb3
Patch up runConstructors() change in Immediate.cpp
beccadax Mar 6, 2020
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
4 changes: 2 additions & 2 deletions include/swift/AST/ASTMangler.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class ASTMangler : public Mangler {
bool OptimizeProtocolNames = true;

/// If enabled, use Objective-C runtime names when mangling @objc Swift
/// protocols.
bool UseObjCProtocolNames = false;
/// protocols and classes.
bool UseObjCRuntimeNames = false;

/// If enabled, non-canonical types are allowed and type alias types get a
/// special mangling.
Expand Down
8 changes: 8 additions & 0 deletions include/swift/AST/DiagnosticsCommon.def
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ ERROR(sdk_node_unrecognized_decl_kind,none,
ERROR(sdk_node_unrecognized_accessor_kind,none,
"unrecognized accessor kind '%0' in SDK node", (StringRef))

// Emitted from ModuleDecl::computeMagicFileStringMap()
WARNING(pound_source_location_creates_pound_file_conflicts,none,
"'#sourceLocation' directive produces '#file' string of '%0', which "
"conflicts with '#file' strings produced by other paths in the module",
(StringRef))
NOTE(fixit_correct_source_location_file,none,
"change file in '#sourceLocation' to '%0'", (StringRef))

//------------------------------------------------------------------------------
// MARK: Circular reference diagnostics
//------------------------------------------------------------------------------
Expand Down
50 changes: 50 additions & 0 deletions include/swift/AST/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,38 @@ enum class SourceFileKind {
Interface ///< Came from a .swiftinterface file, representing another module.
};

/// Contains information about where a particular path is used in
/// \c SourceFiles.
struct SourceFilePathInfo {
struct Comparator {
bool operator () (SourceLoc lhs, SourceLoc rhs) const {
return lhs.getOpaquePointerValue() <
rhs.getOpaquePointerValue();
}
};

SourceLoc physicalFileLoc{};
std::set<SourceLoc, Comparator> virtualFileLocs{}; // std::set for sorting

SourceFilePathInfo() = default;

void merge(const SourceFilePathInfo &other) {
if (other.physicalFileLoc.isValid()) {
assert(!physicalFileLoc.isValid());
physicalFileLoc = other.physicalFileLoc;
}

for (auto &elem : other.virtualFileLocs) {
virtualFileLocs.insert(elem);
}
}

bool operator == (const SourceFilePathInfo &other) const {
return physicalFileLoc == other.physicalFileLoc &&
virtualFileLocs == other.virtualFileLocs;
}
};

/// Discriminator for resilience strategy.
enum class ResilienceStrategy : unsigned {
/// Public nominal types: fragile
Expand Down Expand Up @@ -257,6 +289,24 @@ class ModuleDecl : public DeclContext, public TypeDecl {
void addFile(FileUnit &newFile);
void removeFile(FileUnit &existingFile);

/// Creates a map from \c #filePath strings to corresponding \c #file
/// strings, diagnosing any conflicts.
///
/// A given \c #filePath string always maps to exactly one \c #file string,
/// but it is possible for \c #sourceLocation directives to introduce
/// duplicates in the opposite direction. If there are such conflicts, this
/// method will diagnose the conflict and choose a "winner" among the paths
/// in a reproducible way. The \c bool paired with the \c #file string is
/// \c true for paths which did not have a conflict or won a conflict, and
/// \c false for paths which lost a conflict. Thus, if you want to generate a
/// reverse mapping, you should drop or special-case the \c #file strings that
/// are paired with \c false.
///
/// Note that this returns an empty StringMap if concise \c #file strings are
/// disabled. Users should fall back to using the file path in this case.
llvm::StringMap<std::pair<std::string, /*isWinner=*/bool>>
computeMagicFileStringMap(bool shouldDiagnose) const;

/// Add a file declaring a cross-import overlay.
void addCrossImportOverlayFile(StringRef file);

Expand Down
6 changes: 6 additions & 0 deletions include/swift/AST/SourceFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,12 @@ class SourceFile final : public FileUnit {
/// forwarded on to IRGen.
ASTStage_t ASTStage = Unprocessed;

/// Virtual filenames declared by #sourceLocation(file:) directives in this
/// file.
llvm::SmallVector<Located<StringRef>, 0> VirtualFilenames;

llvm::StringMap<SourceFilePathInfo> getInfoForUsedFilePaths() const;

SourceFile(ModuleDecl &M, SourceFileKind K, Optional<unsigned> bufferID,
ImplicitModuleImportKind ModImpKind, bool KeepParsedTokens = false,
bool KeepSyntaxTree = false, ParsingOptions parsingOpts = {});
Expand Down
92 changes: 92 additions & 0 deletions include/swift/SIL/OwnershipUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ struct BorrowScopeIntroducingValueKind {
llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
BorrowScopeIntroducingValueKind kind);

struct InteriorPointerOperand;

/// A higher level construct for working with values that represent the
/// introduction of a new borrow scope.
///
Expand Down Expand Up @@ -337,6 +339,15 @@ struct BorrowScopeIntroducingValue {
void print(llvm::raw_ostream &os) const;
SWIFT_DEBUG_DUMP { print(llvm::dbgs()); }

/// Visit each of the interior pointer uses of this underlying borrow
/// introduced value. These object -> address projections and any transitive
/// address uses must be treated as liveness requiring uses of the guaranteed
/// value and we can not shrink the scope beyond that point. Returns true if
/// we were able to understand all uses and thus guarantee we found all
/// interior pointer uses. Returns false otherwise.
bool visitInteriorPointerOperands(
function_ref<void(const InteriorPointerOperand &)> func) const;

private:
/// Internal constructor for failable static constructor. Please do not expand
/// its usage since it assumes the code passed in is well formed.
Expand Down Expand Up @@ -375,6 +386,87 @@ getSingleBorrowIntroducingValue(SILValue value);
Optional<BorrowScopeIntroducingValue>
getSingleBorrowIntroducingValue(SILValue inputValue);

struct InteriorPointerOperandKind {
using UnderlyingKindTy = std::underlying_type<SILInstructionKind>::type;

enum Kind : UnderlyingKindTy {
RefElementAddr = UnderlyingKindTy(SILInstructionKind::RefElementAddrInst),
RefTailAddr = UnderlyingKindTy(SILInstructionKind::RefTailAddrInst),
};

Kind value;

InteriorPointerOperandKind(Kind newValue) : value(newValue) {}
InteriorPointerOperandKind(const InteriorPointerOperandKind &other)
: value(other.value) {}
operator Kind() const { return value; }

static Optional<InteriorPointerOperandKind> get(Operand *use) {
switch (use->getUser()->getKind()) {
default:
return None;
case SILInstructionKind::RefElementAddrInst:
return InteriorPointerOperandKind(RefElementAddr);
case SILInstructionKind::RefTailAddrInst:
return InteriorPointerOperandKind(RefTailAddr);
}
}

void print(llvm::raw_ostream &os) const;
SWIFT_DEBUG_DUMP;
};

/// A mixed object->address projection that projects a memory location out of an
/// object with guaranteed ownership. All transitive address uses of the
/// interior pointer must be within the lifetime of the guaranteed lifetime. As
/// such, these must be treated as implicit uses of the parent guaranteed value.
struct InteriorPointerOperand {
Operand *operand;
InteriorPointerOperandKind kind;

InteriorPointerOperand(Operand *op)
: operand(op), kind(*InteriorPointerOperandKind::get(op)) {}

/// If value is a borrow introducer return it after doing some checks.
static Optional<InteriorPointerOperand> get(Operand *op) {
auto kind = InteriorPointerOperandKind::get(op);
if (!kind)
return None;
return InteriorPointerOperand(op, *kind);
}

/// Return the end scope of all borrow introducers of the parent value of this
/// projection. Returns true if we were able to find all borrow introducing
/// values.
bool visitBaseValueScopeEndingUses(function_ref<void(Operand *)> func) const {
SmallVector<BorrowScopeIntroducingValue, 4> introducers;
if (!getAllBorrowIntroducingValues(operand->get(), introducers))
return false;
for (const auto &introducer : introducers) {
if (!introducer.isLocalScope())
continue;
introducer.visitLocalScopeEndingUses(func);
}
return true;
}

SILValue getProjectedAddress() const {
switch (kind) {
case InteriorPointerOperandKind::RefElementAddr:
return cast<RefElementAddrInst>(operand->getUser());
case InteriorPointerOperandKind::RefTailAddr:
return cast<RefTailAddrInst>(operand->getUser());
}
llvm_unreachable("Covered switch isn't covered?!");
}

private:
/// Internal constructor for failable static constructor. Please do not expand
/// its usage since it assumes the code passed in is well formed.
InteriorPointerOperand(Operand *op, InteriorPointerOperandKind kind)
: operand(op), kind(kind) {}
};

} // namespace swift

#endif
27 changes: 20 additions & 7 deletions lib/AST/ASTMangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ void ASTMangler::appendDeclName(const ValueDecl *decl) {
break;
}
} else if (auto objCName =
getOverriddenSwiftProtocolObjCName(decl, UseObjCProtocolNames)) {
getOverriddenSwiftProtocolObjCName(decl, UseObjCRuntimeNames)) {
// @objc Swift protocols should be mangled as Objective-C protocols,
// so append the Objective-C runtime name.
appendIdentifier(*objCName);
Expand Down Expand Up @@ -1298,7 +1298,7 @@ void ASTMangler::appendBoundGenericArgs(Type type, bool &isFirstArgList) {
genericArgs = boundType->getGenericArgs();
if (Type parent = boundType->getParent()) {
GenericTypeDecl *decl = boundType->getAnyGeneric();
if (!getSpecialManglingContext(decl, UseObjCProtocolNames))
if (!getSpecialManglingContext(decl, UseObjCRuntimeNames))
appendBoundGenericArgs(parent->getDesugaredType(), isFirstArgList);
}
}
Expand Down Expand Up @@ -1610,7 +1610,7 @@ ASTMangler::getSpecialManglingContext(const ValueDecl *decl,
/// This is the top-level entrypoint for mangling <context>.
void ASTMangler::appendContextOf(const ValueDecl *decl) {
// Check for a special mangling context.
if (auto context = getSpecialManglingContext(decl, UseObjCProtocolNames)) {
if (auto context = getSpecialManglingContext(decl, UseObjCRuntimeNames)) {
switch (*context) {
case ClangImporterContext:
return appendOperator("SC");
Expand Down Expand Up @@ -1857,7 +1857,10 @@ void ASTMangler::appendProtocolName(const ProtocolDecl *protocol,

appendContextOf(protocol);
auto *clangDecl = protocol->getClangDecl();
if (auto *clangProto = cast_or_null<clang::ObjCProtocolDecl>(clangDecl))
auto clangProto = cast_or_null<clang::ObjCProtocolDecl>(clangDecl);
if (clangProto && UseObjCRuntimeNames)
appendIdentifier(clangProto->getObjCRuntimeNameAsString());
else if (clangProto)
appendIdentifier(clangProto->getName());
else
appendDeclName(protocol);
Expand Down Expand Up @@ -1928,15 +1931,25 @@ void ASTMangler::appendAnyGenericType(const GenericTypeDecl *decl) {
if (!namedDecl)
return false;

appendIdentifier(namedDecl->getName());
// Mangle ObjC classes using their runtime names.
auto interface = dyn_cast<clang::ObjCInterfaceDecl>(namedDecl);
auto protocol = dyn_cast<clang::ObjCProtocolDecl>(namedDecl);

if (UseObjCRuntimeNames && interface) {
appendIdentifier(interface->getObjCRuntimeNameAsString());
} else if (UseObjCRuntimeNames && protocol) {
appendIdentifier(protocol->getObjCRuntimeNameAsString());
} else {
appendIdentifier(namedDecl->getName());
}

// The important distinctions to maintain here are Objective-C's various
// namespaces: protocols, tags (struct/enum/union), and unqualified names.
// We continue to mangle "class" the standard Swift way because it feels
// weird to call that an alias, but they're really in the same namespace.
if (isa<clang::ObjCInterfaceDecl>(namedDecl)) {
if (interface) {
appendOperator("C");
} else if (isa<clang::ObjCProtocolDecl>(namedDecl)) {
} else if (protocol) {
appendOperator("P");
} else if (isa<clang::TagDecl>(namedDecl)) {
// Note: This includes enums, but that's okay. A Clang enum is not always
Expand Down
Loading