Skip to content

Commit 203a253

Browse files
rintaronkcsgexi
authored andcommitted
[Parse/Migrator] Drop Swift3 migration support for type(of:) (#17932)
In Swift3, shadowning type(of:) was impossible, because it was a parser magic. In Swift4, type(of:) is resolved as normal function in stdlib so it can be shadowed. 'TypeOfMigratorPass' was a targeted migrator pass that prepend 'Swift.' to 'type(of:)' so that it refers Swift.type(of:) stdlib builtin function.
1 parent 7b7488d commit 203a253

File tree

9 files changed

+0
-294
lines changed

9 files changed

+0
-294
lines changed

include/swift/Migrator/ASTMigratorPass.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,6 @@ void runTupleSplatMigratorPass(EditorAdapter &Editor,
5555
SourceFile *SF,
5656
const MigratorOptions &Opts);
5757

58-
/// Run a pass to prepend 'Swift.' to `type(of:)` expressions if they will
59-
/// be shadowed in Swift 4, as these are now resolved by normal overload
60-
/// resolution.
61-
void runTypeOfMigratorPass(EditorAdapter &Editor,
62-
SourceFile *SF,
63-
const MigratorOptions &Opts);
64-
6558
} // end namespace migrator
6659
} // end namespace swift
6760

lib/Migrator/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ add_swift_library(swiftMigrator STATIC
5555
MigrationState.cpp
5656
RewriteBufferEditsReceiver.cpp
5757
TupleSplatMigratorPass.cpp
58-
TypeOfMigratorPass.cpp
5958
LINK_LIBRARIES swiftSyntax swiftIDE)
6059

6160
add_dependencies(swiftMigrator

lib/Migrator/Migrator.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,6 @@ bool Migrator::performSyntacticPasses() {
216216
getMigratorOptions());
217217
runTupleSplatMigratorPass(Editor, StartInstance->getPrimarySourceFile(),
218218
getMigratorOptions());
219-
runTypeOfMigratorPass(Editor, StartInstance->getPrimarySourceFile(),
220-
getMigratorOptions());
221219

222220
Edits.commit(Editor.getEdits());
223221

lib/Migrator/TypeOfMigratorPass.cpp

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

lib/Parse/ParseExpr.cpp

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,38 +1088,6 @@ getMagicIdentifierLiteralKind(tok Kind) {
10881088
}
10891089
}
10901090

1091-
/// See if type(of: <expr>) can be parsed backtracking on failure.
1092-
static bool canParseTypeOf(Parser &P) {
1093-
// We parsed `type(of:)` as a special syntactic form in Swift 3. In Swift 4
1094-
// it is handled by overload resolution.
1095-
if (!P.Context.LangOpts.isSwiftVersion3())
1096-
return false;
1097-
1098-
if (!(P.Tok.getText() == "type" && P.peekToken().is(tok::l_paren))) {
1099-
return false;
1100-
}
1101-
// Look ahead to parse the parenthesized expression.
1102-
Parser::BacktrackingScope Backtrack(P);
1103-
P.consumeToken(tok::identifier);
1104-
P.consumeToken(tok::l_paren);
1105-
// The first argument label must be 'of'.
1106-
if (!(P.Tok.getText() == "of" && P.peekToken().is(tok::colon))) {
1107-
return false;
1108-
}
1109-
1110-
// Parse to the closing paren.
1111-
while (!P.Tok.is(tok::r_paren) && !P.Tok.is(tok::eof)) {
1112-
// Anything that looks like another argument label is bogus. It is
1113-
// sufficient to parse for a single trailing comma. Backtracking will
1114-
// fall back to an unresolved decl.
1115-
if (P.Tok.is(tok::comma)) {
1116-
return false;
1117-
}
1118-
P.skipSingle();
1119-
}
1120-
return true;
1121-
}
1122-
11231091
ParserResult<Expr>
11241092
Parser::parseExprPostfixSuffix(ParserResult<Expr> Result, bool isExprBasic,
11251093
bool periodHasKeyPathBehavior,
@@ -1559,10 +1527,6 @@ ParserResult<Expr> Parser::parseExprPrimary(Diag<> ID, bool isExprBasic) {
15591527

15601528
case tok::identifier: // foo
15611529
case tok::kw_self: // self
1562-
// Attempt to parse for 'type(of: <expr>)'.
1563-
if (canParseTypeOf(*this)) {
1564-
return parseExprTypeOf();
1565-
}
15661530

15671531
// If we are parsing a refutable pattern and are inside a let/var pattern,
15681532
// the identifiers change to be value bindings instead of decl references.
@@ -3560,70 +3524,3 @@ Parser::parsePlatformVersionConstraintSpec() {
35603524
return makeParserResult(new (Context) PlatformVersionConstraintAvailabilitySpec(
35613525
Platform.getValue(), PlatformLoc, Version, VersionRange));
35623526
}
3563-
3564-
/// parseExprTypeOf
3565-
///
3566-
/// expr-dynamictype:
3567-
/// 'type' '(' 'of:' expr ')'
3568-
///
3569-
ParserResult<Expr> Parser::parseExprTypeOf() {
3570-
// In libSyntax parsing, we parse 'type(of: <expr>)' as a normal function call
3571-
// expression. The semantic AST builder should treat this as a
3572-
// DynamicTypeExpr.
3573-
SyntaxParsingContext CallCtxt(SyntaxContext, SyntaxKind::FunctionCallExpr);
3574-
3575-
SourceLoc keywordLoc;
3576-
{
3577-
SyntaxParsingContext IdentifierExprContext(SyntaxContext,
3578-
SyntaxKind::IdentifierExpr);
3579-
// Consume 'type'
3580-
keywordLoc = consumeToken();
3581-
}
3582-
3583-
// Parse the leading '('.
3584-
SourceLoc lParenLoc = consumeToken(tok::l_paren);
3585-
3586-
ParserResult<Expr> subExpr;
3587-
{
3588-
SyntaxParsingContext ArgCtxt(SyntaxContext,
3589-
SyntaxKind::FunctionCallArgument);
3590-
// Parse `of` label.
3591-
if (Tok.getText() == "of" && peekToken().is(tok::colon)) {
3592-
// Consume the label.
3593-
consumeToken();
3594-
consumeToken(tok::colon);
3595-
} else {
3596-
// There cannot be a richer diagnostic here because the user may have
3597-
// defined a function `type(...)` that conflicts with the magic expr.
3598-
diagnose(Tok, diag::expr_typeof_expected_label_of);
3599-
}
3600-
3601-
// Parse the subexpression.
3602-
subExpr = parseExpr(diag::expr_typeof_expected_expr);
3603-
if (subExpr.hasCodeCompletion())
3604-
return makeParserCodeCompletionResult<Expr>();
3605-
}
3606-
CallCtxt.collectNodesInPlace(SyntaxKind::FunctionCallArgumentList);
3607-
3608-
// Parse the closing ')'
3609-
SourceLoc rParenLoc;
3610-
if (subExpr.isParseError()) {
3611-
skipUntilDeclStmtRBrace(tok::r_paren);
3612-
if (Tok.is(tok::r_paren))
3613-
rParenLoc = consumeToken();
3614-
else
3615-
rParenLoc = PreviousLoc;
3616-
} else {
3617-
parseMatchingToken(tok::r_paren, rParenLoc,
3618-
diag::expr_typeof_expected_rparen, lParenLoc);
3619-
}
3620-
3621-
// If the subexpression was in error, just propagate the error.
3622-
if (subExpr.isParseError())
3623-
return makeParserResult<Expr>(
3624-
new (Context) ErrorExpr(SourceRange(keywordLoc, rParenLoc)));
3625-
3626-
return makeParserResult(
3627-
new (Context) DynamicTypeExpr(keywordLoc, lParenLoc,
3628-
subExpr.get(), rParenLoc, Type()));
3629-
}

test/Migrator/prefix_typeof_expr.swift

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

test/Migrator/prefix_typeof_expr.swift.expected

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

test/Migrator/prefix_typeof_expr_unneeded.swift

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

test/Migrator/prefix_typeof_expr_unneeded.swift.expected

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

0 commit comments

Comments
 (0)