Skip to content

Commit 846d5ec

Browse files
Merge pull request #4402 from swiftwasm/main
[pull] swiftwasm from main
2 parents 1e4ac49 + 333b086 commit 846d5ec

File tree

53 files changed

+416
-488
lines changed

Some content is hidden

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

53 files changed

+416
-488
lines changed

include/swift/AST/Requirement.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,13 @@ class Requirement
4242
Requirement(RequirementKind kind, Type first, LayoutConstraint second)
4343
: RequirementBase(kind, first, second) {}
4444

45-
/// Whether this requirement is in its canonical form.
45+
/// Whether this requirement's types contain ErrorTypes.
46+
bool hasError() const;
47+
48+
/// Whether this requirement is written with canonical types.
4649
bool isCanonical() const;
4750

48-
/// Get the canonical form of this requirement.
51+
/// Canonicalize the types in this requirement.
4952
Requirement getCanonical() const;
5053

5154
/// Subst the types involved in this requirement.

include/swift/Basic/LangOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,9 @@ namespace swift {
561561
/// Enables dumping type witness systems from associated type inference.
562562
bool DumpTypeWitnessSystems = false;
563563

564+
/// Enables `/.../` syntax regular-expression literals
565+
bool EnableForwardSlashRegexLiterals = false;
566+
564567
/// Sets the target we are building for and updates platform conditions
565568
/// to match.
566569
///

include/swift/Option/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,10 @@ def disable_actor_data_race_checks :
676676
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
677677
HelpText<"Disable runtime checks for actor data races">;
678678

679+
def enable_regex_literals : Flag<["-"], "enable-regex-literals">,
680+
Flags<[FrontendOption, ModuleInterfaceOptionIgnorable]>,
681+
HelpText<"Enable the use of regular-expression literals">;
682+
679683
def warn_implicit_overrides :
680684
Flag<["-"], "warn-implicit-overrides">,
681685
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,

include/swift/Runtime/AtomicWaitQueue.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,10 @@ class AtomicWaitQueue {
424424
private:
425425
template <class... Args>
426426
static Impl *createNewQueue(Args &&...args) {
427+
#if !defined(__cpp_aligned_new)
428+
static_assert(std::alignment_of<Impl>::value <= __STDCPP_DEFAULT_NEW_ALIGNMENT__,
429+
"type is over-aligned for non-alignment aware operator new");
430+
#endif
427431
auto queue = new Impl(std::forward<Args>(args)...);
428432
queue->WaitQueueLock.lock();
429433
return queue;

lib/AST/GenericSignature.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -591,15 +591,26 @@ void swift::simple_display(raw_ostream &out, GenericSignature sig) {
591591
out << "NULL";
592592
}
593593

594+
bool Requirement::hasError() const {
595+
if (getFirstType()->hasError())
596+
return true;
597+
598+
if (getKind() != RequirementKind::Layout &&
599+
getSecondType()->hasError())
600+
return true;
601+
602+
return false;
603+
}
604+
594605
bool Requirement::isCanonical() const {
595-
if (getFirstType() && !getFirstType()->isCanonical())
606+
if (!getFirstType()->isCanonical())
596607
return false;
597608

598609
switch (getKind()) {
599610
case RequirementKind::Conformance:
600611
case RequirementKind::SameType:
601612
case RequirementKind::Superclass:
602-
if (getSecondType() && !getSecondType()->isCanonical())
613+
if (!getSecondType()->isCanonical())
603614
return false;
604615
break;
605616

@@ -612,17 +623,13 @@ bool Requirement::isCanonical() const {
612623

613624
/// Get the canonical form of this requirement.
614625
Requirement Requirement::getCanonical() const {
615-
Type firstType = getFirstType();
616-
if (firstType)
617-
firstType = firstType->getCanonicalType();
626+
Type firstType = getFirstType()->getCanonicalType();
618627

619628
switch (getKind()) {
620629
case RequirementKind::Conformance:
621630
case RequirementKind::SameType:
622631
case RequirementKind::Superclass: {
623-
Type secondType = getSecondType();
624-
if (secondType)
625-
secondType = secondType->getCanonicalType();
632+
Type secondType = getSecondType()->getCanonicalType();
626633
return Requirement(getKind(), firstType, secondType);
627634
}
628635

lib/AST/RequirementMachine/ConcreteContraction.cpp

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ class ConcreteContraction {
182182

183183
bool performConcreteContraction(
184184
ArrayRef<StructuralRequirement> requirements,
185-
SmallVectorImpl<StructuralRequirement> &result);
185+
SmallVectorImpl<StructuralRequirement> &result,
186+
SmallVectorImpl<RequirementError> &errors);
186187
};
187188

188189
} // end namespace
@@ -380,6 +381,13 @@ ConcreteContraction::substRequirement(const Requirement &req) const {
380381

381382
case RequirementKind::Layout: {
382383
auto substFirstType = substTypeParameter(firstType);
384+
if (!substFirstType->isTypeParameter() &&
385+
!substFirstType->satisfiesClassConstraint() &&
386+
req.getLayoutConstraint()->isClass()) {
387+
// If the concrete type doesn't satisfy the layout constraint,
388+
// leave it unsubstituted so that we produce a better diagnostic.
389+
return req;
390+
}
383391

384392
return Requirement(req.getKind(),
385393
substFirstType,
@@ -464,7 +472,8 @@ bool ConcreteContraction::preserveSameTypeRequirement(
464472
/// original \p requirements.
465473
bool ConcreteContraction::performConcreteContraction(
466474
ArrayRef<StructuralRequirement> requirements,
467-
SmallVectorImpl<StructuralRequirement> &result) {
475+
SmallVectorImpl<StructuralRequirement> &result,
476+
SmallVectorImpl<RequirementError> &errors) {
468477

469478
// Phase 1 - collect concrete type and superclass requirements where the
470479
// subject type is a generic parameter.
@@ -577,47 +586,25 @@ bool ConcreteContraction::performConcreteContraction(
577586
llvm::dbgs() << "\n";
578587
}
579588

580-
if (preserveSameTypeRequirement(req.req)) {
581-
if (Debug) {
582-
llvm::dbgs() << "@ Preserving original requirement: ";
583-
req.req.dump(llvm::dbgs());
584-
llvm::dbgs() << "\n";
585-
}
586-
587-
// Make the duplicated requirement 'inferred' so that we don't diagnose
588-
// it as redundant.
589-
result.push_back({req.req, SourceLoc(), /*inferred=*/true});
590-
}
591-
592589
// Substitute the requirement.
593-
Optional<Requirement> substReq = substRequirement(req.req);
594-
595-
// If substitution failed, we have a conflict; bail out here so that we can
596-
// diagnose the conflict later.
597-
if (!substReq) {
598-
if (Debug) {
599-
llvm::dbgs() << "@ Concrete contraction cannot proceed; requirement ";
600-
llvm::dbgs() << "substitution failed:\n";
601-
req.req.dump(llvm::dbgs());
602-
llvm::dbgs() << "\n";
603-
}
604-
605-
continue;
606-
}
590+
auto substReq = substRequirement(req.req);
607591

608592
if (Debug) {
609593
llvm::dbgs() << "@ Substituted requirement: ";
610-
substReq->dump(llvm::dbgs());
594+
substReq.dump(llvm::dbgs());
611595
llvm::dbgs() << "\n";
612596
}
613597

614598
// Otherwise, desugar the requirement again, since we might now have a
615599
// requirement where the left hand side is not a type parameter.
616-
//
617-
// FIXME: Do we need to check for errors? Right now they're just ignored.
618600
SmallVector<Requirement, 4> reqs;
619-
SmallVector<RequirementError, 1> errors;
620-
desugarRequirement(*substReq, reqs, errors);
601+
if (req.inferred) {
602+
SmallVector<RequirementError, 4> discardErrors;
603+
desugarRequirement(substReq, SourceLoc(), reqs, discardErrors);
604+
} else {
605+
desugarRequirement(substReq, req.loc, reqs, errors);
606+
}
607+
621608
for (auto desugaredReq : reqs) {
622609
if (Debug) {
623610
llvm::dbgs() << "@@ Desugared requirement: ";
@@ -626,6 +613,20 @@ bool ConcreteContraction::performConcreteContraction(
626613
}
627614
result.push_back({desugaredReq, req.loc, req.inferred});
628615
}
616+
617+
if (preserveSameTypeRequirement(req.req) &&
618+
(!req.req.getFirstType()->isEqual(substReq.getFirstType()) ||
619+
!req.req.getSecondType()->isEqual(substReq.getSecondType()))) {
620+
if (Debug) {
621+
llvm::dbgs() << "@ Preserving original requirement: ";
622+
req.req.dump(llvm::dbgs());
623+
llvm::dbgs() << "\n";
624+
}
625+
626+
// Make the duplicated requirement 'inferred' so that we don't diagnose
627+
// it as redundant.
628+
result.push_back({req.req, SourceLoc(), /*inferred=*/true});
629+
}
629630
}
630631

631632
if (Debug) {
@@ -647,7 +648,9 @@ bool ConcreteContraction::performConcreteContraction(
647648
bool swift::rewriting::performConcreteContraction(
648649
ArrayRef<StructuralRequirement> requirements,
649650
SmallVectorImpl<StructuralRequirement> &result,
651+
SmallVectorImpl<RequirementError> &errors,
650652
bool debug) {
651653
ConcreteContraction concreteContraction(debug);
652-
return concreteContraction.performConcreteContraction(requirements, result);
654+
return concreteContraction.performConcreteContraction(
655+
requirements, result, errors);
653656
}

lib/AST/RequirementMachine/ConcreteTypeWitness.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ void PropertyMap::inferConditionalRequirements(
568568
llvm::dbgs() << "\n";
569569
}
570570

571-
desugarRequirement(req, desugaredRequirements, errors);
571+
desugarRequirement(req, SourceLoc(), desugaredRequirements, errors);
572572
}
573573

574574
// Now, convert desugared conditional requirements to rules.

lib/AST/RequirementMachine/PropertyUnification.cpp

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -666,51 +666,59 @@ void PropertyMap::checkConcreteTypeRequirements() {
666666
auto concreteType = pair.first;
667667
unsigned concreteTypeRule = pair.second;
668668

669-
// A rule (T.[concrete: C] => T) where C is a class type induces a rule
670-
// (T.[superclass: C] => T).
671-
if (concreteType.getConcreteType()->getClassOrBoundGenericClass()) {
672-
auto superclassSymbol = Symbol::forSuperclass(
673-
concreteType.getConcreteType(),
674-
concreteType.getSubstitutions(),
675-
Context);
676-
677-
recordRelation(props->getKey(), concreteTypeRule,
678-
superclassSymbol, System, debug);
679-
680669
// If the concrete type is not a class and we have a superclass
681670
// requirement, we have a conflict.
682-
} else if (props->hasSuperclassBound()) {
671+
if (!concreteType.getConcreteType()->getClassOrBoundGenericClass() &&
672+
props->hasSuperclassBound()) {
683673
const auto &req = props->getSuperclassRequirement();
684674
for (auto pair : req.SuperclassRules) {
685-
System.recordConflict(concreteTypeRule, pair.second);
675+
if (checkRulePairOnce(concreteTypeRule, pair.second))
676+
System.recordConflict(concreteTypeRule, pair.second);
686677
}
687678
}
688679

689-
// A rule (T.[concrete: C] => T) where C is a class type induces a rule
690-
// (T.[layout: L] => T), where L is either AnyObject or _NativeObject.
691-
if (concreteType.getConcreteType()->satisfiesClassConstraint()) {
692-
Type superclassType = concreteType.getConcreteType();
693-
if (!superclassType->getClassOrBoundGenericClass())
694-
superclassType = superclassType->getSuperclass();
695-
696-
auto layoutConstraint = LayoutConstraintKind::Class;
697-
if (superclassType)
698-
if (auto *classDecl = superclassType->getClassOrBoundGenericClass())
699-
layoutConstraint = classDecl->getLayoutConstraintKind();
700-
701-
auto layout =
702-
LayoutConstraint::getLayoutConstraint(
703-
layoutConstraint, Context.getASTContext());
704-
auto layoutSymbol = Symbol::forLayout(layout, Context);
680+
if (checkRuleOnce(concreteTypeRule)) {
681+
if (concreteType.getConcreteType()->getClassOrBoundGenericClass()) {
682+
// A rule (T.[concrete: C] => T) where C is a class type induces a rule
683+
// (T.[superclass: C] => T).
684+
auto superclassSymbol = Symbol::forSuperclass(
685+
concreteType.getConcreteType(),
686+
concreteType.getSubstitutions(),
687+
Context);
688+
689+
recordRelation(props->getKey(), concreteTypeRule,
690+
superclassSymbol, System, debug);
691+
}
705692

706-
recordRelation(props->getKey(), concreteTypeRule,
707-
layoutSymbol, System, debug);
693+
// A rule (T.[concrete: C] => T) where C is a class type induces a rule
694+
// (T.[layout: L] => T), where L is either AnyObject or _NativeObject.
695+
if (concreteType.getConcreteType()->satisfiesClassConstraint()) {
696+
Type superclassType = concreteType.getConcreteType();
697+
if (!superclassType->getClassOrBoundGenericClass())
698+
superclassType = superclassType->getSuperclass();
699+
700+
auto layoutConstraint = LayoutConstraintKind::Class;
701+
if (superclassType)
702+
if (auto *classDecl = superclassType->getClassOrBoundGenericClass())
703+
layoutConstraint = classDecl->getLayoutConstraintKind();
704+
705+
auto layout =
706+
LayoutConstraint::getLayoutConstraint(
707+
layoutConstraint, Context.getASTContext());
708+
auto layoutSymbol = Symbol::forLayout(layout, Context);
709+
710+
recordRelation(props->getKey(), concreteTypeRule,
711+
layoutSymbol, System, debug);
712+
}
713+
}
708714

709715
// If the concrete type does not satisfy a class layout constraint and
710716
// we have such a layout requirement, we have a conflict.
711-
} else if (props->LayoutRule &&
712-
props->Layout->isClass()) {
713-
System.recordConflict(concreteTypeRule, *props->LayoutRule);
717+
if (!concreteType.getConcreteType()->satisfiesClassConstraint() &&
718+
props->LayoutRule &&
719+
props->Layout->isClass()) {
720+
if (checkRulePairOnce(concreteTypeRule, *props->LayoutRule))
721+
System.recordConflict(concreteTypeRule, *props->LayoutRule);
714722
}
715723
}
716724
}

0 commit comments

Comments
 (0)