Commit Graph

784 Commits

Author SHA1 Message Date
Kuba (Brecka) Mracek
eb23d3bc0a Merge pull request #85074 from kubamracek/section
SE-0492: Stabilize @_section/@_used into @section/@used
2025-10-24 12:29:48 -07:00
Henrik G. Olsson
6f1936ff73 Merge pull request #85059 from hnrklssn/swiftify-import-protocol
[Swiftify] Add _SwiftifyImportProtocol for safe overloads for protocols
2025-10-23 11:37:09 -07:00
Kuba Mracek
c63db8af1d Fix test expectations for @DebugDescription changes around @section syntactic checking 2025-10-23 08:49:57 -07:00
Henrik G. Olsson
7c1fd54701 update failing tests 2025-10-22 18:25:57 -07:00
Kuba Mracek
adeb40f261 SE-0492: Stabilize @_section/@_used into @section/@used
Removes the underscored prefixes from the @_section and @_used attributes, making them public as @section and @used respectively. The SymbolLinkageMarkers experimental feature has been removed as these attributes are now part of the standard language. Implemented expression syntactic checking rules per SE-0492.

Major parts:
- Renamed @_section to @section and @_used to @used
- Removed the SymbolLinkageMarkers experimental feature
- Added parsing support for the old underscored names with deprecation warnings
- Updated all tests and examples to use the new attribute names
- Added syntactic validation for @section to align with SE-0492 (reusing the legality checker by @artemcm)
- Changed @DebugDescription macro to explicitly use a tuple type instead of type inferring it, to comply with the expression syntax rules
- Added a testcase for the various allowed and disallowed syntactic forms, `test/ConstValues/SectionSyntactic.swift`.
2025-10-22 16:05:39 -07:00
Henrik G. Olsson
48f81c82dd [Swiftify] Add _SwiftifyImportProtocol for safe overloads for protocols
The existing _SwiftifyImport macro is a peer macro, limiting it to only
emitting function wrappers in the same scope as the original function.
Protocols cannot contain function implementations, so these need to be
placed in a separate protocol extension instead. _SwiftifyImportProtocol
is an extension macro rather than a peer macro, to enable this
functionality.

Rather than operating on a single function, like _SwiftifyImport,
_SwiftifyImportProtocol takes information about multiple methods and
creates a single protocol extension with all wrappers in a one-shot
operation.

rdar://144335990
2025-10-21 21:19:54 -07:00
Henrik G. Olsson
3266b5f4a6 Merge pull request #84774 from hnrklssn/fix-std-span-linux
Fix std::span tests on linux
2025-10-20 16:06:35 -07:00
Henrik G. Olsson
c844d483ff [cxx-interop] Add llvm-lit feature 'std_span'
This adds a check in lit.local.cfg for whether the current C++ stdlib
contains the 'span' header. If so, the llvm-lit feature 'std_span' is
set. Also adds 'REQUIRES: std_span' to interop tests that include
'span'. This means we no longer have to choose between blanket disabling
`std::span` tests on all Linux distributions, or listing every Linux
distro with a libstdc++ version without `std::span` support as
unsupported.

I couldn't find any existing path to the MSVC stdlib in lit, and we
don't test versions of MSVC old enought to not support std::span
anyways, so 'std_span' is unconditionally enabled when targeting
windows-msvc.

rdar://161999160
rdar://161999174
rdar://162106580
rdar://162106619
rdar://162106643
rdar://162106653
rdar://162106722
rdar://162106747
2025-10-17 15:41:26 -07:00
Hamish Knight
364eba482d [AST] Use CustomAttr's DeclContext for ResolveMacroRequest
Remove the DeclContext parameter from ResolveMacroRequest, we can now
retrieve the DeclContext either from the CustomAttr or macro expansion
expr/decl directly.
2025-10-16 11:21:54 +01:00
Rintaro Ishizaki
9956cda3cb Merge pull request #84887 from rintaro/macros-attached-opfolding-rdar162208759
[Macros] Add test cases for operator foldings
2025-10-15 16:50:27 -07:00
Henrik G. Olsson
81f1e75b4f Merge pull request #84843 from hnrklssn/filecheck-sanitize-tmp-dir
[Utils] Sanitize %t with PathSanitizingFileCheck
2025-10-15 15:43:58 -07:00
Rintaro Ishizaki
25bdbb6f81 [Macros] Add test cases for operator foldings
Macro implementation should receive only see the macro syntax (i.e.
`#macroName(...)` or `@macroName(...)` are operator folded, not other
syntax - the attached declration, member, etc.

rdar://162208759
2025-10-15 10:38:21 -07:00
Hamish Knight
b14dc227f7 Merge pull request #84855 from hamishknight/loc-ness-monster
[Parse] Avoid setting closure `in` SourceLoc if missing
2025-10-14 09:16:12 +01:00
Henrik G. Olsson
bae041c192 Merge pull request #84841 from hnrklssn/swiftify-return-opaque
[Swiftify] Cast OpaquePointer to UnsafeRawPointer before RawSpan
2025-10-13 13:35:24 -07:00
Rintaro Ishizaki
8c798469d1 Merge pull request #84829 from rintaro/plugin-termsignal-rdar160820381
[Macros] Send termination signal to macro plugin
2025-10-13 10:27:47 -07:00
Hamish Knight
b83cf1eaa5 [Parse] Avoid setting closure in SourceLoc if missing
Clients should be able to handle closures without a valid `in`
SourceLoc, let's avoid setting it to a recovery location. This avoids
crashing in cases where we set an `in` loc that's after the closure's
end loc.
2025-10-13 15:34:57 +01:00
Henrik G. Olsson
9e2a18d401 fix tests with TMP_DIR 2025-10-12 16:01:30 -07:00
Henrik G. Olsson
7d5fd7d9f5 filter out swift runtime warnings 2025-10-11 16:33:24 -07:00
Henrik G. Olsson
a62b0054f5 [Swiftify] Cast OpaquePointer to UnsafeRawPointer before RawSpan
The initializers for RawSpan and UnsafeRawBufferPointer take an
UnsafeRawPointer, so when the underlying function returns an
OpaquePointer we need to cast it first.

rdar://162091516
2025-10-11 13:06:09 -07:00
Henrik G. Olsson
2e01ba308f [Swiftify] Don't use unsafe for Unsafe[Mut][Raw]BufferPointer.count
Although the type is unsafe, the count is marked `@safe`, and this use
of `unsafe` results in a warning (regardless of whether strict memory
safety is enabled or not).
Keep emitting `unsafe` when the pointer buffer is wrapped in Optional
for now however, because that is currently flagged as unsafe.

rdar://162416566
2025-10-10 22:51:24 -07:00
Rintaro Ishizaki
a0b9b54944 [Macros] Send termination signal to macro plugin
When shutting down, the plugin, we send SIGTERM, then wait(2) on it. But
we observed some cases the compiler waits for the plugin process exit
for long time.

To resolve that, send an empty message to the plugin and let them exit
itself.

rdar://160820381
2025-10-10 15:13:13 -07:00
Henrik G. Olsson
cbc0ec3b88 Add -verify-ignore-unrelated where necessary (NFC)
These are tests that fail in the next commit without this flag. This
does not add -verify-ignore-unrelated to all tests with -verify, only
the ones that would fail without it. This is NFC since this flag is
currently a no-op.
2025-10-04 14:19:52 -07:00
Doug Gregor
c4527dc47d Merge pull request #84580 from DougGregor/static-build-configure 2025-09-30 20:47:04 -07:00
Doug Gregor
3082b04b75 [Macros] Feed the static build configuration into macro expansions
Thread the static build configuration (formed from language options) in
to the macro plugin handler, which will serialize it for use in the
macro implementation. test this with a simple macro that checks
whether a particular custom configuration (set via `-D`) is enabled or
not.

This required some re-layering, sinking the logic for building a
StaticBuildConfiguration from language options down into a new
swiftBasicSwift library, which sits on top of the C++ swiftBasic and
provides Swift functionality for it. That can be used by the C++
swiftAST to cache the StaticBuildConfiguration on the ASTContext,
making it available for other parts of ASTGen.
2025-09-29 18:42:15 -07:00
Hamish Knight
1e6fbc1a36 [test] Require concurrency runtime for macro_expand_body.swift
The test is implicitly using `async` main so the `SwiftStdlib 5.1`
checks weren't actually preventing it from exercising the concurrency
runtime. Just require the runtime to be present.
2025-09-24 22:42:02 +01:00
Henrik G. Olsson
e443cf142a Fix UnexpectedCountType.swift
This test case failed in CI when using a strict diff, because the output
also contained the text "swift runtime: unknown backtracing setting
'warnings'". Switch to using FileCheck to ignore this output.
2025-09-19 18:27:00 -07:00
Henrik G. Olsson
4668a0c70f update test/Macros/macro_attribute_expansiondecl.swift 2025-09-19 14:36:36 -07:00
Henrik G. Olsson
b2069a3e66 Update tests with diagnostics in macro expansions 2025-09-18 16:41:07 -07:00
Henrik G. Olsson
e3d92dbf0f [DiagnosticVerifier] implement expected-expansion
Since freestanding macro expansion buffer names include the line number
of their invocation, it can become quite fiddly to try to update a test
file with multiple macro expansions. This adds the option to use an
expected-expansion block and use a relative line number, nesting other
expected diagnostic statements inside this block.

Example syntax:
```swift
let myVar = #myMacro
/*
expected-expansion@-2:1{{
  expected-error@13:37{{I can't believe you've done this}}
  expected-note@14:38{{look at this and ponder your mistake}}
}}
*/
```
2025-09-18 16:33:42 -07:00
Henrik G. Olsson
70ec916d17 [Swiftify] Remove XFAIL from UnexpectedPointerType.swift test
Now that the DiagnosticsVerifier supports verifying diagnostics in
macro expansions it's time to enable this test case.
2025-09-15 14:27:54 -07:00
Rintaro Ishizaki
b119407966 [Parse] Change whitespace rule between attribute name and '(' in Swift 6
In Swift 6 and later, whitespace is no longer permitted between an
attribute name and the opening parenthesis. Update the parser so that
in Swift 6+, a `(` without preceding whitespace is always treated as
the start of the argument list, while a '(' with preceding whitespace is
considered the start of the argument list _only when_ it is unambiguous.

This change makes the following closure be parsed correctly:

  { @MainActor (arg: Int) in ... }

rdar://147785544
2025-09-09 16:44:29 -07:00
Eric Miotto
89c3f47c41 Require build of StringProcessing for some Macros tests (#84126)
Also mark them as not executable, since they don't call `%target-run`.
    
This is needed in back deployment configurations where StringProcessing is
not supported.
    
Addresses rdar://159635486
2025-09-05 22:34:12 -07:00
Doug Gregor
5023b90f93 Merge pull request #82921 from DougGregor/sendable-prohibits-mainactor-by-default
[SE-0466] Enable SendableProhibitsMainActorInference by default
2025-07-23 16:21:37 -07:00
Meghana Gupta
b705b8fa13 Update tests 2025-07-22 13:07:03 -07:00
Konrad 'ktoso' Malawski
03774d245a fix some tests due to diagnostic rewording 2025-07-15 11:16:13 +09:00
Konrad 'ktoso' Malawski
f52f445358 [Concurrency] add fixit to add final to non-sendable class -> Sendable
The previous message was just suggesting unchecked Sendable, but instead
we should be suggesting to add final to the class. We also don't
outright suggest using unchecked Sendable -- following
https://github.com/swiftlang/swift/pull/81738 precedent.

Resolves rdar://155790695
2025-07-15 10:42:25 +09:00
Doug Gregor
d2afd8700e [SE-0466] Enable SendableProhibitsMainActorInference by default
This implements the SE-0466 amendment under discussion for all code
with default main-actor isolation.

Finalizes rdar://151029300.
2025-07-09 10:44:39 -07:00
Nate Cook
85208293c9 Allow inout parameters in expression macros (#82370)
Sema seems to be flagging inout expressions (e.g. &foo) in expression
macros as invalid, setting up a catch 22 where Sema emits an error when
a parameter has the '&' sigil and type checking fails when it doesn't.

This resolves the issue by allowing inout expressions inside macro
expansion expressions.

Resolves https://github.com/swiftlang/swift/issues/82369.
2025-07-03 23:52:16 -07:00
Konrad `ktoso` Malawski
ec8caf3cdd Remove the experimental @Task macro (#82437) 2025-07-03 10:15:21 -07:00
Hamish Knight
e4e82ec8fc [Sema] Avoid applying diagnostic hack to caller-side expression macros
We can't assume that type-checking the expression macro in the
parameter will also fail if it fails at the call site since e.g
name lookup may differ. Make sure we only apply this logic to simple
literals.

rdar://154771596
2025-07-02 17:46:10 +01:00
Doug Gregor
a9d0a055c3 Add missing feature requirement 2025-06-27 20:32:28 -07:00
Doug Gregor
d6c8812bca Add tests for SendableProhibitsMainActorInference 2025-06-27 13:54:06 -07:00
Slava Pestov
22cdba4a59 Sema: Add missing test case for 63a5731da1 2025-06-22 23:23:49 -04:00
Hamish Knight
c6ec3156f7 [CS] Distinguish locators for generic args in addSpecializationConstraint
Make sure we give each argument a different locator to ensure we
can correctly record any opened types.

rdar://153674889
2025-06-18 12:19:12 +01:00
Meghana Gupta
44e05fa858 [NFC] Update tests and diagnostics 2025-06-07 12:49:01 -07:00
Henrik G. Olsson
89b09a69e4 Merge pull request #81752 from hnrklssn/swiftify-sized-sizedby
[Swiftify] Support __sized_by on byte-sized pointee types
2025-06-05 08:42:42 -07:00
Henrik G. Olsson
1773ea03ea fix test 2025-05-29 22:02:14 -07:00
Henrik G. Olsson
0f0a2ca4bb [Swiftify] Support __sized_by on byte-sized pointee types
Previously we would emit a macro that would error on expansion when
trying to add a safe wrapper to a function with __sized_by on a type
that mapped to UnsafePointer<T> instead of UnsafeRawPointer or
OpaquePointer. __sized_by is acceptable when used on byte-sized pointee
types, so this adds machinery in the macro expansion to support that.
Meanwhile on the ClangImporter side, we add a check so that __sized_by
on pointee types with a size is ignored if that size is larger than 1
byte.

When _SwiftifyImport applies .sizedBy to a pointer of type
UnsafePointer<T> it will still map it to a
RawSpan/UnsafeRawBufferPointer in the safe overload. The assumption is
that any API using __sized_by is dealing with raw bytes, so raw pointers
are a better Swift abstraction than UnsafePointer<CChar> etc. It also
lets the user avoid doing a scary pointer cast from some potentially
larger-than-byte-sized pointer to a byte-sized pointer. Casts to
RawPointers are generally safer and more ergonomic.

rdar://150966684
rdar://150966021
2025-05-29 13:32:53 -07:00
Anthony Latsis
0a1b8b0d50 [test] Fix misspelled FileCheck directives 2025-05-29 15:09:36 +01:00
Henrik G. Olsson
f5fa481205 [Swiftify] Always remove count parameters when possible (#81585)
Previously we did not remove count parameters if any count parameters
were shared between count expressions, or if any count expression
contained operations. Buffer sizes were also just checked to be larger
than or equal than the given count.

We now extract the count from Spans/BufferPointers whenever possible,
and store that value in a variable at the start of the function. If
multiple parameters share the same count, a bounds check is emitted to
make sure that they have the same size. Subspans can be used if one span
is larger than necessary.

The message in the bounds check is changed so that it includes the
expected and actual value, to aid in debugging.

This patch also fixes some incorrect indentation, and adds the
Whitespace.swift test case to act as a regression test in case the
indentation changes, since the other test cases don't use significant
whitespace.

rdar://151488820
rdar://151511090
rdar://146333006
rdar://147715799
2025-05-24 22:08:51 -07:00