Skip to content

Commit d100148

Browse files
committed
Merge branch 'main' of github.com:apple/swift into maxd/main-merge
# Conflicts: # lib/ClangImporter/ClangImporter.cpp
2 parents ebd62db + 9f95d01 commit d100148

37 files changed

+346
-339
lines changed

CODE_OF_CONDUCT.md

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,5 @@
11
# Code of Conduct
2-
To be a truly great community, Swift.org needs to welcome developers from all walks of life,
3-
with different backgrounds, and with a wide range of experience. A diverse and friendly
4-
community will have more great ideas, more unique perspectives, and produce more great
5-
code. We will work diligently to make the Swift community welcoming to everyone.
62

7-
To give clarity of what is expected of our members, Swift.org has adopted the code of conduct
8-
defined by [contributor-covenant.org](https://www.contributor-covenant.org). This document is used across many open source
9-
communities, and we think it articulates our values well. The full text is copied below:
3+
The code of conduct for this project can be found at https://swift.org/code-of-conduct.
104

11-
### Contributor Code of Conduct v1.3
12-
As contributors and maintainers of this project, and in the interest of fostering an open and
13-
welcoming community, we pledge to respect all people who contribute through reporting
14-
issues, posting feature requests, updating documentation, submitting pull requests or patches,
15-
and other activities.
16-
17-
We are committed to making participation in this project a harassment-free experience for
18-
everyone, regardless of level of experience, gender, gender identity and expression, sexual
19-
orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or
20-
nationality.
21-
22-
Examples of unacceptable behavior by participants include:
23-
- The use of sexualized language or imagery
24-
- Personal attacks
25-
- Trolling or insulting/derogatory comments
26-
- Public or private harassment
27-
- Publishing other’s private information, such as physical or electronic addresses, without explicit permission
28-
- Other unethical or unprofessional conduct
29-
30-
Project maintainers have the right and responsibility to remove, edit, or reject comments,
31-
commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of
32-
Conduct, or to ban temporarily or permanently any contributor for other behaviors that they
33-
deem inappropriate, threatening, offensive, or harmful.
34-
35-
By adopting this Code of Conduct, project maintainers commit themselves to fairly and
36-
consistently applying these principles to every aspect of managing this project. Project
37-
maintainers who do not follow or enforce the Code of Conduct may be permanently removed
38-
from the project team.
39-
40-
This code of conduct applies both within project spaces and in public spaces when an
41-
individual is representing the project or its community.
42-
43-
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by
44-
contacting a project maintainer at [[email protected]](mailto:[email protected]). All complaints will be reviewed and
45-
investigated and will result in a response that is deemed necessary and appropriate to the
46-
circumstances. Maintainers are obligated to maintain confidentiality with regard to the reporter
47-
of an incident.
48-
49-
*This policy is adapted from the Contributor Code of Conduct [version 1.3.0](http://contributor-covenant.org/version/1/3/0/).*
50-
51-
### Reporting
52-
A working group of community members is committed to promptly addressing any [reported
53-
issues](mailto:[email protected]). Working group members are volunteers appointed by the project lead, with a
54-
preference for individuals with varied backgrounds and perspectives. Membership is expected
55-
to change regularly, and may grow or shrink.
5+
<!-- Copyright (c) 2021 Apple Inc and the Swift Project authors. All Rights Reserved. -->

include/swift/Basic/LangOptions.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ namespace swift {
8888
Enabled = 1,
8989

9090
/// Use both and assert if the results do not match.
91-
Verify = 2
91+
Verify = 2,
92+
93+
/// Use both, print a message only but do not assert on mismatch.
94+
Check = 3,
9295
};
9396

9497
/// A collection of options that affect the language dialect and

include/swift/Option/Options.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -626,15 +626,15 @@ def no_emit_module_separately:
626626

627627
def requirement_machine_protocol_signatures_EQ : Joined<["-"], "requirement-machine-protocol-signatures=">,
628628
Flags<[FrontendOption]>,
629-
HelpText<"Control usage of experimental protocol requirement signature minimization: 'on', 'off', or 'verify'">;
629+
HelpText<"Control usage of experimental protocol requirement signature minimization: 'on', 'off', 'verify' or 'check'">;
630630

631631
def requirement_machine_abstract_signatures_EQ : Joined<["-"], "requirement-machine-abstract-signatures=">,
632632
Flags<[FrontendOption]>,
633-
HelpText<"Control usage of experimental generic signature minimization: 'on', 'off', or 'verify'">;
633+
HelpText<"Control usage of experimental generic signature minimization: 'on', 'off', 'verify' or 'check'">;
634634

635635
def requirement_machine_inferred_signatures_EQ : Joined<["-"], "requirement-machine-inferred-signatures=">,
636636
Flags<[FrontendOption]>,
637-
HelpText<"Control usage of experimental generic signature minimization: 'on', 'off', or 'verify'">;
637+
HelpText<"Control usage of experimental generic signature minimization: 'on', 'off', 'verify' or 'check'">;
638638

639639
def experimental_hermetic_seal_at_link:
640640
Flag<["-"], "experimental-hermetic-seal-at-link">,

include/swift/Sema/ConstraintLocator.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ enum ContextualTypePurpose : uint8_t {
8585
CTP_ComposedPropertyWrapper, ///< Composed wrapper type expected to match
8686
///< former 'wrappedValue' type
8787

88+
CTP_ExprPattern, ///< `~=` operator application associated with expression
89+
/// pattern.
90+
8891
CTP_CannotFail, ///< Conversion can never fail. abort() if it does.
8992
};
9093

include/swift/Sema/ConstraintSystem.h

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,7 @@ class SolutionApplicationTargetsKey {
968968
stmtCondElement,
969969
expr,
970970
stmt,
971+
pattern,
971972
patternBindingEntry,
972973
varDecl,
973974
};
@@ -982,6 +983,8 @@ class SolutionApplicationTargetsKey {
982983

983984
const Stmt *stmt;
984985

986+
const Pattern *pattern;
987+
985988
struct PatternBindingEntry {
986989
const PatternBindingDecl *patternBinding;
987990
unsigned index;
@@ -1011,6 +1014,11 @@ class SolutionApplicationTargetsKey {
10111014
storage.stmt = stmt;
10121015
}
10131016

1017+
SolutionApplicationTargetsKey(const Pattern *pattern) {
1018+
kind = Kind::pattern;
1019+
storage.pattern = pattern;
1020+
}
1021+
10141022
SolutionApplicationTargetsKey(
10151023
const PatternBindingDecl *patternBinding, unsigned index) {
10161024
kind = Kind::patternBindingEntry;
@@ -1042,6 +1050,9 @@ class SolutionApplicationTargetsKey {
10421050
case Kind::stmt:
10431051
return lhs.storage.stmt == rhs.storage.stmt;
10441052

1053+
case Kind::pattern:
1054+
return lhs.storage.pattern == rhs.storage.pattern;
1055+
10451056
case Kind::patternBindingEntry:
10461057
return (lhs.storage.patternBindingEntry.patternBinding
10471058
== rhs.storage.patternBindingEntry.patternBinding) &&
@@ -1083,6 +1094,11 @@ class SolutionApplicationTargetsKey {
10831094
DenseMapInfo<unsigned>::getHashValue(static_cast<unsigned>(kind)),
10841095
DenseMapInfo<void *>::getHashValue(storage.stmt));
10851096

1097+
case Kind::pattern:
1098+
return hash_combine(
1099+
DenseMapInfo<unsigned>::getHashValue(static_cast<unsigned>(kind)),
1100+
DenseMapInfo<void *>::getHashValue(storage.pattern));
1101+
10861102
case Kind::patternBindingEntry:
10871103
return hash_combine(
10881104
DenseMapInfo<unsigned>::getHashValue(static_cast<unsigned>(kind)),
@@ -1701,6 +1717,13 @@ class SolutionApplicationTarget {
17011717
ContextualTypePurpose contextualPurpose,
17021718
TypeLoc convertType, bool isDiscarded);
17031719

1720+
SolutionApplicationTarget(Expr *expr, DeclContext *dc, ExprPattern *pattern,
1721+
Type patternType)
1722+
: SolutionApplicationTarget(expr, dc, CTP_ExprPattern, patternType,
1723+
/*isDiscarded=*/false) {
1724+
setPattern(pattern);
1725+
}
1726+
17041727
SolutionApplicationTarget(AnyFunctionRef fn)
17051728
: SolutionApplicationTarget(fn, fn.getBody()) { }
17061729

@@ -1786,6 +1809,12 @@ class SolutionApplicationTarget {
17861809
static SolutionApplicationTarget forPropertyWrapperInitializer(
17871810
VarDecl *wrappedVar, DeclContext *dc, Expr *initializer);
17881811

1812+
static SolutionApplicationTarget forExprPattern(Expr *expr, DeclContext *dc,
1813+
ExprPattern *pattern,
1814+
Type patternTy) {
1815+
return {expr, dc, pattern, patternTy};
1816+
}
1817+
17891818
Expr *getAsExpr() const {
17901819
switch (kind) {
17911820
case Kind::expression:
@@ -1888,6 +1917,12 @@ class SolutionApplicationTarget {
18881917
return expression.pattern;
18891918
}
18901919

1920+
ExprPattern *getExprPattern() const {
1921+
assert(kind == Kind::expression);
1922+
assert(expression.contextualPurpose == CTP_ExprPattern);
1923+
return cast<ExprPattern>(expression.pattern);
1924+
}
1925+
18911926
/// For a pattern initialization target, retrieve the contextual pattern.
18921927
ContextualPattern getContextualPattern() const;
18931928

@@ -2008,7 +2043,8 @@ class SolutionApplicationTarget {
20082043
assert(kind == Kind::expression);
20092044
assert(expression.contextualPurpose == CTP_Initialization ||
20102045
expression.contextualPurpose == CTP_ForEachStmt ||
2011-
expression.contextualPurpose == CTP_ForEachSequence);
2046+
expression.contextualPurpose == CTP_ForEachSequence ||
2047+
expression.contextualPurpose == CTP_ExprPattern);
20122048
expression.pattern = pattern;
20132049
}
20142050

@@ -5107,6 +5143,15 @@ class ConstraintSystem {
51075143
= FreeTypeVariableBinding::Disallow);
51085144

51095145
public:
5146+
/// Pre-check the target, validating any types that occur in it
5147+
/// and folding sequence expressions.
5148+
///
5149+
/// \param replaceInvalidRefsWithErrors Indicates whether it's allowed
5150+
/// to replace any discovered invalid member references with `ErrorExpr`.
5151+
static bool preCheckTarget(SolutionApplicationTarget &target,
5152+
bool replaceInvalidRefsWithErrors,
5153+
bool leaveClosureBodiesUnchecked);
5154+
51105155
/// Pre-check the expression, validating any types that occur in the
51115156
/// expression and folding sequence expressions.
51125157
///

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8382,7 +8382,8 @@ AbstractGenericSignatureRequest::evaluate(
83828382
case RequirementMachineMode::Enabled:
83838383
return buildViaRQM();
83848384

8385-
case RequirementMachineMode::Verify: {
8385+
case RequirementMachineMode::Verify:
8386+
case RequirementMachineMode::Check: {
83868387
auto rqmResult = buildViaRQM();
83878388
auto gsbResult = buildViaGSB();
83888389

@@ -8401,7 +8402,9 @@ AbstractGenericSignatureRequest::evaluate(
84018402
gsbResult.getPointer()->print(llvm::errs(), opts);
84028403
llvm::errs() << "\n";
84038404

8404-
abort();
8405+
if (ctx.LangOpts.RequirementMachineAbstractSignatures
8406+
== RequirementMachineMode::Verify)
8407+
abort();
84058408
}
84068409

84078410
return rqmResult;
@@ -8559,7 +8562,8 @@ InferredGenericSignatureRequest::evaluate(
85598562
case RequirementMachineMode::Enabled:
85608563
return buildViaRQM();
85618564

8562-
case RequirementMachineMode::Verify: {
8565+
case RequirementMachineMode::Verify:
8566+
case RequirementMachineMode::Check: {
85638567
auto rqmResult = buildViaRQM();
85648568
auto gsbResult = buildViaGSB();
85658569

@@ -8578,7 +8582,9 @@ InferredGenericSignatureRequest::evaluate(
85788582
gsbResult.getPointer()->print(llvm::errs(), opts);
85798583
llvm::errs() << "\n";
85808584

8581-
abort();
8585+
if (ctx.LangOpts.RequirementMachineInferredSignatures
8586+
== RequirementMachineMode::Verify)
8587+
abort();
85828588
}
85838589

85848590
return rqmResult;
@@ -8672,7 +8678,8 @@ RequirementSignatureRequest::evaluate(Evaluator &evaluator,
86728678
case RequirementMachineMode::Enabled:
86738679
return buildViaRQM();
86748680

8675-
case RequirementMachineMode::Verify: {
8681+
case RequirementMachineMode::Verify:
8682+
case RequirementMachineMode::Check: {
86768683
auto rqmResult = buildViaRQM();
86778684
auto gsbResult = buildViaGSB();
86788685

@@ -8697,7 +8704,9 @@ RequirementSignatureRequest::evaluate(Evaluator &evaluator,
86978704
gsbSig.print(llvm::errs(), opts);
86988705
llvm::errs() << "\n";
86998706

8700-
abort();
8707+
if (ctx.LangOpts.RequirementMachineProtocolSignatures
8708+
== RequirementMachineMode::Verify)
8709+
abort();
87018710
}
87028711

87038712
return rqmResult;

lib/ClangImporter/ClangImporter.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,7 @@ importer::getNormalInvocationArguments(
523523
ClangImporterOptions &importerOpts = ctx.ClangImporterOpts;
524524
auto languageVersion = ctx.LangOpts.EffectiveLanguageVersion;
525525

526-
if (llvm::sys::path::extension(importerOpts.BridgingHeader)
527-
.endswith(file_types::getExtension(file_types::TY_PCH))) {
526+
if (isPCHFilenameExtension(importerOpts.BridgingHeader)) {
528527
invocationArgStrs.insert(invocationArgStrs.end(), {
529528
"-include-pch", importerOpts.BridgingHeader
530529
});
@@ -966,8 +965,7 @@ bool ClangImporter::canReadPCH(StringRef PCHFilename) {
966965
Optional<std::string>
967966
ClangImporter::getPCHFilename(const ClangImporterOptions &ImporterOptions,
968967
StringRef SwiftPCHHash, bool &isExplicit) {
969-
if (llvm::sys::path::extension(ImporterOptions.BridgingHeader)
970-
.endswith(file_types::getExtension(file_types::TY_PCH))) {
968+
if (isPCHFilenameExtension(ImporterOptions.BridgingHeader)) {
971969
isExplicit = true;
972970
return ImporterOptions.BridgingHeader;
973971
}
@@ -1127,8 +1125,7 @@ ClangImporter::create(ASTContext &ctx,
11271125

11281126

11291127

1130-
if (llvm::sys::path::extension(importerOpts.BridgingHeader)
1131-
.endswith(file_types::getExtension(file_types::TY_PCH))) {
1128+
if (isPCHFilenameExtension(importerOpts.BridgingHeader)) {
11321129
importer->Impl.setSinglePCHImport(importerOpts.BridgingHeader);
11331130
importer->Impl.IsReadingBridgingPCH = true;
11341131
if (tracker) {
@@ -1554,8 +1551,7 @@ bool ClangImporter::importBridgingHeader(StringRef header, ModuleDecl *adapter,
15541551
SourceLoc diagLoc,
15551552
bool trackParsedSymbols,
15561553
bool implicitImport) {
1557-
if (llvm::sys::path::extension(header)
1558-
.endswith(file_types::getExtension(file_types::TY_PCH))) {
1554+
if (isPCHFilenameExtension(header)) {
15591555
Impl.ImportedHeaderOwners.push_back(adapter);
15601556
// We already imported this with -include-pch above, so we should have
15611557
// collected a bunch of PCH-encoded module imports that we just need to

lib/ClangImporter/ImportDecl.cpp

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3444,11 +3444,12 @@ namespace {
34443444
// that differ this way so we can disambiguate later
34453445
for (auto m : decl->decls()) {
34463446
if (auto method = dyn_cast<clang::CXXMethodDecl>(m)) {
3447-
if(method->getDeclName().isIdentifier()) {
3448-
if(Impl.cxxMethods.find(method->getName()) == Impl.cxxMethods.end()) {
3447+
if (method->getDeclName().isIdentifier()) {
3448+
if (Impl.cxxMethods.find(method->getName()) ==
3449+
Impl.cxxMethods.end()) {
34493450
Impl.cxxMethods[method->getName()] = {};
34503451
}
3451-
if(method->isConst()) {
3452+
if (method->isConst()) {
34523453
// Add to const set
34533454
Impl.cxxMethods[method->getName()].first.insert(method);
34543455
} else {
@@ -3478,8 +3479,8 @@ namespace {
34783479

34793480
if (auto field = dyn_cast<clang::FieldDecl>(nd)) {
34803481
// Non-nullable pointers can't be zero-initialized.
3481-
if (auto nullability = field->getType()
3482-
->getNullability(Impl.getClangASTContext())) {
3482+
if (auto nullability =
3483+
field->getType()->getNullability(Impl.getClangASTContext())) {
34833484
if (*nullability == clang::NullabilityKind::NonNull)
34843485
hasZeroInitializableStorage = false;
34853486
}
@@ -3522,6 +3523,18 @@ namespace {
35223523
}
35233524

35243525
if (auto MD = dyn_cast<FuncDecl>(member)) {
3526+
3527+
// When 2 CXXMethods diff by "constness" alone we differentiate them
3528+
// by changing the name of one. That changed method needs to be added
3529+
// to the lookup table since it cannot be found lazily.
3530+
if (auto cxxMethod = dyn_cast<clang::CXXMethodDecl>(m)) {
3531+
if (cxxMethod->getDeclName().isIdentifier()) {
3532+
auto &mutableFuncPtrs = Impl.cxxMethods[cxxMethod->getName()].second;
3533+
if(mutableFuncPtrs.contains(cxxMethod)) {
3534+
result->addMemberToLookupTable(member);
3535+
}
3536+
}
3537+
}
35253538
methods.push_back(MD);
35263539
continue;
35273540
}
@@ -3602,10 +3615,10 @@ namespace {
36023615
//
36033616
// If we can completely represent the struct in SIL, leave the body
36043617
// implicit, otherwise synthesize one to call property setters.
3605-
auto valueCtor = createValueConstructor(
3606-
Impl, result, members,
3607-
/*want param names*/true,
3608-
/*want body*/hasUnreferenceableStorage);
3618+
auto valueCtor =
3619+
createValueConstructor(Impl, result, members,
3620+
/*want param names*/ true,
3621+
/*want body*/ hasUnreferenceableStorage);
36093622
if (!hasUnreferenceableStorage)
36103623
valueCtor->setIsMemberwiseInitializer();
36113624

@@ -3636,8 +3649,8 @@ namespace {
36363649
continue;
36373650

36383651
auto getterAndSetter = subscriptInfo.second;
3639-
auto subscript = makeSubscript(getterAndSetter.first,
3640-
getterAndSetter.second);
3652+
auto subscript =
3653+
makeSubscript(getterAndSetter.first, getterAndSetter.second);
36413654
// Also add subscripts directly because they won't be found from the
36423655
// clang decl.
36433656
result->addMember(subscript);

0 commit comments

Comments
 (0)