Skip to content

Commit c1a6ac9

Browse files
committed
[ASTGen] Remove ASTGenTypes experimental feature
There's no reason to generate only TypeRepr using ASTGen anymore. Use ParserASTGen feature to test test/ASTGen/types.swift because ASTGen now can generate the whole test file for type checking.
1 parent e470232 commit c1a6ac9

File tree

6 files changed

+53
-12
lines changed

6 files changed

+53
-12
lines changed

include/swift/Basic/Features.def

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,6 @@ EXPERIMENTAL_FEATURE(ImplicitSome, false)
193193
/// corresponding syntax tree.
194194
EXPERIMENTAL_FEATURE(ParserASTGen, false)
195195

196-
/// Use the syntax tree produced by the Swift (swift-syntax) parser for type
197-
/// parsing, using ASTGen to translate them into AST nodes.
198-
EXPERIMENTAL_FEATURE(ASTGenTypes, false)
199-
200196
/// Parse using the Swift (swift-syntax) parser and use ASTGen to generate the
201197
/// corresponding syntax tree.
202198
EXPERIMENTAL_FEATURE(BuiltinMacros, false)

lib/AST/ASTBridging.cpp

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,42 @@ BridgedParamDecl BridgedParamDecl_createParsed(
326326
auto *paramDecl = new (cContext.unbridged())
327327
ParamDecl(cSpecifierLoc.unbridged(), firstNameLoc, firstName,
328328
secondNameLoc, secondName, declContext);
329-
paramDecl->setTypeRepr(opaqueType.unbridged());
329+
330+
if (auto type = opaqueType.unbridged()) {
331+
paramDecl->setTypeRepr(type);
332+
333+
// FIXME: Copied from 'Parser::parsePattern()'. This should be in Sema.
334+
// Dig through the type to find any attributes or modifiers that are
335+
// associated with the type but should also be reflected on the
336+
// declaration.
337+
auto unwrappedType = type;
338+
while (true) {
339+
if (auto *ATR = dyn_cast<AttributedTypeRepr>(unwrappedType)) {
340+
auto &attrs = ATR->getAttrs();
341+
// At this point we actually don't know if that's valid to mark
342+
// this parameter declaration as `autoclosure` because type has
343+
// not been resolved yet - it should either be a function type
344+
// or typealias with underlying function type.
345+
paramDecl->setAutoClosure(attrs.has(TypeAttrKind::TAK_autoclosure));
346+
347+
unwrappedType = ATR->getTypeRepr();
348+
continue;
349+
}
350+
351+
if (auto *STR = dyn_cast<SpecifierTypeRepr>(unwrappedType)) {
352+
if (isa<IsolatedTypeRepr>(STR))
353+
paramDecl->setIsolated(true);
354+
else if (isa<CompileTimeConstTypeRepr>(STR))
355+
paramDecl->setCompileTimeConst(true);
356+
357+
unwrappedType = STR->getBase();
358+
continue;
359+
}
360+
361+
break;
362+
}
363+
}
364+
330365
paramDecl->setDefaultExpr(defaultValue, /*isTypeChecked*/ false);
331366
paramDecl->setDefaultArgumentKind(defaultArgumentKind);
332367

lib/AST/ASTPrinter.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3422,10 +3422,6 @@ static bool usesFeatureParserASTGen(Decl *decl) {
34223422
return false;
34233423
}
34243424

3425-
static bool usesFeatureASTGenTypes(Decl *decl) {
3426-
return false;
3427-
}
3428-
34293425
static bool usesFeatureBuiltinMacros(Decl *decl) {
34303426
return false;
34313427
}

lib/ASTGen/Sources/ASTGen/ParameterClause.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ fileprivate protocol ValueParameterSyntax: SyntaxProtocol {
3131
// FIXME: Rename once we support covariant witnesses.
3232
var optionalType: TypeSyntax? { get }
3333

34+
var ellipsis: TokenSyntax? { get }
35+
3436
var defaultValue: InitializerClauseSyntax? { get }
3537
}
3638

@@ -52,6 +54,10 @@ extension EnumCaseParameterSyntax: ValueParameterSyntax {
5254
fileprivate var optionalType: TypeSyntax? {
5355
type
5456
}
57+
58+
fileprivate var ellipsis: TokenSyntax? {
59+
nil
60+
}
5561
}
5662

5763
extension ASTGenVisitor {
@@ -77,6 +83,15 @@ extension ASTGenVisitor {
7783

7884
let (secondName, secondNameLoc) = node.secondName.bridgedIdentifierAndSourceLoc(in: self)
7985

86+
var type = self.generate(node.optionalType)
87+
if let ellipsis = node.ellipsis, let base = type {
88+
type = BridgedVarargTypeRepr.createParsed(
89+
self.ctx,
90+
base: base,
91+
ellipsisLoc: ellipsis.bridgedSourceLoc(in: self)
92+
)
93+
}
94+
8095
return .createParsed(
8196
self.ctx,
8297
declContext: self.declContext,
@@ -85,7 +100,7 @@ extension ASTGenVisitor {
85100
firstNameLoc: node.optionalFirstName.bridgedSourceLoc(in: self),
86101
secondName: secondName,
87102
secondNameLoc: secondNameLoc,
88-
type: self.generate(node.optionalType).asNullable,
103+
type: type.asNullable,
89104
defaultValue: self.generate(node.defaultValue?.value).asNullable
90105
)
91106
}

test/ASTGen/types.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -enable-experimental-feature ASTGenTypes
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-feature ParserASTGen
22

33
// -enable-experimental-feature requires an asserts build
44
// REQUIRES: asserts

test/ASTGen/verify-parse.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// RUN: %diff -u %t/astgen.ast %t/cpp-parser.ast
66

77
// RUN: %target-run-simple-swift(-Xfrontend -disable-availability-checking -enable-experimental-feature SwiftParser -enable-experimental-feature ParserASTGen)
8-
// RUN: %target-run-simple-swift(-Xfrontend -disable-availability-checking -enable-experimental-feature ASTGenTypes)
98

109
// REQUIRES: executable_test
1110

0 commit comments

Comments
 (0)