Somewhat working

Test shadowed variable of same type

Fully type check caller side macro expansion

Skip macro default arg caller side expr at decl primary

Test macro expand more complex expressions

Set synthesized expression as implicit

Add test case for with argument, not compiling currently

Test with swiftinterface

Always use the string representation of the default argument

Now works across module boundary

Check works for multiple files

Make default argument expression work in single file

Use expected-error

Disallow expression macro as default argument

Using as a sub expression in default argument still allowed as expression macros behave the same as built-in magic literals
This commit is contained in:
Apollo Zhu
2023-09-20 12:51:09 -07:00
parent d93d742c66
commit b09a22a9a0
40 changed files with 496 additions and 21 deletions

View File

@@ -8290,6 +8290,9 @@ DefaultArgumentKind swift::getDefaultArgKind(Expr *init) {
if (isa<NilLiteralExpr>(init))
return DefaultArgumentKind::NilLiteral;
if (isa<MacroExpansionExpr>(init))
return DefaultArgumentKind::ExpressionMacro;
auto magic = dyn_cast<MagicIdentifierLiteralExpr>(init);
if (!magic)
return DefaultArgumentKind::Normal;
@@ -8489,6 +8492,7 @@ bool ParamDecl::hasDefaultExpr() const {
#define MAGIC_IDENTIFIER(NAME, STRING, SYNTAX_KIND) \
case DefaultArgumentKind::NAME:
#include "swift/AST/MagicIdentifierKinds.def"
case DefaultArgumentKind::ExpressionMacro:
case DefaultArgumentKind::NilLiteral:
case DefaultArgumentKind::EmptyArray:
case DefaultArgumentKind::EmptyDictionary:
@@ -8512,6 +8516,7 @@ bool ParamDecl::hasCallerSideDefaultExpr() const {
case DefaultArgumentKind::NilLiteral:
case DefaultArgumentKind::EmptyArray:
case DefaultArgumentKind::EmptyDictionary:
case DefaultArgumentKind::ExpressionMacro:
return true;
}
llvm_unreachable("invalid default argument kind");
@@ -8708,6 +8713,7 @@ ParamDecl::getDefaultValueStringRepresentation(
switch (getDefaultArgumentKind()) {
case DefaultArgumentKind::None:
llvm_unreachable("called on a ParamDecl with no default value");
case DefaultArgumentKind::ExpressionMacro:
case DefaultArgumentKind::Normal: {
assert(DefaultValueAndFlags.getPointer() &&
"default value not provided yet");
@@ -8800,7 +8806,8 @@ ParamDecl::getDefaultValueStringRepresentation(
void
ParamDecl::setDefaultValueStringRepresentation(StringRef stringRepresentation) {
assert(getDefaultArgumentKind() == DefaultArgumentKind::Normal ||
getDefaultArgumentKind() == DefaultArgumentKind::StoredProperty);
getDefaultArgumentKind() == DefaultArgumentKind::StoredProperty ||
getDefaultArgumentKind() == DefaultArgumentKind::ExpressionMacro);
assert(!stringRepresentation.empty());
if (!DefaultValueAndFlags.getPointer()) {
@@ -12008,6 +12015,7 @@ MacroDiscriminatorContext MacroDiscriminatorContext::getParentOf(
#include "swift/Basic/MacroRoles.def"
case GeneratedSourceInfo::PrettyPrinted:
case GeneratedSourceInfo::ReplacedFunctionBody:
case GeneratedSourceInfo::DefaultArgument:
return origDC;
}
}