Skip to content

Commit b3d5482

Browse files
committed
NCGenerics: omit flag in interfaces
Also cleans-up legacy code and tests that are no longer needed.
1 parent f4d7327 commit b3d5482

11 files changed

+6
-308
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -949,19 +949,6 @@ ERROR(expected_rparen_layout_constraint,none,
949949
ERROR(layout_constraints_only_inside_specialize_attr,none,
950950
"layout constraints are only allowed inside '_specialize' attributes", ())
951951

952-
//------------------------------------------------------------------------------
953-
// MARK: Conformance suppression diagnostics
954-
//------------------------------------------------------------------------------
955-
956-
ERROR(cannot_suppress_here,none,
957-
"cannot suppress conformances here", ())
958-
959-
ERROR(only_suppress_copyable,none,
960-
"can only suppress 'Copyable'", ())
961-
962-
ERROR(already_suppressed_copyable,none,
963-
"duplicate suppression of 'Copyable'", ())
964-
965952
//------------------------------------------------------------------------------
966953
// MARK: Pattern parsing diagnostics
967954
//------------------------------------------------------------------------------

include/swift/Parse/Parser.h

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,6 @@ class Parser {
158158
// Note: This doesn't affect anything in non-SWIFT_BUILD_SWIFT_SYNTAX envs.
159159
bool IsForASTGen = false;
160160

161-
// A cached answer to
162-
// Context.LangOpts.hasFeature(Feature::NoncopyableGenerics)
163-
// to ensure there's no parsing performance regression.
164-
bool EnabledNoncopyableGenerics;
165-
166-
bool canSuppressConformancesWithTilde() const {
167-
return EnabledNoncopyableGenerics ||
168-
Context.LangOpts.hasFeature(Feature::ConformanceSuppression);
169-
}
170-
171161
/// Whether we should delay parsing nominal type, extension, and function
172162
/// bodies.
173163
bool isDelayedParsingEnabled() const;
@@ -1308,13 +1298,9 @@ class Parser {
13081298
///
13091299
/// \param allowClassRequirement whether to permit parsing of 'class'
13101300
/// \param allowAnyObject whether to permit parsing of 'AnyObject'
1311-
/// \param parseTildeCopyable if non-null, permits parsing of `~Copyable`
1312-
/// and writes out a valid source location if it was parsed. If null, then a
1313-
/// parsing error will be emitted upon the appearance of `~` in the clause.
13141301
ParserStatus parseInheritance(SmallVectorImpl<InheritedEntry> &Inherited,
13151302
bool allowClassRequirement,
1316-
bool allowAnyObject,
1317-
SourceLoc *parseTildeCopyable = nullptr);
1303+
bool allowAnyObject);
13181304
ParserStatus parseDeclItem(bool &PreviousHadSemi,
13191305
llvm::function_ref<void(Decl *)> handler);
13201306
std::pair<std::vector<Decl *>, std::optional<Fingerprint>>

lib/AST/ConformanceLookup.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -630,17 +630,6 @@ LookupConformanceInModuleRequest::evaluate(
630630
} else {
631631
return ProtocolConformanceRef::forMissingOrInvalid(type, protocol);
632632
}
633-
} else if (protocol->isSpecificProtocol(KnownProtocolKind::Copyable)) {
634-
if (!ctx.LangOpts.hasFeature(Feature::NoncopyableGenerics)) {
635-
// Return an abstract conformance to maintain legacy compatability.
636-
// We only need to do this until we are properly dealing with or
637-
// omitting Copyable conformances in modules/interfaces.
638-
639-
if (nominal->canBeCopyable())
640-
return ProtocolConformanceRef(protocol);
641-
}
642-
643-
return ProtocolConformanceRef::forMissingOrInvalid(type, protocol);
644633
} else if (protocol->isSpecificProtocol(
645634
KnownProtocolKind::BitwiseCopyable)) {
646635
// Try to infer BitwiseCopyable conformance.

lib/Parse/ParseDecl.cpp

Lines changed: 3 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -6718,32 +6718,6 @@ ParserResult<ImportDecl> Parser::parseDeclImport(ParseDeclOptions Flags,
67186718
return DCC.fixupParserResult(ID);
67196719
}
67206720

6721-
static void addMoveOnlyAttrIf(SourceLoc const &parsedTildeCopyable,
6722-
ASTContext &Context,
6723-
Decl *decl) {
6724-
if (parsedTildeCopyable.isInvalid())
6725-
return;
6726-
6727-
if (Context.LangOpts.hasFeature(Feature::NoncopyableGenerics))
6728-
llvm_unreachable("unexpected use of legacy ~Copyable parsing");
6729-
6730-
auto &attrs = decl->getAttrs();
6731-
6732-
// Don't add if it's already explicitly written on the decl, but error about
6733-
// the duplication and point to the `~Copyable`.
6734-
if (auto attr = attrs.getAttribute<MoveOnlyAttr>()) {
6735-
const bool sayModifier = false;
6736-
Context.Diags.diagnose(attr->getLocation(), diag::duplicate_attribute,
6737-
sayModifier)
6738-
.fixItRemove(attr->getRange());
6739-
Context.Diags.diagnose(parsedTildeCopyable, diag::previous_attribute,
6740-
sayModifier);
6741-
return;
6742-
}
6743-
6744-
attrs.add(new(Context) MoveOnlyAttr(/*IsImplicit=*/true));
6745-
}
6746-
67476721
/// Parse an inheritance clause.
67486722
///
67496723
/// \verbatim
@@ -6758,14 +6732,12 @@ static void addMoveOnlyAttrIf(SourceLoc const &parsedTildeCopyable,
67586732
ParserStatus Parser::parseInheritance(
67596733
SmallVectorImpl<InheritedEntry> &Inherited,
67606734
bool allowClassRequirement,
6761-
bool allowAnyObject,
6762-
SourceLoc *parseTildeCopyable) {
6735+
bool allowAnyObject) {
67636736
consumeToken(tok::colon);
67646737

67656738
SourceLoc classRequirementLoc;
67666739

67676740
ParserStatus Status;
6768-
SourceLoc TildeCopyableLoc;
67696741
SourceLoc prevComma;
67706742
bool HasNextType;
67716743
do {
@@ -6817,49 +6789,6 @@ ParserStatus Parser::parseInheritance(
68176789
continue;
68186790
}
68196791

6820-
if (!canSuppressConformancesWithTilde() && Tok.isTilde()) {
6821-
ErrorTypeRepr *error = nullptr;
6822-
if (parseTildeCopyable) {
6823-
const auto &nextTok = peekToken(); // lookahead
6824-
if (isIdentifier(nextTok, Context.Id_Copyable.str())) {
6825-
auto tildeLoc = consumeToken();
6826-
consumeToken(); // the 'Copyable' token
6827-
6828-
if (TildeCopyableLoc)
6829-
Inherited.push_back(InheritedEntry(
6830-
ErrorTypeRepr::create(Context, tildeLoc,
6831-
diag::already_suppressed_copyable)));
6832-
else
6833-
TildeCopyableLoc = tildeLoc;
6834-
6835-
continue; // success
6836-
}
6837-
6838-
if (nextTok.is(tok::code_complete)) {
6839-
consumeToken(); // consume '~'
6840-
Status.setHasCodeCompletionAndIsError();
6841-
if (CodeCompletionCallbacks) {
6842-
CodeCompletionCallbacks->completeWithoutConstraintType();
6843-
}
6844-
consumeToken(tok::code_complete);
6845-
}
6846-
6847-
// can't suppress whatever is between '~' and ',' or '{'.
6848-
error = ErrorTypeRepr::create(Context, consumeToken(),
6849-
diag::only_suppress_copyable);
6850-
} else {
6851-
// Otherwise, a suppression isn't allowed here unless noncopyable
6852-
// generics is enabled, so record a delayed error diagnostic and
6853-
// eat the token to prevent further parsing errors.
6854-
error = ErrorTypeRepr::create(Context, consumeToken(),
6855-
diag::cannot_suppress_here);
6856-
}
6857-
6858-
// Record the error parsing ~Copyable, but continue on to parseType.
6859-
if (error)
6860-
Inherited.push_back(InheritedEntry(error));
6861-
}
6862-
68636792
auto ParsedTypeResult = parseType();
68646793
Status |= ParsedTypeResult;
68656794

@@ -6868,9 +6797,6 @@ ParserStatus Parser::parseInheritance(
68686797
Inherited.push_back(InheritedEntry(ParsedTypeResult.get()));
68696798
} while (HasNextType);
68706799

6871-
if (parseTildeCopyable)
6872-
*parseTildeCopyable = TildeCopyableLoc;
6873-
68746800
return Status;
68756801
}
68766802

@@ -9165,14 +9091,10 @@ ParserResult<EnumDecl> Parser::parseDeclEnum(ParseDeclOptions Flags,
91659091
// Parse optional inheritance clause within the context of the enum.
91669092
if (Tok.is(tok::colon)) {
91679093
SmallVector<InheritedEntry, 2> Inherited;
9168-
SourceLoc parsedTildeCopyable;
91699094
Status |= parseInheritance(Inherited,
91709095
/*allowClassRequirement=*/false,
9171-
/*allowAnyObject=*/false,
9172-
&parsedTildeCopyable);
9096+
/*allowAnyObject=*/false);
91739097
ED->setInherited(Context.AllocateCopy(Inherited));
9174-
9175-
addMoveOnlyAttrIf(parsedTildeCopyable, Context, ED);
91769098
}
91779099

91789100
diagnoseWhereClauseInGenericParamList(GenericParams);
@@ -9431,14 +9353,10 @@ ParserResult<StructDecl> Parser::parseDeclStruct(ParseDeclOptions Flags,
94319353
// Parse optional inheritance clause within the context of the struct.
94329354
if (Tok.is(tok::colon)) {
94339355
SmallVector<InheritedEntry, 2> Inherited;
9434-
SourceLoc parsedTildeCopyable;
94359356
Status |= parseInheritance(Inherited,
94369357
/*allowClassRequirement=*/false,
9437-
/*allowAnyObject=*/false,
9438-
&parsedTildeCopyable);
9358+
/*allowAnyObject=*/false);
94399359
SD->setInherited(Context.AllocateCopy(Inherited));
9440-
9441-
addMoveOnlyAttrIf(parsedTildeCopyable, Context, SD);
94429360
}
94439361

94449362
diagnoseWhereClauseInGenericParamList(GenericParams);

lib/Parse/ParseType.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -311,13 +311,7 @@ ParserResult<TypeRepr> Parser::parseTypeSimple(
311311

312312
// Wrap in an InverseTypeRepr if needed.
313313
if (tildeLoc) {
314-
TypeRepr *repr;
315-
if (canSuppressConformancesWithTilde())
316-
repr = new (Context) InverseTypeRepr(tildeLoc, ty.get());
317-
else
318-
repr =
319-
ErrorTypeRepr::create(Context, tildeLoc, diag::cannot_suppress_here);
320-
314+
TypeRepr *repr = new (Context) InverseTypeRepr(tildeLoc, ty.get());
321315
ty = makeParserResult(ty, repr);
322316
}
323317

lib/Parse/Parser.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -496,9 +496,6 @@ Parser::Parser(std::unique_ptr<Lexer> Lex, SourceFile &SF,
496496
// Set the token to a sentinel so that we know the lexer isn't primed yet.
497497
// This cannot be tok::unknown, since that is a token the lexer could produce.
498498
Tok.setKind(tok::NUM_TOKENS);
499-
500-
EnabledNoncopyableGenerics =
501-
Context.LangOpts.hasFeature(Feature::NoncopyableGenerics);
502499
}
503500

504501
Parser::~Parser() {

lib/Sema/CSDiagnostics.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6416,8 +6416,7 @@ bool NotCopyableFailure::diagnoseAsError() {
64166416
return false;
64176417
};
64186418

6419-
// NOTE: a non-requirement constraint locator might now be impossible after
6420-
// having made Copyable a Requirement in Feature::NoncopyableGenerics
6419+
// NOTE: a non-requirement constraint locator might now be impossible.
64216420
if (diagnoseGenericTypeParamType(loc->getGenericParameter()))
64226421
return true;
64236422

test/Generics/inverse_copyable_requirement_legacy_errors.swift

Lines changed: 0 additions & 34 deletions
This file was deleted.

test/Parse/inverses_legacy.swift

Lines changed: 0 additions & 77 deletions
This file was deleted.

0 commit comments

Comments
 (0)