Skip to content

Commit f3c7423

Browse files
MaxDesiatovfinagolfinbenrimmingtonbeccadax3405691582
authored
Resolve master conflicts (#730)
* [build-script] Add the installation prefix to the toolchain path In several places, it was assumed to be /usr and hard-coded to that. This makes sure the installation prefix actually passed in is used. * [stdlib] StaticString: extension per conformance * Fix @available(macCatalyst N, iOS N+M) bug Previously, availability checking computed a declaration’s availability as the intersection of all @available attributes with active platforms. This meant that Swift would not allow you to use an API that was available earlier in a child platform than in its parent until it was also available in the parent platform. That was incorrect. This PR corrects availability checking to find the most specific @available attribute with an introduced version and use that instead. Fixes rdar://60892534. * [stdlib] Buildfix differentiation for OpenBSD. New files were added in swiftlang#30875 which did not include os(OpenBSD), so add this. add_swift_target_library in AddSwiftStdlib subsequently required modification. _add_target_variant_link_flags likely needs modification as well, but this is better suited to a separate PR. * Handle multiple @available attributes correctly The previous commit broke a promise made by the implementation it replaced: if there were two or more @available(introduced:) attributes for the same platform, the greatest version wins. This commit restores that property while still completely overriding the parent platform’s availability with a child platform’s. * [Diagnostics] Provide anchors on demand instead of storing in `FailureDiagnostic` This decouples `FailureDiagnostic` from expression. * [Diagnostics] Switch `get{Raw}Anchor` to return `TypedNode` In preparation to anchor `ConstraintLocator` from `TypedNode` let's refactor diagnostics (which is the biggest user of locators) to support `TypedNode` instead of `Expr *`. * [Diagnostics] Switch `getConstraintLocator` variants to accept `TypedNode` * [Diagnostics] Switch `getContextualType*` to use `TypedNode` * [Diagnostics] Switch `getType` to use `TypedNode` * [Diagnostics] Resolve const-ness problems introduced by `TypedNode` Since `TypedNode` elements are all marked as `const` diagnostics need to get some of the APIs adjusted to support passing `const Expr *`. * Add compiler option to *disable* warnings-as-errors `-no-warnings-as-errors` This functionality is required for build systems to be able to overload/disable a given Swift project's preference of treating warnings as errors. Resolves rdar://problem/35699776 * [Diagnostics] Add helper functions to work with anchors - `{castTo, getAs, is}Expr` * [Diagnostics] Adjust `getCallInfo` to accept `TypedNode` instead of expression * Avoid unnecessary performTypeChecking() in REPL * [SIL Diagnostics] Improve diagnostics for capture of inout values within escaping autoclosures. <rdar://problem/60551844> * [NFC] Refactor validateTBDIfNeeded Inline the conditions for the astGuaranteedToCorrespondToSIL parameter and clean up the logic here to be more const-friendly. Also try to centralize and document the reasons we skip TBD validation. * Revert "[Darwin] Further restrict inference of the simulator environment" * [Gardening] Const-qualify CompilerInstance::getInvocation() * [NFC] Formalize isModuleExternallyConsumed Yank this parameter and document the historical scope creep of this value. * More StringRef -> std::string conversion fixes. This is needed for the master-next branch. * Devirtualizer: fix a miscompile due to handling of cast instructions. getInstanceWithExactDynamicType returns a new instance and for this the class decl has to be updated. https://bugs.swift.org/browse/SR-12538 rdar://problem/61911112 * [NFC] Fix typo in SerializedModuleLoader.cpp Co-authored-by: Butta <[email protected]> Co-authored-by: Ben Rimmington <[email protected]> Co-authored-by: Brent Royal-Gordon <[email protected]> Co-authored-by: 3405691582 <[email protected]> Co-authored-by: Pavel Yaskevich <[email protected]> Co-authored-by: Artem Chikin <[email protected]> Co-authored-by: Rintaro Ishizaki <[email protected]> Co-authored-by: Ravi Kandhadai <[email protected]> Co-authored-by: Robert Widmann <[email protected]> Co-authored-by: Saleem Abdulrasool <[email protected]> Co-authored-by: Mishal Shah <[email protected]> Co-authored-by: Michael Forster <[email protected]> Co-authored-by: swift-ci <[email protected]> Co-authored-by: Erik Eckstein <[email protected]> Co-authored-by: Ravi Kandhadai <[email protected]> Co-authored-by: Pavel Yaskevich <[email protected]>
1 parent caf026f commit f3c7423

File tree

16 files changed

+615
-419
lines changed

16 files changed

+615
-419
lines changed

include/swift/AST/DiagnosticsSIL.def

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ ERROR(capture_before_declaration_defer,none,
108108
NOTE(captured_value_declared_here,none,
109109
"captured value declared here", ())
110110

111-
#define SELECT_ESCAPING_CLOSURE_KIND "escaping %select{local function|closure}0"
111+
#define SELECT_ESCAPING_CLOSURE_KIND "escaping %select{local function|closure|autoclosure}0"
112112

113113
// Invalid escaping capture diagnostics.
114114
ERROR(escaping_inout_capture,none,
@@ -133,6 +133,10 @@ ERROR(escaping_noescape_var_capture,none,
133133

134134
NOTE(value_captured_here,none,"captured here", ())
135135

136+
NOTE(copy_inout_captured_by_autoclosure,none, "pass a copy of %0", (Identifier))
137+
138+
NOTE(copy_self_captured_by_autoclosure,none, "pass a copy of 'self'", ())
139+
136140
#undef SELECT_ESCAPING_CLOSURE_KIND
137141

138142
NOTE(value_captured_transitively,none,

include/swift/AST/Expr.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3759,7 +3759,12 @@ class ClosureExpr : public AbstractClosureExpr {
37593759
assert(hasExplicitResultType() && "No explicit result type");
37603760
return ExplicitResultType;
37613761
}
3762-
3762+
3763+
TypeRepr *getExplicitResultTypeRepr() const {
3764+
assert(hasExplicitResultType() && "No explicit result type");
3765+
return ExplicitResultType.getTypeRepr();
3766+
}
3767+
37633768
void setExplicitResultType(SourceLoc arrowLoc, TypeLoc resultType) {
37643769
ArrowLoc = arrowLoc;
37653770
ExplicitResultType = resultType;

lib/AST/Availability.cpp

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,29 @@ void AvailabilityInference::applyInferredAvailableAttrs(
132132
}
133133
}
134134

135+
/// Returns true if the introduced version in \p newAttr should be used instead
136+
/// of the introduced version in \p prevAttr when both are attached to the same
137+
/// declaration and refer to the active platform.
138+
static bool isBetterThan(const AvailableAttr *newAttr,
139+
const AvailableAttr *prevAttr) {
140+
assert(newAttr);
141+
142+
// If there is no prevAttr, newAttr of course wins.
143+
if (!prevAttr)
144+
return true;
145+
146+
// If they belong to the same platform, the one that introduces later wins.
147+
if (prevAttr->Platform == newAttr->Platform)
148+
return prevAttr->Introduced.getValue() < newAttr->Introduced.getValue();
149+
150+
// If the new attribute's platform inherits from the old one, it wins.
151+
return inheritsAvailabilityFromPlatform(newAttr->Platform,
152+
prevAttr->Platform);
153+
}
154+
135155
Optional<AvailabilityContext>
136156
AvailabilityInference::annotatedAvailableRange(const Decl *D, ASTContext &Ctx) {
137-
Optional<AvailabilityContext> AnnotatedRange;
157+
const AvailableAttr *bestAvailAttr = nullptr;
138158

139159
for (auto Attr : D->getAttrs()) {
140160
auto *AvailAttr = dyn_cast<AvailableAttr>(Attr);
@@ -145,21 +165,15 @@ AvailabilityInference::annotatedAvailableRange(const Decl *D, ASTContext &Ctx) {
145165
continue;
146166
}
147167

148-
AvailabilityContext AttrRange{
149-
VersionRange::allGTE(AvailAttr->Introduced.getValue())};
150-
151-
// If we have multiple introduction versions, we will conservatively
152-
// assume the worst case scenario. We may want to be more precise here
153-
// in the future or emit a diagnostic.
154-
155-
if (AnnotatedRange.hasValue()) {
156-
AnnotatedRange.getValue().intersectWith(AttrRange);
157-
} else {
158-
AnnotatedRange = AttrRange;
159-
}
168+
if (isBetterThan(AvailAttr, bestAvailAttr))
169+
bestAvailAttr = AvailAttr;
160170
}
161171

162-
return AnnotatedRange;
172+
if (!bestAvailAttr)
173+
return None;
174+
175+
return AvailabilityContext{
176+
VersionRange::allGTE(bestAvailAttr->Introduced.getValue())};
163177
}
164178

165179
AvailabilityContext AvailabilityInference::availableRange(const Decl *D,

lib/SILOptimizer/Mandatory/DiagnoseInvalidEscapingCaptures.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "swift/AST/ASTContext.h"
1919
#include "swift/AST/DiagnosticsSIL.h"
20+
#include "swift/AST/Expr.h"
2021
#include "swift/AST/Types.h"
2122
#include "swift/SIL/ApplySite.h"
2223
#include "swift/SIL/InstructionUtils.h"
@@ -332,17 +333,22 @@ static void checkPartialApply(ASTContext &Context, DeclContext *DC,
332333
// Should match SELECT_ESCAPING_CLOSURE_KIND in DiagnosticsSIL.def.
333334
enum {
334335
EscapingLocalFunction,
335-
EscapingClosure
336+
EscapingClosure,
337+
EscapingAutoClosure,
336338
} functionKind = EscapingClosure;
337339

338340
if (auto *F = PAI->getReferencedFunctionOrNull()) {
339341
if (auto loc = F->getLocation()) {
340-
if (loc.isASTNode<FuncDecl>())
342+
if (loc.isASTNode<FuncDecl>()) {
341343
functionKind = EscapingLocalFunction;
344+
} else if (loc.isASTNode<AutoClosureExpr>()) {
345+
functionKind = EscapingAutoClosure;
346+
}
342347
}
343348
}
344349
// First, diagnose the inout captures, if any.
345350
for (auto inoutCapture : inoutCaptures) {
351+
Optional<Identifier> paramName = None;
346352
if (isUseOfSelfInInitializer(inoutCapture)) {
347353
diagnose(Context, PAI->getLoc(), diag::escaping_mutable_self_capture,
348354
functionKind);
@@ -352,14 +358,23 @@ static void checkPartialApply(ASTContext &Context, DeclContext *DC,
352358
diagnose(Context, PAI->getLoc(), diag::escaping_mutable_self_capture,
353359
functionKind);
354360
else {
361+
paramName = param->getName();
355362
diagnose(Context, PAI->getLoc(), diag::escaping_inout_capture,
356363
functionKind, param->getName());
357364
diagnose(Context, param->getLoc(), diag::inout_param_defined_here,
358365
param->getName());
359366
}
360367
}
361-
362-
diagnoseCaptureLoc(Context, DC, PAI, inoutCapture);
368+
if (functionKind != EscapingAutoClosure) {
369+
diagnoseCaptureLoc(Context, DC, PAI, inoutCapture);
370+
continue;
371+
}
372+
// For an autoclosure capture, present a way to fix the problem.
373+
if (paramName)
374+
diagnose(Context, PAI->getLoc(), diag::copy_inout_captured_by_autoclosure,
375+
paramName.getValue());
376+
else
377+
diagnose(Context, PAI->getLoc(), diag::copy_self_captured_by_autoclosure);
363378
}
364379

365380
// Finally, diagnose captures of values with noescape type.

lib/Sema/CSApply.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,17 @@ ConstraintLocator *Solution::getCalleeLocator(ConstraintLocator *locator,
166166
}
167167

168168
ConstraintLocator *
169-
Solution::getConstraintLocator(Expr *anchor,
169+
Solution::getConstraintLocator(const Expr *anchor,
170170
ArrayRef<LocatorPathElt> path) const {
171171
auto &cs = getConstraintSystem();
172-
return cs.getConstraintLocator(anchor, path);
172+
return cs.getConstraintLocator(const_cast<Expr *>(anchor), path);
173+
}
174+
175+
ConstraintLocator *
176+
Solution::getConstraintLocator(ConstraintLocator *base,
177+
ArrayRef<LocatorPathElt> path) const {
178+
auto &cs = getConstraintSystem();
179+
return cs.getConstraintLocator(base, path);
173180
}
174181

175182
/// Return the implicit access kind for a MemberRefExpr with the

0 commit comments

Comments
 (0)