Skip to content

Commit 5c789fa

Browse files
authored
Merge pull request #2929 from swiftwasm/main
[pull] swiftwasm from main
2 parents fd98026 + 3824528 commit 5c789fa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1261
-547
lines changed

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,24 @@ CHANGELOG
2929
Swift 5.5
3030
---------
3131

32+
* The determination of whether a call to a `rethrows` function can throw now considers default arguments of `Optional` type.
33+
34+
In Swift 5.4, such default arguments were ignored entirely by `rethrows` checking. This meant that the following example was accepted:
35+
36+
```swift
37+
func foo(_: (() throws -> ())? = nil) rethrows {}
38+
foo() // no 'try' needed
39+
```
40+
41+
However, it also meant that the following was accepted, even though the call to `foo()` can throw and the call site is not marked with `try`:
42+
43+
```swift
44+
func foo(_: (() throws -> ())? = { throw myError }) rethrows {}
45+
foo() // 'try' *should* be required here
46+
```
47+
48+
The new behavior is that the first example is accepted because the default argument is syntactically written as `nil`, which is known not to throw. The second example is correctly rejected, on account of missing a `try` since the default argument *can* throw.
49+
3250
* [SE-0293][]:
3351

3452
Property wrappers can now be applied to function and closure parameters:

include/swift/AST/DiagnosticsSema.def

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2414,16 +2414,17 @@ NOTE(same_type_redundancy_here,none,
24142414
"same-type constraint %1 == %2 %select{written here|implied here|"
24152415
"inferred from type here}0",
24162416
(unsigned, Type, Type))
2417-
ERROR(requires_superclass_conflict,none,
2418-
"%select{generic parameter %1 cannot|protocol %1 cannot require 'Self' to|"
2419-
"%1 cannot}0 be a subclass of both %2 and %3",
2420-
(unsigned, Type, Type, Type))
2417+
ERROR(conflicting_superclass_constraints,none,
2418+
"type %0 cannot be a subclass of both %1 and %2",
2419+
(Type, Type, Type))
2420+
NOTE(conflicting_superclass_constraint,none,
2421+
"constraint conflicts with %0 : %1",
2422+
(Type, Type))
24212423
WARNING(redundant_superclass_constraint,none,
24222424
"redundant superclass constraint %0 : %1", (Type, Type))
24232425
NOTE(superclass_redundancy_here,none,
2424-
"superclass constraint %1 : %2 %select{written here|implied here|"
2425-
"inferred from type here}0",
2426-
(unsigned, Type, Type))
2426+
"superclass constraint %0 : %1 implied here",
2427+
(Type, Type))
24272428

24282429
ERROR(conflicting_layout_constraints,none,
24292430
"type %0 has conflicting constraints %1 and %2",

include/swift/AST/GenericSignatureBuilder.h

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,15 @@ class GenericSignatureBuilder {
427427
Type superclass,
428428
FloatingRequirementSource source);
429429

430+
/// Update the layout constraint for the equivalence class of \c T.
431+
///
432+
/// This assumes that the constraint has already been recorded.
433+
///
434+
/// \returns true if anything in the equivalence class changed, false
435+
/// otherwise.
436+
bool updateLayout(ResolvedType type,
437+
LayoutConstraint layout);
438+
430439
private:
431440
/// Add a new superclass requirement specifying that the given
432441
/// potential archetype has the given type as an ancestor.
@@ -528,8 +537,7 @@ class GenericSignatureBuilder {
528537
LookUpConformanceInBuilder getLookupConformanceFn();
529538

530539
/// Lookup a protocol conformance in a module-agnostic manner.
531-
ProtocolConformanceRef lookupConformance(CanType dependentType,
532-
Type conformingReplacementType,
540+
ProtocolConformanceRef lookupConformance(Type conformingReplacementType,
533541
ProtocolDecl *conformedProtocol);
534542

535543
/// Enumerate the requirements that describe the signature of this
@@ -653,6 +661,8 @@ class GenericSignatureBuilder {
653661

654662
void diagnoseRedundantRequirements() const;
655663

664+
void diagnoseConflictingConcreteTypeRequirements() const;
665+
656666
bool hasExplicitConformancesImpliedByConcrete() const;
657667

658668
/// Describes the relationship between a given constraint and
@@ -696,34 +706,6 @@ class GenericSignatureBuilder {
696706
Diag<Type, T> redundancyDiag,
697707
Diag<unsigned, Type, T> otherNoteDiag);
698708

699-
/// Check a list of constraints, removing self-derived constraints
700-
/// and diagnosing redundant constraints.
701-
///
702-
/// \param isSuitableRepresentative Determines whether the given constraint
703-
/// is a suitable representative.
704-
///
705-
/// \param checkConstraint Checks the given constraint against the
706-
/// canonical constraint to determine which diagnostics (if any) should be
707-
/// emitted.
708-
///
709-
/// \returns the representative constraint.
710-
template<typename T, typename DiagT>
711-
Constraint<T> checkConstraintList(
712-
TypeArrayView<GenericTypeParamType> genericParams,
713-
std::vector<Constraint<T>> &constraints,
714-
RequirementKind kind,
715-
llvm::function_ref<bool(const Constraint<T> &)>
716-
isSuitableRepresentative,
717-
llvm::function_ref<
718-
ConstraintRelation(const Constraint<T>&)>
719-
checkConstraint,
720-
Optional<Diag<unsigned, Type, DiagT, DiagT>>
721-
conflictingDiag,
722-
Diag<Type, DiagT> redundancyDiag,
723-
Diag<unsigned, Type, DiagT> otherNoteDiag,
724-
llvm::function_ref<DiagT(const T&)> diagValue,
725-
bool removeSelfDerived);
726-
727709
/// Check the concrete type constraints within the equivalence
728710
/// class of the given potential archetype.
729711
void checkConcreteTypeConstraints(

lib/AST/GenericSignature.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,7 @@ bool GenericSignatureImpl::isRequirementSatisfied(
440440
if (canFirstType->isTypeParameter())
441441
return requiresProtocol(canFirstType, protocol);
442442
else
443-
return (bool)GSB->lookupConformance(/*dependentType=*/CanType(),
444-
canFirstType, protocol);
443+
return (bool)GSB->lookupConformance(canFirstType, protocol);
445444
}
446445

447446
case RequirementKind::SameType: {

0 commit comments

Comments
 (0)