Skip to content

Merge main 2023-06-11 #5511

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b2a52ff
[move-only] Do not attempt to lazily deserialize the moveonly deinit …
gottesmm Jun 9, 2023
3c04cff
[Macros] Provide the freestanding macro role for expansion operations.
DougGregor Jun 9, 2023
c5ec389
Diagnose macros that have multiple freestanding macro roles.
DougGregor Jun 9, 2023
e3d940e
Move _used+_section from DECL_MODIFIER_KINDS to DECL_ATTR_KINDS in At…
kubamracek Jun 9, 2023
1957bd6
Sema: Reword diagnostics to say 'without a type annotation' instead o…
slavapestov Jun 9, 2023
4d1d8a9
[Observation] Add property definite initialization support (#65984)
phausler Jun 9, 2023
04ecc35
[Observation] Ensure type access is qualified to the module name (#66…
phausler Jun 10, 2023
160433b
Merge pull request #66505 from gottesmm/pr-13b73601ca744f17bd595d547b…
gottesmm Jun 10, 2023
24e3fe0
Merge pull request #66509 from DougGregor/unambiguous-freestanding-ma…
DougGregor Jun 10, 2023
91d547f
[Runtime] Properly handle unaligned reads in readTagBytes for layout …
drexin Jun 10, 2023
1c0aaef
Updating docs with new CI triggers
etcwilde Jun 10, 2023
c78afdc
[Macros] Tighten restriction on non-expression macros not having retu…
DougGregor Jun 10, 2023
7fb1ba9
[AST printer] Stop printing `-> ()` types on all macro declarations.
DougGregor Jun 10, 2023
f7de3a3
[Macros] Downgrade "void return for non-expression macro" error in in…
DougGregor Jun 10, 2023
0bd1c51
Update the trigger for Ubuntu 22.04
shahmishal Jun 10, 2023
51c2af6
Update the build toolchain to `Please Build Toolchain`
shahmishal Jun 10, 2023
f3e940d
Merge pull request #66528 from etcwilde/ewilde/update-CI-docs
shahmishal Jun 10, 2023
330af0b
Remove out of date triggers
shahmishal Jun 10, 2023
3198412
[wasm][stdlib] Fix return-address strategy selection
kateinoigakukun Jun 10, 2023
792196f
[wasm][stdlib] Add -D_WASI_EMULATED_PROCESS_CLOCKS to CFLAGS
kateinoigakukun Jun 10, 2023
9b9d576
Merge pull request #66526 from DougGregor/non-expression-macro-no-void
DougGregor Jun 10, 2023
743eefb
Merge pull request #66498 from slavapestov/reword-diagnostics-in-curr…
slavapestov Jun 10, 2023
6dadb6e
Merge pull request #66535 from kateinoigakukun/pr-c6aaf6abd931b4569de…
kateinoigakukun Jun 10, 2023
4e2f3b1
Merge pull request #66536 from kateinoigakukun/pr-03edd9bf0dc40dacaff…
kateinoigakukun Jun 10, 2023
f5f4b84
Merge remote-tracking branch 'origin/main' into katei/merge-main-2023…
kateinoigakukun Jun 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions docs/ContinuousIntegration.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,18 @@ macOS platform | @swift-ci Please Sourcekit Stress test | Swift Sourcekit Stress
Platform | Comment | Check Status
------------ | ------- | ------------
macOS platform | @swift-ci Please Build Toolchain macOS Platform| Swift Build Toolchain macOS Platform
Linux platform | @swift-ci Please Build Toolchain Linux Platform| Swift Build Toolchain Linux Platform
Linux platform | @swift-ci Please Build Toolchain Linux Platform| Swift Build Toolchain Ubuntu 22.04 (x86_64)

You can also build a toolchain for a specific Linux distribution

Distro | Comment | Check Status
-------------- | ------------------------------------------------ | ----------------------------------------------
UBI9 | @swift-ci Please Build Toolchain UBI9 | Swift Build Toolchain UBI9 (x86_64)
CentOS 7 | @swift-ci Please Build Toolchain CentOS 7 | Swift Build Toolchain CentOS 7 (x86_64)
Ubuntu 18.04 | @swift-ci Please Build Toolchain Ubuntu 18.04 | Swift Build Toolchain Ubuntu 18.04 (x86_64)
Ubuntu 20.04 | @swift-ci Please Build Toolchain Ubuntu 20.04 | Swift Build Toolchain Ubuntu 20.04 (x86_64)
Ubuntu 22.04 | @swift-ci Please Build Toolchain Ubuntu 22.04 | Swift Build Toolchain Ubuntu 22.04 (x86_64)
Amazon Linux 2 | @swift-ci Please Build Toolchain Amazon Linux 2 | Swift Build Toolchain Amazon Linux 2 (x86_64)

### Build and Test Stdlib against Snapshot Toolchain

Expand Down Expand Up @@ -275,9 +286,6 @@ Currently, supported pull request testing triggers:
Platform | Comment | Check Status
------------ | ------- | ------------
Windows | @swift-ci Please test Windows platform | Swift Test Windows Platform
Linux | @swift-ci Please test Tensorflow Linux platform | Swift Test Linux Platform (TensorFlow)
Linux (GPU) | @swift-ci Please test Tensorflow Linux GPU platform |Swift Test Linux Platform with GPU (TensorFlow)
macOS | @swift-ci Please test Tensorflow macOS platform | Swift Test macOS Platform (TensorFlow)

## ci.swift.org bots

Expand Down
8 changes: 5 additions & 3 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,10 @@ ERROR(no_candidates_match_argument_type,none,
(StringRef, Type, unsigned))

ERROR(cannot_infer_closure_parameter_type,none,
"unable to infer type of a closure parameter %0 in the current context",
"cannot infer type of closure parameter %0 without a type annotation",
(StringRef))
ERROR(cannot_infer_closure_type,none,
"unable to infer closure type in the current context", ())
"unable to infer closure type without a type annotation", ())
ERROR(cannot_infer_empty_closure_result_type,none,
"cannot infer return type of empty closure", ())
ERROR(cannot_infer_closure_result_type,none,
Expand Down Expand Up @@ -4163,7 +4163,7 @@ ERROR(could_not_infer_placeholder,none,
"could not infer type for placeholder", ())

ERROR(type_of_expression_is_ambiguous,none,
"type of expression is ambiguous without more context", ())
"type of expression is ambiguous without a type annotation", ())

ERROR(failed_to_produce_diagnostic,Fatal,
"failed to produce diagnostic for expression; "
Expand Down Expand Up @@ -7146,6 +7146,8 @@ NOTE(macro_remove_result_type,none,
())
NOTE(macro_make_freestanding_expression,none,
"make this macro a freestanding expression macro", ())
ERROR(macro_multiple_freestanding_roles,none,
"macro can only have a single freestanding role", ())
ERROR(macro_expansion_missing_pound,none,
"expansion of macro %0 requires leading '#'", (DeclName))
ERROR(macro_expansion_missing_arguments,none,
Expand Down
8 changes: 3 additions & 5 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4811,16 +4811,14 @@ void PrintAST::visitMacroDecl(MacroDecl *decl) {
}
);

{
if (decl->resultType.getTypeRepr() ||
!decl->getResultInterfaceType()->isVoid()) {
Printer.printStructurePre(PrintStructureKind::DeclResultTypeClause);
SWIFT_DEFER {
Printer.printStructurePost(PrintStructureKind::DeclResultTypeClause);
};

if (decl->parameterList)
Printer << " -> ";
else
Printer << ": ";
Printer << " -> ";

TypeLoc resultTypeLoc(
decl->resultType.getTypeRepr(), decl->getResultInterfaceType());
Expand Down
21 changes: 21 additions & 0 deletions lib/ASTGen/Sources/ASTGen/Macros.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ extension MacroRole {
case 0x10: self = .member
case 0x20: self = .peer
case 0x40: self = .conformance
case 0x80: self = .codeItem

default: fatalError("unknown macro role")
}
}
Expand Down Expand Up @@ -414,6 +416,7 @@ func expandFreestandingMacro(
macroKind: UInt8,
discriminatorText: UnsafePointer<UInt8>,
discriminatorTextLength: Int,
rawMacroRole: UInt8,
sourceFilePtr: UnsafeRawPointer,
sourceLocationPtr: UnsafePointer<UInt8>?,
expandedSourcePointer: UnsafeMutablePointer<UnsafePointer<UInt8>?>,
Expand Down Expand Up @@ -446,18 +449,21 @@ func expandFreestandingMacro(
)
let discriminator = String(decoding: discriminatorBuffer, as: UTF8.self)

let macroRole = MacroRole(rawMacroRole: rawMacroRole)
let expandedSource: String?
switch MacroPluginKind(rawValue: macroKind)! {
case .InProcess:
expandedSource = expandFreestandingMacroInProcess(
macroPtr: macroPtr,
macroRole: macroRole,
diagEnginePtr: diagEnginePtr,
expansionSyntax: expansion,
sourceFilePtr: sourceFilePtr,
discriminator: discriminator)
case .Executable:
expandedSource = expandFreestandingMacroIPC(
macroPtr: macroPtr,
macroRole: macroRole,
diagEnginePtr: diagEnginePtr,
expansionSyntax: expansion,
sourceFilePtr: sourceFilePtr,
Expand Down Expand Up @@ -485,6 +491,7 @@ func expandFreestandingMacro(

func expandFreestandingMacroIPC(
macroPtr: UnsafeRawPointer,
macroRole: MacroRole,
diagEnginePtr: UnsafeMutablePointer<UInt8>,
expansionSyntax: FreestandingMacroExpansionSyntax,
sourceFilePtr: UnsafePointer<ExportedSourceFile>,
Expand All @@ -502,9 +509,21 @@ func expandFreestandingMacroIPC(

let macro = macroPtr.assumingMemoryBound(to: ExportedExecutableMacro.self).pointee

// Map the macro role.
let pluginMacroRole: PluginMessage.MacroRole
switch macroRole {
case .accessor, .member, .memberAttribute, .peer, .conformance:
preconditionFailure("unhandled macro role for freestanding macro")

case .expression: pluginMacroRole = .expression
case .declaration: pluginMacroRole = .freeStandingDeclaration
case .codeItem: pluginMacroRole = .codeItem
}

// Send the message.
let message = HostToPluginMessage.expandFreestandingMacro(
macro: .init(moduleName: macro.moduleName, typeName: macro.typeName, name: macroName),
macroRole: pluginMacroRole,
discriminator: discriminator,
syntax: PluginMessage.Syntax(syntax: Syntax(expansionSyntax), in: sourceFilePtr)!)
do {
Expand Down Expand Up @@ -541,6 +560,7 @@ func expandFreestandingMacroIPC(

func expandFreestandingMacroInProcess(
macroPtr: UnsafeRawPointer,
macroRole: MacroRole,
diagEnginePtr: UnsafeMutablePointer<UInt8>,
expansionSyntax: FreestandingMacroExpansionSyntax,
sourceFilePtr: UnsafePointer<ExportedSourceFile>,
Expand Down Expand Up @@ -580,6 +600,7 @@ func expandFreestandingMacroInProcess(

return SwiftSyntaxMacroExpansion.expandFreestandingMacro(
definition: macro,
macroRole: macroRole,
node: node,
in: context
)
Expand Down
2 changes: 2 additions & 0 deletions lib/ASTGen/Sources/ASTGen/PluginMessages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ internal enum HostToPluginMessage: Codable {
/// Expand a '@freestanding' macro.
case expandFreestandingMacro(
macro: PluginMessage.MacroReference,
macroRole: PluginMessage.MacroRole? = nil,
discriminator: String,
syntax: PluginMessage.Syntax
)
Expand Down Expand Up @@ -91,6 +92,7 @@ internal enum PluginToHostMessage: Codable {
case member
case peer
case conformance
case codeItem
}

struct SourceLocation: Codable {
Expand Down
2 changes: 1 addition & 1 deletion lib/IDETool/SyntacticMacroExpansion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ void SyntacticMacroExpansionInstance::expand(
SourceFile *SF, const MacroExpansionSpecifier &expansion,
SourceEditConsumer &consumer) {

// Find the expansion at 'expantion.offset'.
// Find the expansion at 'expansion.offset'.
MacroExpansionFinder expansionFinder(
SourceMgr,
SourceMgr.getLocForOffset(*SF->getBufferID(), expansion.offset));
Expand Down
6 changes: 4 additions & 2 deletions lib/IRGen/GenType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2897,9 +2897,11 @@ static bool tryEmitDeinitCall(IRGenFunction &IGF,
return false;
}

auto deinitTable = IGF.getSILModule().lookUpMoveOnlyDeinit(nominal);
auto deinitTable = IGF.getSILModule().lookUpMoveOnlyDeinit(
nominal, false /*deserialize lazily*/);

// If we do not have a deinit table, call the value witness instead.
// If we do not have a deinit table already deserialized, call the value
// witness instead.
if (!deinitTable) {
irgen::emitDestroyCall(IGF, T, indirect());
indirectCleanup();
Expand Down
50 changes: 36 additions & 14 deletions lib/Macros/Sources/ObservationMacros/ObservableMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ import SwiftSyntaxMacros
@_implementationOnly import SwiftSyntaxBuilder

public struct ObservableMacro {
static let moduleName = "_Observation"

static let conformanceName = "Observable"
static var qualifiedConformanceName: String {
return "\(moduleName).\(conformanceName)"
}

static var observableConformanceType: TypeSyntax {
"\(raw: qualifiedConformanceName)"
}

static let registrarTypeName = "ObservationRegistrar"
static var qualifiedRegistrarTypeName: String {
return "\(moduleName).\(registrarTypeName)"
}

static let trackedMacroName = "ObservationTracked"
static let ignoredMacroName = "ObservationIgnored"

Expand All @@ -25,7 +41,7 @@ public struct ObservableMacro {
static func registrarVariable(_ observableType: TokenSyntax) -> DeclSyntax {
return
"""
@\(raw: ignoredMacroName) private let \(raw: registrarVariableName) = ObservationRegistrar()
@\(raw: ignoredMacroName) private let \(raw: registrarVariableName) = \(raw: qualifiedRegistrarTypeName)()
"""
}

Expand Down Expand Up @@ -202,17 +218,15 @@ extension ObservableMacro: MemberMacro {
declaration.addIfNeeded(ObservableMacro.registrarVariable(observableType), to: &declarations)
declaration.addIfNeeded(ObservableMacro.accessFunction(observableType), to: &declarations)
declaration.addIfNeeded(ObservableMacro.withMutationFunction(observableType), to: &declarations)


#if !OBSERVATION_SUPPORTS_PEER_MACROS
let storedInstanceVariables = declaration.definedVariables.filter { $0.isValidForObservation }
for property in storedInstanceVariables {
if property.hasMacroApplication(ObservableMacro.ignoredMacroName) { continue }
if property.initializer == nil {
context.addDiagnostics(from: DiagnosticsError(syntax: property, message: "@Observable requires property '\(property.identifier?.text ?? "")' to have an initial value", id: .missingInitializer), node: property)
}
let storage = DeclSyntax(property.privatePrefixed("_", addingAttribute: ObservableMacro.ignoredAttribute))
declaration.addIfNeeded(storage, to: &declarations)

if property.hasMacroApplication(ObservableMacro.ignoredMacroName) { continue }
let storage = DeclSyntax(property.privatePrefixed("_", addingAttribute: ObservableMacro.ignoredAttribute))
declaration.addIfNeeded(storage, to: &declarations)
}
#endif

return declarations
}
Expand Down Expand Up @@ -264,13 +278,13 @@ extension ObservableMacro: ConformanceMacro {

if let inheritanceList {
for inheritance in inheritanceList {
if inheritance.typeName.identifier == "Observable" {
if inheritance.typeName.identifier == ObservableMacro.conformanceName {
return []
}
}
}

return [("Observable", nil)]
return [(ObservableMacro.observableConformanceType, nil)]
}
}

Expand All @@ -293,6 +307,13 @@ public struct ObservationTrackedMacro: AccessorMacro {
return []
}

let initAccessor: AccessorDeclSyntax =
"""
init(initialValue) initializes(_\(identifier)) {
_\(identifier) = initialValue
}
"""

let getAccessor: AccessorDeclSyntax =
"""
get {
Expand All @@ -310,7 +331,7 @@ public struct ObservationTrackedMacro: AccessorMacro {
}
"""

return [getAccessor, setAccessor]
return [initAccessor, getAccessor, setAccessor]
}
}

Expand All @@ -327,8 +348,9 @@ extension ObservationTrackedMacro: PeerMacro {
property.isValidForObservation else {
return []
}

if property.hasMacroApplication(ObservableMacro.ignoredMacroName) {

if property.hasMacroApplication(ObservableMacro.ignoredMacroName) ||
property.hasMacroApplication(ObservableMacro.trackedMacroName) {
return []
}

Expand Down
42 changes: 35 additions & 7 deletions lib/Sema/TypeCheckDeclPrimary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2017,6 +2017,17 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
llvm_unreachable("should always be type-checked already");
}

/// Determine the number of bits set.
static unsigned numBitsSet(uint64_t value) {
unsigned count = 0;
for (uint64_t i : range(0, 63)) {
if (value & (uint64_t(1) << i))
++count;
}

return count;
}

void visitMacroDecl(MacroDecl *MD) {
TypeChecker::checkDeclAttributes(MD);
checkAccessControl(MD);
Expand Down Expand Up @@ -2061,22 +2072,39 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
}
}

// If the macro has a (non-Void) result type, it must have the freestanding
// If the macro has a result type, it must have the freestanding
// expression role. Other roles cannot have result types.
if (auto resultTypeRepr = MD->getResultTypeRepr()) {
if (!MD->getMacroRoles().contains(MacroRole::Expression) &&
!MD->getResultInterfaceType()->isEqual(Ctx.getVoidType())) {
auto resultType = MD->getResultInterfaceType();
Ctx.Diags.diagnose(
MD->arrowLoc, diag::macro_result_type_cannot_be_used, resultType)
.highlight(resultTypeRepr->getSourceRange());
if (!MD->getMacroRoles().contains(MacroRole::Expression)) {
auto resultType = MD->getResultInterfaceType(); {
auto diag = Ctx.Diags.diagnose(
MD->arrowLoc, diag::macro_result_type_cannot_be_used, resultType);
diag.highlight(resultTypeRepr->getSourceRange());

// In a .swiftinterface file, downgrade this diagnostic to a warning.
// This allows the compiler to process existing .swiftinterface
// files that contain this issue.
if (resultType->isVoid()) {
if (auto sourceFile = MD->getParentSourceFile())
if (sourceFile->Kind == SourceFileKind::Interface)
diag.limitBehavior(DiagnosticBehavior::Warning);
}
}

Ctx.Diags.diagnose(MD->arrowLoc, diag::macro_make_freestanding_expression)
.fixItInsert(MD->getAttributeInsertionLoc(false),
"@freestanding(expression)\n");
Ctx.Diags.diagnose(MD->arrowLoc, diag::macro_remove_result_type)
.fixItRemove(SourceRange(MD->arrowLoc, resultTypeRepr->getEndLoc()));
}
}

// A macro can only have a single freestanding macro role.
MacroRoles freestandingRolesInhabited =
MD->getMacroRoles() & getFreestandingMacroRoles();
if (numBitsSet(freestandingRolesInhabited.toRaw()) > 1) {
MD->diagnose(diag::macro_multiple_freestanding_roles);
}
}

void visitMacroExpansionDecl(MacroExpansionDecl *MED) {
Expand Down
Loading